Skip to content

Commit

Permalink
Merge pull request #13 from Dropelikeit/tax_fix
Browse files Browse the repository at this point in the history
Fix tax calculation bug
  • Loading branch information
Dropelikeit committed Nov 3, 2018
2 parents 61fbf0a + 64d5c8c commit 6c2d0fe
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
7 changes: 3 additions & 4 deletions src/PriceCalculator.php
Expand Up @@ -6,9 +6,7 @@
use MarcelStrahl\PriceCalculator\Helpers\Types\VatInterface;

/**
* Class PriceCalculator
* @author Marcel Strahl <info@marcel-strahl.de>
* @package Src
*/
class PriceCalculator implements PriceCalculatorInterface
{
Expand All @@ -18,7 +16,7 @@ class PriceCalculator implements PriceCalculatorInterface
private $vat;

/**
* @param $vat
* @param VatInterface $vat
*/
public function __construct(VatInterface $vat)
{
Expand Down Expand Up @@ -70,7 +68,8 @@ public function mulPrice(float $amount, float $price): float
*/
public function calculatePriceWithSalesTax(float $netPrice): float
{
return (float)round((float)bcmul($netPrice, $this->vat->getVatToCalculate(), 2));
$vat = (float)round((float)bcmul($netPrice, bcdiv($this->vat->getVat(), 100, 2), 4), 2);
return (float)bcadd($netPrice, $vat, 2);
}

/**
Expand Down
11 changes: 6 additions & 5 deletions tests/PriceCalculatorTest.php
Expand Up @@ -10,9 +10,7 @@
use MarcelStrahl\PriceCalculator\PriceCalculator;

/**
* Class PriceCalculatorTest
* @author Marcel Strahl <info@marcel-strahl.de>
* @package Tests
*/
class PriceCalculatorTest extends TestCase
{
Expand Down Expand Up @@ -184,16 +182,19 @@ public function dataProviderPriceWithSalesTax(): array
{
return [
[
252, 300
31.51, 37.50
],
[
340, 405
252, 299.88
],
[
340, 404.60
],
[
200, 238
],
[
13, 15
13, 15.47
],
[
64000, 76160
Expand Down

0 comments on commit 6c2d0fe

Please sign in to comment.