Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
15 / 15 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| LineTaxResult | |
100.00% |
14 / 14 |
|
100.00% |
2 / 2 |
2 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| toArray | |
100.00% |
13 / 13 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | /** @license For full copyright and license information, please see the LICENSE.md file. */ |
| 6 | |
| 7 | namespace App\Modules\Tax\Domain\ValueObject; |
| 8 | |
| 9 | defined('AMMONLY_APP') || exit('Direct script access is forbidden.'); |
| 10 | |
| 11 | /** |
| 12 | * Immutable Value Object representing the calculated tax outcome for a single line item. |
| 13 | */ |
| 14 | final readonly class LineTaxResult |
| 15 | { |
| 16 | /** |
| 17 | * LineTaxResult constructor. |
| 18 | * |
| 19 | * @param string $taxCode Unique tax code (e.g. VAT_23) |
| 20 | * @param string $taxName Display tax name |
| 21 | * @param float $ratePercent Tax rate percentage (e.g. 23.0) |
| 22 | * @param TaxCalculationMode $calculationMode Mode used for calculation |
| 23 | * @param TaxStatus $taxStatus Legal tax status |
| 24 | * @param float $netAmount Net base amount after line discount |
| 25 | * @param float $taxAmount Calculated tax amount |
| 26 | * @param float $grossAmount Calculated gross amount |
| 27 | * @param float $whtAmount Optional withholding tax amount deducted |
| 28 | * @param string|null $legalClause Optional legal exemption or reverse charge clause |
| 29 | * @param string|null $fiscalCode Optional reporting code for e-invoicing |
| 30 | */ |
| 31 | public function __construct( |
| 32 | public string $taxCode, |
| 33 | public string $taxName, |
| 34 | public float $ratePercent, |
| 35 | public TaxCalculationMode $calculationMode, |
| 36 | public TaxStatus $taxStatus, |
| 37 | public float $netAmount, |
| 38 | public float $taxAmount, |
| 39 | public float $grossAmount, |
| 40 | public float $whtAmount = 0.0, |
| 41 | public ?string $legalClause = null, |
| 42 | public ?string $fiscalCode = null, |
| 43 | ) { |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Convert LineTaxResult to associative array for JSON serialization or snapshots. |
| 48 | * |
| 49 | * @return array<string, mixed> |
| 50 | */ |
| 51 | public function toArray(): array |
| 52 | { |
| 53 | return [ |
| 54 | 'tax_code' => $this->taxCode, |
| 55 | 'tax_name' => $this->taxName, |
| 56 | 'rate_percent' => $this->ratePercent, |
| 57 | 'calculation_mode' => $this->calculationMode->value, |
| 58 | 'tax_status' => $this->taxStatus->value, |
| 59 | 'net_amount' => $this->netAmount, |
| 60 | 'tax_amount' => $this->taxAmount, |
| 61 | 'gross_amount' => $this->grossAmount, |
| 62 | 'wht_amount' => $this->whtAmount, |
| 63 | 'legal_clause' => $this->legalClause, |
| 64 | 'fiscal_code' => $this->fiscalCode, |
| 65 | ]; |
| 66 | } |
| 67 | } |