Merge branch '636-fix-timing-of-vat-computation' into 'master-fix'

Resolve "Fix timing of vat computation"

See merge request jankstudio/resq!747
This commit is contained in:
Kendrick Chan 2021-10-26 05:20:02 +00:00
commit 764c9e690c
2 changed files with 28 additions and 4 deletions

View file

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

View file

@ -552,7 +552,7 @@
</div>
<div class="col-lg-3">
<label>VAT</label>
<input type="text" id="invoice-vat" class="form-control m-input text-right" value="{{ obj.getInvoice ? obj.getInvoice.getVAT|number_format : '0.00' }}" disabled>
<input type="text" id="invoice-vat" class="form-control m-input text-right" value="{{ obj.getInvoice ? obj.getInvoice.getVAT|number_format(2) : '0.00' }}" disabled>
</div>
<div class="col-lg-6">
<label>Total Amount</label>