From 84eb3eb4bcda89f570942ec3f46f1f8b43168315 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Thu, 7 Jul 2022 18:50:35 +0300 Subject: [PATCH] Correct rounding for line item discounts --- lib/data/models/mixins/invoice_mixin.dart | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/data/models/mixins/invoice_mixin.dart b/lib/data/models/mixins/invoice_mixin.dart index 71db426d2..f1eae94ad 100644 --- a/lib/data/models/mixins/invoice_mixin.dart +++ b/lib/data/models/mixins/invoice_mixin.dart @@ -183,7 +183,7 @@ abstract class CalculateInvoiceTotal { InvoiceItemEntity item, double invoiceTotal, int precision) { final double qty = round(item.quantity, 5); final double cost = round(item.cost, 5); - final double itemDiscount = round(item.discount, precision); + final double itemDiscount = round(item.discount, 5); double lineTotal = qty * cost; if (discount != 0) { @@ -216,7 +216,7 @@ abstract class CalculateInvoiceTotal { lineItems.forEach((item) { final double qty = round(item.quantity, 5); final double cost = round(item.cost, 5); - final double itemDiscount = round(item.discount, precision); + final double itemDiscount = round(item.discount, 5); final double taxRate1 = round(item.taxRate1, 3); final double taxRate2 = round(item.taxRate2, 3); final double taxRate3 = round(item.taxRate3, 3); @@ -226,14 +226,14 @@ abstract class CalculateInvoiceTotal { if (isAmountDiscount) { lineTotal -= itemDiscount; } else { - lineTotal -= round(lineTotal * itemDiscount / 100, 4); + lineTotal -= round(lineTotal * itemDiscount / 100, precision); } } if (discount != 0) { if (isAmountDiscount) { if (total != 0) { - lineTotal -= round(lineTotal / total * discount, 4); + lineTotal -= round(lineTotal / total * discount, precision); } } } @@ -305,7 +305,7 @@ abstract class CalculateInvoiceTotal { lineItems.forEach((item) { final double qty = round(item.quantity, 5); final double cost = round(item.cost, 5); - final double discount = round(item.discount, precision); + final double discount = round(item.discount, 5); double lineTotal = qty * cost; @@ -313,7 +313,7 @@ abstract class CalculateInvoiceTotal { if (isAmountDiscount) { lineTotal -= discount; } else { - lineTotal -= round(lineTotal * discount / 100, 4); + lineTotal -= round(lineTotal * discount / 100, precision); } }