Bug fixes

This commit is contained in:
Hillel Coren 2015-11-19 00:02:01 +02:00
parent 4a0906a92c
commit dede870fed

View File

@ -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;