Merge branch 'v5-develop' of https://github.com/LarsK1/invoiceninja into v5-develop

This commit is contained in:
David Bomba 2023-08-03 18:13:38 +10:00
commit c164ab1970
5 changed files with 73 additions and 24 deletions

View File

@ -63,13 +63,13 @@ class CreateEInvoice implements ShouldQueue
case "XInvoice-Extended": case "XInvoice-Extended":
case "XInvoice-BasicWL": case "XInvoice-BasicWL":
case "XInvoice-Basic": case "XInvoice-Basic":
return (new ZugferdEInvoice($this->invoice, $this->alterPDF, $this->custom_pdf_path))->run(); return (new ZugferdEInvoice($this->invoice))->run();
case "Facturae_3.2": case "Facturae_3.2":
case "Facturae_3.2.1": case "Facturae_3.2.1":
case "Facturae_3.2.2": case "Facturae_3.2.2":
return (new FacturaEInvoice($this->invoice, str_replace("Facturae_", "", $e_invoice_type)))->run(); return (new FacturaEInvoice($this->invoice, str_replace("Facturae_", "", $e_invoice_type)))->run();
default: default:
return (new ZugferdEInvoice($this->invoice, $this->alterPDF, $this->custom_pdf_path))->run(); return (new ZugferdEInvoice($this->invoice))->run();
} }

View File

@ -23,7 +23,7 @@ use horstoeko\zugferd\codelists\ZugferdDutyTaxFeeCategories;
class ZugferdEInvoice extends AbstractService class ZugferdEInvoice extends AbstractService
{ {
public function __construct(public Invoice $invoice, private bool $alterPDF, private string $custom_pdf_path = "", private array $tax_map = []) public function __construct(public Invoice $invoice, private array $tax_map = [])
{ {
} }
@ -175,22 +175,6 @@ class ZugferdEInvoice extends AbstractService
$xrechnung->writeFile(Storage::disk($disk)->path($client->e_invoice_filepath($this->invoice->invitations->first()) . $this->invoice->getFileName("xml"))); $xrechnung->writeFile(Storage::disk($disk)->path($client->e_invoice_filepath($this->invoice->invitations->first()) . $this->invoice->getFileName("xml")));
// The validity can be checked using https://portal3.gefeg.com/invoice/validation or https://e-rechnung.bayern.de/app/#/upload // The validity can be checked using https://portal3.gefeg.com/invoice/validation or https://e-rechnung.bayern.de/app/#/upload
if ($this->alterPDF) {
if ($this->custom_pdf_path != "") {
$pdfBuilder = new ZugferdDocumentPdfBuilder($xrechnung, $this->custom_pdf_path);
$pdfBuilder->generateDocument();
$pdfBuilder->saveDocument($this->custom_pdf_path);
} else {
$filepath_pdf = $client->invoice_filepath($this->invoice->invitations->first()) . $this->invoice->getFileName();
$file = Storage::disk($disk)->exists($filepath_pdf);
if ($file) {
$pdfBuilder = new ZugferdDocumentPdfBuilder($xrechnung, Storage::disk($disk)->path($filepath_pdf));
$pdfBuilder->generateDocument();
$pdfBuilder->saveDocument(Storage::disk($disk)->path($filepath_pdf));
}
}
}
return $client->e_invoice_filepath($this->invoice->invitations->first()) . $this->invoice->getFileName("xml"); return $client->e_invoice_filepath($this->invoice->invitations->first()) . $this->invoice->getFileName("xml");
} }

View File

@ -17,7 +17,7 @@ use App\Models\Invoice;
use App\Services\AbstractService; use App\Services\AbstractService;
use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\Storage;
class GetInvoiceXInvoice extends AbstractService class GetInvoiceEInvoice extends AbstractService
{ {
public function __construct(public Invoice $invoice, public ?ClientContact $contact = null) public function __construct(public Invoice $invoice, public ?ClientContact $contact = null)
{ {

View File

@ -194,9 +194,13 @@ class InvoiceService
public function getEInvoice($contact = null) public function getEInvoice($contact = null)
{ {
return (new GetInvoiceXInvoice($this->invoice, $contact))->run(); return (new GetInvoiceEInvoice($this->invoice, $contact))->run();
} }
public function mergeEInvoice($contact = null): void
{
(new MergeEInvoice($this->invoice, $contact))->run();
}
public function sendEmail($contact = null) public function sendEmail($contact = null)
{ {
$send_email = new SendEmail($this->invoice, null, $contact); $send_email = new SendEmail($this->invoice, null, $contact);

View File

@ -0,0 +1,61 @@
<?php
namespace App\Services\Invoice;
use App\Models\ClientContact;
use App\Models\Invoice;
use App\Services\AbstractService;
use horstoeko\zugferd\ZugferdDocumentPdfBuilder;
use Illuminate\Support\Facades\Storage;
use horstoeko\zugferd\ZugferdDocumentReader;
class MergeEInvoice extends AbstractService
{
public function __construct(public Invoice $invoice, public ?ClientContact $contact = null)
{
}
/**
* @throws \Exception
*/
public function run(): void
{
$e_invoice_type = $this->invoice->client->getSetting('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":
$this->embedEInvoiceZuGFerD();
//case "Facturae_3.2":
//case "Facturae_3.2.1":
//case "Facturae_3.2.2":
//
default:
$this->embedEInvoiceZuGFerD();
break;
}
}
/**
* @throws \Exception
*/
private function embedEInvoiceZuGFerD(): void
{
$filepath_pdf = $this->invoice->client->invoice_filepath($this->invoice->invitations->first()) . $this->invoice->getFileName();
$e_invoice_path = $this->invoice->client->e_invoice_filepath($this->invoice->invitations->first()) . $this->invoice->getFileName("xml");
$document = ZugferdDocumentReader::readAndGuessFromFile($e_invoice_path);
$disk = config('filesystems.default');
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()));
}
$pdfBuilder = new ZugferdDocumentPdfBuilder($document, Storage::disk($disk)->path($filepath_pdf));
$pdfBuilder->generateDocument();
$pdfBuilder->saveDocument(Storage::disk($disk)->path($filepath_pdf));
}
}