Merged in hotfix/IO-3001-null-cieca-scrubbing (pull request #2025)
IO-3001 Add CIECA data check for scrubbing.
This commit is contained in:
@@ -49,7 +49,8 @@ exports.totalsSsu = async function (req, res) {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.log("job-totals-ssu-USA-error", "ERROR", req?.user?.email, id, {
|
logger.log("job-totals-ssu-USA-error", "ERROR", req?.user?.email, id, {
|
||||||
jobid: id,
|
jobid: id,
|
||||||
error: error.message
|
error: error.message,
|
||||||
|
stack: error.stack
|
||||||
});
|
});
|
||||||
res.status(503).send();
|
res.status(503).send();
|
||||||
}
|
}
|
||||||
@@ -68,59 +69,63 @@ async function TotalsServerSide(req, res) {
|
|||||||
ret.additional = CalculateAdditional(job);
|
ret.additional = CalculateAdditional(job);
|
||||||
ret.totals = CalculateTaxesTotals(job, ret);
|
ret.totals = CalculateTaxesTotals(job, ret);
|
||||||
|
|
||||||
// Sub total scrubbbing.
|
//If we don't have the CIECA_TTL, we can't scrub. E.g. a private estimate.
|
||||||
const emsTotal =
|
if (job.cieca_ttl) {
|
||||||
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.
|
// Sub total scrubbbing.
|
||||||
? job.cieca_ttl.data.n_ttl_amt - job.cieca_ttl.data.g_tax
|
const emsTotal =
|
||||||
: 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 === job.cieca_ttl.data.g_ttl_amt //It looks like sometimes, gross and net are the same, but they shouldn't be.
|
||||||
const ttlDifference =
|
? job.cieca_ttl.data.n_ttl_amt - job.cieca_ttl.data.g_tax
|
||||||
emsTotal -
|
: 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.
|
||||||
ret.totals.subtotal
|
const ttlDifference =
|
||||||
.add(
|
emsTotal -
|
||||||
Dinero({
|
ret.totals.subtotal
|
||||||
amount: Math.round((job.adjustment_bottom_line || 0) * 100)
|
.add(
|
||||||
}).multiply(-1) //Add back in the adjustment to the subtotal. We don't want to scrub it twice.
|
Dinero({
|
||||||
)
|
amount: Math.round((job.adjustment_bottom_line || 0) * 100)
|
||||||
.getAmount() /
|
}).multiply(-1) //Add back in the adjustment to the subtotal. We don't want to scrub it twice.
|
||||||
|
)
|
||||||
|
.getAmount() /
|
||||||
|
100;
|
||||||
|
|
||||||
|
if (Math.abs(ttlDifference) > 0.0) {
|
||||||
|
//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;
|
100;
|
||||||
|
const ttlTaxDifference = emsTaxTotal - totalUsTaxes;
|
||||||
|
|
||||||
if (Math.abs(ttlDifference) > 0.0) {
|
if (Math.abs(ttlTaxDifference) > 0.0) {
|
||||||
//If difference is greater than a pennny, we need to adjust it.
|
//If difference is greater than a pennny, we need to adjust it.
|
||||||
ret.totals.ttl_adjustment = Dinero({ amount: Math.round(ttlDifference * 100) });
|
ret.totals.ttl_tax_adjustment = Dinero({ amount: Math.round(ttlTaxDifference * 100) });
|
||||||
ret.totals.subtotal = ret.totals.subtotal.add(ret.totals.ttl_adjustment);
|
ret.totals.total_repairs = ret.totals.total_repairs.add(ret.totals.ttl_tax_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_tax_adjustment);
|
||||||
ret.totals.net_repairs = ret.totals.net_repairs.add(ret.totals.ttl_adjustment);
|
logger.log("job-totals-USA-ttl-tax-adj", "DEBUG", null, job.id, {
|
||||||
logger.log("job-totals-USA-ttl-adj", "DEBUG", null, job.id, {
|
adjAmount: ttlTaxDifference
|
||||||
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.0) {
|
|
||||||
//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;
|
return ret;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.log("job-totals-ssu-USA-error", "ERROR", req.user?.email, job.id, {
|
logger.log("job-totals-ssu-USA-error", "ERROR", req.user?.email, job.id, {
|
||||||
jobid: job.id,
|
jobid: job.id,
|
||||||
error
|
error: error.message,
|
||||||
|
stack: error.stack
|
||||||
});
|
});
|
||||||
res.status(400).send(JSON.stringify(error));
|
res.status(400).send(JSON.stringify(error));
|
||||||
}
|
}
|
||||||
@@ -150,7 +155,8 @@ async function Totals(req, res) {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.log("job-totals-USA-error", "ERROR", req.user.email, job.id, {
|
logger.log("job-totals-USA-error", "ERROR", req.user.email, job.id, {
|
||||||
jobid: job.id,
|
jobid: job.id,
|
||||||
error
|
error: error.message,
|
||||||
|
stack: error.stack
|
||||||
});
|
});
|
||||||
res.status(400).send(JSON.stringify(error));
|
res.status(400).send(JSON.stringify(error));
|
||||||
}
|
}
|
||||||
@@ -1075,7 +1081,8 @@ function CalculateTaxesTotals(job, otherTotals) {
|
|||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.log("job-totals-USA - PFP Calculation Error", "error", null, job.id, {
|
logger.log("job-totals-USA - PFP Calculation Error", "error", null, job.id, {
|
||||||
error: error.message
|
error: error.message,
|
||||||
|
stack: error.stack
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user