From 2f32f9666d6a12ad4c7d0bfcb5f555706f4f2367 Mon Sep 17 00:00:00 2001 From: Kendrick Chan Date: Tue, 6 Nov 2018 15:14:22 +0800 Subject: [PATCH] Adjust computation for services #167 --- src/Service/InvoiceCreator.php | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/src/Service/InvoiceCreator.php b/src/Service/InvoiceCreator.php index 063b0b0a..1c6a74a7 100644 --- a/src/Service/InvoiceCreator.php +++ b/src/Service/InvoiceCreator.php @@ -27,7 +27,8 @@ class InvoiceCreator public function getVATAmount($price) { $vat_ex_price = $this->getVATExclusivePrice($price); - return round($vat_ex_price * self::VAT_RATE, 2); + return $price - $vat_ex_price; + // return round($vat_ex_price * self::VAT_RATE, 2); } public function getVATExclusivePrice($price) @@ -300,9 +301,10 @@ class InvoiceCreator $total_price += 1600; } - $vat = round($total_price * self::VAT_RATE, 2); + $vat_ex_price = $this->getVATExclusivePrice($total_price); + $vat = $total_price - $vat_ex_price; $total['total_price'] = $total_price; - $total['vat_ex_price'] = $total_price - $vat; + $total['vat_ex_price'] = $vat_ex_price; $total['vat'] = $vat; } @@ -322,9 +324,10 @@ class InvoiceCreator $invoice->addItem($item); $total_price = $fee; - $vat = round($total_price * self::VAT_RATE, 2); + $vat_ex_price = $this->getVATExclusivePrice($total_price); + $vat = $total_price - $vat_ex_price; $total['total_price'] = $total_price; - $total['vat_ex_price'] = $total_price - $vat; + $total['vat_ex_price'] = $vat_ex_price; $total['vat'] = $vat; } @@ -348,6 +351,9 @@ class InvoiceCreator $total_price = $fee; // $total['total_price'] = 200.00; + $gas_price = 260; + $diesel_price = 220; + $fuel = new InvoiceItem(); error_log('fuel type - ' . $ftype); switch ($ftype) @@ -356,20 +362,20 @@ class InvoiceCreator $fuel->setInvoice($invoice) ->setTitle('4L Fuel - Gas') ->setQuantity(1) - ->setPrice(240); + ->setPrice($gas_price); $invoice->addItem($fuel); - $total_price += 240.00; + $total_price += $gas_price; break; case FuelType::DIESEL: $fuel->setInvoice($invoice) ->setTitle('4L Fuel - Diesel') ->setQuantity(1) - ->setPrice(200); - $total_price += 200.00; + ->setPrice($diesel_price); + $total_price += $diesel_price; $invoice->addItem($fuel); break; default: - // should never get to this point + // NOTE: should never get to this point $fuel->setInvoice($invoice) ->setTitle('Fuel - Unknown') ->setQuantity(1) @@ -379,9 +385,10 @@ class InvoiceCreator break; } - $vat = round($total_price * self::VAT_RATE, 2); + $vat_ex_price = $this->getVATExclusivePrice($total_price); + $vat = $total_price - $vat_ex_price; $total['total_price'] = $total_price; - $total['vat_ex_price'] = $total_price - $vat; + $total['vat_ex_price'] = $vat_ex_price; $total['vat'] = $vat; }