From 8f3952a938fd4eb8cc4ee726d60695f219cfba02 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Sat, 23 Dec 2017 22:06:30 +0200 Subject: [PATCH] Include line item discounts in tax reports --- app/Models/InvoiceItem.php | 9 +++++++++ app/Ninja/PaymentDrivers/BasePaymentDriver.php | 4 +++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/app/Models/InvoiceItem.php b/app/Models/InvoiceItem.php index e04ebe9e90..c30b16037f 100644 --- a/app/Models/InvoiceItem.php +++ b/app/Models/InvoiceItem.php @@ -78,6 +78,15 @@ class InvoiceItem extends EntityModel public function amount() { $amount = $this->cost * $this->qty; + + if ($this->discount != 0) { + if ($this->invoice->is_amount_discount) { + $amount -= $this->discount; + } else { + $amount -= $amount * $this->discount / 100; + } + } + $preTaxAmount = $amount; if ($this->tax_rate1) { diff --git a/app/Ninja/PaymentDrivers/BasePaymentDriver.php b/app/Ninja/PaymentDrivers/BasePaymentDriver.php index ba4ad5f1bf..8e4384bb3e 100644 --- a/app/Ninja/PaymentDrivers/BasePaymentDriver.php +++ b/app/Ninja/PaymentDrivers/BasePaymentDriver.php @@ -374,7 +374,9 @@ class BasePaymentDriver ]); $items[] = $item; - $total += $invoiceItem->cost * $invoiceItem->qty; + + $invoiceItem->setRelation('invoice', $invoice); + $total += $invoiceItem->amount(); } if ($total != $invoice->getRequestedAmount()) {