-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from Dropelikeit/tax_fix
Fix tax calculation bug
- Loading branch information
Showing
2 changed files
with
9 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,9 +6,7 @@ | |
use MarcelStrahl\PriceCalculator\Helpers\Types\VatInterface; | ||
|
||
/** | ||
* Class PriceCalculator | ||
* @author Marcel Strahl <[email protected]> | ||
* @package Src | ||
*/ | ||
class PriceCalculator implements PriceCalculatorInterface | ||
{ | ||
|
@@ -18,7 +16,7 @@ class PriceCalculator implements PriceCalculatorInterface | |
private $vat; | ||
|
||
/** | ||
* @param $vat | ||
* @param VatInterface $vat | ||
*/ | ||
public function __construct(VatInterface $vat) | ||
{ | ||
|
@@ -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); | ||
} | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,9 +10,7 @@ | |
use MarcelStrahl\PriceCalculator\PriceCalculator; | ||
|
||
/** | ||
* Class PriceCalculatorTest | ||
* @author Marcel Strahl <[email protected]> | ||
* @package Tests | ||
*/ | ||
class PriceCalculatorTest extends TestCase | ||
{ | ||
|
@@ -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 | ||
|