From e6c7599813b94b228121e844216f4455abc63199 Mon Sep 17 00:00:00 2001 From: Patrick Fic <> Date: Wed, 21 Apr 2021 16:02:53 -0700 Subject: [PATCH] IO-854 Resolve missing profit centers in job costing --- .../jobs-close-auto-allocate.component.jsx | 1 + server/job/job-costing.js | 50 +++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/client/src/components/jobs-close-auto-allocate/jobs-close-auto-allocate.component.jsx b/client/src/components/jobs-close-auto-allocate/jobs-close-auto-allocate.component.jsx index c99bc4623..df988d465 100644 --- a/client/src/components/jobs-close-auto-allocate/jobs-close-auto-allocate.component.jsx +++ b/client/src/components/jobs-close-auto-allocate/jobs-close-auto-allocate.component.jsx @@ -30,6 +30,7 @@ export function JobsCloseAutoAllocate({ bodyshop, joblines, form, disabled }) { } else { ret.profitcenter_labor = null; } + //Verify that this is also manually updated in server/job-costing if (!jl.part_type && !jl.mod_lbr_ty) { const lineDesc = jl.line_desc.toLowerCase(); if (lineDesc.includes("shop materials")) { diff --git a/server/job/job-costing.js b/server/job/job-costing.js index 3beea43ca..378ec5ee2 100644 --- a/server/job/job-costing.js +++ b/server/job/job-costing.js @@ -272,6 +272,36 @@ function GenerateCostingData(job) { partsAmount ); } + + //To deal with additional costs. + if (!val.part_type && !val.mod_lbr_ty) { + //Does it already have a defined profit center? + //If so, use it, otherwise try to use the same from the auto-allocate logic in IO app jobs-close-auto-allocate. + const partsProfitCenter = + val.profitcenter_part || + getAdditionalCostCenter(val, defaultProfits) || + "?"; + + if (partsProfitCenter === "?") { + console.log("Unknown type", val.part_type); + } else { + const partsAmount = Dinero({ + amount: Math.round((val.act_price || 0) * 100), + }).multiply(val.part_qty || 1); + console.log( + `*** partsAmount`, + val.line_desc, + partsProfitCenter, + partsAmount.toJSON() + ); + if (!acc.parts[partsProfitCenter]) + acc.parts[partsProfitCenter] = Dinero(); + acc.parts[partsProfitCenter] = acc.parts[partsProfitCenter].add( + partsAmount + ); + } + } + return acc; }, { parts: {}, labor: {} } @@ -411,3 +441,23 @@ const formatGpPercent = (gppercent) => { return gppercentFormatted; }; + +//Verify that this stays in line with jobs-close-auto-allocate logic from the application. +const getAdditionalCostCenter = (jl, profitCenters) => { + console.log("Checking additional cost center", jl.line_desc); + if (!jl.part_type && !jl.mod_lbr_ty) { + const lineDesc = jl.line_desc.toLowerCase(); + //This logic is covered prior and assigned based on the labor type of the lines + // if (lineDesc.includes("shop materials")) { + // return profitCenters["MASH"]; + // } else if (lineDesc.includes("paint/materials")) { + // return profitCenters["MAPA"]; + // } else + //End covered logic + if (lineDesc.includes("ats amount")) { + return profitCenters["ATS"]; + } else { + return null; + } + } +};