Correct rounding for line item discounts

This commit is contained in:
Hillel Coren 2022-07-07 18:50:35 +03:00
parent 471528f5b5
commit 84eb3eb4bc
1 changed files with 6 additions and 6 deletions

View File

@ -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);
}
}