Correct tax report
This commit is contained in:
parent
dcd9f1e0cf
commit
abc08eeafd
|
|
@ -988,11 +988,18 @@ abstract class InvoiceEntity extends Object
|
||||||
/// Gets taxes in the form { taxName1: { amount: 0, paid: 0} , ... }
|
/// Gets taxes in the form { taxName1: { amount: 0, paid: 0} , ... }
|
||||||
Map<String, Map<String, dynamic>> getTaxes(int precision) {
|
Map<String, Map<String, dynamic>> getTaxes(int precision) {
|
||||||
final taxes = <String, Map<String, dynamic>>{};
|
final taxes = <String, Map<String, dynamic>>{};
|
||||||
final taxable = calculateTaxes(
|
final taxable = getTaxable();
|
||||||
useInclusiveTaxes: usesInclusiveTaxes, precision: precision);
|
|
||||||
|
double calculateAmount(double taxable, double rate) {
|
||||||
|
if (usesInclusiveTaxes) {
|
||||||
|
return round(taxable - (taxable / (1 + (rate / 100))), 2);
|
||||||
|
} else {
|
||||||
|
return round(taxable * (rate / 100), 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (taxRate1 != 0) {
|
if (taxRate1 != 0) {
|
||||||
final invoiceTaxAmount = taxable[taxName1];
|
final invoiceTaxAmount = calculateAmount(taxable, taxRate1);
|
||||||
final invoicePaidAmount = (amount * invoiceTaxAmount != 0)
|
final invoicePaidAmount = (amount * invoiceTaxAmount != 0)
|
||||||
? (paidToDate / amount * invoiceTaxAmount)
|
? (paidToDate / amount * invoiceTaxAmount)
|
||||||
: 0.0;
|
: 0.0;
|
||||||
|
|
@ -1001,7 +1008,7 @@ abstract class InvoiceEntity extends Object
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taxRate2 != 0) {
|
if (taxRate2 != 0) {
|
||||||
final invoiceTaxAmount = taxable[taxName2];
|
final invoiceTaxAmount = calculateAmount(taxable, taxRate2);
|
||||||
final invoicePaidAmount = (amount * invoiceTaxAmount != 0)
|
final invoicePaidAmount = (amount * invoiceTaxAmount != 0)
|
||||||
? (paidToDate / amount * invoiceTaxAmount)
|
? (paidToDate / amount * invoiceTaxAmount)
|
||||||
: 0.0;
|
: 0.0;
|
||||||
|
|
@ -1010,7 +1017,7 @@ abstract class InvoiceEntity extends Object
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taxRate3 != 0) {
|
if (taxRate3 != 0) {
|
||||||
final invoiceTaxAmount = taxable[taxName3];
|
final invoiceTaxAmount = calculateAmount(taxable, taxRate3);
|
||||||
final invoicePaidAmount = (amount * invoiceTaxAmount != 0)
|
final invoicePaidAmount = (amount * invoiceTaxAmount != 0)
|
||||||
? (paidToDate / amount * invoiceTaxAmount)
|
? (paidToDate / amount * invoiceTaxAmount)
|
||||||
: 0.0;
|
: 0.0;
|
||||||
|
|
@ -1019,19 +1026,22 @@ abstract class InvoiceEntity extends Object
|
||||||
}
|
}
|
||||||
|
|
||||||
for (final item in lineItems) {
|
for (final item in lineItems) {
|
||||||
|
final itemTaxable = getItemTaxable(item, amount, precision);
|
||||||
|
|
||||||
if (item.taxRate1 != 0) {
|
if (item.taxRate1 != 0) {
|
||||||
final itemTaxAmount = taxable[item.taxName1];
|
final itemTaxAmount = calculateAmount(itemTaxable, item.taxRate1);
|
||||||
final itemPaidAmount = amount != null &&
|
final itemPaidAmount = amount != null &&
|
||||||
itemTaxAmount != null &&
|
itemTaxAmount != null &&
|
||||||
amount * itemTaxAmount != 0
|
amount * itemTaxAmount != 0
|
||||||
? (paidToDate / amount * itemTaxAmount)
|
? (paidToDate / amount * itemTaxAmount)
|
||||||
: 0.0;
|
: 0.0;
|
||||||
|
|
||||||
_calculateTax(
|
_calculateTax(
|
||||||
taxes, item.taxName1, item.taxRate1, itemTaxAmount, itemPaidAmount);
|
taxes, item.taxName1, item.taxRate1, itemTaxAmount, itemPaidAmount);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (item.taxRate2 != 0) {
|
if (item.taxRate2 != 0) {
|
||||||
final itemTaxAmount = taxable[item.taxName2];
|
final itemTaxAmount = calculateAmount(itemTaxable, item.taxRate2);
|
||||||
final itemPaidAmount = amount != null &&
|
final itemPaidAmount = amount != null &&
|
||||||
itemTaxAmount != null &&
|
itemTaxAmount != null &&
|
||||||
amount * itemTaxAmount != 0
|
amount * itemTaxAmount != 0
|
||||||
|
|
@ -1042,7 +1052,7 @@ abstract class InvoiceEntity extends Object
|
||||||
}
|
}
|
||||||
|
|
||||||
if (item.taxRate3 != 0) {
|
if (item.taxRate3 != 0) {
|
||||||
final itemTaxAmount = taxable[item.taxName3];
|
final itemTaxAmount = calculateAmount(itemTaxable, item.taxRate3);
|
||||||
final itemPaidAmount = amount != null &&
|
final itemPaidAmount = amount != null &&
|
||||||
itemTaxAmount != null &&
|
itemTaxAmount != null &&
|
||||||
amount * itemTaxAmount != 0
|
amount * itemTaxAmount != 0
|
||||||
|
|
|
||||||
|
|
@ -124,18 +124,64 @@ abstract class CalculateInvoiceTotal {
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double getTaxable() {
|
||||||
|
double total = 0;
|
||||||
|
|
||||||
|
lineItems.forEach((invoiceItem) {
|
||||||
|
double lineTotal = invoiceItem.quantity * invoiceItem.cost;
|
||||||
|
|
||||||
|
if (invoiceItem.discount != 0) {
|
||||||
|
if (isAmountDiscount) {
|
||||||
|
lineTotal -= invoiceItem.discount;
|
||||||
|
} else {
|
||||||
|
lineTotal -= lineTotal * invoiceItem.discount / 100;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
total += lineTotal;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (discount > 0) {
|
||||||
|
if (isAmountDiscount) {
|
||||||
|
total -= discount;
|
||||||
|
} else {
|
||||||
|
total *= (100 - discount) / 100;
|
||||||
|
total = round(total, 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (customTaxes1) {
|
||||||
|
total += customSurcharge1;
|
||||||
|
}
|
||||||
|
if (customTaxes2) {
|
||||||
|
total += customSurcharge2;
|
||||||
|
}
|
||||||
|
if (customTaxes3) {
|
||||||
|
total += customSurcharge3;
|
||||||
|
}
|
||||||
|
if (customTaxes4) {
|
||||||
|
total += customSurcharge4;
|
||||||
|
}
|
||||||
|
|
||||||
|
return total;
|
||||||
|
}
|
||||||
|
|
||||||
double getItemTaxable(
|
double getItemTaxable(
|
||||||
InvoiceItemEntity item, double invoiceTotal, int precision) {
|
InvoiceItemEntity item, double invoiceTotal, int precision) {
|
||||||
final double qty = round(item.quantity, 4);
|
final double qty = round(item.quantity, 5);
|
||||||
final double cost = round(item.cost, 4);
|
final double cost = round(item.cost, 4);
|
||||||
final double itemDiscount = round(item.discount, precision);
|
final double itemDiscount = round(item.discount, precision);
|
||||||
double lineTotal = qty * cost;
|
double lineTotal = qty * cost;
|
||||||
|
|
||||||
if (discount != 0) {
|
if (discount != 0) {
|
||||||
if (isAmountDiscount) {
|
if (isAmountDiscount) {
|
||||||
if (invoiceTotal != 0) {
|
if (invoiceTotal + discount != 0) {
|
||||||
lineTotal -= round(lineTotal / invoiceTotal * discount, 4);
|
lineTotal -= invoiceTotal != 0
|
||||||
|
? (lineTotal / (invoiceTotal + discount) * discount)
|
||||||
|
: 0;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
lineTotal *= (100 - discount) / 100;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -143,7 +189,7 @@ abstract class CalculateInvoiceTotal {
|
||||||
if (isAmountDiscount) {
|
if (isAmountDiscount) {
|
||||||
lineTotal -= itemDiscount;
|
lineTotal -= itemDiscount;
|
||||||
} else {
|
} else {
|
||||||
lineTotal -= round(lineTotal * itemDiscount / 100, 4);
|
lineTotal -= lineTotal * itemDiscount / 100;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue