From 3ca07241c8f8e897f6b0e72c888eb5336a102433 Mon Sep 17 00:00:00 2001 From: Marek Konderla Date: Mon, 18 Feb 2019 21:44:46 +0100 Subject: [PATCH] total vat method implementation return types fix --- src/Taxes/CalcLogic.php | 4 ++++ src/Taxes/ICalcLogic.php | 8 ++++++++ src/Taxes/Price.php | 4 ++++ src/Taxes/PriceList.php | 11 ++++++----- 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/Taxes/CalcLogic.php b/src/Taxes/CalcLogic.php index dd4cf5f..231616e 100644 --- a/src/Taxes/CalcLogic.php +++ b/src/Taxes/CalcLogic.php @@ -98,6 +98,10 @@ public function getTotalsWithoutVatFromPrices($prices) return $totals; } + public function getTotalVatFromPriceObject(Price $price){ + return round($price->getTotalPriceWithVat() - $price->getTotalPriceWithoutVat(), 2); + } + /** * Returns correctly rounded var coefficient * diff --git a/src/Taxes/ICalcLogic.php b/src/Taxes/ICalcLogic.php index 4a27977..f4de4d4 100644 --- a/src/Taxes/ICalcLogic.php +++ b/src/Taxes/ICalcLogic.php @@ -56,6 +56,14 @@ public function getTotalsWithVatFromPrices($prices); */ public function getTotalsWithoutVatFromPrices($prices); + /** + * Method for calculating amout of vat + * + * @param Price $price + * @return mixed + */ + public function getTotalVatFromPriceObject(Price $price); + /** * Returns correctly rounded var coefficient * diff --git a/src/Taxes/Price.php b/src/Taxes/Price.php index 7841974..d2dbcfe 100644 --- a/src/Taxes/Price.php +++ b/src/Taxes/Price.php @@ -94,6 +94,10 @@ public function getTotalPriceWithoutVat() return $this->calcLogic->getTotalPriceWithoutVatFromPriceObject($this); } + public function getTotalVat(){ + return $this->calcLogic->getTotalVatFromPriceObject($this); + } + /** * @return float */ diff --git a/src/Taxes/PriceList.php b/src/Taxes/PriceList.php index 598827d..ab47d93 100644 --- a/src/Taxes/PriceList.php +++ b/src/Taxes/PriceList.php @@ -44,7 +44,7 @@ public function addWithVat($priceWithVat, $quantity = 1.0, $vatPercent = null, $ if (!isset($vatPercent)) $vatPercent = $this->defaultVatPercent; $this->prices[] = $price = Price::createFromPriceWithVat($this->calcLogic, $vatPercent, $priceWithVat, $quantity); - if(isset($priceId)) + if (isset($priceId)) $this->pricesMap[$priceId] = $price; return $price; } @@ -61,17 +61,18 @@ public function addWithoutVat($priceWithoutVat, $quantity = 1.0, $vatPercent = n if (!isset($vatPercent)) $vatPercent = $this->defaultVatPercent; $this->prices[] = $price = Price::createFromPriceWithoutVat($this->calcLogic, $vatPercent, $priceWithoutVat, $quantity); - if(isset($priceId)) + if (isset($priceId)) $this->pricesMap[$priceId] = $price; return $price; } /** * @param $priceId - * @return mixed|null + * @return Price|null */ - public function getPriceById($priceId){ - if(isset($this->pricesMap[$priceId])) + public function getPriceById($priceId) + { + if (isset($this->pricesMap[$priceId])) return $this->pricesMap[$priceId]; return null; }