IO-3001 Initial adjustments to totals.
This commit is contained in:
@@ -1365,6 +1365,7 @@ exports.GET_JOB_BY_PK = `query GET_JOB_BY_PK($id: uuid!) {
|
||||
cieca_pfl
|
||||
cieca_pft
|
||||
cieca_pfo
|
||||
cieca_ttl
|
||||
vehicle {
|
||||
id
|
||||
notes
|
||||
|
||||
@@ -68,6 +68,45 @@ async function TotalsServerSide(req, res) {
|
||||
ret.additional = CalculateAdditional(job);
|
||||
ret.totals = CalculateTaxesTotals(job, ret);
|
||||
|
||||
// Sub total scrubbbing.
|
||||
const emsTotal =
|
||||
job.cieca_ttl.data.n_ttl_amt === job.cieca_ttl.data.g_ttl_amt //It looks like sometimes, gross and net are the same, but they shouldn't be.
|
||||
? job.cieca_ttl.data.g_ttl_amt - job.cieca_ttl.data.g_tax //If they are, adjust the gross total down by the tax amount.
|
||||
: job.cieca_ttl.data.n_ttl_amt;
|
||||
const ttlDifference = emsTotal - ret.totals.subtotal.getAmount() / 100;
|
||||
|
||||
if (Math.abs(ttlDifference) > 0.01) {
|
||||
//If difference is greater than a pennny, we need to adjust it.
|
||||
ret.totals.ttl_adjustment = Dinero({ amount: Math.round(ttlDifference * 100) });
|
||||
ret.totals.subtotal = ret.totals.subtotal.add(ret.totals.ttl_adjustment);
|
||||
ret.totals.total_repairs = ret.totals.total_repairs.add(ret.totals.ttl_adjustment);
|
||||
ret.totals.net_repairs = ret.totals.net_repairs.add(ret.totals.ttl_adjustment);
|
||||
logger.log("job-totals-USA-ttl-adj", "DEBUG", null, job.id, {
|
||||
adjAmount: ttlDifference
|
||||
});
|
||||
}
|
||||
|
||||
//Taxes Scrubbing
|
||||
const emsTaxTotal = job.cieca_ttl.data.g_tax;
|
||||
const totalUsTaxes =
|
||||
(ret.totals.us_sales_tax_breakdown.ty1Tax.getAmount() +
|
||||
ret.totals.us_sales_tax_breakdown.ty2Tax.getAmount() +
|
||||
ret.totals.us_sales_tax_breakdown.ty3Tax.getAmount() +
|
||||
ret.totals.us_sales_tax_breakdown.ty4Tax.getAmount() +
|
||||
ret.totals.us_sales_tax_breakdown.ty5Tax.getAmount()) /
|
||||
100;
|
||||
const ttlTaxDifference = emsTaxTotal - totalUsTaxes;
|
||||
|
||||
if (Math.abs(ttlTaxDifference) > 0.01) {
|
||||
//If difference is greater than a pennny, we need to adjust it.
|
||||
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);
|
||||
logger.log("job-totals-USA-ttl-tax-adj", "DEBUG", null, job.id, {
|
||||
adjAmount: ttlTaxDifference
|
||||
});
|
||||
}
|
||||
|
||||
return ret;
|
||||
} catch (error) {
|
||||
logger.log("job-totals-ssu-USA-error", "ERROR", req.user?.email, job.id, {
|
||||
|
||||
Reference in New Issue
Block a user