From e85be1c1737b15df331a75425d21eb6d1910adc6 Mon Sep 17 00:00:00 2001 From: Patrick Fic <> Date: Wed, 31 Mar 2021 11:02:11 -0700 Subject: [PATCH] IO-813 Calculation updates to include adjustments --- .../job-totals-table.component.jsx | 6 +- .../job-totals.table.other.component.jsx | 26 ++++++- server/accounting/qbxml/qbxml-receivables.js | 2 +- server/job/job-totals.js | 69 +++++++++++-------- 4 files changed, 67 insertions(+), 36 deletions(-) diff --git a/client/src/components/job-totals-table/job-totals-table.component.jsx b/client/src/components/job-totals-table/job-totals-table.component.jsx index ab660b784..6262e2835 100644 --- a/client/src/components/job-totals-table/job-totals-table.component.jsx +++ b/client/src/components/job-totals-table/job-totals-table.component.jsx @@ -46,13 +46,13 @@ export function JobsTotalsTableComponent({ jobRO, job }) { - - + + - + diff --git a/client/src/components/job-totals-table/job-totals.table.other.component.jsx b/client/src/components/job-totals-table/job-totals.table.other.component.jsx index c3160e866..24f322f71 100644 --- a/client/src/components/job-totals-table/job-totals.table.other.component.jsx +++ b/client/src/components/job-totals-table/job-totals.table.other.component.jsx @@ -17,9 +17,29 @@ export default function JobTotalsTableOther({ job }) { key: t("jobs.labels.subletstotal"), total: job.job_totals.parts.sublets.total, }, + ...((job.job_totals.additional.additionalCostItems && + job.job_totals.additional.additionalCostItems.map((i) => { + return { + key: i.key, + total: i.total, + }; + })) || + []), { - key: t("jobs.labels.additionaltotal"), - total: job.job_totals.additional, + key: t("jobs.fields.adjustment_bottom_line"), + total: job.job_totals.additional.adjustments, + }, + { + key: t("jobs.fields.towing"), + total: job.job_totals.additional.towing, + }, + { + key: t("jobs.fields.storage"), + total: job.job_totals.additional.storage, + }, + { + key: t("jobs.fields.pvrt"), + total: job.job_totals.additional.pvrt, }, ]; }, [job.job_totals, t]); @@ -67,7 +87,7 @@ export default function JobTotalsTableOther({ job }) { - {Dinero(job.job_totals.parts.parts.total).toFormat()} + {Dinero(job.job_totals.additional.total).toFormat()} diff --git a/server/accounting/qbxml/qbxml-receivables.js b/server/accounting/qbxml/qbxml-receivables.js index bc5cc2eb4..cb1c6a6e6 100644 --- a/server/accounting/qbxml/qbxml-receivables.js +++ b/server/accounting/qbxml/qbxml-receivables.js @@ -199,7 +199,7 @@ const generateInvoiceQbxml = ( (i) => jobline.profitcenter_part.toLowerCase() === i.name.toLowerCase() ); - if (!!!account) { + if (!account) { throw new Error( `A matching account does not exist for the allocation. Center: ${center}` ); diff --git a/server/job/job-totals.js b/server/job/job-totals.js index f17a32e5c..06c5674a3 100644 --- a/server/job/job-totals.js +++ b/server/job/job-totals.js @@ -279,31 +279,41 @@ function IsAdditionalCost(jobLine) { } function CalculateAdditional(job) { - let ret = job.joblines + let ret = { + additionalCosts: null, + additionalCostItems: [], + adjustments: null, + towing: null, + storage: null, + pvrt: null, + total: null, + }; + ret.additionalCosts = job.joblines .filter((jl) => !jl.removed && IsAdditionalCost(jl)) .reduce((acc, val) => { - return acc.add( - Dinero({ amount: Math.round((val.act_price || 0) * 100) }).multiply( - val.part_qty || 1 - ) - ); + const lineValue = Dinero({ + amount: Math.round((val.act_price || 0) * 100), + }).multiply(val.part_qty || 1); + ret.additionalCostItems.push({ key: val.line_desc, total: lineValue }); + return acc.add(lineValue); }, Dinero()); - ret = ret - .add( - Dinero({ - amount: Math.round((job.towing_payable || 0) * 100), - }) - ) - .add( - Dinero({ - amount: Math.round((job.storage_payable || 0) * 100), - }) - ) - .add( - Dinero({ - amount: Math.round((job.ca_bc_pvrt || 0) * 100), - }) - ); + ret.adjustments = Dinero({ + amount: Math.round((job.adjustment_bottom_line || 0) * 100), + }); + ret.towing = Dinero({ + amount: Math.round((job.towing_payable || 0) * 100), + }); + ret.storage = Dinero({ + amount: Math.round((job.storage_payable || 0) * 100), + }); + ret.pvrt = Dinero({ + amount: Math.round((job.ca_bc_pvrt || 0) * 100), + }); + ret.total = ret.additionalCosts + .add(ret.adjustments) //IO-813 Adjustment takes care of GST & PST at labor rate. + .add(ret.towing) + .add(ret.storage) + .add(ret.pvrt); return ret; } @@ -312,7 +322,7 @@ function CalculateTaxesTotals(job, otherTotals) { const subtotal = otherTotals.parts.parts.subtotal .add(otherTotals.parts.sublets.subtotal) .add(otherTotals.rates.subtotal) //No longer using just rates subtotal to include mapa/mash. - .add(otherTotals.additional); + .add(otherTotals.additional.total); // .add(Dinero({ amount: (job.towing_payable || 0) * 100 })) // .add(Dinero({ amount: (job.storage_payable || 0) * 100 })); @@ -371,14 +381,15 @@ function CalculateTaxesTotals(job, otherTotals) { otherTotals.rates.subtotal.percentage((job.tax_lbr_rt || 0) * 100) // THis is currently using the lbr tax rate from PFH not PFL. ) .add( - Dinero({ - amount: Math.round((job.towing_payable || 0) * 100), - }).percentage((job.tax_tow_rt || 0) * 100) + otherTotals.additional.adjustments.percentage( + (job.tax_lbr_rt || 0) * 100 + ) ) .add( - Dinero({ - amount: Math.round((job.storage_payable || 0) * 100), - }).percentage((job.tax_str_rt || 0) * 100) + otherTotals.additional.towing.percentage((job.tax_tow_rt || 0) * 100) + ) + .add( + otherTotals.additional.storage.percentage((job.tax_str_rt || 0) * 100) ) .add(additionalItemsTax), local_tax: subtotal.percentage((job.local_tax_rate || 0) * 100),