This commit is contained in:
Lars Kusch 2023-08-14 12:08:25 +02:00
parent c5316f2ad2
commit 19fcab3b35
5 changed files with 21 additions and 22 deletions

View File

@ -203,8 +203,11 @@ class CreateRawPdf implements ShouldQueue
if ($pdf) { if ($pdf) {
$maker =null; $maker =null;
$state = null; $state = null;
if ($this->invitation->invoice->client->getSetting('enable_e_invoice') && $this->entity == "invoice"){ if ($this->invitation->invoice->client->getSetting('enable_e_invoice') && $this->entity_string == "invoice"){
(new \App\Services\Invoice\MergeEInvoice($this->invitation->invoice))->run(); $filename = tempnam(sys_get_temp_dir(), 'InvoiceNinja').".pdf";
file_put_contents($filename, $pdf);
(new \App\Services\Invoice\MergeEInvoice($this->invitation->invoice, $filename))->run();
return file_get_contents($filename);
}; };
return $pdf; return $pdf;
} }

View File

@ -11,7 +11,7 @@ use horstoeko\zugferd\ZugferdDocumentReader;
class MergeEInvoice implements ShouldQueue class MergeEInvoice implements ShouldQueue
{ {
public function __construct(public Invoice $invoice, public ?ClientContact $contact = null) public function __construct(public Invoice $invoice, private string $pdf_path = "")
{ {
} }
@ -46,14 +46,17 @@ class MergeEInvoice implements ShouldQueue
*/ */
private function embedEInvoiceZuGFerD(): void private function embedEInvoiceZuGFerD(): void
{ {
$filepath_pdf = $this->invoice->client->invoice_filepath($this->invoice->invitations->first()) . $this->invoice->getFileName(); $filepath_pdf = !empty($this->pdf_path) ? $this->pdf_path : $this->invoice->service()->getInvoicePdf();
$disk = config('filesystems.default'); $disk = config('filesystems.default');
$xrechnung = (new CreateEInvoice($this->invoice, true))->handle(); $e_rechnung = (new CreateEInvoice($this->invoice, true))->handle();
if (!Storage::disk($disk)->exists($this->invoice->client->e_invoice_filepath($this->invoice->invitations->first()))) { if (!empty($this->pdf_path)){
Storage::makeDirectory($this->invoice->client->e_invoice_filepath($this->invoice->invitations->first())); $realpath_pdf = $filepath_pdf;
} }
$pdfBuilder = new ZugferdDocumentPdfBuilder($xrechnung, Storage::disk($disk)->path($filepath_pdf)); else {
$realpath_pdf = Storage::disk($disk)->path($filepath_pdf);
}
$pdfBuilder = new ZugferdDocumentPdfBuilder($e_rechnung, $realpath_pdf);
$pdfBuilder->generateDocument(); $pdfBuilder->generateDocument();
$pdfBuilder->saveDocument(Storage::disk($disk)->path($filepath_pdf)); $pdfBuilder->saveDocument($realpath_pdf);
} }
} }

View File

@ -47,7 +47,6 @@ class GetInvoiceEInvoice extends AbstractService
(new \App\Jobs\Invoice\MergeEInvoice($this->invoice))->handle(); (new \App\Jobs\Invoice\MergeEInvoice($this->invoice))->handle();
} }
return $file_path; return $file_path;
} }
} }

View File

@ -51,7 +51,7 @@ class GetInvoicePdf extends AbstractService
} }
if ($this->invoice->client->getSetting('enable_e_invoice')){ if ($this->invoice->client->getSetting('enable_e_invoice')){
(new CreateEInvoice($this->invoice))->handle(); (new CreateEInvoice($this->invoice))->handle();
(new MergeEInvoice($this->invoice))->handle(); (new MergeEInvoice($this->invoice, $file_path))->handle();
} }
return $file_path; return $file_path;
} }

View File

@ -11,23 +11,17 @@ class MergeEInvoice
/** /**
* @param Invoice $invoice * @param Invoice $invoice
* @param mixed|null $contact
*/ */
public function __construct(public Invoice $invoice, public ?ClientContact $contact = null) public function __construct(public Invoice $invoice, public string $pdf_path = "")
{ {
} }
public function run(): void public function run(): void
{ {
$file_path_xml = $this->invoice->client->e_invoice_filepath($this->invoice->invitations->first()). $this->invoice->getFileName("xml"); if (!empty($this->pdf_path)) {
$file_path_pdf = $this->invoice->getFileName(); (new \App\Jobs\Invoice\MergeEInvoice($this->invoice, $this->pdf_path))->handle();
// $disk = 'public'; }
$disk = config('filesystems.default'); else {
$file_xml = Storage::disk($disk)->exists($file_path_xml);
$file_pdf = Storage::disk($disk)->exists($file_path_pdf);
if ($file_xml && $file_pdf) {
(new \App\Jobs\Invoice\MergeEInvoice($this->invoice))->handle(); (new \App\Jobs\Invoice\MergeEInvoice($this->invoice))->handle();
} }