From 0bcf67a5f5d34b2959a1575492983b4231b12756 Mon Sep 17 00:00:00 2001 From: Patrick Fic Date: Thu, 31 Aug 2023 14:30:49 -0700 Subject: [PATCH] Improve totals calculation. --- server/job/job-totals.js | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/server/job/job-totals.js b/server/job/job-totals.js index 19d2c9c69..9c825ada4 100644 --- a/server/job/job-totals.js +++ b/server/job/job-totals.js @@ -389,7 +389,7 @@ async function CalculateRatesTotals({ job, client }) { lbr_op: "OP11", lbr_amt: 0, op_code_desc: "REMOVE / REPLACE", - tax_part: true, + tax_part: hasMahwLine.tax_amt > 0 ? true : false, db_ref: null, manual_line: true, jobid: job.id, @@ -399,6 +399,26 @@ async function CalculateRatesTotals({ job, client }) { lineInput: [newMahwLine], }); } + + //Materials Scrubbing as required by CCC. + let matTotalLine = job.cieca_stl.data.find((l) => l.ttl_typecd === "MAT"); + let shopMatLine = job.cieca_stl.data.find((l) => l.ttl_typecd === "MASH"); + + if (matTotalLine && shopMatLine) { + //Check to see if theyre different + let calcMapaAmount = Dinero({ + amount: Math.round( + (matTotalLine?.ttl_amt - shopMatLine?.ttl_amt - stlMahw?.ttl_amt) * 100 + ), + }); + let mapaDifference = calcMapaAmount.subtract(ret.mapa.total); + if (mapaDifference.getAmount() > 0) { + //fix it. + ret.mapa.total = calcMapaAmount; + //Add the difference to the subt total as well. + subtotal = subtotal.add(mapaDifference); + } + } ret.subtotal = subtotal; ret.rates_subtotal = rates_subtotal; @@ -690,7 +710,7 @@ function CalculateAdditional(job) { .reduce((acc, val) => { const lineValue = Dinero({ amount: Math.round((val.act_price || 0) * 100), - }).multiply(val.part_qty || 1); + }).multiply(val.part_qty); if (val.db_ref === "936004") { //Shipping line IO-1921. @@ -796,13 +816,11 @@ function CalculateTaxesTotals(job, otherTotals) { ) ); } - console.log(statePartsTax.toFormat(), val.line_desc); }); - console.log("Total State Parts Tax", statePartsTax.toFormat()); let laborTaxTotal = Dinero(); - if (Object.keys(job.cieca_pfl) > 0) { + if (Object.keys(job.cieca_pfl).length > 0) { //Do it by labor type const types = [ "la1", @@ -828,7 +846,6 @@ function CalculateTaxesTotals(job, otherTotals) { : (job.tax_lbr_rt || 0) * 100 ) ); - console.log("Lab Tax Total", type, laborTaxTotal.toFormat()); }); } else { //We don't have it, just add in how it was before. @@ -836,7 +853,6 @@ function CalculateTaxesTotals(job, otherTotals) { (job.tax_lbr_rt || 0) * 100 ); // THis is currently using the lbr tax rate from PFH not PFL. } - let ret = { subtotal: subtotal, federal_tax: subtotal @@ -918,18 +934,15 @@ function DiscountNotAlreadyCounted(jobline, joblines) { (jobline.prt_dsmk_m / (jobline.act_price - jobline.prt_dsmk_m)) * 100 ) === Math.abs(jobline.prt_dsmk_p) ) { - console.log(jobline.line_desc, "Already had the discount counted."); return false; } //Check it against the database price too? If it's an OE part. - console.log(jobline.db_price - jobline.act_price); if ( Math.abs(jobline.db_price - jobline.act_price) - Math.abs(jobline.prt_dsmk_m) < 0.01 ) { - console.log(jobline.line_desc, "Already had the discount counted."); return false; }