Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
ExclusiveVatCalculator
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
1 / 1
 calculate
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3declare(strict_types=1);
4
5/** @license For full copyright and license information, please see the LICENSE.md file. */
6
7namespace App\Modules\Tax\Domain\Service\Calculator;
8
9defined('AMMONLY_APP') || exit('Direct script access is forbidden.');
10
11use App\Modules\Tax\Domain\Model\TaxRate;
12use App\Modules\Tax\Domain\ValueObject\LineTaxResult;
13use 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 */
18final 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}