2020-04-06 14:32:27 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
2020-04-06 14:32:27 +02:00
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2021-01-03 22:54:54 +01:00
|
|
|
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
2020-04-06 14:32:27 +02:00
|
|
|
*
|
|
|
|
* @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-09-06 11:38:10 +02:00
|
|
|
if ($invoice->status_id <= Invoice::STATUS_SENT &&
|
|
|
|
$invoice->is_deleted == false &&
|
|
|
|
$invoice->deleted_at == null &&
|
2020-06-15 01:34:18 +02:00
|
|
|
$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-09-06 11:38:10 +02:00
|
|
|
if (($invoice->status_id == Invoice::STATUS_SENT ||
|
|
|
|
$invoice->status_id == Invoice::STATUS_PARTIAL) &&
|
|
|
|
$invoice->is_deleted == false &&
|
2020-06-15 01:34:18 +02:00
|
|
|
$invoice->deleted_at == null) {
|
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 invoiceReversable($invoice) :bool
|
2020-04-06 14:32:27 +02:00
|
|
|
{
|
2020-09-06 11:38:10 +02:00
|
|
|
if (($invoice->status_id == Invoice::STATUS_SENT ||
|
|
|
|
$invoice->status_id == Invoice::STATUS_PARTIAL ||
|
|
|
|
$invoice->status_id == Invoice::STATUS_CANCELLED ||
|
|
|
|
$invoice->status_id == Invoice::STATUS_PAID) &&
|
|
|
|
$invoice->is_deleted == false &&
|
2020-06-15 01:34:18 +02:00
|
|
|
$invoice->deleted_at == null) {
|
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
|
|
|
}
|
|
|
|
}
|