diff --git a/src/entity/price/Price.php b/src/entity/price/Price.php index 0ab355c..39676e1 100644 --- a/src/entity/price/Price.php +++ b/src/entity/price/Price.php @@ -2,6 +2,7 @@ namespace entity\price; use entity\currency\CurrencyInterface; +use entity\currency\Euro; /** * @@ -10,14 +11,43 @@ use entity\currency\CurrencyInterface; */ final class Price implements PriceInterface { + /** + * + * @var int|null + */ + private $tax; + + /** + * + * @var int + */ + private $netto; + public function getGross(): CurrencyInterface - {} + { + $gross = new Euro(); + $gross->setCents($this->netto->getCents()*(100+$this->tax)/100); + return $gross; + } public function getNetto(): CurrencyInterface - {} + { + return $this->netto; + } - public function setPrice(CurrencyInterface $price): void - {} + public function setPrice(CurrencyInterface $netto): void + { + $this->netto = $netto; + } + + public function setTax(int $percent): void + { + $this->tax = $percent; + } + public function getTax(): int + { + return $this->tax; + } } diff --git a/src/entity/price/PriceInterface.php b/src/entity/price/PriceInterface.php index 674bdd1..96cdf1e 100644 --- a/src/entity/price/PriceInterface.php +++ b/src/entity/price/PriceInterface.php @@ -14,7 +14,7 @@ interface PriceInterface * Sets the price * @param CurrencyInterface $price */ - public function setPrice(CurrencyInterface $price):void; + public function setPrice(CurrencyInterface $netto):void; /** * Returns the netto price @@ -27,5 +27,9 @@ interface PriceInterface * @return int */ public function getGross():CurrencyInterface; + + public function setTax(int $percent):void; + + public function getTax():int; } diff --git a/src/entity/price/PriceTest.php b/src/entity/price/PriceTest.php new file mode 100644 index 0000000..398bf15 --- /dev/null +++ b/src/entity/price/PriceTest.php @@ -0,0 +1,51 @@ +nettoEuro = new Euro(); + $this->nettoEuro->setCents(100); + $this->price = new Price(); + $this->price->setTax(self::TAX); + $this->price->setPrice($this->nettoEuro); + } + + public function testNetto():void{ + $this->assertEquals(self::NETTO, $this->price->getNetto()->getCents()); + } + + public function testGross():void{ + $this->assertEquals(self::GROSS, $this->price->getGross()->getCents()); + } + + public function testTax():void{ + $this->assertEquals(self::TAX, $this->price->getTax()); + } +} \ No newline at end of file