From 91563a41022c827bd8671c145315e964efd2b4b9 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sun, 23 Apr 2023 16:59:17 +1000 Subject: [PATCH 1/3] Fixes for taxes --- app/DataMapper/Tax/BaseRule.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/DataMapper/Tax/BaseRule.php b/app/DataMapper/Tax/BaseRule.php index 34c32268a4fe..1c154e6035d1 100644 --- a/app/DataMapper/Tax/BaseRule.php +++ b/app/DataMapper/Tax/BaseRule.php @@ -118,7 +118,7 @@ class BaseRule implements RuleInterface protected ?Response $tax_data; - public ?Invoice $invoice; + public mixed $invoice; public function __construct() { @@ -129,7 +129,7 @@ class BaseRule implements RuleInterface return $this; } - public function setInvoice(Invoice $invoice): self + public function setInvoice(mixed $invoice): self { $this->invoice = $invoice; From 8e145b81dcc722b96625d1ed285ecadb70dccd0d Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 24 Apr 2023 08:22:49 +1000 Subject: [PATCH 2/3] Fixes for 0 rate taxes --- app/Jobs/Invoice/ZipInvoices.php | 27 ++++++++++++------- app/Mail/TemplateEmail.php | 4 +-- app/Models/Company.php | 2 +- .../Invoice/EInvoice/ZugferdEInvoice.php | 14 +++++++--- app/Services/Invoice/GetInvoiceXInvoice.php | 2 +- 5 files changed, 32 insertions(+), 17 deletions(-) diff --git a/app/Jobs/Invoice/ZipInvoices.php b/app/Jobs/Invoice/ZipInvoices.php index 22476675c2f4..991a6e08eb30 100644 --- a/app/Jobs/Invoice/ZipInvoices.php +++ b/app/Jobs/Invoice/ZipInvoices.php @@ -62,11 +62,8 @@ class ZipInvoices implements ShouldQueue * Execute the job. * * @return void - * @throws \ZipStream\Exception\FileNotFoundException - * @throws \ZipStream\Exception\FileNotReadableException - * @throws \ZipStream\Exception\OverflowException */ - public function handle() + public function handle(): void { MultiDB::setDb($this->company->db); @@ -78,24 +75,36 @@ class ZipInvoices implements ShouldQueue $this->invoices->each(function ($invoice) { (new CreateEntityPdf($invoice->invitations()->first()))->handle(); - if ($this->company->use_xinvoice){ + if ($this->company->enable_e_invoice){ (new CreateEInvoice($invoice, false))->handle(); } }); try { + foreach ($this->invoices as $invoice) { $file = $invoice->service()->getInvoicePdf(); - $xinvoice = $invoice->service()->getXInvoice(); + // $xinvoice = $invoice->service()->getEInvoice(); $zip_file_name = basename($file); - $xinvoice_zip_file_name = basename($xinvoice); - $zipFile->addFromString($zip_file_name, Storage::get($file)) - ->addDir($xinvoice_zip_file_name, Storage::get($xinvoice)); + // $xinvoice_zip_file_name = basename($xinvoice); + $zipFile->addFromString($zip_file_name, Storage::get($file)); + + // ->addDir($xinvoice_zip_file_name, Storage::get($xinvoice)); //$download_file = file_get_contents($invoice->pdf_file_path($invitation, 'url', true)); //$zipFile->addFromString(basename($invoice->pdf_file_path($invitation)), $download_file); } + nlog($this->company->enable_e_invoice); + nlog($this->company->id); + if($this->company->enable_e_invoice){ + foreach ($this->invoices as $invoice) { + $xinvoice = $invoice->service()->getEInvoice(); + $xinvoice_zip_file_name = basename($xinvoice); + $zipFile->addFromString($xinvoice_zip_file_name, Storage::get($xinvoice)); + } + } + Storage::put($path.$file_name, $zipFile->outputAsString()); $nmo = new NinjaMailerObject; diff --git a/app/Mail/TemplateEmail.php b/app/Mail/TemplateEmail.php index 11f83ba3f990..231f4e027e71 100644 --- a/app/Mail/TemplateEmail.php +++ b/app/Mail/TemplateEmail.php @@ -153,8 +153,8 @@ class TemplateEmail extends Mailable $this->attachData($ubl_string, $this->invitation->invoice->getFileName('xml')); } } - if ($this->invitation && $this->invitation->invoice && $company->use_xinvoice && $this->company->account->hasFeature(Account::FEATURE_PDF_ATTACHMENT)) { - $this->invitation->invoice->service()->getXInvoice($this->invitation->contact); + if ($this->invitation && $this->invitation->invoice && $company->enable_e_invoice && $this->company->account->hasFeature(Account::FEATURE_PDF_ATTACHMENT)) { + $this->invitation->invoice->service()->getEInvoice($this->invitation->contact); $disk = config('filesystems.default'); $this->attach(Storage::disk($disk)->path($this->invitation->invoice->client->xinvoice_filepath($this->invitation->invoice->invitations->first()) . $this->invitation->invoice->getFileName("xml"))); } diff --git a/app/Models/Company.php b/app/Models/Company.php index f4aff444c365..666b91f63c97 100644 --- a/app/Models/Company.php +++ b/app/Models/Company.php @@ -641,7 +641,7 @@ use Laracasts\Presenter\PresentableTrait; * @property-read \Illuminate\Database\Eloquent\Collection $vendors * @property-read \Illuminate\Database\Eloquent\Collection $webhooks * @property int $tax_all_products - * @property int $use_xinvoice + * @property int $enable_e_invoice * @property string $xinvoice_type * @property-read \Illuminate\Database\Eloquent\Collection $activities * @property-read \Illuminate\Database\Eloquent\Collection $all_activities diff --git a/app/Services/Invoice/EInvoice/ZugferdEInvoice.php b/app/Services/Invoice/EInvoice/ZugferdEInvoice.php index 07e7c4cc25f8..34d84fdffe47 100644 --- a/app/Services/Invoice/EInvoice/ZugferdEInvoice.php +++ b/app/Services/Invoice/EInvoice/ZugferdEInvoice.php @@ -158,15 +158,21 @@ class ZugferdEInvoice extends AbstractService $xrechnung->setDocumentSummation($this->invoice->amount, $this->invoice->balance, $invoicing_data->getSubTotal(), $invoicing_data->getTotalSurcharges(), $invoicing_data->getTotalDiscount(), $invoicing_data->getSubTotal(), $invoicing_data->getItemTotalTaxes(), null, 0.0); } + foreach ($invoicing_data->getTaxMap() as $item) { - $tax = explode(" ", $item["name"]); - $xrechnung->addDocumentTax($this->getTaxType(""), "VAT", $item["total"] / (explode("%", end($tax))[0] / 100), $item["total"], explode("%", end($tax))[0]); + + $tax_name = explode(" ", $item["name"]); + $tax_rate = (explode("%", end($tax_name))[0] / 100); + + $total_tax = $tax_rate == 0 ? 0 : $item["total"] / $tax_rate; + + $xrechnung->addDocumentTax($this->getTaxType(""), "VAT", $total_tax, $item["total"], explode("%", end($tax_name))[0]); // TODO: Add correct tax type within getTaxType } if (!empty($globaltax && isset($invoicing_data->getTotalTaxMap()[$globaltax]["name"]))) { - $tax = explode(" ", $invoicing_data->getTotalTaxMap()[$globaltax]["name"]); - $xrechnung->addDocumentTax($this->getTaxType(""), "VAT", $invoicing_data->getTotalTaxMap()[$globaltax]["total"] / (explode("%", end($tax))[0] / 100), $invoicing_data->getTotalTaxMap()[$globaltax]["total"], explode("%", end($tax))[0]); + $tax_name = explode(" ", $invoicing_data->getTotalTaxMap()[$globaltax]["name"]); + $xrechnung->addDocumentTax($this->getTaxType(""), "VAT", $invoicing_data->getTotalTaxMap()[$globaltax]["total"] / (explode("%", end($tax_name))[0] / 100), $invoicing_data->getTotalTaxMap()[$globaltax]["total"], explode("%", end($tax_name))[0]); // TODO: Add correct tax type within getTaxType } diff --git a/app/Services/Invoice/GetInvoiceXInvoice.php b/app/Services/Invoice/GetInvoiceXInvoice.php index 9fcde4017a1e..c3f312382058 100644 --- a/app/Services/Invoice/GetInvoiceXInvoice.php +++ b/app/Services/Invoice/GetInvoiceXInvoice.php @@ -19,7 +19,7 @@ use Illuminate\Support\Facades\Storage; class GetInvoiceXInvoice extends AbstractService { - public function __construct(public Invoice $invoice, public ClientContact $contact = null) + public function __construct(public Invoice $invoice, public ?ClientContact $contact = null) { } From 8e4237d97a48be30217271ddbc1311b3d716362c Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 24 Apr 2023 08:28:56 +1000 Subject: [PATCH 3/3] Handle zipping e-invoices --- app/Jobs/Invoice/ZipInvoices.php | 9 --------- 1 file changed, 9 deletions(-) diff --git a/app/Jobs/Invoice/ZipInvoices.php b/app/Jobs/Invoice/ZipInvoices.php index 991a6e08eb30..0a70ea3e4d59 100644 --- a/app/Jobs/Invoice/ZipInvoices.php +++ b/app/Jobs/Invoice/ZipInvoices.php @@ -84,19 +84,10 @@ class ZipInvoices implements ShouldQueue foreach ($this->invoices as $invoice) { $file = $invoice->service()->getInvoicePdf(); - // $xinvoice = $invoice->service()->getEInvoice(); $zip_file_name = basename($file); - // $xinvoice_zip_file_name = basename($xinvoice); $zipFile->addFromString($zip_file_name, Storage::get($file)); - - // ->addDir($xinvoice_zip_file_name, Storage::get($xinvoice)); - - //$download_file = file_get_contents($invoice->pdf_file_path($invitation, 'url', true)); - //$zipFile->addFromString(basename($invoice->pdf_file_path($invitation)), $download_file); } - nlog($this->company->enable_e_invoice); - nlog($this->company->id); if($this->company->enable_e_invoice){ foreach ($this->invoices as $invoice) { $xinvoice = $invoice->service()->getEInvoice();