2019-12-22 11:28:41 +01:00
|
|
|
<?php
|
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* Quote Ninja (https://invoiceninja.com).
|
2019-12-22 11:28:41 +01:00
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2021-01-03 22:54:54 +01:00
|
|
|
* @copyright Copyright (c) 2021. Quote Ninja LLC (https://invoiceninja.com)
|
2019-12-22 11:28:41 +01:00
|
|
|
*
|
|
|
|
* @license https://opensource.org/licenses/AAL
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Jobs\Quote;
|
|
|
|
|
2019-12-27 01:28:36 +01:00
|
|
|
use App\Libraries\MultiDB;
|
|
|
|
use App\Models\Company;
|
|
|
|
use App\Models\Quote;
|
2019-12-22 11:28:41 +01:00
|
|
|
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;
|
|
|
|
|
|
|
|
class ApplyQuoteNumber implements ShouldQueue
|
|
|
|
{
|
|
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, NumberFormatter, GeneratesCounter;
|
|
|
|
|
|
|
|
private $quote;
|
|
|
|
|
|
|
|
private $settings;
|
|
|
|
|
2019-12-27 01:28:36 +01:00
|
|
|
private $company;
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2019-12-22 11:28:41 +01:00
|
|
|
/**
|
|
|
|
* Create a new job instance.
|
|
|
|
*
|
2020-10-28 11:10:49 +01:00
|
|
|
* @param Quote $quote
|
|
|
|
* @param $settings
|
|
|
|
* @param Company $company
|
2019-12-22 11:28:41 +01:00
|
|
|
*/
|
2019-12-27 01:28:36 +01:00
|
|
|
public function __construct(Quote $quote, $settings, Company $company)
|
2019-12-22 11:28:41 +01:00
|
|
|
{
|
|
|
|
$this->quote = $quote;
|
|
|
|
|
|
|
|
$this->settings = $settings;
|
2019-12-27 01:28:36 +01:00
|
|
|
|
|
|
|
$this->company = $company;
|
2019-12-22 11:28:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute the job.
|
|
|
|
*
|
2019-12-30 22:59:12 +01:00
|
|
|
*
|
2020-10-28 11:10:49 +01:00
|
|
|
* @return Quote
|
2019-12-22 11:28:41 +01:00
|
|
|
*/
|
|
|
|
public function handle()
|
|
|
|
{
|
2019-12-27 01:28:36 +01:00
|
|
|
MultiDB::setDB($this->company->db);
|
|
|
|
|
2019-12-22 11:28:41 +01:00
|
|
|
//return early
|
2019-12-30 22:59:12 +01:00
|
|
|
if ($this->quote->number != '') {
|
2019-12-22 11:28:41 +01:00
|
|
|
return $this->quote;
|
2019-12-30 22:59:12 +01:00
|
|
|
}
|
2019-12-22 11:28:41 +01:00
|
|
|
|
|
|
|
switch ($this->settings->quote_number_applied) {
|
|
|
|
case 'when_saved':
|
|
|
|
$this->quote->number = $this->getNextQuoteNumber($this->quote->client);
|
|
|
|
break;
|
|
|
|
case 'when_sent':
|
2019-12-30 22:59:12 +01:00
|
|
|
if ($this->quote->status_id == Quote::STATUS_SENT) {
|
2019-12-22 11:28:41 +01:00
|
|
|
$this->quote->number = $this->getNextQuoteNumber($this->quote->client);
|
2019-12-30 22:59:12 +01:00
|
|
|
}
|
2019-12-22 11:28:41 +01:00
|
|
|
break;
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2019-12-22 11:28:41 +01:00
|
|
|
default:
|
2020-09-06 11:38:10 +02:00
|
|
|
// code...
|
2019-12-22 11:28:41 +01:00
|
|
|
break;
|
|
|
|
}
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2019-12-22 11:28:41 +01:00
|
|
|
$this->quote->save();
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2019-12-22 11:28:41 +01:00
|
|
|
return $this->quote;
|
|
|
|
}
|
|
|
|
}
|