tax in loops

This commit is contained in:
Etienne Roudeix
2013-09-09 16:27:46 +02:00
parent fa36b64f51
commit ca4df15910
9 changed files with 91 additions and 17 deletions

View File

@@ -67,14 +67,16 @@ class Calculator
return $this;
}
public function getTaxAmount()
public function getTaxAmount($amount)
{
if(false === filter_var($amount, FILTER_VALIDATE_FLOAT)) {
throw new TaxEngineException('BAD AMOUNT FORMAT', TaxEngineException::BAD_AMOUNT_FORMAT);
}
if(null === $this->taxRulesGroupedCollection) {
throw new TaxEngineException('Tax rules collection is empty in Calculator::getTaxAmount', TaxEngineException::UNDEFINED_TAX_RULES_COLLECTION);
}
$amount = $this->product->getRealLowestPrice();
$taxRateAmount = 0;
foreach($this->taxRulesGroupedCollection as $taxRule) {
$taxRateAmount += $taxRule->getTaxRuleRateSum();
@@ -83,8 +85,12 @@ class Calculator
return $amount * $taxRateAmount * 0.01;
}
public function getTaxedPrice()
public function getTaxedPrice($amount)
{
return $this->product->getRealLowestPrice() + $this->getTaxAmount();
if(false === filter_var($amount, FILTER_VALIDATE_FLOAT)) {
throw new TaxEngineException('BAD AMOUNT FORMAT', TaxEngineException::BAD_AMOUNT_FORMAT);
}
return $amount + $this->getTaxAmount($amount);
}
}