Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
17 / 17
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
TaxRate
100.00% covered (success)
100.00%
16 / 16
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%
15 / 15
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\Model;
8
9defined('AMMONLY_APP') || exit('Direct script access is forbidden.');
10
11use App\Modules\Tax\Domain\ValueObject\TaxCalculationMode;
12use App\Modules\Tax\Domain\ValueObject\TaxStatus;
13
14/**
15 * Domain Aggregate Root representing a tax rate configuration.
16 */
17final class TaxRate
18{
19    /**
20     * TaxRate constructor.
21     *
22     * @param int|null $id Database primary key ID
23     * @param string $taxCode Unique identifying code (e.g. VAT_23)
24     * @param string $taxName Descriptive name of the tax rate
25     * @param float $ratePercent Numerical tax rate percentage
26     * @param TaxCalculationMode $calculationMode Calculation algorithm mode
27     * @param TaxStatus $taxStatus Legal accounting tax status
28     * @param string|null $legalExemptionNote Statutory legal exemption note
29     * @param string|null $fiscalCode Fiscal code for e-invoices (JPK/KSeF/OSS)
30     * @param bool $isDefault Flag indicating if this is default rate for new products
31     * @param bool $isActive Flag indicating if rate is currently available for selection
32     * @param int $owner User ID of the owner
33     * @param string|null $createdAt Timestamp of creation
34     * @param string|null $updatedAt Timestamp of last update
35     */
36    public function __construct(
37        public ?int $id,
38        public string $taxCode,
39        public string $taxName,
40        public float $ratePercent,
41        public TaxCalculationMode $calculationMode,
42        public TaxStatus $taxStatus,
43        public ?string $legalExemptionNote = null,
44        public ?string $fiscalCode = null,
45        public bool $isDefault = false,
46        public bool $isActive = true,
47        public int $owner = 1,
48        public ?string $createdAt = null,
49        public ?string $updatedAt = null,
50    ) {
51    }
52
53    /**
54     * Convert TaxRate aggregate to associative array.
55     *
56     * @return array<string, mixed>
57     */
58    public function toArray(): array
59    {
60        return [
61            'id' => $this->id,
62            'tax_code' => $this->taxCode,
63            'tax_name' => $this->taxName,
64            'rate_percent' => $this->ratePercent,
65            'calculation_mode' => $this->calculationMode->value,
66            'tax_status' => $this->taxStatus->value,
67            'legal_exemption_note' => $this->legalExemptionNote,
68            'fiscal_code' => $this->fiscalCode,
69            'is_default' => $this->isDefault,
70            'is_active' => $this->isActive,
71            'owner' => $this->owner,
72            'created_at' => $this->createdAt,
73            'updated_at' => $this->updatedAt,
74        ];
75    }
76}