1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-11 05:32:39 +01:00
invoiceninja/app/Jobs/Invoice/ApplyInvoiceNumber.php
David Bomba a78b6aaacd
Set casts on Invoice Line Items (#3049)
* Implement client/group/company level counters clientCounter, groupCounter and counter

* Implement functionalityfor customising the timing of invoice_number creation

* Add Jobs

* adjustments

* clean line items at the request layer

* Clean line items at the request layer
2019-11-08 11:38:22 +11:00

82 lines
1.9 KiB
PHP

<?php
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2019. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Jobs\Invoice;
use App\Models\Invoice;
use App\Models\Payment;
use App\Models\PaymentTerm;
use App\Repositories\InvoiceRepository;
use App\Utils\Traits\GeneratesCounter;
use App\Utils\Traits\NumberFormatter;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Carbon;
class ApplyInvoiceNumber implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, NumberFormatter, GeneratesCounter;
public $invoice;
public $settings;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct(Invoice $invoice, $settings)
{
$this->invoice = $invoice;
$this->settings = $settings;
}
/**
* Execute the job.
*
*
* @return void
*/
public function handle()
{
//return early
if($this->invoice->invoice_number != '')
return $this->invoice;
switch ($this->settings->counter_number_applied) {
case 'when_saved':
$this->invoice->invoice_number = $this->getNextInvoiceNumber($this->invoice->client);
break;
case 'when_sent':
if($this->invoice->status_id == Invoice::STATUS_SENT)
$this->invoice->invoice_number = $this->getNextInvoiceNumber($this->invoice->client);
break;
default:
# code...
break;
}
$this->invoice->save();
return $this->invoice;
}
}