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
|
|
|
|
*
|
2024-04-12 06:15:41 +02:00
|
|
|
* @copyright Copyright (c) 2024. Invoice Ninja LLC (https://invoiceninja.com)
|
2020-04-06 14:32:27 +02:00
|
|
|
*
|
2021-06-16 08:58:16 +02:00
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
2020-04-06 14:32:27 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
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
|
|
|
|
{
|
2024-01-14 05:05:00 +01: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
|
|
|
}
|
|
|
|
|
2024-01-14 05:05:00 +01: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
|
|
|
}
|
|
|
|
|
2024-01-14 05:05:00 +01: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
|
|
|
}
|
|
|
|
}
|