mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Refactor pdf generation
This commit is contained in:
parent
651a1a6cbe
commit
8d508bb1f9
@ -28,7 +28,6 @@ use App\Http\Requests\Invoice\EditInvoiceRequest;
|
||||
use App\Http\Requests\Invoice\ShowInvoiceRequest;
|
||||
use App\Http\Requests\Invoice\StoreInvoiceRequest;
|
||||
use App\Http\Requests\Invoice\UpdateInvoiceRequest;
|
||||
use App\Jobs\Invoice\CreateInvoicePdf;
|
||||
use App\Jobs\Invoice\EmailInvoice;
|
||||
use App\Jobs\Invoice\StoreInvoice;
|
||||
use App\Jobs\Invoice\ZipInvoices;
|
||||
|
@ -14,7 +14,6 @@ namespace App\Http\Controllers;
|
||||
use App\Designs\Custom;
|
||||
use App\Designs\Designer;
|
||||
use App\Factory\InvoiceFactory;
|
||||
use App\Jobs\Invoice\CreateInvoicePdf;
|
||||
use App\Jobs\Util\PreviewPdf;
|
||||
use App\Models\Client;
|
||||
use App\Models\ClientContact;
|
||||
|
@ -18,16 +18,22 @@ use App\Designs\Modern;
|
||||
use App\Libraries\MultiDB;
|
||||
use App\Models\ClientContact;
|
||||
use App\Models\Company;
|
||||
use App\Models\Credit;
|
||||
use App\Models\CreditInvitation;
|
||||
use App\Models\Design;
|
||||
use App\Models\Entity;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\InvoiceInvitation;
|
||||
use App\Models\Quote;
|
||||
use App\Models\QuoteInvitation;
|
||||
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;
|
||||
use App\Utils\HtmlEngine;
|
||||
use App\Utils\PhantomJS\Phantom;
|
||||
use App\Utils\Traits\MakesEntityHtml;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
use App\Utils\Traits\MakesInvoiceHtml;
|
||||
use App\Utils\Traits\NumberFormatter;
|
||||
use App\Utils\Traits\Pdf\PdfMaker;
|
||||
use Illuminate\Bus\Queueable;
|
||||
@ -41,7 +47,7 @@ use Spatie\Browsershot\Browsershot;
|
||||
|
||||
class CreateEntityPdf implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, NumberFormatter, MakesEntityHtml, PdfMaker, MakesHash;
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels, NumberFormatter, MakesInvoiceHtml, PdfMaker, MakesHash;
|
||||
|
||||
public $entity;
|
||||
|
||||
@ -53,6 +59,8 @@ class CreateEntityPdf implements ShouldQueue
|
||||
|
||||
public $invitation;
|
||||
|
||||
public $entity_string = '';
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
@ -62,12 +70,22 @@ class CreateEntityPdf implements ShouldQueue
|
||||
{
|
||||
$this->invitation = $invitation;
|
||||
|
||||
if($invitation->invoice)
|
||||
if($invitation instanceof InvoiceInvitation){
|
||||
$this->entity = $invitation->invoice;
|
||||
elseif($invitation->quote)
|
||||
$this->entity_string = 'invoice';
|
||||
}
|
||||
elseif($invitation instanceof QuoteInvitation){
|
||||
$this->entity = $invitation->quote;
|
||||
elseif($invitation->credit))
|
||||
$this->entity_string = 'quote';
|
||||
}
|
||||
elseif($invitation instanceof CreditInvitation){
|
||||
$this->entity = $invitation->credit;
|
||||
$this->entity_string = 'credit';
|
||||
}
|
||||
elseif($invitation instanceof RecurringInvoiceInvitation){
|
||||
$this->entity = $invitation->recurring_invoice;
|
||||
$this->entity_string = 'recurring_invoice';
|
||||
}
|
||||
|
||||
$this->company = $invitation->company;
|
||||
|
||||
@ -94,10 +112,12 @@ class CreateEntityPdf implements ShouldQueue
|
||||
|
||||
$file_path = $path.$this->entity->number.'.pdf';
|
||||
|
||||
info($file_path);
|
||||
|
||||
$entity_design_id = $this->entity->design_id ? $this->entity->design_id : $this->decodePrimaryKey($this->entity->client->getSetting('invoice_design_id'));
|
||||
|
||||
$design = Design::find($entity_design_id);
|
||||
$html = new HtmlEngine(null, $this->invitation, 'entity');
|
||||
$html = new HtmlEngine(null, $this->invitation, $this->entity_string);
|
||||
|
||||
if ($design->is_custom) {
|
||||
$options = [
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
namespace App\Listeners\Invoice;
|
||||
|
||||
use App\Jobs\Entity\CreateEntityPdf;
|
||||
use App\Jobs\Invoice\CreateInvoicePdf as PdfCreator;
|
||||
use App\Libraries\MultiDB;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
@ -38,7 +39,7 @@ class CreateInvoicePdf implements ShouldQueue
|
||||
MultiDB::setDb($event->company->db);
|
||||
|
||||
$event->invoice->invitations->each(function ($invitation) {
|
||||
PdfCreator::dispatch($invitation);
|
||||
CreateEntityPdf::dispatch($invitation);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ namespace App\Models;
|
||||
use App\Events\Credit\CreditWasUpdated;
|
||||
use App\Helpers\Invoice\InvoiceSum;
|
||||
use App\Helpers\Invoice\InvoiceSumInclusive;
|
||||
use App\Jobs\Credit\CreateCreditPdf;
|
||||
use App\Jobs\Entity\CreateEntityPdf;
|
||||
use App\Models\Filterable;
|
||||
use App\Services\Credit\CreditService;
|
||||
use App\Services\Ledger\LedgerService;
|
||||
@ -244,10 +244,10 @@ class Credit extends BaseModel
|
||||
|
||||
if (! $invitation) {
|
||||
event(new CreditWasUpdated($this, $this->company, Ninja::eventVars()));
|
||||
CreateCreditPdf::dispatchNow($this, $this->company, $this->client->primary_contact()->first());
|
||||
CreateEntityPdf::dispatchNow($this, $this->company, $this->client->primary_contact()->first());
|
||||
} else {
|
||||
event(new CreditWasUpdated($this, $this->company, Ninja::eventVars()));
|
||||
CreateCreditPdf::dispatchNow($invitation->credit, $invitation->company, $invitation->contact);
|
||||
CreateEntityPdf::dispatchNow($invitation->credit, $invitation->company, $invitation->contact);
|
||||
}
|
||||
|
||||
return $storage_path;
|
||||
|
@ -12,7 +12,7 @@
|
||||
namespace App\Models;
|
||||
|
||||
use App\Events\Credit\CreditWasUpdated;
|
||||
use App\Jobs\Credit\CreateCreditPdf;
|
||||
use App\Jobs\Entity\CreateEntityPdf;
|
||||
use App\Models\Invoice;
|
||||
use App\Utils\Ninja;
|
||||
use App\Utils\Traits\Inviteable;
|
||||
@ -131,7 +131,7 @@ class CreditInvitation extends BaseModel
|
||||
|
||||
if (! Storage::exists($this->credit->client->credit_filepath().$this->credit->number.'.pdf')) {
|
||||
event(new CreditWasUpdated($this, $this->company, Ninja::eventVars()));
|
||||
CreateCreditPdf::dispatchNow($this);
|
||||
CreateEntityPdf::dispatchNow($this);
|
||||
}
|
||||
|
||||
return $storage_path;
|
||||
|
@ -18,6 +18,7 @@ use App\Helpers\Invoice\InvoiceSum;
|
||||
use App\Helpers\Invoice\InvoiceSumInclusive;
|
||||
use App\Jobs\Client\UpdateClientBalance;
|
||||
use App\Jobs\Company\UpdateCompanyLedgerWithInvoice;
|
||||
use App\Jobs\Entity\CreateEntityPdf;
|
||||
use App\Jobs\Invoice\CreateInvoicePdf;
|
||||
use App\Models\Backup;
|
||||
use App\Models\CompanyLedger;
|
||||
@ -29,8 +30,8 @@ use App\Services\Ledger\LedgerService;
|
||||
use App\Utils\Ninja;
|
||||
use App\Utils\Number;
|
||||
use App\Utils\Traits\Archivable;
|
||||
use App\Utils\Traits\Invoice\ActionsInvoice;
|
||||
use App\Utils\Traits\InvoiceEmailBuilder;
|
||||
use App\Utils\Traits\Invoice\ActionsInvoice;
|
||||
use App\Utils\Traits\MakesDates;
|
||||
use App\Utils\Traits\MakesInvoiceValues;
|
||||
use App\Utils\Traits\MakesReminders;
|
||||
@ -395,7 +396,8 @@ class Invoice extends BaseModel
|
||||
|
||||
if (! Storage::exists($this->client->invoice_filepath().$this->number.'.pdf')) {
|
||||
event(new InvoiceWasUpdated($this, $this->company, Ninja::eventVars()));
|
||||
CreateInvoicePdf::dispatchNow($invitation);
|
||||
//CreateInvoicePdf::dispatchNow($invitation);
|
||||
CreateEntityPdf::dispatchNow($invitation);
|
||||
}
|
||||
|
||||
return $storage_path;
|
||||
|
@ -12,6 +12,7 @@
|
||||
namespace App\Models;
|
||||
|
||||
use App\Events\Invoice\InvoiceWasUpdated;
|
||||
use App\Jobs\Entity\CreateEntityPdf;
|
||||
use App\Jobs\Invoice\CreateInvoicePdf;
|
||||
use App\Models\Invoice;
|
||||
use App\Utils\Ninja;
|
||||
@ -144,7 +145,7 @@ class InvoiceInvitation extends BaseModel
|
||||
|
||||
if (! Storage::exists($this->invoice->client->invoice_filepath().$this->invoice->number.'.pdf')) {
|
||||
event(new InvoiceWasUpdated($this->invoice, $this->company, Ninja::eventVars()));
|
||||
CreateInvoicePdf::dispatchNow($this);
|
||||
CreateEntityPdf::dispatchNow($this);
|
||||
}
|
||||
|
||||
return $storage_path;
|
||||
|
@ -14,8 +14,7 @@ namespace App\Models;
|
||||
use App\Events\Quote\QuoteWasUpdated;
|
||||
use App\Helpers\Invoice\InvoiceSum;
|
||||
use App\Helpers\Invoice\InvoiceSumInclusive;
|
||||
use App\Jobs\Invoice\CreateInvoicePdf;
|
||||
use App\Jobs\Quote\CreateQuotePdf;
|
||||
use App\Jobs\Entity\CreateEntityPdf;
|
||||
use App\Models\Filterable;
|
||||
use App\Services\Quote\QuoteService;
|
||||
use App\Utils\Ninja;
|
||||
@ -206,7 +205,7 @@ class Quote extends BaseModel
|
||||
|
||||
event(new QuoteWasUpdated($this, $this->company, Ninja::eventVars()));
|
||||
|
||||
CreateQuotePdf::dispatchNow($invitation);
|
||||
CreateEntityPdf::dispatchNow($invitation);
|
||||
|
||||
return $storage_path;
|
||||
}
|
||||
|
@ -12,7 +12,7 @@
|
||||
namespace App\Models;
|
||||
|
||||
use App\Events\Quote\QuoteWasUpdated;
|
||||
use App\Jobs\Quote\CreateQuotePdf;
|
||||
use App\Jobs\Entity\CreateEntityPdf;
|
||||
use App\Models\Quote;
|
||||
use App\Utils\Ninja;
|
||||
use App\Utils\Traits\Inviteable;
|
||||
@ -135,7 +135,7 @@ class QuoteInvitation extends BaseModel
|
||||
|
||||
if (! Storage::exists($this->quote->client->quote_filepath().$this->quote->number.'.pdf')) {
|
||||
event(new QuoteWasUpdated($this->quote, $this->company, Ninja::eventVars()));
|
||||
CreateQuotePdf::dispatchNow($this);
|
||||
CreateEntityPdf::dispatchNow($this);
|
||||
}
|
||||
|
||||
return $storage_path;
|
||||
|
@ -11,7 +11,8 @@
|
||||
|
||||
namespace App\Services\Credit;
|
||||
|
||||
use App\Jobs\Credit\CreateCreditPdf;
|
||||
use App\Jobs\Credit\CreateEntityPdf;
|
||||
use App\Jobs\Entity\CreateEntityPdf;
|
||||
use App\Jobs\Invoice\CreateInvoicePdf;
|
||||
use App\Models\ClientContact;
|
||||
use App\Models\Credit;
|
||||
@ -45,7 +46,7 @@ class GetCreditPdf extends AbstractService
|
||||
$file = Storage::disk($disk)->exists($file_path);
|
||||
|
||||
if (! $file) {
|
||||
$file_path = CreateCreditPdf::dispatchNow($this->credit, $this->credit->company, $this->contact);
|
||||
$file_path = CreateEntityPdf::dispatchNow($this->credit, $this->credit->company, $this->contact);
|
||||
}
|
||||
|
||||
return Storage::disk($disk)->path($file_path);
|
||||
|
@ -19,6 +19,7 @@ use App\Models\Credit;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\Payment;
|
||||
use App\Models\PaymentHash;
|
||||
use App\Models\PaymentType;
|
||||
use App\Services\AbstractService;
|
||||
use App\Services\Client\ClientService;
|
||||
use App\Services\Payment\PaymentService;
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
namespace App\Services\Invoice;
|
||||
|
||||
use App\Jobs\Entity\CreateEntityPdf;
|
||||
use App\Jobs\Invoice\CreateInvoicePdf;
|
||||
use App\Models\ClientContact;
|
||||
use App\Models\Invoice;
|
||||
@ -43,7 +44,7 @@ class GetInvoicePdf extends AbstractService
|
||||
$file = Storage::disk($disk)->exists($file_path);
|
||||
|
||||
if (! $file) {
|
||||
$file_path = CreateInvoicePdf::dispatchNow($invitation);
|
||||
$file_path = CreateEntityPdf::dispatchNow($invitation);
|
||||
}
|
||||
|
||||
return Storage::disk($disk)->path($file_path);
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
namespace App\Services\Quote;
|
||||
|
||||
use App\Jobs\Entity\CreateEntityPdf;
|
||||
use App\Jobs\Quote\CreateQuotePdf;
|
||||
use App\Models\ClientContact;
|
||||
use App\Models\Quote;
|
||||
@ -43,7 +44,7 @@ class GetQuotePdf extends AbstractService
|
||||
$file = Storage::disk($disk)->exists($file_path);
|
||||
|
||||
if (! $file) {
|
||||
$file_path = CreateQuotePdf::dispatchNow($invitation);
|
||||
$file_path = CreateEntityPdf::dispatchNow($invitation);
|
||||
}
|
||||
|
||||
return Storage::disk($disk)->path($file_path);
|
||||
|
@ -41,7 +41,7 @@ class HtmlEngine
|
||||
public $designer;
|
||||
|
||||
public function __construct($designer, $invitation, $entity_string)
|
||||
{
|
||||
{info($entity_string);
|
||||
$this->designer = $designer;
|
||||
|
||||
$this->invitation = $invitation;
|
||||
|
Loading…
x
Reference in New Issue
Block a user