From dede870fed0027fdbc27b33fe36dc230ce7e2e44 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Thu, 19 Nov 2015 00:02:01 +0200 Subject: [PATCH] Bug fixes --- app/Models/Invoice.php | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index ee91bc8afab1..97079eb42416 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -194,13 +194,17 @@ class Invoice extends EntityModel implements BalanceAffecting public function updatePaidStatus($save = true) { - if ($this->isPaid() && $this->balance > 0) { - $this->invoice_status_id = ($this->balance == $this->amount ? INVOICE_STATUS_SENT : INVOICE_STATUS_PARTIAL); - if ($save) { - $this->save(); - } - } elseif ($this->invoice_status_id && $this->amount > 0 && $this->balance == 0 && $this->invoice_status_id != INVOICE_STATUS_PAID) { - $this->invoice_status_id = INVOICE_STATUS_PAID; + $statusId = false; + if ($this->amount > 0 && $this->balance == 0) { + $statusId = INVOICE_STATUS_PAID; + } elseif ($this->balance > 0 && $this->balance < $this->amount) { + $statusId = INVOICE_STATUS_PARTIAL; + } elseif ($this->isPartial() && $this->balance > 0) { + $statusId = ($this->balance == $this->amount ? INVOICE_STATUS_SENT : INVOICE_STATUS_PARTIAL); + } + + if ($statusId && $statusId != $this->invoice_status_id) { + $this->invoice_status_id = $statusId; if ($save) { $this->save(); } @@ -263,6 +267,11 @@ class Invoice extends EntityModel implements BalanceAffecting return $this->invoice_status_id >= INVOICE_STATUS_VIEWED; } + public function isPartial() + { + return $this->invoice_status_id >= INVOICE_STATUS_PARTIAL; + } + public function isPaid() { return $this->invoice_status_id >= INVOICE_STATUS_PAID;