From 7504cff2dde86078a265b59fcd8ea119f4e23990 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Sun, 25 Feb 2018 23:03:49 +0200 Subject: [PATCH] Fix for UBL invoices --- app/Jobs/ConvertInvoiceToUbl.php | 42 ++++++++++++-------------------- 1 file changed, 16 insertions(+), 26 deletions(-) diff --git a/app/Jobs/ConvertInvoiceToUbl.php b/app/Jobs/ConvertInvoiceToUbl.php index c19abc5111fb..f50b534069ec 100644 --- a/app/Jobs/ConvertInvoiceToUbl.php +++ b/app/Jobs/ConvertInvoiceToUbl.php @@ -57,22 +57,17 @@ class ConvertInvoiceToUbl extends Job $ublInvoice->setInvoiceLines($invoiceLines); - if ($invoice->hasTaxes()) { - $taxtotal = new TaxTotal(); - $taxAmount1 = $taxAmount2 = 0; + $taxtotal = new TaxTotal(); + $taxAmount1 = $taxAmount2 = 0; - if ($invoice->tax_name1 || floatval($invoice->tax_rate1)) { - $taxAmount1 = $this->createTaxRate($taxtotal, $taxable, $invoice->tax_rate1, $invoice->tax_name1); - } - - if ($invoice->tax_name2 || floatval($invoice->tax_rate2)) { - $taxAmount2 = $this->createTaxRate($taxtotal, $taxable, $invoice->tax_rate2, $invoice->tax_name2); - } - - $taxtotal->setTaxAmount($taxAmount1 + $taxAmount2); - $ublInvoice->setTaxTotal($taxtotal); + $taxAmount1 = $this->createTaxRate($taxtotal, $taxable, $invoice->tax_rate1, $invoice->tax_name1); + if ($invoice->tax_name2 || floatval($invoice->tax_rate2)) { + $taxAmount2 = $this->createTaxRate($taxtotal, $taxable, $invoice->tax_rate2, $invoice->tax_name2); } + $taxtotal->setTaxAmount($taxAmount1 + $taxAmount2); + $ublInvoice->setTaxTotal($taxtotal); + $ublInvoice->setLegalMonetaryTotal((new LegalMonetaryTotal()) //->setLineExtensionAmount() ->setTaxExclusiveAmount($taxable) @@ -118,22 +113,17 @@ class ConvertInvoiceToUbl extends Job ->setDescription($item->description)); //->setSellersItemIdentification("1ABCD")); - if ($item->hasTaxes()) { - $taxtotal = new TaxTotal(); - $itemTaxAmount1 = $itemTaxAmount2 = 0; + $taxtotal = new TaxTotal(); + $itemTaxAmount1 = $itemTaxAmount2 = 0; - if ($item->tax_name1 || floatval($item->tax_rate1)) { - $itemTaxAmount1 = $this->createTaxRate($taxtotal, $taxable, $item->tax_rate1, $item->tax_name1); - } - - if ($item->tax_name2 || floatval($item->tax_rate2)) { - $itemTaxAmount2 = $this->createTaxRate($taxtotal, $taxable, $item->tax_rate2, $item->tax_name2); - } - - $taxtotal->setTaxAmount($itemTaxAmount1 + $itemTaxAmount2); - $invoiceLine->setTaxTotal($taxtotal); + $itemTaxAmount1 = $this->createTaxRate($taxtotal, $taxable, $item->tax_rate1, $item->tax_name1); + if ($item->tax_name2 || floatval($item->tax_rate2)) { + $itemTaxAmount2 = $this->createTaxRate($taxtotal, $taxable, $item->tax_rate2, $item->tax_name2); } + $taxtotal->setTaxAmount($itemTaxAmount1 + $itemTaxAmount2); + $invoiceLine->setTaxTotal($taxtotal); + return $invoiceLine; }