From c97213bc9626ec53be3024c59bc336eef141128c Mon Sep 17 00:00:00 2001 From: Allan Carr Date: Tue, 24 Mar 2026 18:12:04 -0700 Subject: [PATCH] IO-3599 Taxable Amount Signed-off-by: Allan Carr --- server/job/job-totals-USA.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/server/job/job-totals-USA.js b/server/job/job-totals-USA.js index a8bd632cc..cdf5ec3b0 100644 --- a/server/job/job-totals-USA.js +++ b/server/job/job-totals-USA.js @@ -116,6 +116,32 @@ async function TotalsServerSide(req, res) { ret.totals.ttl_tax_adjustment = Dinero({ amount: Math.round(ttlTaxDifference * 100) }); ret.totals.total_repairs = ret.totals.total_repairs.add(ret.totals.ttl_tax_adjustment); ret.totals.net_repairs = ret.totals.net_repairs.add(ret.totals.ttl_tax_adjustment); + + if (Math.abs(totalUsTaxes) === 0) { + const laborRates = Object.values(job.cieca_pfl) + .map((v) => v.lbr_taxp) + .filter((v) => v != null); + const materialRates = Object.values(job.materials) + .map((v) => v.mat_taxp) + .filter((v) => v != null); + const partsRates = Object.values(job.parts_tax_rates) + .map((v) => { + const field = v.prt_tax_rt ?? v.part_tax_rt; + if (field == null) return null; + const raw = typeof field === "object" ? field.parsedValue : field; + return raw != null ? raw * 100 : null; + }) + .filter((v) => v != null); + const taxRate = Math.max(...laborRates, ...materialRates, ...partsRates); + + const totalTaxes = ret.totals.taxableAmounts.total.multiply(taxRate > 1 ? taxRate / 100 : taxRate); + ret.totals.taxableAmounts.total = ret.totals.taxableAmounts.total + .multiply(emsTaxTotal) + .divide(totalTaxes.toUnit()); + } else { + ret.totals.taxableAmounts.total = ret.totals.taxableAmounts.total.multiply(emsTaxTotal).divide(totalUsTaxes); + } + logger.log("job-totals-USA-ttl-tax-adj", "debug", null, job.id, { adjAmount: ttlTaxDifference }); @@ -979,6 +1005,8 @@ function CalculateTaxesTotals(job, otherTotals) { } }); + taxableAmounts.total = Object.values(taxableAmounts).reduce((acc, amount) => acc.add(amount), Dinero({ amount: 0 })); + // console.log("*** Taxable Amounts***"); // console.table(JSON.parse(JSON.stringify(taxableAmounts))); @@ -1174,6 +1202,7 @@ function CalculateTaxesTotals(job, otherTotals) { let ret = { subtotal: subtotal, + taxableAmounts: taxableAmounts, federal_tax: subtotal .percentage((job.federal_tax_rate || 0) * 100) .add(otherTotals.additional.pvrt.percentage((job.federal_tax_rate || 0) * 100)),