Update job calculation logic. IO-642

This commit is contained in:
Patrick Fic
2021-02-23 15:15:20 -08:00
parent ded12bdb3f
commit 541ace7414
24 changed files with 543 additions and 12 deletions

View File

@@ -207,13 +207,27 @@ function IsAdditionalCost(jobLine) {
}
function CalculateAdditional(job) {
return job.joblines
let ret = job.joblines
.filter((jl) => !jl.removed && IsAdditionalCost(jl))
.reduce((acc, val) => {
return acc.add(
Dinero({ amount: Math.round((val.act_price || 0) * 100) })
Dinero({ amount: Math.round((val.act_price || 0) * 100) }).multiply(
val.part_qty || 1
)
);
}, Dinero());
ret = ret
.add(
Dinero({
amount: Math.round((job.towing_payable || 0) * 100),
})
)
.add(
Dinero({
amount: Math.round((job.storage_payable || 0) * 100),
})
);
return ret;
}
function CalculateTaxesTotals(job, otherTotals) {
@@ -236,17 +250,18 @@ function CalculateTaxesTotals(job, otherTotals) {
if (!!!val.tax_part || !!!val.part_type || IsAdditionalCost(val)) {
additionalItemsTax = additionalItemsTax.add(
Dinero({ amount: Math.round((val.act_price || 0) * 100) })
.multiply(val.part_qty || 0)
.multiply(val.part_qty || 1)
.percentage(
(job.parts_tax_rates &&
((job.parts_tax_rates &&
job.parts_tax_rates["PAN"] &&
job.parts_tax_rates["PAN"].prt_tax_rt) * 100
job.parts_tax_rates["PAN"].prt_tax_rt) ||
0) * 100
)
);
} else {
statePartsTax = statePartsTax.add(
Dinero({ amount: Math.round((val.act_price || 0) * 100) })
.multiply(val.part_qty || 0)
.multiply(val.part_qty || 1)
.percentage(
(job.parts_tax_rates &&
job.parts_tax_rates[val.part_type] &&
@@ -288,7 +303,7 @@ function CalculateTaxesTotals(job, otherTotals) {
other_customer_amount: Dinero({
amount: (job.other_amount_payable || 0) * 100,
}),
dep_taxes: Dinero({ amount: job.depreciation_taxes || 0 }),
dep_taxes: Dinero({ amount: (job.depreciation_taxes || 0) * 100 }),
};
ret.custPayable.total = ret.custPayable.deductible