From 49a9f71d192d4c0657b0c070f251c58aeabc972d Mon Sep 17 00:00:00 2001 From: Patrick Fic <> Date: Tue, 2 Feb 2021 14:43:09 -0800 Subject: [PATCH] Changed global Dinero rounding IO-469. --- .../bill-enter-modal/bill-enter-modal.container.jsx | 8 -------- .../components/bill-form/bill-form.lines.component.jsx | 8 ++++++-- .../src/components/bill-form/bill-form.totals.utility.js | 5 ++++- client/src/index.js | 1 + server/job/job-totals.js | 1 + 5 files changed, 12 insertions(+), 11 deletions(-) diff --git a/client/src/components/bill-enter-modal/bill-enter-modal.container.jsx b/client/src/components/bill-enter-modal/bill-enter-modal.container.jsx index 1caf66328..2f661e150 100644 --- a/client/src/components/bill-enter-modal/bill-enter-modal.container.jsx +++ b/client/src/components/bill-enter-modal/bill-enter-modal.container.jsx @@ -97,20 +97,12 @@ function BillEnterModalContainer({ const newAdjustments = _.cloneDeep( existingAdjustments.data.jobs_by_pk.lbr_adjustments ); - console.log( - "🚀 ~ file: bill-enter-modal.container.jsx ~ line 99 ~ handleFinish ~ newAdjustments", - newAdjustments - ); adjKeys.forEach((key) => { newAdjustments[key] = (newAdjustments[key] || 0) + adjustmentsToInsert[key]; }); - console.log( - "🚀 ~ file: bill-enter-modal.container.jsx ~ line 109 ~ adjKeys.forEach ~ newAdjustments", - newAdjustments - ); const jobUpdate = client.mutate({ mutation: UPDATE_JOB, variables: { diff --git a/client/src/components/bill-form/bill-form.lines.component.jsx b/client/src/components/bill-form/bill-form.lines.component.jsx index 06b14f3c2..3ffdbb689 100644 --- a/client/src/components/bill-form/bill-form.lines.component.jsx +++ b/client/src/components/bill-form/bill-form.lines.component.jsx @@ -140,8 +140,12 @@ export function BillEnterModalLinesComponent({ ...item, actual_cost: !!item.actual_cost ? item.actual_cost - : parseFloat(e.target.value) * - (1 - discount), + : Math.round( + (parseFloat(e.target.value) * + (1 - discount) + + Number.EPSILON) * + 100 + ) / 100, }; } return item; diff --git a/client/src/components/bill-form/bill-form.totals.utility.js b/client/src/components/bill-form/bill-form.totals.utility.js index 8189d3f7b..a906462f9 100644 --- a/client/src/components/bill-form/bill-form.totals.utility.js +++ b/client/src/components/bill-form/bill-form.totals.utility.js @@ -22,9 +22,12 @@ export const CalculateBillTotal = (invoice) => { billlines.forEach((i) => { if (!!i) { + console.log("Amount:", (i.actual_cost || 0) * 100); const itemTotal = Dinero({ - amount: Math.round((i.actual_cost || 0) * 100) || 0, + amount: + Math.round(((i.actual_cost || 0) * 100 + Number.EPSILON) * 100) / 100, }).multiply(i.quantity || 1); + subtotal = subtotal.add(itemTotal); if (i.applicable_taxes.federal) { federalTax = federalTax.add( diff --git a/client/src/index.js b/client/src/index.js index 5a4a2b851..6e7bbbc71 100644 --- a/client/src/index.js +++ b/client/src/index.js @@ -16,6 +16,7 @@ require("dotenv").config(); Dinero.defaultCurrency = "CAD"; Dinero.globalLocale = "en-CA"; +Dinero.globalRoundingMode = "HALF_UP"; ReactDOM.render( diff --git a/server/job/job-totals.js b/server/job/job-totals.js index caccf22bf..213eff690 100644 --- a/server/job/job-totals.js +++ b/server/job/job-totals.js @@ -2,6 +2,7 @@ const Dinero = require("dinero.js"); Dinero.defaultCurrency = "CAD"; Dinero.globalLocale = "en-CA"; +Dinero.globalRoundingMode = "HALF_UP"; exports.default = async function (req, res) { const { job } = req.body;