2020-04-06 14:32:27 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com)
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
|
|
|
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
|
|
|
|
*
|
|
|
|
* @license https://opensource.org/licenses/AAL
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Utils\Traits\Invoice;
|
|
|
|
|
2020-04-08 12:48:31 +02:00
|
|
|
use App\Models\Invoice;
|
|
|
|
|
2020-04-06 14:32:27 +02:00
|
|
|
trait ActionsInvoice
|
|
|
|
{
|
2020-04-08 12:48:31 +02:00
|
|
|
public function invoiceDeletable($invoice) :bool
|
2020-04-06 14:32:27 +02:00
|
|
|
{
|
2020-05-19 14:54:22 +02:00
|
|
|
if ($invoice->status_id <= Invoice::STATUS_SENT && $invoice->is_deleted == false && $invoice->deleted_at == null && $invoice->balance == 0) {
|
2020-04-15 02:30:52 +02:00
|
|
|
return true;
|
|
|
|
}
|
2020-04-06 14:32:27 +02:00
|
|
|
|
2020-04-15 02:30:52 +02:00
|
|
|
return false;
|
2020-04-06 14:32:27 +02:00
|
|
|
}
|
|
|
|
|
2020-04-08 12:48:31 +02:00
|
|
|
public function invoiceCancellable($invoice) :bool
|
2020-04-06 14:32:27 +02:00
|
|
|
{
|
2020-04-15 02:30:52 +02:00
|
|
|
if (($invoice->status_id == Invoice::STATUS_SENT || $invoice->status_id == Invoice::STATUS_PARTIAL) && $invoice->is_deleted == false && $invoice->deleted_at == null) {
|
|
|
|
return true;
|
|
|
|
}
|
2020-04-06 14:32:27 +02:00
|
|
|
|
2020-04-15 02:30:52 +02:00
|
|
|
return false;
|
2020-04-06 14:32:27 +02:00
|
|
|
}
|
|
|
|
|
2020-04-08 12:48:31 +02:00
|
|
|
public function invoiceReversable($invoice) :bool
|
2020-04-06 14:32:27 +02:00
|
|
|
{
|
2020-04-15 02:30:52 +02:00
|
|
|
if (($invoice->status_id == Invoice::STATUS_SENT || $invoice->status_id == Invoice::STATUS_PARTIAL || $invoice->status_id == Invoice::STATUS_PAID) && $invoice->is_deleted == false && $invoice->deleted_at == null) {
|
|
|
|
return true;
|
|
|
|
}
|
2020-04-06 14:32:27 +02:00
|
|
|
|
2020-04-15 02:30:52 +02:00
|
|
|
return false;
|
2020-04-06 14:32:27 +02:00
|
|
|
}
|
|
|
|
}
|