Files
fewo-stommer/app/Console/Commands/SendPendingAutoOffers.php
T
LarsandClaude Opus 5.5 40d20cb7d1 Pakete 7 und 9: Auskunft und Buchungswunsch, Aufenthalt und Abschluss (Zwischenstand)
- Haltefrist 0: unverbindliche Auskunft mit signiertem Link "Buchung anfragen",
  erneute Prüfung unter Sperre, automatische oder manuelle Bestätigung, Absage
  bei vergebenem Zeitraum, Ablauf unbeantworteter Auskünfte
- Aufenthalt: Anreisedaten, Aufgaben je Wohnung, gebuchte Leistungen,
  Abweichungen und Folgeaufgaben als Aufgaben am Vorgang
- Abschluss getrennt: Aufenthalt abgeschlossen / kaufmännisch abgeschlossen,
  Nachläufer (Forderung, Auszahlung) bleiben sichtbar
- Zahlungsstatus nur aus Geld auf unserem Konto; Altbestand per Vorschau-Befehl
- Verlauf weist Testzustellungen als solche aus
- Abnahmetests T16-T25, T23 über isolierten SMTP-Empfänger

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-02 08:29:19 +01:00

51 lines
2.1 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
namespace App\Console\Commands;
use App\Actions\AutoOffer;
use App\Enums\BookingStatus;
use App\Models\Booking;
use App\Models\Tenant;
use App\Tenancy\TenantRunner;
use Illuminate\Console\Attributes\Description;
use Illuminate\Console\Attributes\Signature;
use Illuminate\Console\Command;
use Throwable;
#[Signature('bookings:auto-offers')]
#[Description('Retry automatic offers of pending requests (e.g. once an instant-booking portal has fetched our calendar) – once per landlord')]
class SendPendingAutoOffers extends Command
{
/**
* Execute the console command.
*/
public function handle(AutoOffer $autoOffer, TenantRunner $runner): int
{
$runner->each(function (Tenant $tenant) use ($autoOffer): void {
$pending = Booking::query()
->where('status', BookingStatus::Reserved)
->where('offer_version', 0)
->where('information_version', 0)
// Held requests while their hold runs; requests without a hold (information, package 7) for two weeks.
->where(fn ($query) => $query->where('hold_expires_at', '>', now())->orWhere(fn ($open) => $open->whereNull('hold_expires_at')->where('created_at', '>', now()->subDays(14))))
->where(fn ($query) => $query->whereNull('intake')->orWhere('intake', 'inquiry'))
->with(['property', 'guest', 'importChannel', 'originChannel'])
->get()
->filter(fn (Booking $booking): bool => $autoOffer->applies($booking) && ($booking->isHoldActive() || ! $booking->process()->preReservation()));
$sent = 0;
foreach ($pending as $booking) {
try {
$sent += $autoOffer->handle($booking) === [] ? 1 : 0;
} catch (Throwable) {
// The request stays pending for the landlord; the next run tries again.
}
}
$this->info("{$tenant->name}: {$sent} von {$pending->count()} Angebot(e) automatisch versendet.");
});
return self::SUCCESS;
}
}