2020-02-03 11:33:07 +01:00
|
|
|
<?php
|
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
2020-02-03 11:33:07 +01: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-02-03 11:33:07 +01:00
|
|
|
*
|
|
|
|
* @license https://opensource.org/licenses/AAL
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Services\Invoice;
|
|
|
|
|
2020-02-17 10:37:44 +01:00
|
|
|
use App\Models\Client;
|
2020-02-03 11:33:07 +01:00
|
|
|
use App\Models\Invoice;
|
2020-02-17 10:37:44 +01:00
|
|
|
use App\Services\AbstractService;
|
2020-02-03 11:33:07 +01:00
|
|
|
use App\Utils\Traits\GeneratesCounter;
|
|
|
|
|
2020-02-17 10:37:44 +01:00
|
|
|
class ApplyNumber extends AbstractService
|
2020-02-03 11:33:07 +01:00
|
|
|
{
|
2020-03-21 06:37:30 +01:00
|
|
|
use GeneratesCounter;
|
2020-02-03 11:33:07 +01:00
|
|
|
|
|
|
|
private $client;
|
|
|
|
|
2020-02-17 10:37:44 +01:00
|
|
|
private $invoice;
|
|
|
|
|
|
|
|
public function __construct(Client $client, Invoice $invoice)
|
2020-02-03 11:33:07 +01:00
|
|
|
{
|
|
|
|
$this->client = $client;
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2020-02-17 10:37:44 +01:00
|
|
|
$this->invoice = $invoice;
|
2020-02-03 11:33:07 +01:00
|
|
|
}
|
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
public function run()
|
2020-02-14 04:32:22 +01:00
|
|
|
{
|
2020-03-21 06:37:30 +01:00
|
|
|
if ($this->invoice->number != '') {
|
2020-02-17 10:37:44 +01:00
|
|
|
return $this->invoice;
|
2020-03-21 06:37:30 +01:00
|
|
|
}
|
2020-02-03 11:33:07 +01:00
|
|
|
|
|
|
|
switch ($this->client->getSetting('counter_number_applied')) {
|
|
|
|
case 'when_saved':
|
2020-10-07 01:16:57 +02:00
|
|
|
$this->invoice->number = $this->getNextInvoiceNumber($this->client, $this->invoice);
|
2020-02-03 11:33:07 +01:00
|
|
|
break;
|
|
|
|
case 'when_sent':
|
2020-02-17 10:37:44 +01:00
|
|
|
if ($this->invoice->status_id == Invoice::STATUS_SENT) {
|
2020-10-07 01:16:57 +02:00
|
|
|
$this->invoice->number = $this->getNextInvoiceNumber($this->client, $this->invoice);
|
2020-02-03 11:33:07 +01:00
|
|
|
}
|
|
|
|
break;
|
2020-02-14 04:32:22 +01:00
|
|
|
|
2020-02-03 11:33:07 +01:00
|
|
|
default:
|
2020-09-06 11:38:10 +02:00
|
|
|
// code...
|
2020-02-03 11:33:07 +01:00
|
|
|
break;
|
|
|
|
}
|
2020-02-14 04:32:22 +01:00
|
|
|
|
2020-02-17 10:37:44 +01:00
|
|
|
return $this->invoice;
|
2020-02-14 04:32:22 +01:00
|
|
|
}
|
|
|
|
}
|