Merged in feature/america (pull request #960)

Improve totals calculation.
This commit is contained in:
Patrick Fic
2023-08-31 21:31:25 +00:00

View File

@@ -389,7 +389,7 @@ async function CalculateRatesTotals({ job, client }) {
lbr_op: "OP11", lbr_op: "OP11",
lbr_amt: 0, lbr_amt: 0,
op_code_desc: "REMOVE / REPLACE", op_code_desc: "REMOVE / REPLACE",
tax_part: true, tax_part: hasMahwLine.tax_amt > 0 ? true : false,
db_ref: null, db_ref: null,
manual_line: true, manual_line: true,
jobid: job.id, jobid: job.id,
@@ -399,6 +399,26 @@ async function CalculateRatesTotals({ job, client }) {
lineInput: [newMahwLine], 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.subtotal = subtotal;
ret.rates_subtotal = rates_subtotal; ret.rates_subtotal = rates_subtotal;
@@ -690,7 +710,7 @@ function CalculateAdditional(job) {
.reduce((acc, val) => { .reduce((acc, val) => {
const lineValue = Dinero({ const lineValue = Dinero({
amount: Math.round((val.act_price || 0) * 100), amount: Math.round((val.act_price || 0) * 100),
}).multiply(val.part_qty || 1); }).multiply(val.part_qty);
if (val.db_ref === "936004") { if (val.db_ref === "936004") {
//Shipping line IO-1921. //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(); let laborTaxTotal = Dinero();
if (Object.keys(job.cieca_pfl) > 0) { if (Object.keys(job.cieca_pfl).length > 0) {
//Do it by labor type //Do it by labor type
const types = [ const types = [
"la1", "la1",
@@ -828,7 +846,6 @@ function CalculateTaxesTotals(job, otherTotals) {
: (job.tax_lbr_rt || 0) * 100 : (job.tax_lbr_rt || 0) * 100
) )
); );
console.log("Lab Tax Total", type, laborTaxTotal.toFormat());
}); });
} else { } else {
//We don't have it, just add in how it was before. //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 (job.tax_lbr_rt || 0) * 100
); // THis is currently using the lbr tax rate from PFH not PFL. ); // THis is currently using the lbr tax rate from PFH not PFL.
} }
let ret = { let ret = {
subtotal: subtotal, subtotal: subtotal,
federal_tax: subtotal federal_tax: subtotal
@@ -918,18 +934,15 @@ function DiscountNotAlreadyCounted(jobline, joblines) {
(jobline.prt_dsmk_m / (jobline.act_price - jobline.prt_dsmk_m)) * 100 (jobline.prt_dsmk_m / (jobline.act_price - jobline.prt_dsmk_m)) * 100
) === Math.abs(jobline.prt_dsmk_p) ) === Math.abs(jobline.prt_dsmk_p)
) { ) {
console.log(jobline.line_desc, "Already had the discount counted.");
return false; return false;
} }
//Check it against the database price too? If it's an OE part. //Check it against the database price too? If it's an OE part.
console.log(jobline.db_price - jobline.act_price);
if ( if (
Math.abs(jobline.db_price - jobline.act_price) - Math.abs(jobline.db_price - jobline.act_price) -
Math.abs(jobline.prt_dsmk_m) < Math.abs(jobline.prt_dsmk_m) <
0.01 0.01
) { ) {
console.log(jobline.line_desc, "Already had the discount counted.");
return false; return false;
} }