2019-11-05 23:52:57 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com)
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2020-01-07 01:13:47 +01:00
|
|
|
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
|
2019-11-05 23:52:57 +01:00
|
|
|
*
|
|
|
|
* @license https://opensource.org/licenses/AAL
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Jobs\Invoice;
|
|
|
|
|
2020-02-17 21:07:32 +01:00
|
|
|
use App\Designs\Custom;
|
2020-02-05 11:28:56 +01:00
|
|
|
use App\Designs\Designer;
|
|
|
|
use App\Designs\Modern;
|
2019-12-27 01:28:36 +01:00
|
|
|
use App\Libraries\MultiDB;
|
2020-02-10 10:53:02 +01:00
|
|
|
use App\Models\ClientContact;
|
2019-12-27 01:28:36 +01:00
|
|
|
use App\Models\Company;
|
2020-02-17 21:07:32 +01:00
|
|
|
use App\Models\Design;
|
2019-11-05 23:52:57 +01:00
|
|
|
use App\Models\Invoice;
|
2020-04-16 10:41:25 +02:00
|
|
|
use App\Utils\HtmlEngine;
|
2020-03-06 13:18:32 +01:00
|
|
|
use App\Utils\Traits\MakesHash;
|
2019-11-20 06:41:49 +01:00
|
|
|
use App\Utils\Traits\MakesInvoiceHtml;
|
2019-12-27 01:28:36 +01:00
|
|
|
use App\Utils\Traits\NumberFormatter;
|
2020-03-06 13:18:32 +01:00
|
|
|
use App\Utils\Traits\Pdf\PdfMaker;
|
2019-11-05 23:52:57 +01:00
|
|
|
use Illuminate\Bus\Queueable;
|
|
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
|
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
|
|
use Illuminate\Queue\SerializesModels;
|
2020-02-10 10:53:02 +01:00
|
|
|
use Illuminate\Support\Facades\App;
|
2019-11-05 23:52:57 +01:00
|
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
use Spatie\Browsershot\Browsershot;
|
2020-02-10 10:53:02 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
class CreateInvoicePdf implements ShouldQueue
|
|
|
|
{
|
|
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, NumberFormatter, MakesInvoiceHtml, PdfMaker, MakesHash;
|
2020-02-12 10:18:56 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
public $invoice;
|
2020-02-10 10:53:02 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
public $company;
|
2020-02-10 10:53:02 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
public $contact;
|
2020-02-10 10:53:02 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
private $disk;
|
2020-02-12 01:41:17 +01:00
|
|
|
|
2020-04-16 10:41:25 +02:00
|
|
|
public $invitation;
|
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
/**
|
|
|
|
* Create a new job instance.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2020-04-16 10:41:25 +02:00
|
|
|
public function __construct($invitation)
|
2020-03-21 06:37:30 +01:00
|
|
|
{
|
2020-04-16 10:41:25 +02:00
|
|
|
$this->invitation = $invitation;
|
|
|
|
|
|
|
|
$this->invoice = $invitation->invoice;
|
2020-02-12 10:18:56 +01:00
|
|
|
|
2020-04-16 10:41:25 +02:00
|
|
|
$this->company = $invitation->company;
|
2020-02-12 01:41:17 +01:00
|
|
|
|
2020-04-16 10:41:25 +02:00
|
|
|
$this->contact = $invitation->contact;
|
2020-02-12 01:41:17 +01:00
|
|
|
|
|
|
|
$this->disk = $disk ?? config('filesystems.default');
|
2020-03-21 06:37:30 +01:00
|
|
|
}
|
2020-02-12 01:41:17 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
public function handle()
|
2020-04-17 12:13:19 +02:00
|
|
|
{
|
2020-03-21 06:37:30 +01:00
|
|
|
App::setLocale($this->contact->preferredLocale());
|
2020-02-17 21:07:32 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$path = $this->invoice->client->invoice_filepath();
|
2020-02-10 10:53:02 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$file_path = $path . $this->invoice->number . '.pdf';
|
|
|
|
|
2020-04-10 07:07:36 +02:00
|
|
|
$design = Design::find($this->decodePrimaryKey($this->invoice->client->getSetting('invoice_design_id')));
|
2020-03-07 07:31:26 +01:00
|
|
|
|
2020-04-10 07:07:36 +02:00
|
|
|
$designer = new Designer($this->invoice, $design, $this->invoice->client->getSetting('pdf_variables'), 'invoice');
|
2020-02-10 10:53:02 +01:00
|
|
|
|
2020-04-16 10:41:25 +02:00
|
|
|
$html = (new HtmlEngine($designer, $this->invitation, 'invoice'))->build();
|
2020-02-10 10:53:02 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
//todo - move this to the client creation stage so we don't keep hitting this unnecessarily
|
|
|
|
Storage::makeDirectory($path, 0755);
|
2020-02-12 01:41:17 +01:00
|
|
|
|
2020-04-10 07:07:36 +02:00
|
|
|
$pdf = $this->makePdf(null, null, $html);
|
2020-02-10 10:53:02 +01:00
|
|
|
|
2020-04-10 07:07:36 +02:00
|
|
|
$instance = Storage::disk($this->disk)->put($file_path, $pdf);
|
2020-02-19 21:44:12 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
return $file_path;
|
|
|
|
}
|
2019-11-05 23:52:57 +01:00
|
|
|
}
|