IO-233 Add missing MAPA/MASH/Discount calulcations.

This commit is contained in:
Patrick Fic
2021-09-15 08:28:54 -07:00
parent 28b1356f76
commit fd161fa9eb
2 changed files with 73 additions and 44 deletions

View File

@@ -47,16 +47,40 @@ exports.default = async function (socket, jobid) {
},
};
//Determine if there are MAPA and MASH lines already on the estimate.
//If there are, don't do anything extra (mitchell estimate)
//Otherwise, calculate them and add them to the default MAPA and MASH centers.
let hasMapaLine = false;
let hasMashLine = false;
const profitCenterHash = job.joblines.reduce((acc, val) => {
//Check the Parts Assignment
if (val.db_ref === "936008") {
//If either of these DB REFs change, they also need to change in job-totals/job-costing calculations.
hasMapaLine = true;
}
if (val.db_ref === "936007") {
hasMashLine = true;
}
if (val.profitcenter_part) {
if (!acc[val.profitcenter_part]) acc[val.profitcenter_part] = Dinero();
acc[val.profitcenter_part] = acc[val.profitcenter_part].add(
Dinero({
amount: Math.round((val.act_price || 0) * 100),
}).multiply(val.part_qty || 0)
);
let DineroAmount = Dinero({
amount: Math.round(val.act_price * 100),
}).multiply(val.part_qty || 1);
if (val.prt_dsmk_p && val.prt_dsmk_p !== 0) {
// console.log("Have a part discount", val);
DineroAmount = DineroAmount.add(
DineroAmount.percentage(Math.abs(val.prt_dsmk_p || 0)).multiply(
val.prt_dsmk_p > 0 ? 1 : -1
)
);
}
acc[val.profitcenter_part] =
acc[val.profitcenter_part].add(DineroAmount);
}
if (val.profitcenter_labor) {
//Check the Labor Assignment.
@@ -86,45 +110,6 @@ exports.default = async function (socket, jobid) {
.multiply(line_val.quantity)
.multiply(bill_val.is_credit_memo ? -1 : 1);
// //Add appropriate tax amounts.
// const {
// applicable_taxes: { local, state, federal },
// } = line_val;
// if (local) {
// if (bodyshop.cdk_configuration.itc_local)
// taxAllocations.local.cost = taxAllocations.local.cost.add(
// lineDinero.percentage(bill_val.local_tax_rate || 0)
// );
// lineDinero = lineDinero.add(
// lineDinero.percentage(bill_val.local_tax_rate || 0)
// );
// }
// if (state) {
// if (bodyshop.cdk_configuration.itc_state)
// taxAllocations.state.cost = taxAllocations.state.cost.add(
// lineDinero.percentage(bill_val.state_tax_rate || 0)
// );
// lineDinero = lineDinero.add(
// lineDinero.percentage(bill_val.state_tax_rate || 0)
// );
// }
// if (federal) {
// //If it's an ITC, add it as a negative cost, otherwise add it to the item cost.
// if (bodyshop.cdk_configuration.itc_federal)
// taxAllocations.federal.cost = taxAllocations.federal.cost.add(
// lineDinero.percentage(bill_val.federal_tax_rate || 0)
// );
// lineDinero = lineDinero.add(
// lineDinero.percentage(bill_val.federal_tax_rate || 0)
// );
// // bill_acc[line_val.cost_center] = bill_acc[line_val.cost_center].add(
// // lineDinero.percentage(bill_val.federal_tax_rate || 0)
// // );
// }
bill_acc[line_val.cost_center] =
bill_acc[line_val.cost_center].add(lineDinero);
return null;
@@ -151,6 +136,49 @@ exports.default = async function (socket, jobid) {
costCenterHash[ticket.cost_center].add(TicketTotal);
});
if (!hasMapaLine && job.job_totals.rates.mapa.total.amount > 0) {
// console.log("Adding MAPA Line Manually.");
const mapaAccountName =
bodyshop.md_responsibility_centers.defaults.profits.MAPA;
const mapaAccount = bodyshop.md_responsibility_centers.profits.find(
(c) => c.name === mapaAccountName
);
if (mapaAccount) {
if (!profitCenterHash[mapaAccountName])
profitCenterHash[mapaAccountName] = Dinero();
profitCenterHash[mapaAccountName] = profitCenterHash[
mapaAccountName
].add(Dinero(job.job_totals.rates.mapa.total));
} else {
//console.log("NO MAPA ACCOUNT FOUND!!");
}
}
if (!hasMashLine && job.job_totals.rates.mash.total.amount > 0) {
// console.log("Adding MASH Line Manually.");
const mashAccountName =
bodyshop.md_responsibility_centers.defaults.profits.MASH;
const mashAccount = bodyshop.md_responsibility_centers.profits.find(
(c) => c.name === mashAccountName
);
if (mashAccount) {
if (!profitCenterHash[mashAccountName])
profitCenterHash[mashAccountName] = Dinero();
profitCenterHash[mashAccountName] = profitCenterHash[
mashAccountName
].add(Dinero(job.job_totals.rates.mash.total));
} else {
// console.log("NO MASH ACCOUNT FOUND!!");
}
}
const jobAllocations = _.union(
Object.keys(profitCenterHash),
Object.keys(costCenterHash)

View File

@@ -1050,6 +1050,7 @@ exports.GET_CDK_ALLOCATIONS = `query QUERY_JOB_CLOSE_DETAILS($id: uuid!) {
part_type
oem_partno
db_price
db_ref
act_price
part_qty
mod_lbr_ty