- Offer workflow: "Angebot senden" in the admin (dates, guests, promo code, manual price adjustment, validity from the property's hold time, message, guest data for the contract) with live price; contract draft PDF; signed, versioned offer page for the guest to accept (acceptance record without IP) or decline; expiry job, landlord notifications, editable offer texts, wording on the website. - 2FA is mandatory for every admin account. - Privacy: complete anonymisation (notes, attribution, review names, offer messages), shorter periods for unbinding requests, portal mail excerpts and attribution (configurable proposals), iCal summary not stored, known e-mail no longer overwrites guest data, security headers, bearer tokens for automations, metadata stripped from photo originals, review link throttled. - Daily database backup (backup:database) and scripts/backup-pull.sh for the NAS. - Theme: brand mark in header/footer, favicon/touch icon, wave divider, icons, illustration as image placeholder; navy follows the text colour for dark appearances. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
95 lines
2.8 KiB
PHP
95 lines
2.8 KiB
PHP
<?php
|
|
|
|
namespace App\Pricing;
|
|
|
|
use App\Enums\QuoteLineType;
|
|
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 ?bool $promoCodeApplied = null,
|
|
) {}
|
|
|
|
/**
|
|
* The same quote with one more line, e.g. a manual adjustment in an offer.
|
|
*/
|
|
public function withLine(QuoteLine $line): self
|
|
{
|
|
return new self($this->arrival, $this->departure, $this->guests, [...$this->lines, $line], $this->depositPercent, $this->balanceDueOn, $this->promoCodeApplied);
|
|
}
|
|
|
|
/**
|
|
* Total of all special offer discounts as a positive amount.
|
|
*/
|
|
public function discount(): int
|
|
{
|
|
return -array_sum(array_map(
|
|
fn (QuoteLine $line): int => $line->type === QuoteLineType::Discount ? $line->amount : 0,
|
|
$this->lines,
|
|
));
|
|
}
|
|
|
|
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, discount: int}
|
|
*/
|
|
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(),
|
|
'discount' => $this->discount(),
|
|
];
|
|
}
|
|
}
|