Phase 1: Wohnungen, Saisons & Preisberechnung
- Datenmodell Property/Season/Extra (Beträge in Cent), Seeder mit Preisliste 2026 - PriceCalculator: Saison-Splitting, Mindestaufenthalt, Zusatzperson, Endreinigung, Extras, Anzahlung/Restzahlung - Filament-Verwaltung: Wohnungen, Saisons (Überschneidungsprüfung, Lückenwarnung, Kopie ins Folgejahr, Preisrechner), Zusatzleistungen - Tests für Preisberechnung und Saisonverwaltung Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
bf4c1c0838
commit
2e9a391b37
35 files changed
+1766
-12
No files matched your search
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace App\Pricing;
|
||||
|
||||
use Carbon\CarbonImmutable;
|
||||
|
||||
/**
|
||||
* The complete price of a stay. Amounts are in euro cents.
|
||||
*/
|
||||
final readonly class PriceQuote
|
||||
{
|
||||
/**
|
||||
* @param list<QuoteLine> $lines
|
||||
*/
|
||||
public function __construct(
|
||||
public CarbonImmutable $arrival,
|
||||
public CarbonImmutable $departure,
|
||||
public int $guests,
|
||||
public array $lines,
|
||||
public int $depositPercent,
|
||||
public CarbonImmutable $balanceDueOn,
|
||||
) {}
|
||||
|
||||
public function nights(): int
|
||||
{
|
||||
return (int) $this->arrival->diffInDays($this->departure);
|
||||
}
|
||||
|
||||
public function total(): int
|
||||
{
|
||||
return array_sum(array_map(fn (QuoteLine $line): int => $line->amount, $this->lines));
|
||||
}
|
||||
|
||||
public function rent(): int
|
||||
{
|
||||
return array_sum(array_map(
|
||||
fn (QuoteLine $line): int => $line->type->isRent() ? $line->amount : 0,
|
||||
$this->lines,
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Deposit as a share of the rent (nights and extra guests, without cleaning and extras), rounded to full cents.
|
||||
*/
|
||||
public function deposit(): int
|
||||
{
|
||||
return intdiv($this->rent() * $this->depositPercent + 50, 100);
|
||||
}
|
||||
|
||||
public function balance(): int
|
||||
{
|
||||
return $this->total() - $this->deposit();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{arrival: string, departure: string, nights: int, guests: int, lines: list<array<string, mixed>>, total: int, deposit: int, balance: int, balance_due_on: string}
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
return [
|
||||
'arrival' => $this->arrival->toDateString(),
|
||||
'departure' => $this->departure->toDateString(),
|
||||
'nights' => $this->nights(),
|
||||
'guests' => $this->guests,
|
||||
'lines' => array_map(fn (QuoteLine $line): array => $line->toArray(), $this->lines),
|
||||
'total' => $this->total(),
|
||||
'deposit' => $this->deposit(),
|
||||
'balance' => $this->balance(),
|
||||
'balance_due_on' => $this->balanceDueOn->toDateString(),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user