Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
16 / 16
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
DocumentTaxSummary
100.00% covered (success)
100.00%
15 / 15
100.00% covered (success)
100.00%
2 / 2
2
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 toArray
100.00% covered (success)
100.00%
14 / 14
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\ValueObject;
8
9defined('AMMONLY_APP') || exit('Direct script access is forbidden.');
10
11/**
12 * Value Object representing the complete calculation result for an entire document.
13 */
14final readonly class DocumentTaxSummary
15{
16    /**
17     * DocumentTaxSummary constructor.
18     *
19     * @param LineTaxResult[] $lineResults Array of calculated lines
20     * @param TaxSummaryEntry[] $taxBreakdown Aggregated summary table per tax rate
21     * @param float $totalNet Total net base of document
22     * @param float $totalTax Total tax amount of document
23     * @param float $totalGross Total gross value of document
24     * @param float $totalWht Total withholding tax deducted
25     * @param float $totalPaymentDue Final amount to pay (Gross - WHT + Returnable deposits)
26     * @param RoundingStrategy $roundingStrategy Strategy used for rounding
27     * @param RoundingMethod $roundingMethod Rounding algorithm used
28     */
29    public function __construct(
30        public array $lineResults,
31        public array $taxBreakdown,
32        public float $totalNet,
33        public float $totalTax,
34        public float $totalGross,
35        public float $totalWht,
36        public float $totalPaymentDue,
37        public RoundingStrategy $roundingStrategy,
38        public RoundingMethod $roundingMethod,
39    ) {
40    }
41
42    /**
43     * Convert full document summary to associative array for API responses and JSON snapshots.
44     *
45     * @return array<string, mixed>
46     */
47    public function toArray(): array
48    {
49        return [
50            'lines' => array_map(static fn(LineTaxResult $line): array => $line->toArray(), $this->lineResults),
51            'tax_breakdown' => array_map(
52                static fn(TaxSummaryEntry $entry): array => $entry->toArray(),
53                $this->taxBreakdown
54            ),
55            'total_net' => $this->totalNet,
56            'total_tax' => $this->totalTax,
57            'total_gross' => $this->totalGross,
58            'total_wht' => $this->totalWht,
59            'total_payment_due' => $this->totalPaymentDue,
60            'rounding_strategy' => $this->roundingStrategy->value,
61            'rounding_method' => $this->roundingMethod->value,
62        ];
63    }
64}