From 6e0675f28bce3ac905da376f4ac4f6b92836a2bb Mon Sep 17 00:00:00 2001 From: Patrick Fic <> Date: Thu, 2 Sep 2021 15:48:54 -0700 Subject: [PATCH] IO-1342 Resolve negative parts discount crash on job totals. --- server/accounting/qbxml/qbxml-receivables.js | 2 +- server/job/job-costing.js | 4 ++-- server/job/job-totals.js | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/server/accounting/qbxml/qbxml-receivables.js b/server/accounting/qbxml/qbxml-receivables.js index ff3c98e4a..8e2d05685 100644 --- a/server/accounting/qbxml/qbxml-receivables.js +++ b/server/accounting/qbxml/qbxml-receivables.js @@ -257,7 +257,7 @@ const generateInvoiceQbxml = ( if (jobline.prt_dsmk_p && jobline.prt_dsmk_p !== 0) { // console.log("Have a part discount", jobline); DineroAmount = DineroAmount.add( - DineroAmount.percentage(jobline.prt_dsmk_p || 0) + DineroAmount.percentage(Math.abs(jobline.prt_dsmk_p || 0)) ); } const account = responsibilityCenters.profits.find( diff --git a/server/job/job-costing.js b/server/job/job-costing.js index a143959a4..235e0fcd7 100644 --- a/server/job/job-costing.js +++ b/server/job/job-costing.js @@ -301,7 +301,7 @@ function GenerateCostingData(job) { amount: Math.round((val.act_price || 0) * 100), }) .multiply(val.part_qty || 0) - .percentage(val.prt_dsmk_p || 0) + .percentage(Math.abs(val.prt_dsmk_p || 0)) ); if (!acc.parts[partsProfitCenter]) acc.parts[partsProfitCenter] = Dinero(); @@ -330,7 +330,7 @@ function GenerateCostingData(job) { amount: Math.round((val.act_price || 0) * 100), }) .multiply(val.part_qty || 0) - .percentage(val.prt_dsmk_p || 0) + .percentage(Math.abs(val.prt_dsmk_p || 0)) ); if (!acc.parts[partsProfitCenter]) diff --git a/server/job/job-totals.js b/server/job/job-totals.js index 2bd40d284..aafd6b955 100644 --- a/server/job/job-totals.js +++ b/server/job/job-totals.js @@ -258,7 +258,7 @@ function CalculatePartsTotals(jobLines) { amount: Math.round((value.act_price || 0) * 100), }) .multiply(value.part_qty || 0) - .percentage(value.prt_dsmk_p || 0) + .percentage(Math.abs(value.prt_dsmk_p || 0)) ), list: { ...acc.parts.list, @@ -289,7 +289,7 @@ function CalculatePartsTotals(jobLines) { amount: Math.round((value.act_price || 0) * 100), }) .multiply(value.part_qty || 0) - .percentage(value.prt_dsmk_p || 0) + .percentage(Math.abs(value.prt_dsmk_p || 0)) ), }, }; @@ -425,7 +425,7 @@ function CalculateTaxesTotals(job, otherTotals) { amount: Math.round((val.act_price || 0) * 100), }) .multiply(val.part_qty || 0) - .percentage(val.prt_dsmk_p || 0) + .percentage(Math.abs(val.prt_dsmk_p || 0)) ) .percentage( ((job.parts_tax_rates &&