$lines */ public function __construct( public int $id, public string $soldAt, public int $sellerId, public string $sellerName, public ?string $customerName, public PaymentMethod $paymentMethod, public int $totalCents, public array $lines, public ?int $creditsSaleId, public ?int $creditedBySaleId, public ?string $receiptEmail = null, public ?string $receiptSentAt = null, public bool $receiptFailed = false, ) {} /** * The emailed receipt's state: null without an address, otherwise * 'sent', 'failed' or 'pending' (still in the queue). */ public function receiptStatus(): ?string { return match (true) { $this->receiptEmail === null => null, $this->receiptFailed => 'failed', $this->receiptSentAt !== null => 'sent', default => 'pending', }; } public function isCredit(): bool { return $this->creditsSaleId !== null; } public function canBeCredited(): bool { return $this->creditsSaleId === null && $this->creditedBySaleId === null; } /** * The sale's VAT by rate, highest rate first, as on its receipt. * * @return list */ public function vatTotals(): array { $grossByRate = []; foreach ($this->lines as $line) { $grossByRate[$line->vatBasisPoints] = ($grossByRate[$line->vatBasisPoints] ?? 0) + $line->totalCents; } krsort($grossByRate); return array_map( fn (int $basisPoints, int $gross): VatTotal => VatTotal::ofGross($basisPoints, $gross), array_keys($grossByRate), array_values($grossByRate), ); } }