diff --git a/app/Http/Controllers/InvoiceController.php b/app/Http/Controllers/InvoiceController.php index cdbcfffb361e..26cf34d64788 100644 --- a/app/Http/Controllers/InvoiceController.php +++ b/app/Http/Controllers/InvoiceController.php @@ -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; diff --git a/app/Http/Controllers/PreviewController.php b/app/Http/Controllers/PreviewController.php index 7637e07572fd..f2fd5a8f46c7 100644 --- a/app/Http/Controllers/PreviewController.php +++ b/app/Http/Controllers/PreviewController.php @@ -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; diff --git a/app/Jobs/Entity/CreateEntityPdf.php b/app/Jobs/Entity/CreateEntityPdf.php index 5b7ea22278c9..5363ab986b47 100644 --- a/app/Jobs/Entity/CreateEntityPdf.php +++ b/app/Jobs/Entity/CreateEntityPdf.php @@ -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 = [ diff --git a/app/Listeners/Invoice/CreateInvoicePdf.php b/app/Listeners/Invoice/CreateInvoicePdf.php index 824006fe6dc1..d7a434579326 100644 --- a/app/Listeners/Invoice/CreateInvoicePdf.php +++ b/app/Listeners/Invoice/CreateInvoicePdf.php @@ -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); }); } } diff --git a/app/Models/Credit.php b/app/Models/Credit.php index 4c1a0ef25998..f1517bb654ba 100644 --- a/app/Models/Credit.php +++ b/app/Models/Credit.php @@ -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; diff --git a/app/Models/CreditInvitation.php b/app/Models/CreditInvitation.php index 7cc5df13d891..02f5428c7ef4 100644 --- a/app/Models/CreditInvitation.php +++ b/app/Models/CreditInvitation.php @@ -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; diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index 2da78e574a7f..ab691bc89adb 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -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; diff --git a/app/Models/InvoiceInvitation.php b/app/Models/InvoiceInvitation.php index 4b27681c2ca5..f2ec53dd19fc 100644 --- a/app/Models/InvoiceInvitation.php +++ b/app/Models/InvoiceInvitation.php @@ -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; diff --git a/app/Models/Quote.php b/app/Models/Quote.php index 5ee3026c4345..caed1e3fd3c1 100644 --- a/app/Models/Quote.php +++ b/app/Models/Quote.php @@ -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; } diff --git a/app/Models/QuoteInvitation.php b/app/Models/QuoteInvitation.php index 78b1ae7e4cc4..d46e1ce901f7 100644 --- a/app/Models/QuoteInvitation.php +++ b/app/Models/QuoteInvitation.php @@ -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; diff --git a/app/Services/Credit/GetCreditPdf.php b/app/Services/Credit/GetCreditPdf.php index 32657e07afe2..edf3462f6695 100644 --- a/app/Services/Credit/GetCreditPdf.php +++ b/app/Services/Credit/GetCreditPdf.php @@ -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); diff --git a/app/Services/Invoice/AutoBillInvoice.php b/app/Services/Invoice/AutoBillInvoice.php index 582f4f60fbea..48d9742a2aa6 100644 --- a/app/Services/Invoice/AutoBillInvoice.php +++ b/app/Services/Invoice/AutoBillInvoice.php @@ -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; diff --git a/app/Services/Invoice/GetInvoicePdf.php b/app/Services/Invoice/GetInvoicePdf.php index 6dba525fb1f1..ff43cfdcc7c6 100644 --- a/app/Services/Invoice/GetInvoicePdf.php +++ b/app/Services/Invoice/GetInvoicePdf.php @@ -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); diff --git a/app/Services/Quote/GetQuotePdf.php b/app/Services/Quote/GetQuotePdf.php index 2625679c5b38..22e588dd6a0b 100644 --- a/app/Services/Quote/GetQuotePdf.php +++ b/app/Services/Quote/GetQuotePdf.php @@ -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); diff --git a/app/Utils/HtmlEngine.php b/app/Utils/HtmlEngine.php index 401a173d55ce..70b64c15d2e6 100644 --- a/app/Utils/HtmlEngine.php +++ b/app/Utils/HtmlEngine.php @@ -41,7 +41,7 @@ class HtmlEngine public $designer; public function __construct($designer, $invitation, $entity_string) - { + {info($entity_string); $this->designer = $designer; $this->invitation = $invitation;