Commit 054881ae authored by Thorsten Buss's avatar Thorsten Buss

add missing taxAmountOnly() to TaxedMoney

parent fff3d842
......@@ -183,6 +183,15 @@ class TaxedMoney extends Money {
throw new MoneyException('Problems with defined types in TaxedMoney');
}
/**
* return the tax amount
* @param int $precision the number of precision positions for better calucations with the amount
* @return float|int
*/
public function taxAmountOnly($precision=0) {
return $this->calcTax($this->amountWithoutTax(), $precision);
}
/**
* return the amount with tax
* @param int $precision the number of precision positions for better calucations with the amount
......@@ -225,6 +234,16 @@ class TaxedMoney extends Money {
return $this->round($amount * (1 + $this->tax/100), $precision);
}
/**
* calc the tax amount with the percentage of tax from the given amount
* @param float|int $amount
* @param int $precision the number of precision positions for better calucations with the amount
* @return float|int int if precision=0
*/
protected function calcTax($amount, $precision=0) {
return $this->round($amount * ($this->tax/100), $precision);
}
/**
* round the given float value from calulations as int
* @param float $amount
......
......@@ -34,24 +34,29 @@ class TaxedMoneyTest extends MoneyTest {
$m = $this->money(123456, 'EUR', 19);
$this->assertEquals(123456, $m->amountWithoutTax(), 'without tax (no calculaction)');
$this->assertEquals(146913, $m->amountWithTax(), 'with tax');
$this->assertEquals(23457, $m->taxAmountOnly(), 'only tax');
$this->assertEquals(146913, $m->amount(), 'with tax (auto detect)');
// Gross -> Gross
$m = $this->money(123456, 'EUR', 19, TaxedMoney::TYPE_GROSS);
$this->assertEquals(103745, $m->amountWithoutTax(), 'without tax');
$this->assertEquals(123456, $m->amountWithTax(), 'with tax (no calculaction)');
// calculationProblem -> 19711.55
$this->assertEquals(19712, $m->taxAmountOnly(), 'only tax');
$this->assertEquals(123456, $m->amount(), 'with tax (auto detect)');
// Net -> Net
$m = $this->money(123456, 'EUR', 19, TaxedMoney::TYPE_NET, TaxedMoney::TYPE_NET);
$this->assertEquals(123456, $m->amountWithoutTax(), 'without tax (no calculaction)');
$this->assertEquals(146913, $m->amountWithTax(), 'with tax');
$this->assertEquals(23457, $m->taxAmountOnly(), 'only tax');
$this->assertEquals(123456, $m->amount(), 'with tax (auto detect)');
// Gross -> Net
$m = $this->money(123456, 'EUR', 19, TaxedMoney::TYPE_GROSS, TaxedMoney::TYPE_NET);
$this->assertEquals(103745, $m->amountWithoutTax(), 'without tax');
$this->assertEquals(123456, $m->amountWithTax(), 'with tax (no calculaction)');
$this->assertEquals(19712, $m->taxAmountOnly(), 'only tax');
$this->assertEquals(103745, $m->amount(), 'with tax (auto detect)');
}
......@@ -70,6 +75,7 @@ class TaxedMoneyTest extends MoneyTest {
$m = $this->money(123456, 'EUR', 19.99999, TaxedMoney::TYPE_NET, TaxedMoney::TYPE_GROSS);
$this->assertEquals(148147.1876544, $m->amountWithTax(10), 'with tax');
$this->assertEquals(24691.1876544, $m->taxAmountOnly(10), 'only tax');
$this->assertEquals(148147.1876544, $m->amount(10), 'with tax (auto detect)');
}
......@@ -110,6 +116,7 @@ class TaxedMoneyTest extends MoneyTest {
// return the gross: 11.90EUR
$this->assertEquals(1190, $m->amount());
$this->assertEquals(1190, $m->amountWithTax());
$this->assertEquals(190, $m->taxAmountOnly());
}
public function testMultiplication() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment