Fixes for 0 rate taxes

This commit is contained in:
David Bomba 2023-04-24 08:22:49 +10:00
parent 91563a4102
commit 8e145b81dc
5 changed files with 32 additions and 17 deletions

View File

@ -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;

View File

@ -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")));
}

View File

@ -641,7 +641,7 @@ use Laracasts\Presenter\PresentableTrait;
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Vendor> $vendors
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Webhook> $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<int, \App\Models\Activity> $activities
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Activity> $all_activities

View File

@ -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
}

View File

@ -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)
{
}