mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Fixes for invoice status
This commit is contained in:
parent
af7939b002
commit
fc223e3432
@ -1 +1 @@
|
||||
5.1.49
|
||||
5.1.50
|
@ -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) {
|
||||
|
58
tests/Unit/InvoiceStatusTest.php
Normal file
58
tests/Unit/InvoiceStatusTest.php
Normal file
@ -0,0 +1,58 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://opensource.org/licenses/AAL
|
||||
*/
|
||||
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;
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @covers App\Helpers\Invoice\InvoiceSum
|
||||
*/
|
||||
class InvoiceStatusTest extends TestCase
|
||||
{
|
||||
use MockAccountData;
|
||||
use DatabaseTransactions;
|
||||
|
||||
public $invoice;
|
||||
|
||||
public $invoice_calc;
|
||||
|
||||
public $settings;
|
||||
|
||||
public function setUp() :void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->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());
|
||||
}
|
||||
}
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user