Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
87.50% covered (warning)
87.50%
7 / 8
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
InclusiveVatCalculator
85.71% covered (warning)
85.71%
6 / 7
0.00% covered (danger)
0.00%
0 / 1
2.01
0.00% covered (danger)
0.00%
0 / 1
 calculate
85.71% covered (warning)
85.71%
6 / 7
0.00% covered (danger)
0.00%
0 / 1
2.01
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 Inclusive Tax (B2C / Retail: Unit price is Gross, Tax is extracted).
17 */
18final readonly class InclusiveVatCalculator 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        $gross = $this->calculateBaseAmount($unitPrice, $quantity, $discountAmount, $roundingMethod);
32
33        if (!$this->isStandardTaxableRate($taxRate)) {
34            return $this->buildZeroTaxResult($taxRate, $gross);
35        }
36
37        $divisor = 1.0 + ($taxRate->ratePercent / 100.0);
38        $net = $roundingMethod->round($gross / $divisor, 2);
39        $tax = $roundingMethod->round($gross - $net, 2);
40
41        return $this->buildResult($taxRate, $net, $tax, $gross);
42    }
43}