1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-08 12:12:48 +01:00

Fix line item discount rounding

This commit is contained in:
Hillel Coren 2017-12-30 21:22:03 +02:00
parent 014f51e2ad
commit b705982110
7 changed files with 43 additions and 40 deletions

View File

@ -541,10 +541,11 @@ class InvoiceRepository extends BaseRepository
$invoiceItemCost = Utils::roundSignificant(Utils::parseFloat($item['cost']));
$invoiceItemQty = Utils::roundSignificant(Utils::parseFloat($item['qty']));
$discount = empty($item['discount']) ? 0 : round(Utils::parseFloat($item['discount']), 2);
$lineTotal = $invoiceItemCost * $invoiceItemQty;
if (! empty($item['discount']) && $discount = Utils::parseFloat($item['discount'])) {
if ($discount) {
if ($invoice->is_amount_discount) {
$lineTotal -= $discount;
} else {
@ -559,9 +560,10 @@ class InvoiceRepository extends BaseRepository
$item = (array) $item;
$invoiceItemCost = Utils::roundSignificant(Utils::parseFloat($item['cost']));
$invoiceItemQty = Utils::roundSignificant(Utils::parseFloat($item['qty']));
$discount = empty($item['discount']) ? 0 : round(Utils::parseFloat($item['discount']), 2);
$lineTotal = $invoiceItemCost * $invoiceItemQty;
if (! empty($item['discount']) && $discount = Utils::parseFloat($item['discount'])) {
if ($discount) {
if ($invoice->is_amount_discount) {
$lineTotal -= $discount;
} else {
@ -593,7 +595,7 @@ class InvoiceRepository extends BaseRepository
}
}
if ($invoice->discount > 0) {
if ($invoice->discount != 0) {
if ($invoice->is_amount_discount) {
$total -= $invoice->discount;
} else {

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -670,7 +670,7 @@ NINJA.invoiceLines = function(invoice, isSecondTable) {
var item = invoice.invoice_items[i];
var cost = NINJA.parseFloat(item.cost) ? formatMoneyInvoice(NINJA.parseFloat(item.cost), invoice, null, getPrecision(NINJA.parseFloat(item.cost))) : ' ';
var qty = NINJA.parseFloat(item.qty) ? roundSignificant(NINJA.parseFloat(item.qty)) + '' : ' ';
var discount = NINJA.parseFloat(item.discount);
var discount = roundToTwo(NINJA.parseFloat(item.discount));
var notes = item.notes;
var productKey = item.product_key;
var tax1 = '';
@ -770,7 +770,7 @@ NINJA.invoiceLines = function(invoice, isSecondTable) {
}
} else if (field == 'discount') {
if (parseInt(invoice.is_amount_discount)) {
value = roundSignificant(discount, true);
value = formatMoneyInvoice(discount, invoice);
} else {
value = discount + '%';
}

View File

@ -588,8 +588,8 @@ function calculateAmounts(invoice) {
if (invoice.is_statement) {
var lineTotal = roundToTwo(NINJA.parseFloat(item.balance));
} else {
var lineTotal = roundSignificant(NINJA.parseFloat(item.cost) * NINJA.parseFloat(item.qty));
var discount = NINJA.parseFloat(item.discount);
var lineTotal = roundSignificant(NINJA.parseFloat(item.cost)) * roundSignificant(NINJA.parseFloat(item.qty));
var discount = roundToTwo(NINJA.parseFloat(item.discount));
if (discount != 0) {
if (parseInt(invoice.is_amount_discount)) {
lineTotal -= discount;
@ -644,8 +644,8 @@ function calculateAmounts(invoice) {
}
// calculate line item tax
var lineTotal = roundSignificant(NINJA.parseFloat(item.cost) * NINJA.parseFloat(item.qty));
var discount = NINJA.parseFloat(item.discount);
var lineTotal = roundSignificant(NINJA.parseFloat(item.cost)) * roundSignificant(NINJA.parseFloat(item.qty));
var discount = roundToTwo(NINJA.parseFloat(item.discount));
if (discount != 0) {
if (parseInt(invoice.is_amount_discount)) {
lineTotal -= discount;
@ -656,10 +656,11 @@ function calculateAmounts(invoice) {
lineTotal = roundToTwo(lineTotal);
if (invoice.discount != 0) {
var discount = roundToTwo(NINJA.parseFloat(invoice.discount));
if (parseInt(invoice.is_amount_discount)) {
lineTotal -= roundToTwo((lineTotal/total) * invoice.discount);
lineTotal -= roundToTwo((lineTotal/total) * discount);
} else {
lineTotal -= roundToTwo(lineTotal * invoice.discount / 100);
lineTotal -= roundToTwo(lineTotal * discount / 100);
}
}
@ -702,7 +703,7 @@ function calculateAmounts(invoice) {
if (parseInt(invoice.is_amount_discount)) {
discount = roundToTwo(invoice.discount);
} else {
discount = roundToTwo(total * invoice.discount / 100);
discount = roundToTwo(total * roundToTwo(invoice.discount) / 100);
}
total -= discount;
}

View File

@ -399,7 +399,7 @@ function InvoiceModel(data) {
if (parseInt(self.is_amount_discount())) {
return roundToTwo(self.discount());
} else {
return roundToTwo(self.totals.rawSubtotal() * self.discount() / 100);
return roundToTwo(self.totals.rawSubtotal() * roundToTwo(self.discount()) / 100);
}
});
@ -449,9 +449,9 @@ function InvoiceModel(data) {
var lineTotal = item.totals.rawTotal();
if (self.discount()) {
if (parseInt(self.is_amount_discount())) {
lineTotal -= roundToTwo((lineTotal/total) * self.discount());
lineTotal -= roundToTwo((lineTotal/total) * roundToTwo(self.discount()));
} else {
lineTotal -= roundToTwo(lineTotal * self.discount() / 100);
lineTotal -= roundToTwo(lineTotal * roundToTwo(self.discount()) / 100);
}
}
@ -898,7 +898,7 @@ function ItemModel(data) {
this.totals.rawTotal = ko.computed(function() {
var value = roundSignificant(NINJA.parseFloat(self.cost()) * NINJA.parseFloat(self.qty()));
if (self.discount()) {
var discount = NINJA.parseFloat(self.discount());
var discount = roundToTwo(NINJA.parseFloat(self.discount()));
if (parseInt(model.invoice().is_amount_discount())) {
value -= discount;
} else {

View File

@ -70,10 +70,10 @@ class DiscountCest
$I->click('Mark Sent');
$total = $itemAmount * $quantity;
$total -= $total * $itemDiscount / 100;
$total -= $total * $discount / 100;
$total += $total * $itemTaxRate / 100;
$total -= round($total * round($itemDiscount, 2) / 100, 2);
$total -= round($total * round($discount, 2) / 100, 2);
$total += round($total * $itemTaxRate / 100, 2);
$I->see(number_format($total,2));
$I->see(number_format($total, 2));
}
}