Improve backwards compatibility for job totals calculations.

This commit is contained in:
Patrick Fic
2023-01-20 07:59:47 -08:00
parent 018f8a19bb
commit 41c63cbfe9
4 changed files with 4316 additions and 33 deletions

View File

@@ -261,8 +261,8 @@ function CalculateRatesTotals(ratesList) {
//Otherwise, calculate them and add them to the default MAPA and MASH centers.
let hasMapaLine = false;
let hasMashLine = false;
let mapaOpCodes = ParseCalopCode(ratesList.materials["mapa"].cal_opcode);
let mashOpCodes = ParseCalopCode(ratesList.materials["mash"].cal_opcode);
let mapaOpCodes = ParseCalopCode(ratesList.materials["mapa"]?.cal_opcode);
let mashOpCodes = ParseCalopCode(ratesList.materials["mash"]?.cal_opcode);
jobLines.forEach((item) => {
//IO-1317 Use the lines on the estimate if they exist instead.
@@ -312,7 +312,7 @@ function CalculateRatesTotals(ratesList) {
ret.mapa.hours = ret.mapa.hours + item.mod_lb_hrs;
// }
} else {
if (mashOpCodes.includes(item.lbr_op)) {
if (mashOpCodes.length === 0 || mashOpCodes.includes(item.lbr_op)) {
// Added when processing CIECA ID 14A60015 to have materials match.
ret.mash.hours = ret.mash.hours + item.mod_lb_hrs; //Apparently there may be an exclusion for glass hours in BC.
}
@@ -370,6 +370,8 @@ function CalculateRatesTotals(ratesList) {
ret.subtotal = subtotal;
ret.rates_subtotal = rates_subtotal;
ret.mapa.hasMapaLine = hasMapaLine;
ret.mash.hasMashLine = hasMashLine;
return ret;
}
@@ -573,18 +575,19 @@ function IsAdditionalCost(jobLine) {
const isPaintOrShopMat =
jobLine.db_ref === "936008" || jobLine.db_ref === "936007";
if (process.env.COUNTRY === "USA") {
return (
jobLine.lbr_op === "OP13" || //Added to resolve manual job lines coming into other totals because they have no reference.
(jobLine.part_type === null && (jobLine.act_price || 0 > 0))
);
} else {
return (
(jobLine.lbr_op === "OP13" || //Added to resolve manual job lines coming into other totals because they have no reference.
(jobLine.db_ref && jobLine.db_ref.startsWith("9360"))) && //This ref works in Canada, but DB_REFS in the US do not fill in.
!isPaintOrShopMat
);
}
// if (process.env.COUNTRY === "USA") {
// return (
// jobLine.lbr_op === "OP13" || //Added to resolve manual job lines coming into other totals because they have no reference.
// (jobLine.part_type === null && (jobLine.act_price || 0 > 0))
// );
// } else {
return (
(jobLine.lbr_op === "OP13" || //Added to resolve manual job lines coming into other totals because they have no reference.
(jobLine.part_type === null && (jobLine.act_price || 0 > 0)) ||
(jobLine.db_ref && jobLine.db_ref.startsWith("9360"))) && //This ref works in Canada, but DB_REFS in the US do not fill in.
!isPaintOrShopMat
);
//}
}
function CalculateAdditional(job) {
@@ -738,18 +741,21 @@ function CalculateTaxesTotals(job, otherTotals) {
.add(
otherTotals.additional.storage.percentage((job.tax_str_rt || 0) * 100)
)
.add(additionalItemsTax)
.add(
process.env.COUNTRY === "USA"
? otherTotals.rates.mapa.total
.percentage((job.tax_paint_mat_rt || 0) * 100)
.add(
otherTotals.rates.mash.total.percentage(
(job.tax_paint_mat_rt || 0) * 100
)
)
: Dinero()
),
.add(additionalItemsTax),
// .add(
// otherTotals.rates.mapa.hasMapaLine === false //If parts and materials were not added as lines, we must calculate the taxes on them.
// ? otherTotals.rates.mapa.total.percentage(
// (job.tax_paint_mat_rt || 0) * 100
// )
// : Dinero()
// )
// .add(
// otherTotals.rates.mash.hasMashLine === false //If parts and materials were not added as lines, we must calculate the taxes on them.
// ? otherTotals.rates.mash.total.percentage(
// (job.tax_paint_mat_rt || 0) * 100
// )
// : Dinero()
// )
// .add(otherTotals.additional.pvrt),
local_tax: subtotal.percentage((job.local_tax_rate || 0) * 100),
};