From 5f23c8912186923a1bb0f9dbde1068b6684032a9 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Fri, 17 Mar 2017 13:57:56 +0200 Subject: [PATCH] Working on gateway fees --- app/Models/Invoice.php | 14 ++++++++++++++ app/Models/InvoiceItem.php | 8 ++++++++ 2 files changed, 22 insertions(+) diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index 76394cdb818d..4e7144bb1332 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -575,6 +575,13 @@ class Invoice extends EntityModel implements BalanceAffecting return; } + $balanceAdjustment = floatval($balanceAdjustment); + $partial = floatval($partial); + + if (! $balanceAdjustment && $this->partial == $partial) { + return; + } + $this->balance = $this->balance + $balanceAdjustment; if ($this->partial > 0) { @@ -582,6 +589,13 @@ class Invoice extends EntityModel implements BalanceAffecting } $this->save(); + + // mark fees as paid + if ($balanceAdjustment != 0 && $this->account->gateway_fee_location == FEE_LOCATION_ITEM) { + if ($invoiceItem = $this->getGatewayFeeItem()) { + $invoiceItem->markFeePaid(); + } + } } /** diff --git a/app/Models/InvoiceItem.php b/app/Models/InvoiceItem.php index 431a2a9a36a3..ba12d00aeb74 100644 --- a/app/Models/InvoiceItem.php +++ b/app/Models/InvoiceItem.php @@ -89,4 +89,12 @@ class InvoiceItem extends EntityModel return $amount; } + + public function markFeePaid() + { + if ($this->invoice_item_type_id == INVOICE_ITEM_TYPE_PENDING_GATEWAY_FEE) { + $this->invoice_item_type_id = INVOICE_ITEM_TYPE_PAID_GATEWAY_FEE; + $this->save(); + } + } }