Amount.php
Pfad: src/Domain/Rechnung/Amount.php
Ext: php
Größe: 1145 Bytes
Geändert: 2026-07-16T14:10:20+02:00
Frühere Version vom 2026-07-16T14:10:20+02:00 · zur aktuellen Fassung
<?php
declare(strict_types=1);
namespace Demo\Domain\Rechnung;
/**
* Geldbetrags-Block mit einfacher Plausibilitaetspruefung.
*/
final class Amount
{
/**
* @param float $netto Netto.
* @param float $steuer Steuer.
* @param float $brutto Brutto.
* @param string $währung ISO-4217.
*/
public function __construct(
public readonly float $netto,
public readonly float $steuer,
public readonly float $brutto,
public readonly string $währung
) {
}
/**
* @param float $toleranz Toleranz fuer Netto + Steuer = Brutto.
* @return bool True, wenn die Saldenlogik plausibel ist.
*/
public function isConsistent(float $toleranz): bool
{
return abs(($this->netto + $this->steuer) - $this->brutto) <= $toleranz;
}
/**
* @return array<string,mixed> Strukturierte Ausfuehrung.
*/
public function toArray(): array
{
return [
'netto' => $this->netto,
'steuer' => $this->steuer,
'brutto' => $this->brutto,
'währung' => $this->währung,
];
}
}