1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 05:02:36 +01:00
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) {
$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();
if ($this->invitation->invoice->client->getSetting('enable_e_invoice') && $this->entity_string == "invoice"){
$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;
}

View File

@ -11,7 +11,7 @@ use horstoeko\zugferd\ZugferdDocumentReader;
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
{
$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');
$xrechnung = (new CreateEInvoice($this->invoice, true))->handle();
if (!Storage::disk($disk)->exists($this->invoice->client->e_invoice_filepath($this->invoice->invitations->first()))) {
Storage::makeDirectory($this->invoice->client->e_invoice_filepath($this->invoice->invitations->first()));
$e_rechnung = (new CreateEInvoice($this->invoice, true))->handle();
if (!empty($this->pdf_path)){
$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->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();
}
return $file_path;
}
}

View File

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

View File

@ -11,23 +11,17 @@ class MergeEInvoice
/**
* @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
{
$file_path_xml = $this->invoice->client->e_invoice_filepath($this->invoice->invitations->first()). $this->invoice->getFileName("xml");
$file_path_pdf = $this->invoice->getFileName();
// $disk = 'public';
$disk = config('filesystems.default');
$file_xml = Storage::disk($disk)->exists($file_path_xml);
$file_pdf = Storage::disk($disk)->exists($file_path_pdf);
if ($file_xml && $file_pdf) {
if (!empty($this->pdf_path)) {
(new \App\Jobs\Invoice\MergeEInvoice($this->invoice, $this->pdf_path))->handle();
}
else {
(new \App\Jobs\Invoice\MergeEInvoice($this->invoice))->handle();
}