Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| ExclusiveVatCalculator | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
2 | |
100.00% |
1 / 1 |
| calculate | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | /** @license For full copyright and license information, please see the LICENSE.md file. */ |
| 6 | |
| 7 | namespace App\Modules\Tax\Domain\Service\Calculator; |
| 8 | |
| 9 | defined('AMMONLY_APP') || exit('Direct script access is forbidden.'); |
| 10 | |
| 11 | use App\Modules\Tax\Domain\Model\TaxRate; |
| 12 | use App\Modules\Tax\Domain\ValueObject\LineTaxResult; |
| 13 | use App\Modules\Tax\Domain\ValueObject\RoundingMethod; |
| 14 | |
| 15 | /** |
| 16 | * Calculator for Exclusive Tax (Standard B2B: Unit price is Net, Tax is added on top). |
| 17 | */ |
| 18 | final readonly class ExclusiveVatCalculator extends AbstractTaxCalculator |
| 19 | { |
| 20 | /** |
| 21 | * @inheritDoc |
| 22 | */ |
| 23 | public function calculate( |
| 24 | float $unitPrice, |
| 25 | float $quantity, |
| 26 | float $discountAmount, |
| 27 | TaxRate $taxRate, |
| 28 | RoundingMethod $roundingMethod, |
| 29 | ?float $costPrice = null, |
| 30 | ): LineTaxResult { |
| 31 | $net = $this->calculateBaseAmount($unitPrice, $quantity, $discountAmount, $roundingMethod); |
| 32 | |
| 33 | if (!$this->isStandardTaxableRate($taxRate)) { |
| 34 | return $this->buildZeroTaxResult($taxRate, $net); |
| 35 | } |
| 36 | |
| 37 | $rawTax = $net * ($taxRate->ratePercent / 100.0); |
| 38 | $tax = $roundingMethod->round($rawTax, 2); |
| 39 | $gross = $roundingMethod->round($net + $tax, 2); |
| 40 | |
| 41 | return $this->buildResult($taxRate, $net, $tax, $gross); |
| 42 | } |
| 43 | } |