IO-854 Resolve missing profit centers in job costing

This commit is contained in:
Patrick Fic
2021-04-21 16:02:53 -07:00
parent e57f4b7382
commit e6c7599813
2 changed files with 51 additions and 0 deletions

View File

@@ -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")) {

View File

@@ -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;
}
}
};