mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
updates for PdfService
This commit is contained in:
parent
a7c63a35d9
commit
0d285b606d
@ -12,17 +12,20 @@
|
|||||||
namespace App\Services\Pdf;
|
namespace App\Services\Pdf;
|
||||||
|
|
||||||
use App\Models\Company;
|
use App\Models\Company;
|
||||||
use App\Models\CreditInvitation;
|
use App\Models\Invoice;
|
||||||
use App\Models\InvoiceInvitation;
|
|
||||||
use App\Models\PurchaseOrderInvitation;
|
|
||||||
use App\Models\QuoteInvitation;
|
|
||||||
use App\Models\RecurringInvoiceInvitation;
|
|
||||||
use App\Utils\HostedPDF\NinjaPdf;
|
|
||||||
use App\Utils\HtmlEngine;
|
use App\Utils\HtmlEngine;
|
||||||
use App\Utils\PhantomJS\Phantom;
|
use App\Models\QuoteInvitation;
|
||||||
use App\Utils\Traits\Pdf\PageNumbering;
|
|
||||||
use App\Utils\Traits\Pdf\PdfMaker;
|
|
||||||
use App\Utils\VendorHtmlEngine;
|
use App\Utils\VendorHtmlEngine;
|
||||||
|
use App\Models\CreditInvitation;
|
||||||
|
use App\Utils\PhantomJS\Phantom;
|
||||||
|
use App\Models\InvoiceInvitation;
|
||||||
|
use App\Utils\HostedPDF\NinjaPdf;
|
||||||
|
use App\Utils\Traits\Pdf\PdfMaker;
|
||||||
|
use App\Jobs\Invoice\CreateEInvoice;
|
||||||
|
use App\Models\PurchaseOrderInvitation;
|
||||||
|
use App\Utils\Traits\Pdf\PageNumbering;
|
||||||
|
use App\Models\RecurringInvoiceInvitation;
|
||||||
|
use horstoeko\zugferd\ZugferdDocumentPdfBuilder;
|
||||||
|
|
||||||
class PdfService
|
class PdfService
|
||||||
{
|
{
|
||||||
@ -92,6 +95,11 @@ class PdfService
|
|||||||
if ($numbered_pdf) {
|
if ($numbered_pdf) {
|
||||||
$pdf = $numbered_pdf;
|
$pdf = $numbered_pdf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($this->config->entity_string == "invoice" && $this->config->settings->enable_e_invoice) {
|
||||||
|
$pdf = $this->checkEInvoice($pdf);
|
||||||
|
}
|
||||||
|
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
nlog(print_r($e->getMessage(), 1));
|
nlog(print_r($e->getMessage(), 1));
|
||||||
throw new \Exception($e->getMessage(), $e->getCode());
|
throw new \Exception($e->getMessage(), $e->getCode());
|
||||||
@ -162,4 +170,61 @@ class PdfService
|
|||||||
|
|
||||||
return $pdf;
|
return $pdf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Switch to determine if we need to embed the xml into the PDF itself
|
||||||
|
*
|
||||||
|
* @param string $pdf
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
private function checkEInvoice(string $pdf): string
|
||||||
|
{
|
||||||
|
if(!$this->config->entity instanceof Invoice)
|
||||||
|
return $pdf;
|
||||||
|
|
||||||
|
$e_invoice_type = $this->config->settings->e_invoice_type;
|
||||||
|
|
||||||
|
switch ($e_invoice_type) {
|
||||||
|
case "EN16931":
|
||||||
|
case "XInvoice_2_2":
|
||||||
|
case "XInvoice_2_1":
|
||||||
|
case "XInvoice_2_0":
|
||||||
|
case "XInvoice_1_0":
|
||||||
|
case "XInvoice-Extended":
|
||||||
|
case "XInvoice-BasicWL":
|
||||||
|
case "XInvoice-Basic":
|
||||||
|
return $this->embedEInvoiceZuGFerD($pdf) ?? $pdf;
|
||||||
|
//case "Facturae_3.2":
|
||||||
|
//case "Facturae_3.2.1":
|
||||||
|
//case "Facturae_3.2.2":
|
||||||
|
//
|
||||||
|
default:
|
||||||
|
return $pdf;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Embed the .xml file into the PDF
|
||||||
|
*
|
||||||
|
* @param string $pdf
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
private function embedEInvoiceZuGFerD(string $pdf): string
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
|
||||||
|
$e_rechnung = (new CreateEInvoice($this->config->entity, true))->handle();
|
||||||
|
$pdfBuilder = new ZugferdDocumentPdfBuilder($e_rechnung, $pdf);
|
||||||
|
$pdfBuilder->generateDocument();
|
||||||
|
|
||||||
|
return $pdfBuilder->downloadString(basename($this->config->entity->getFileName()));
|
||||||
|
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
nlog("E_Invoice Merge failed - " . $e->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
return $pdf;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user