From eaf7e22060d95feff6569675f430b449a7718d82 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Sat, 23 Dec 2017 21:51:40 +0200 Subject: [PATCH] Include line item discounts in tax reports --- app/Models/Invoice.php | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index 39bb3de4d4be..a83bd283ab13 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -1292,7 +1292,7 @@ class Invoice extends EntityModel implements BalanceAffecting { $total = $invoiceItem->qty * $invoiceItem->cost; - if ($this->discount > 0) { + if ($this->discount != 0) { if ($this->is_amount_discount) { $total -= $invoiceTotal ? ($total / ($invoiceTotal + $this->discount) * $this->discount) : 0; } else { @@ -1300,6 +1300,14 @@ class Invoice extends EntityModel implements BalanceAffecting } } + if ($invoiceItem->discount != 0) { + if ($this->is_amount_discount) { + $total -= $invoiceItem->discount; + } else { + $total -= $total * $invoiceItem->discount / 100; + } + } + return round($total, 2); } @@ -1311,7 +1319,17 @@ class Invoice extends EntityModel implements BalanceAffecting $total = 0; foreach ($this->invoice_items as $invoiceItem) { - $total += $invoiceItem->qty * $invoiceItem->cost; + $lineTotal = $invoiceItem->qty * $invoiceItem->cost; + + if ($invoiceItem->discount != 0) { + if ($this->is_amount_discount) { + $lineTotal -= $invoiceItem->discount; + } else { + $lineTotal -= $lineTotal * $invoiceItem->discount / 100; + } + } + + $total += $lineTotal; } if ($this->discount > 0) {