2020-10-26 01:58:08 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
2022-06-06 00:49:41 +02:00
|
|
|
* Invoice Ninja (https://entityninja.com).
|
2020-10-26 01:58:08 +01:00
|
|
|
*
|
2022-06-06 00:49:41 +02:00
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
2020-10-26 01:58:08 +01:00
|
|
|
*
|
2022-06-06 00:49:41 +02:00
|
|
|
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
|
2020-10-26 01:58:08 +01:00
|
|
|
*
|
2021-06-16 08:58:16 +02:00
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
2020-10-26 01:58:08 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Jobs\Entity;
|
|
|
|
|
2021-04-12 06:36:51 +02:00
|
|
|
use App\Exceptions\FilePermissionsFailure;
|
2022-01-04 02:52:17 +01:00
|
|
|
use App\Libraries\MultiDB;
|
2021-03-17 02:04:54 +01:00
|
|
|
use App\Models\Account;
|
2020-10-26 05:06:58 +01:00
|
|
|
use App\Models\Credit;
|
|
|
|
use App\Models\CreditInvitation;
|
2020-10-26 01:58:08 +01:00
|
|
|
use App\Models\Design;
|
2020-10-26 05:06:58 +01:00
|
|
|
use App\Models\Invoice;
|
|
|
|
use App\Models\InvoiceInvitation;
|
2020-10-26 01:58:08 +01:00
|
|
|
use App\Models\Quote;
|
2020-10-26 05:06:58 +01:00
|
|
|
use App\Models\QuoteInvitation;
|
2021-01-15 03:02:55 +01:00
|
|
|
use App\Models\RecurringInvoice;
|
2020-10-26 05:06:58 +01:00
|
|
|
use App\Models\RecurringInvoiceInvitation;
|
2022-12-28 15:50:11 +01:00
|
|
|
use App\Services\Pdf\PdfService;
|
2020-10-26 01:58:08 +01:00
|
|
|
use App\Services\PdfMaker\Design as PdfDesignModel;
|
|
|
|
use App\Services\PdfMaker\Design as PdfMakerDesign;
|
|
|
|
use App\Services\PdfMaker\PdfMaker as PdfMakerService;
|
2021-03-18 01:53:08 +01:00
|
|
|
use App\Utils\HostedPDF\NinjaPdf;
|
2020-10-26 01:58:08 +01:00
|
|
|
use App\Utils\HtmlEngine;
|
2020-11-10 05:04:53 +01:00
|
|
|
use App\Utils\Ninja;
|
2020-10-26 01:58:08 +01:00
|
|
|
use App\Utils\PhantomJS\Phantom;
|
|
|
|
use App\Utils\Traits\MakesHash;
|
2020-10-26 05:06:58 +01:00
|
|
|
use App\Utils\Traits\MakesInvoiceHtml;
|
2020-10-26 01:58:08 +01:00
|
|
|
use App\Utils\Traits\NumberFormatter;
|
2022-05-25 08:34:43 +02:00
|
|
|
use App\Utils\Traits\Pdf\PageNumbering;
|
|
|
|
use App\Utils\Traits\Pdf\PDF;
|
2020-10-26 01:58:08 +01:00
|
|
|
use App\Utils\Traits\Pdf\PdfMaker;
|
|
|
|
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\Facades\App;
|
2020-11-10 05:04:53 +01:00
|
|
|
use Illuminate\Support\Facades\Lang;
|
2020-10-26 01:58:08 +01:00
|
|
|
use Illuminate\Support\Facades\Storage;
|
2022-05-25 08:34:43 +02:00
|
|
|
use setasign\Fpdi\PdfParser\StreamReader;
|
2020-10-26 01:58:08 +01:00
|
|
|
|
|
|
|
class CreateEntityPdf implements ShouldQueue
|
|
|
|
{
|
2022-12-28 15:50:11 +01:00
|
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
2020-10-26 01:58:08 +01:00
|
|
|
|
|
|
|
public $entity;
|
|
|
|
|
|
|
|
private $disk;
|
|
|
|
|
|
|
|
public $invitation;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new job instance.
|
|
|
|
*
|
2020-10-28 11:10:49 +01:00
|
|
|
* @param $invitation
|
2020-10-26 01:58:08 +01:00
|
|
|
*/
|
2022-06-13 01:33:40 +02:00
|
|
|
public function __construct($invitation, $disk = null)
|
2020-10-26 01:58:08 +01:00
|
|
|
{
|
|
|
|
|
2022-12-28 15:50:11 +01:00
|
|
|
$this->invitation = $invitation;
|
2021-07-07 13:39:49 +02:00
|
|
|
|
2022-06-21 11:57:17 +02:00
|
|
|
$this->disk = $disk ?? config('filesystems.default');
|
2022-12-28 15:50:11 +01:00
|
|
|
|
2020-10-26 01:58:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function handle()
|
|
|
|
{
|
2021-10-14 07:25:09 +02:00
|
|
|
|
2022-12-28 15:50:11 +01:00
|
|
|
$starttime = microtime(true);
|
2021-05-07 06:28:34 +02:00
|
|
|
|
2022-12-28 15:50:11 +01:00
|
|
|
MultiDB::setDb($this->invitation->company->db);
|
2020-12-11 09:54:40 +01:00
|
|
|
|
2022-12-28 15:50:11 +01:00
|
|
|
if ($this->invitation instanceof InvoiceInvitation) {
|
|
|
|
$this->entity = $this->invitation->invoice;
|
|
|
|
$path = $this->invitation->contact->client->invoice_filepath($this->invitation);
|
|
|
|
} elseif ($this->invitation instanceof QuoteInvitation) {
|
|
|
|
$this->entity = $this->invitation->quote;
|
|
|
|
$path = $this->invitation->contact->client->quote_filepath($this->invitation);
|
|
|
|
} elseif ($this->invitation instanceof CreditInvitation) {
|
|
|
|
$this->entity = $this->invitation->credit;
|
|
|
|
$path = $this->invitation->contact->client->credit_filepath($this->invitation);
|
|
|
|
} elseif ($this->invitation instanceof RecurringInvoiceInvitation) {
|
|
|
|
$this->entity = $this->invitation->recurring_invoice;
|
|
|
|
$path = $this->invitation->contact->client->recurring_invoice_filepath($this->invitation);
|
2020-10-26 01:58:08 +01:00
|
|
|
|
2020-10-26 10:13:00 +01:00
|
|
|
}
|
2020-10-26 01:58:08 +01:00
|
|
|
|
2021-03-17 12:29:20 +01:00
|
|
|
$file_path = $path.$this->entity->numberFormatter().'.pdf';
|
2022-12-28 15:50:11 +01:00
|
|
|
|
|
|
|
$pdf = (new PdfService($this->invitation))->getPdf();
|
|
|
|
|
|
|
|
$endtime = microtime(true);
|
|
|
|
nlog($endtime - $starttime);
|
2020-12-17 15:44:01 +01:00
|
|
|
|
2021-05-15 04:19:36 +02:00
|
|
|
if ($pdf) {
|
2022-06-21 11:57:17 +02:00
|
|
|
try {
|
2022-10-23 23:42:38 +02:00
|
|
|
Storage::disk($this->disk)->put($file_path, $pdf);
|
2022-06-21 11:57:17 +02:00
|
|
|
} catch (\Exception $e) {
|
2021-05-16 01:41:12 +02:00
|
|
|
throw new FilePermissionsFailure($e->getMessage());
|
2021-05-15 04:19:36 +02:00
|
|
|
}
|
|
|
|
}
|
2022-11-01 07:10:05 +01:00
|
|
|
|
2022-11-01 11:20:28 +01:00
|
|
|
|
2021-05-15 04:19:36 +02:00
|
|
|
return $file_path;
|
2020-10-26 01:58:08 +01:00
|
|
|
}
|
2020-12-13 11:33:30 +01:00
|
|
|
|
2021-01-08 02:44:31 +01:00
|
|
|
public function failed($e)
|
2020-12-13 11:33:30 +01:00
|
|
|
{
|
|
|
|
}
|
2020-10-26 01:58:08 +01:00
|
|
|
}
|