mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-23 20:00:33 -04:00
More adjustments
This commit is contained in:
parent
9f3a58129f
commit
0c83ca51c5
61
app/Jobs/Invoice/MergeEInvoice.php
Normal file
61
app/Jobs/Invoice/MergeEInvoice.php
Normal file
@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs\Invoice;
|
||||
|
||||
use App\Models\ClientContact;
|
||||
use App\Models\Invoice;
|
||||
use horstoeko\zugferd\ZugferdDocumentPdfBuilder;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use horstoeko\zugferd\ZugferdDocumentReader;
|
||||
|
||||
class MergeEInvoice implements ShouldQueue
|
||||
{
|
||||
public function __construct(public Invoice $invoice, public ?ClientContact $contact = null)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function handle(): 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));
|
||||
}
|
||||
}
|
@ -12,6 +12,8 @@
|
||||
namespace App\Services\Invoice;
|
||||
|
||||
use App\Jobs\Entity\CreateEntityPdf;
|
||||
use App\Jobs\Invoice\CreateEInvoice;
|
||||
use App\Jobs\Invoice\MergeEInvoice;
|
||||
use App\Models\ClientContact;
|
||||
use App\Models\Invoice;
|
||||
use App\Services\AbstractService;
|
||||
@ -47,7 +49,10 @@ class GetInvoicePdf extends AbstractService
|
||||
if (! $file) {
|
||||
$file_path = (new CreateEntityPdf($invitation))->handle();
|
||||
}
|
||||
|
||||
if ($this->invoice->client->getSetting('enable_e_invoice')){
|
||||
(new CreateEInvoice($this->invoice))->handle();
|
||||
(new MergeEInvoice($this->invoice))->handle();
|
||||
}
|
||||
return $file_path;
|
||||
}
|
||||
}
|
||||
|
@ -4,58 +4,31 @@ 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
|
||||
class MergeEInvoice
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Invoice $invoice
|
||||
* @param mixed|null $contact
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
$file_path = $this->invoice->client->e_invoice_filepath($this->invoice->invitations->first()). $this->invoice->getFileName("xml");
|
||||
|
||||
/**
|
||||
* @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 = 'public';
|
||||
$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()));
|
||||
$file = Storage::disk($disk)->exists($file_path);
|
||||
|
||||
if (! $file) {
|
||||
(new \App\Jobs\Invoice\MergeEInvoice($this->invoice))->handle();
|
||||
}
|
||||
$pdfBuilder = new ZugferdDocumentPdfBuilder($document, Storage::disk($disk)->path($filepath_pdf));
|
||||
$pdfBuilder->generateDocument();
|
||||
$pdfBuilder->saveDocument(Storage::disk($disk)->path($filepath_pdf));
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user