diff --git a/app/Models/InvoiceItem.php b/app/Models/InvoiceItem.php index e04ebe9e903f..c30b16037f99 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 ba4ad5f1bfd8..8e4384bb3e55 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()) {