Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
WithholdingTaxCalculator
100.00% covered (success)
100.00%
11 / 11
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 calculate
100.00% covered (success)
100.00%
11 / 11
100.00% covered (success)
100.00%
1 / 1
1
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 Withholding Tax (WHT: Deducted at source from payable amount).
17 */
18final readonly class WithholdingTaxCalculator extends AbstractTaxCalculator
19{
20    private const string DEFAULT_WHT_CLAUSE = 'Withholding tax deduction';
21
22    /**
23     * @inheritDoc
24     */
25    public function calculate(
26        float $unitPrice,
27        float $quantity,
28        float $discountAmount,
29        TaxRate $taxRate,
30        RoundingMethod $roundingMethod,
31        ?float $costPrice = null,
32    ): LineTaxResult {
33        $net = $this->calculateBaseAmount($unitPrice, $quantity, $discountAmount, $roundingMethod);
34        $rawWht = $net * ($taxRate->ratePercent / 100.0);
35        $wht = $roundingMethod->round($rawWht, 2);
36
37        return $this->buildResult(
38            taxRate: $taxRate,
39            netAmount: $net,
40            taxAmount: 0.0,
41            grossAmount: $net,
42            whtAmount: $wht,
43            defaultLegalClause: self::DEFAULT_WHT_CLAUSE
44        );
45    }
46}