From 44611915e5275a199f72b56597b5f51a2e9f9857 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Mon, 25 Oct 2021 08:37:19 +0000 Subject: [PATCH 1/2] Fix VAT computation when trade ins and discounts are present. #636 --- .../InvoiceGenerator/ResqInvoiceGenerator.php | 30 +++++++++++++++++-- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/src/Service/InvoiceGenerator/ResqInvoiceGenerator.php b/src/Service/InvoiceGenerator/ResqInvoiceGenerator.php index 6c3cbf36..0ce95e75 100644 --- a/src/Service/InvoiceGenerator/ResqInvoiceGenerator.php +++ b/src/Service/InvoiceGenerator/ResqInvoiceGenerator.php @@ -363,6 +363,7 @@ class ResqInvoiceGenerator implements InvoiceGeneratorInterface $this->processBatteries($total, $con_batts, $invoice); $this->processTradeIns($total, $con_tis, $invoice); + $this->processVAT($total); } protected function processBatteries(&$total, $con_batts, Invoice $invoice) @@ -374,12 +375,13 @@ class ResqInvoiceGenerator implements InvoiceGeneratorInterface $qty = $con_data['qty']; $sell_price = $batt->getSellingPrice(); - $vat = $this->getTaxAmount($sell_price); + // comment out the getting of tax amount + // $vat = $this->getTaxAmount($sell_price); // $vat_ex_price = $this->getTaxExclusivePrice($sell_price); $total['sell_price'] += $sell_price * $qty; - $total['vat'] += $vat * $qty; - $total['vat_ex_price'] += ($sell_price - $vat) * $qty; + // $total['vat'] += $vat * $qty; + // $total['vat_ex_price'] += ($sell_price - $vat) * $qty; $total['total_price'] += $sell_price * $qty; @@ -816,4 +818,26 @@ class ResqInvoiceGenerator implements InvoiceGeneratorInterface } return $cust_tag_info; } + + protected function processVAT(&$total) + { + // total trade in amount to deduct from SRP before we compute VAT + $total_ti_amt = 0; + // need to check if there are trade-ins + if (isset($total['ti_rate'])) + $total_ti_amt = $total['ti_rate']; + + // compute the vat for battery + // get the total selling price. That should be SRP. + // we need to deduct the trade-ins before computing VAT + $total_srp = $total['sell_price']; + + $total_price_minus_ti = bcsub($total_srp, $total_ti_amt, 2); + + $total_vat = $this->getTaxAmount($total_price_minus_ti); + $total_vat_ex_price = bcsub($total_price_minus_ti, $total_vat, 2); + + $total['vat'] = $total_vat; + $total['vat_ex_price'] = $total_vat_ex_price; + } } From 0fe66f4719cd0d9ea8d2c29762a2b5ccbf944c7e Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Mon, 25 Oct 2021 08:50:15 +0000 Subject: [PATCH 2/2] Fix display of VAT. #636 --- templates/job-order/form.html.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/job-order/form.html.twig b/templates/job-order/form.html.twig index e29d7aa5..e85a89f3 100644 --- a/templates/job-order/form.html.twig +++ b/templates/job-order/form.html.twig @@ -552,7 +552,7 @@
- +