diff --git a/app/Http/Livewire/PdfSlot.php b/app/Http/Livewire/PdfSlot.php index 8c8770eb12..306fcf961c 100644 --- a/app/Http/Livewire/PdfSlot.php +++ b/app/Http/Livewire/PdfSlot.php @@ -12,6 +12,7 @@ namespace App\Http\Livewire; +use App\Services\Invoice\GetInvoiceEInvoice; use App\Utils\Number; use Livewire\Component; use App\Utils\HtmlEngine; @@ -38,7 +39,7 @@ class PdfSlot extends Component public $pdf; public $url; - + private $settings; private $html_variables; @@ -61,7 +62,7 @@ class PdfSlot extends Component } public function getPdf() - { + { // $this->pdf = $this->entity->fullscreenPdfViewer($this->invitation); $blob = [ @@ -74,14 +75,14 @@ class PdfSlot extends Component $hash = Str::random(64); Cache::put($hash, $blob, now()->addMinutes(2)); - + $this->pdf = $hash; } public function downloadPdf() { - + $file_name = $this->entity->numberFormatter().'.pdf'; if($this->entity instanceof \App\Models\PurchaseOrder) @@ -95,11 +96,25 @@ class PdfSlot extends Component echo $file; }, $file_name, $headers); + } + public function downloadEInvoice() + { + + $file_name = $this->entity->numberFormatter().'.xml'; + + $file = (new GetInvoiceEInvoice($this->entity))->run(); + + $headers = ['Content-Type' => 'application/xml']; + + return response()->streamDownload(function () use ($file) { + echo $file; + }, $file_name, $headers); + } public function render() { - + $this->entity_type = $this->resolveEntityType(); $this->settings = $this->entity->client ? $this->entity->client->getMergedSettings() : $this->entity->company->settings; @@ -146,7 +161,7 @@ class PdfSlot extends Component private function getCompanyAddress() { - + $company_address = ""; foreach($this->settings->pdf_variables->company_address as $variable) { @@ -166,7 +181,7 @@ class PdfSlot extends Component } return $this->convertVariables($company_details); - + } private function getEntityDetails() @@ -174,9 +189,9 @@ class PdfSlot extends Component $entity_details = ""; if($this->entity_type == 'invoice' || $this->entity_type == 'recurring_invoice') { - foreach($this->settings->pdf_variables->invoice_details as $variable) + foreach($this->settings->pdf_variables->invoice_details as $variable) $entity_details .= "
{$variable}_label
{$variable}
{$variable}_label
{$variable}
{$variable}
"; } } - + return $this->convertVariables($user_details); } diff --git a/app/Jobs/Entity/CreateRawPdf.php b/app/Jobs/Entity/CreateRawPdf.php index 4231b6595b..e4297068d4 100644 --- a/app/Jobs/Entity/CreateRawPdf.php +++ b/app/Jobs/Entity/CreateRawPdf.php @@ -12,6 +12,7 @@ namespace App\Jobs\Entity; use App\Exceptions\FilePermissionsFailure; +use App\Jobs\Invoice\MergeEInvoice; use App\Libraries\MultiDB; use App\Models\Credit; use App\Models\CreditInvitation; @@ -202,6 +203,9 @@ class CreateRawPdf implements ShouldQueue if ($pdf) { $maker =null; $state = null; + if ($this->invitation->invoice->client->getSetting('enable_e_invoice') && $this->entity == "invoice"){ + (new \App\Services\Invoice\MergeEInvoice($this->invitation->invoice))->run(); + }; return $pdf; } diff --git a/resources/views/portal/ninja2020/components/livewire/pdf-slot.blade.php b/resources/views/portal/ninja2020/components/livewire/pdf-slot.blade.php index 992c75e869..8d6154df9b 100644 --- a/resources/views/portal/ninja2020/components/livewire/pdf-slot.blade.php +++ b/resources/views/portal/ninja2020/components/livewire/pdf-slot.blade.php @@ -9,6 +9,15 @@ +