Deploy FeWo mit PipelineManager / deploy (push) Successful in 4m44s
- Paket 8: Zahlungsarten (Gast an uns, laut Portal, Auszahlung, Erstattung), Portalbeträge als Angaben mit Quelle, Übersicht nach Zuständigkeit (R09). - Paket 5: Ändern mit Folgenvorschau, vereinbart oder dem Gast vorgeschlagen (signierter Link), ein Stornoweg mit Grund und Erstattung, Portalstorno erst nach Bestätigung. - Paket 6: eigene Nutzung, Besuch und Sperre als Vorgang mit Kurabgabe und Aufenthaltsbestätigung; Bestandsübernahme der Sperren mit identischem Export. - Wirksame Einstellungen (Expertenansicht), Abnahmekatalog T01–T14, Ergebnis-, Abnahme- und Konfigurationsdokument. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
68 lines
3.5 KiB
PHP
68 lines
3.5 KiB
PHP
<?php
|
||
|
||
namespace App\Actions;
|
||
|
||
use App\Enums\AmountKind;
|
||
use App\Enums\PaymentKind;
|
||
use App\Enums\PaymentMethod;
|
||
use App\Models\Booking;
|
||
use App\Pricing\PortalPrice;
|
||
use App\Process\CaseAutomation;
|
||
use App\Process\CaseLog;
|
||
use App\Support\Money;
|
||
use Carbon\CarbonImmutable;
|
||
use Illuminate\Support\Facades\DB;
|
||
|
||
/**
|
||
* Takes over what a portal shows about a booking (package 8): the guest's total as the agreed price ("Gesamtpreis laut
|
||
* Portal"), and – as far as the portal shows them – price positions, collective amounts, commission, announced payouts,
|
||
* instalments and what the guest has paid to the portal. Every value is stored with its source and date as stated; the
|
||
* total is never recalculated from the positions, and a statement entered twice is stored once.
|
||
*/
|
||
class RecordPortalAmounts
|
||
{
|
||
public function __construct(private PortalPrice $price, private RecordPayment $payments) {}
|
||
|
||
/**
|
||
* @param list<array{kind: AmountKind|string, label?: ?string, amount: int, due_on?: ?string, note?: ?string}> $amounts
|
||
* @param list<array{amount: int, paid_on: string}> $paidViaPortal instalments the portal shows as paid by the guest
|
||
*/
|
||
public function handle(Booking $booking, ?int $guestTotal, array $amounts, array $paidViaPortal, string $source, ?CarbonImmutable $statedOn = null, ?string $by = null): void
|
||
{
|
||
$statedOn ??= CarbonImmutable::today();
|
||
|
||
DB::transaction(function () use ($booking, $guestTotal, $amounts, $paidViaPortal, $source, $statedOn, $by): void {
|
||
if ($guestTotal !== null && $guestTotal !== $booking->total) {
|
||
$before = $booking->total;
|
||
$booking->update($this->price->columns($booking->property, $booking->arrival, $booking->departure, $booking->guests, $guestTotal, $source));
|
||
CaseLog::record($booking, 'price', 'Gesamtpreis laut '.$source.': '.Money::format($guestTotal).($before !== null ? ' (vorher '.Money::format($before).')' : ''));
|
||
}
|
||
|
||
foreach ($amounts as $row) {
|
||
$kind = $row['kind'] instanceof AmountKind ? $row['kind'] : AmountKind::from((string) $row['kind']);
|
||
$label = filled($row['label'] ?? null) ? trim((string) $row['label']) : null;
|
||
$exists = $booking->amounts()->where('kind', $kind)->where('amount', (int) $row['amount'])->where('source', $source)
|
||
->where(fn ($query) => $label === null ? $query->whereNull('label') : $query->where('label', $label))->exists();
|
||
if ($exists) {
|
||
continue;
|
||
}
|
||
$booking->amounts()->create([
|
||
'kind' => $kind, 'label' => $label, 'amount' => (int) $row['amount'], 'source' => $source,
|
||
'stated_on' => $statedOn->toDateString(), 'due_on' => filled($row['due_on'] ?? null) ? $row['due_on'] : null,
|
||
'note' => filled($row['note'] ?? null) ? trim((string) $row['note']) : null, 'recorded_by' => $by,
|
||
]);
|
||
}
|
||
|
||
foreach ($paidViaPortal as $row) {
|
||
$paidOn = CarbonImmutable::parse($row['paid_on']);
|
||
$known = $booking->payments()->where('kind', PaymentKind::GuestViaPortal)->where('amount', (int) $row['amount'])->whereDate('paid_on', $paidOn)->exists();
|
||
if (! $known) {
|
||
$this->payments->handle($booking, (int) $row['amount'], $paidOn, PaymentMethod::Other, 'laut '.$source, $by, PaymentKind::GuestViaPortal, $source);
|
||
}
|
||
}
|
||
});
|
||
|
||
app(CaseAutomation::class)->advance($booking->fresh());
|
||
}
|
||
}
|