diff --git a/VERSION.txt b/VERSION.txt index b72061af4eb7..0b2699b27e43 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -1 +1 @@ -5.1.49 \ No newline at end of file +5.1.50 \ No newline at end of file diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index dadfa3e222ba..ab11b83696b3 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -245,21 +245,30 @@ class Invoice extends BaseModel public function getStatusAttribute() { - if ($this->status_id == self::STATUS_SENT && $this->due_date > Carbon::now()) { + $due_date = $this->due_date ? Carbon::parse($this->due_date) : false; + $partial_due_date = $this->partial_due_Date ? Carbon::parse($this->partial_due_date) : false; + + if ($this->status_id == self::STATUS_SENT && $due_date && $due_date->gt(now())) { + nlog("1 unpaid"); return self::STATUS_UNPAID; - } elseif ($this->status_id == self::STATUS_PARTIAL && $this->partial_due_date > Carbon::now()) { - return self::STATUS_UNPAID; - } elseif ($this->status_id == self::STATUS_SENT && $this->due_date < Carbon::now()) { + } elseif ($this->status_id == self::STATUS_PARTIAL && $partial_due_date && $partial_due_date->gt(now())) { + nlog("2 partial"); + return self::STATUS_PARTIAL; + } elseif ($this->status_id == self::STATUS_SENT && $due_date && $due_date->lt(now())) { + nlog("3 overdue"); return self::STATUS_OVERDUE; - } elseif ($this->status_id == self::STATUS_PARTIAL && $this->partial_due_date < Carbon::now()) { + } elseif ($this->status_id == self::STATUS_PARTIAL && $partial_due_date && $partial_due_date->lt(now())) { + nlog("4 overdue"); return self::STATUS_OVERDUE; } else { + nlog("status id "); return $this->status_id; } } public function isPayable(): bool { + if ($this->status_id == self::STATUS_DRAFT && $this->is_deleted == false) { return true; } elseif ($this->status_id == self::STATUS_SENT && $this->is_deleted == false) { diff --git a/tests/Unit/InvoiceStatusTest.php b/tests/Unit/InvoiceStatusTest.php new file mode 100644 index 000000000000..fb58f5f74d85 --- /dev/null +++ b/tests/Unit/InvoiceStatusTest.php @@ -0,0 +1,58 @@ +makeTestData(); + + } + + public function testSentStatus() + { + $this->invoice->due_date = now()->addMonth(); + $this->invoice->status_id = Invoice::STATUS_SENT; + + $this->assertEquals(Invoice::STATUS_UNPAID, $this->invoice->getStatusAttribute()); + } + + public function testPartialStatus() + { + $this->invoice->partial_due_date = now()->addMonth(); + $this->invoice->status_id = Invoice::STATUS_SENT; + + $this->assertEquals(Invoice::STATUS_SENT, $this->invoice->getStatusAttribute()); + } +} diff --git a/tests/Unit/InvoiceTest.php b/tests/Unit/InvoiceTest.php index 4ebd38500cd2..ed8c26308f03 100644 --- a/tests/Unit/InvoiceTest.php +++ b/tests/Unit/InvoiceTest.php @@ -12,6 +12,7 @@ namespace Tests\Unit; use App\Factory\InvoiceItemFactory; use App\Helpers\Invoice\InvoiceSum; +use App\Models\Invoice; use Illuminate\Foundation\Testing\DatabaseTransactions; use Tests\MockAccountData; use Tests\TestCase; @@ -220,4 +221,12 @@ class InvoiceTest extends TestCase //$this->assertEquals($this->invoice_calc->getTotalTaxes(), 4); //$this->assertEquals(count($this->invoice_calc->getTaxMap()), 1); } + + public function testSentStatus() + { + $this->invoice->due_date = now()->addMonth(); + $this->invoice->status_id = Invoice::STATUS_SENT; + + $this->assertEquals(Invoice::STATUS_SENT, $this->invoice->getStatusAttribute()); + } }