2022-06-06 00:49:41 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
|
|
|
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
|
|
|
|
*
|
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Jobs\Vendor;
|
|
|
|
|
|
|
|
use App\Exceptions\FilePermissionsFailure;
|
|
|
|
use App\Libraries\MultiDB;
|
|
|
|
use App\Models\Account;
|
|
|
|
use App\Models\Credit;
|
|
|
|
use App\Models\CreditInvitation;
|
|
|
|
use App\Models\Design;
|
|
|
|
use App\Models\Invoice;
|
|
|
|
use App\Models\InvoiceInvitation;
|
|
|
|
use App\Models\Quote;
|
|
|
|
use App\Models\QuoteInvitation;
|
|
|
|
use App\Models\RecurringInvoice;
|
|
|
|
use App\Models\RecurringInvoiceInvitation;
|
|
|
|
use App\Services\PdfMaker\Design as PdfDesignModel;
|
|
|
|
use App\Services\PdfMaker\Design as PdfMakerDesign;
|
|
|
|
use App\Services\PdfMaker\PdfMaker as PdfMakerService;
|
2023-01-08 06:15:04 +01:00
|
|
|
use App\Services\Pdf\PdfService;
|
2022-06-06 00:49:41 +02:00
|
|
|
use App\Utils\HostedPDF\NinjaPdf;
|
|
|
|
use App\Utils\HtmlEngine;
|
|
|
|
use App\Utils\Ninja;
|
|
|
|
use App\Utils\PhantomJS\Phantom;
|
|
|
|
use App\Utils\Traits\MakesHash;
|
|
|
|
use App\Utils\Traits\MakesInvoiceHtml;
|
|
|
|
use App\Utils\Traits\NumberFormatter;
|
|
|
|
use App\Utils\Traits\Pdf\PDF;
|
2022-06-06 05:28:10 +02:00
|
|
|
use App\Utils\Traits\Pdf\PageNumbering;
|
2022-06-06 00:49:41 +02:00
|
|
|
use App\Utils\Traits\Pdf\PdfMaker;
|
2022-06-06 05:28:10 +02:00
|
|
|
use App\Utils\VendorHtmlEngine;
|
2022-06-06 00:49:41 +02:00
|
|
|
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;
|
|
|
|
use Illuminate\Support\Facades\Lang;
|
|
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
use setasign\Fpdi\PdfParser\StreamReader;
|
|
|
|
|
|
|
|
class CreatePurchaseOrderPdf implements ShouldQueue
|
|
|
|
{
|
2023-01-08 06:15:04 +01:00
|
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
2022-06-06 00:49:41 +02:00
|
|
|
|
|
|
|
public $entity;
|
|
|
|
|
|
|
|
private $disk;
|
|
|
|
|
|
|
|
public $invitation;
|
|
|
|
|
2022-06-30 05:32:44 +02:00
|
|
|
|
2022-06-06 00:49:41 +02:00
|
|
|
/**
|
|
|
|
* Create a new job instance.
|
|
|
|
*
|
|
|
|
* @param $invitation
|
|
|
|
*/
|
2022-06-14 14:18:20 +02:00
|
|
|
public function __construct($invitation, $disk = null)
|
2022-06-06 00:49:41 +02:00
|
|
|
{
|
|
|
|
$this->invitation = $invitation;
|
2022-06-06 14:27:17 +02:00
|
|
|
|
2022-06-06 00:49:41 +02:00
|
|
|
$this->entity = $invitation->purchase_order;
|
|
|
|
|
|
|
|
$this->vendor = $invitation->contact->vendor;
|
|
|
|
|
2022-06-14 14:18:20 +02:00
|
|
|
$this->disk = $disk ?? config('filesystems.default');
|
2022-06-06 00:49:41 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public function handle()
|
2022-06-29 03:47:16 +02:00
|
|
|
{
|
|
|
|
|
2023-01-08 06:15:04 +01:00
|
|
|
MultiDB::setDb($this->invitation->company->db);
|
2022-06-06 00:49:41 +02:00
|
|
|
|
2023-01-08 06:15:04 +01:00
|
|
|
$file_path = $this->vendor->purchase_order_filepath($this->invitation);
|
2022-06-06 00:49:41 +02:00
|
|
|
|
2023-01-08 06:15:04 +01:00
|
|
|
$pdf = (new PdfService($this->invitation, 'purchase_order'))->getPdf();
|
2022-06-06 00:49:41 +02:00
|
|
|
|
2023-01-08 06:15:04 +01:00
|
|
|
if ($pdf) {
|
|
|
|
try {
|
|
|
|
Storage::disk($this->disk)->put($file_path, $pdf);
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
throw new FilePermissionsFailure($e->getMessage());
|
2022-06-06 00:49:41 +02:00
|
|
|
}
|
|
|
|
}
|
2022-11-01 11:20:28 +01:00
|
|
|
|
2022-06-29 03:47:16 +02:00
|
|
|
return $pdf;
|
2022-06-06 00:49:41 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public function failed($e)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|