Skip to content

Commit

Permalink
total vat method implementation
Browse files Browse the repository at this point in the history
return types fix
  • Loading branch information
Sofiosko committed Feb 18, 2019
1 parent 2f8425b commit 3ca0724
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
4 changes: 4 additions & 0 deletions src/Taxes/CalcLogic.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
8 changes: 8 additions & 0 deletions src/Taxes/ICalcLogic.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
4 changes: 4 additions & 0 deletions src/Taxes/Price.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ public function getTotalPriceWithoutVat()
return $this->calcLogic->getTotalPriceWithoutVatFromPriceObject($this);
}

public function getTotalVat(){
return $this->calcLogic->getTotalVatFromPriceObject($this);
}

/**
* @return float
*/
Expand Down
11 changes: 6 additions & 5 deletions src/Taxes/PriceList.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down

0 comments on commit 3ca0724

Please sign in to comment.