diff --git a/server/integrations/partsManagement/endpoints/vehicleDamageEstimateAddRq.js b/server/integrations/partsManagement/endpoints/vehicleDamageEstimateAddRq.js index 8093ca2ed..90b175dec 100644 --- a/server/integrations/partsManagement/endpoints/vehicleDamageEstimateAddRq.js +++ b/server/integrations/partsManagement/endpoints/vehicleDamageEstimateAddRq.js @@ -405,6 +405,7 @@ const extractJobLines = (rq) => { if (jobLineType === "PART") { const price = parseFloat(partInfo.PartPrice || partInfo.ListPrice || 0); + // Push the part line with ONLY part pricing/fields out.push({ ...base, part_type: partInfo.PartType || null ? String(partInfo.PartType).toUpperCase() : null, @@ -412,15 +413,6 @@ const extractJobLines = (rq) => { oem_partno: partInfo.OEMPartNum || partInfo.PartNum || null, db_price: price, act_price: price, - // Labor fields only when INCLUDE_LABOR is enabled - ...(INCLUDE_LABOR - ? { - mod_lbr_ty: laborInfo.LaborType || null, - mod_lb_hrs: parseFloat(laborInfo.LaborHours || 0), - lbr_op: laborInfo.LaborOperation || null, - lbr_amt: parseFloat(laborInfo.LaborAmt || 0) - } - : {}), // Tax flag from PartInfo.TaxableInd when provided ...(partInfo.TaxableInd !== undefined && (typeof partInfo.TaxableInd === "string" || @@ -445,6 +437,37 @@ const extractJobLines = (rq) => { } : { manual_line: null }) }); + + // If labor is present on the same damage line, split it to a separate LABOR jobline + // TODO: Verify with patrick this is desired. + if (INCLUDE_LABOR) { + const hrs = parseFloat(laborInfo.LaborHours || 0); + const amt = parseFloat(laborInfo.LaborAmt || 0); + const hasLabor = + (!!laborInfo.LaborType && String(laborInfo.LaborType).length > 0) || + (!isNaN(hrs) && hrs !== 0) || + (!isNaN(amt) && amt !== 0); + if (hasLabor) { + out.push({ + ...base, + // tweak unq_seq to avoid collisions in later upserts + unq_seq: (parseInt(line.UniqueSequenceNum || 0, 10) || 0) + 400000, + mod_lbr_ty: laborInfo.LaborType || null, + mod_lb_hrs: isNaN(hrs) ? 0 : hrs, + lbr_op: laborInfo.LaborOperation || null, + lbr_amt: isNaN(amt) ? 0 : amt, + ...(line.ManualLineInd !== undefined + ? { + manual_line: + line.ManualLineInd === true || + line.ManualLineInd === 1 || + line.ManualLineInd === "1" || + (typeof line.ManualLineInd === "string" && line.ManualLineInd.toUpperCase() === "Y") + } + : { manual_line: null }) + }); + } + } } else if (jobLineType === "SUBLET") { out.push({ ...base,