Fix for inclusive taxes

This commit is contained in:
Hillel Coren 2018-01-23 12:16:48 +02:00
parent dd360fb271
commit e960e4b369
5 changed files with 12 additions and 12 deletions

View File

@ -1429,7 +1429,7 @@ class Invoice extends EntityModel implements BalanceAffecting
$account = $this->account; $account = $this->account;
if ($account->inclusive_taxes) { if ($account->inclusive_taxes) {
return round(($taxable * 100) / (100 + ($rate * 100)), 2); return round($taxable - ($taxable / (1 + ($rate / 100))), 2);
} else { } else {
return round($taxable * ($rate / 100), 2); return round($taxable * ($rate / 100), 2);
} }

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -671,7 +671,7 @@ function calculateAmounts(invoice) {
} else if (invoice.account.inclusive_taxes != '1') { } else if (invoice.account.inclusive_taxes != '1') {
var taxAmount1 = roundToTwo(lineTotal * taxRate1 / 100); var taxAmount1 = roundToTwo(lineTotal * taxRate1 / 100);
} else { } else {
var taxAmount1 = roundToTwo((lineTotal * 100) / (100 + (taxRate1 * 100))); var taxAmount1 = roundToTwo(lineTotal - (lineTotal / (1 + (taxRate1 / 100))))
} }
if (taxAmount1 != 0 || taxName1) { if (taxAmount1 != 0 || taxName1) {
hasTaxes = true; hasTaxes = true;
@ -688,7 +688,7 @@ function calculateAmounts(invoice) {
} else if (invoice.account.inclusive_taxes != '1') { } else if (invoice.account.inclusive_taxes != '1') {
var taxAmount2 = roundToTwo(lineTotal * taxRate2 / 100); var taxAmount2 = roundToTwo(lineTotal * taxRate2 / 100);
} else { } else {
var taxAmount2 = roundToTwo((lineTotal * 100) / (100 + (taxRate2 * 100))); var taxAmount2 = roundToTwo(lineTotal - (lineTotal / (1 + (taxRate2 / 100))))
} }
if (taxAmount2 != 0 || taxName2) { if (taxAmount2 != 0 || taxName2) {
hasTaxes = true; hasTaxes = true;
@ -743,8 +743,8 @@ function calculateAmounts(invoice) {
} }
} }
} else { } else {
taxAmount1 = roundToTwo((total * 100) / (100 + (taxRate1 * 100))); taxAmount1 = roundToTwo(total - (total / (1 + (taxRate1 / 100))))
taxAmount2 = roundToTwo((total * 100) / (100 + (taxRate2 * 100))); taxAmount2 = roundToTwo(total - (total / (1 + (taxRate2 / 100))))
} }
// custom fields w/o with taxes // custom fields w/o with taxes

View File

@ -426,14 +426,14 @@ function InvoiceModel(data) {
var taxRate1 = parseFloat(self.tax_rate1()); var taxRate1 = parseFloat(self.tax_rate1());
@if ($account->inclusive_taxes) @if ($account->inclusive_taxes)
var tax1 = roundToTwo((total * 100) / (100 + (taxRate1 * 100))); var tax1 = roundToTwo(total - (total / (1 + (taxRate1 / 100))));
@else @else
var tax1 = roundToTwo(total * (taxRate1/100)); var tax1 = roundToTwo(total * (taxRate1/100));
@endif @endif
var taxRate2 = parseFloat(self.tax_rate2()); var taxRate2 = parseFloat(self.tax_rate2());
@if ($account->inclusive_taxes) @if ($account->inclusive_taxes)
var tax2 = roundToTwo((total * 100) / (100 + (taxRate2 * 100))); var tax2 = roundToTwo(total - (total / (1 + (taxRate2 / 100))));
@else @else
var tax2 = roundToTwo(total * (taxRate2/100)); var tax2 = roundToTwo(total * (taxRate2/100));
@endif @endif
@ -456,7 +456,7 @@ function InvoiceModel(data) {
} }
@if ($account->inclusive_taxes) @if ($account->inclusive_taxes)
var taxAmount = roundToTwo((lineTotal * 100) / (100 + (item.tax_rate1() * 100))); var taxAmount = roundToTwo(lineTotal - (lineTotal / (1 + (item.tax_rate1() / 100))))
@else @else
var taxAmount = roundToTwo(lineTotal * item.tax_rate1() / 100); var taxAmount = roundToTwo(lineTotal * item.tax_rate1() / 100);
@endif @endif
@ -470,7 +470,7 @@ function InvoiceModel(data) {
} }
@if ($account->inclusive_taxes) @if ($account->inclusive_taxes)
var taxAmount = roundToTwo((lineTotal * 100) / (100 + (item.tax_rate2() * 100))); var taxAmount = roundToTwo(lineTotal - (lineTotal / (1 + (item.tax_rate2() / 100))))
@else @else
var taxAmount = roundToTwo(lineTotal * item.tax_rate2() / 100); var taxAmount = roundToTwo(lineTotal * item.tax_rate2() / 100);
@endif @endif