IO-3515 Checkin. Crude form update with some correct values. Pricing still significantly out.
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -39,9 +39,9 @@ function normalizeLabelName(labelText) {
|
||||
'part_num': standardizedFieldsnames.part_no,
|
||||
'part_number': standardizedFieldsnames.part_no,
|
||||
'price': standardizedFieldsnames.actual_price,
|
||||
'unit_price': standardizedFieldsnames.actual_price,
|
||||
'amount': standardizedFieldsnames.actual_price,
|
||||
'list_price': standardizedFieldsnames.actual_price,
|
||||
'unit_price': standardizedFieldsnames.actual_price,
|
||||
'list': standardizedFieldsnames.actual_price,
|
||||
'retail_price': standardizedFieldsnames.actual_price,
|
||||
'net': standardizedFieldsnames.actual_cost,
|
||||
@@ -145,6 +145,7 @@ function extractInvoiceData(textractResponse) {
|
||||
if (lineItemGroup.LineItems) {
|
||||
lineItemGroup.LineItems.forEach(lineItem => {
|
||||
const item = {};
|
||||
const fieldNameCounts = {}; // Track field name occurrences
|
||||
|
||||
if (lineItem.LineItemExpenseFields) {
|
||||
lineItem.LineItemExpenseFields.forEach(field => {
|
||||
@@ -155,7 +156,14 @@ function extractInvoiceData(textractResponse) {
|
||||
|
||||
if (fieldType && fieldValue) {
|
||||
// Normalize field names
|
||||
const normalizedField = normalizeFieldName(fieldType);
|
||||
let normalizedField = normalizeFieldName(fieldType);
|
||||
|
||||
// Ensure uniqueness by appending a counter if the field already exists
|
||||
if (item.hasOwnProperty(normalizedField)) {
|
||||
fieldNameCounts[normalizedField] = (fieldNameCounts[normalizedField] || 1) + 1;
|
||||
normalizedField = `${normalizedField}_${fieldNameCounts[normalizedField]}`;
|
||||
}
|
||||
|
||||
item[normalizedField] = {
|
||||
value: fieldValue,
|
||||
label: fieldLabel,
|
||||
|
||||
@@ -62,7 +62,19 @@ async function handleBillOcr(request, response) {
|
||||
|
||||
// The uploaded file is available in request.file
|
||||
const uploadedFile = request.file;
|
||||
const { jobid, bodyshopid, parts_orderid } = request.body;
|
||||
const { jobid, bodyshopid, partsorderid, skipTextract } = request.body;
|
||||
|
||||
|
||||
if (skipTextract === 'true') {
|
||||
console.log('Skipping Textract processing as per request');
|
||||
response.status(200).send({
|
||||
success: true,
|
||||
status: 'COMPLETED',
|
||||
data: await generateBillFormData({ processedData: null, jobid, bodyshopid, partsorderid }), //This is broken if the processedData is not overwritten in the function for testing.
|
||||
message: 'Invoice processing completed'
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const fileType = getFileType(uploadedFile);
|
||||
@@ -71,12 +83,12 @@ async function handleBillOcr(request, response) {
|
||||
// Images are always processed synchronously (single page)
|
||||
if (fileType === 'image') {
|
||||
console.log('Image => 1 page, processing synchronously');
|
||||
const result = await processSinglePageDocument(uploadedFile.buffer);
|
||||
|
||||
const processedData = await processSinglePageDocument(uploadedFile.buffer);
|
||||
const billForm = await generateBillFormData({ processedData: processedData, jobid, bodyshopid, partsorderid });
|
||||
response.status(200).send({
|
||||
success: true,
|
||||
status: 'COMPLETED',
|
||||
data: result,
|
||||
data: { ...processedData, billForm },
|
||||
message: 'Invoice processing completed'
|
||||
});
|
||||
} else if (fileType === 'pdf') {
|
||||
@@ -87,13 +99,13 @@ async function handleBillOcr(request, response) {
|
||||
if (pageCount === 1) {
|
||||
// Process synchronously for single-page documents
|
||||
console.log('PDF => 1 page, processing synchronously');
|
||||
const result = await processSinglePageDocument(uploadedFile.buffer);
|
||||
|
||||
const processedData = await processSinglePageDocument(uploadedFile.buffer);
|
||||
const billForm = await generateBillFormData({ processedData: processedData, jobid, bodyshopid, partsorderid });
|
||||
//const billResult = await generateBillFormData({ result, });
|
||||
response.status(200).send({
|
||||
success: true,
|
||||
status: 'COMPLETED',
|
||||
data: { result, },
|
||||
data: { ...processedData, billForm },
|
||||
message: 'Invoice processing completed'
|
||||
});
|
||||
} else {
|
||||
@@ -142,9 +154,13 @@ async function handleBillOcrStatus(request, response) {
|
||||
}
|
||||
|
||||
if (jobStatus.status === 'COMPLETED') {
|
||||
//TODO: This needs to be stored in the redis cache and pulled when it's processed.
|
||||
//const billForm = await generateBillFormData({ jobid, bodyshopid, partsorderid });
|
||||
|
||||
response.status(200).send({
|
||||
status: 'COMPLETED',
|
||||
data: jobStatus.data
|
||||
// data: { ...jobStatus.data, billForm }
|
||||
});
|
||||
} else if (jobStatus.status === 'FAILED') {
|
||||
response.status(500).send({
|
||||
|
||||
Reference in New Issue
Block a user