Files
fewo-stommer/app/Channels/ICal/ICalExportFields.php
LarsandClaude Opus 5.5 3bcfc09417
Deploy FeWo mit PipelineManager / deploy (push) Successful in 4m44s
Pakete 8, 5 und 6: Beträge und Zahlungen, Ändern und Stornieren, A6 im Vorgang
- 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>
2026-11-01 22:16:47 +01:00

73 lines
4.0 KiB
PHP
Raw Permalink 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\Channels\ICal;
use App\Models\BlockedPeriod;
use App\Models\Booking;
use App\Models\Channel;
class ICalExportFields
{
public const FIELDS = ['occupation_label' => 'Belegungsbeschreibung', 'guest_first_name' => 'Gastvorname / Namensbestandteil', 'guest_full_name' => 'Vollständiger Gastname', 'booking_reference' => 'Buchungsreferenz', 'note' => 'Zusätzliche Textinformation', 'property_name' => 'Wohnungsname', 'channel_name' => 'Bekannter Ursprung / Importkanal', 'arrival' => 'Anreise', 'departure' => 'Abreise', 'nights' => 'Anzahl Nächte'];
public const ICAL_FIELDS = ['SUMMARY' => 'SUMMARY – Bezeichnung', 'DESCRIPTION' => 'DESCRIPTION – Beschreibung', 'LOCATION' => 'LOCATION – Ort / Wohnung'];
/** @return array<string, string> */
public function properties(Channel $channel, Booking|BlockedPeriod $occupation): array
{
$context = $this->context($occupation);
if (! $channel->ical_export_names) {
unset($context['guest_first_name'], $context['guest_full_name']);
}
$properties = ['SUMMARY' => 'Belegt'];
foreach ($channel->ical_export_mapping ?? [] as $mapping) {
if (! isset(self::ICAL_FIELDS[$mapping['field'] ?? ''])) {
continue;
}
$parts = [];
foreach ($mapping['items'] ?? [] as $item) {
if (isset(self::FIELDS[$item]) && filled($context[$item] ?? null)) {
$parts[] = $context[$item];
}
}
if ($parts !== []) {
$properties[$mapping['field']] = implode($mapping['separator'] ?? ' – ', $parts);
}
}
return $properties;
}
/** @return array<string, string|null> */
public function context(Booking|BlockedPeriod $occupation): array
{
// Own use, private stays and blocks (A6) are exported exactly like the manual blocks they replace: no reference;
// a guest's name only where the channel exports names at all.
if ($occupation instanceof Booking && $occupation->isInternal()) {
$guest = $occupation->guest?->anonymized_at === null ? $occupation->guest : null;
return ['occupation_label' => 'Belegt', 'property_name' => $occupation->property->name, 'arrival' => $occupation->arrival->format('d.m.Y'),
'departure' => $occupation->departure->format('d.m.Y'), 'nights' => (string) (int) $occupation->arrival->diffInDays($occupation->departure), 'channel_name' => null,
...($guest !== null ? ['guest_first_name' => $guest->first_name, 'guest_full_name' => filled($guest->last_name) ? $guest->full_name : null] : [])];
}
$booking = $occupation instanceof Booking;
$start = $booking ? $occupation->arrival : $occupation->starts_on;
$end = $booking ? $occupation->departure : $occupation->ends_on;
$context = ['occupation_label' => $booking ? 'Buchung' : (ICalRuleEngine::TYPES[$occupation->ical_event_type] ?? 'Belegt'),
'property_name' => $occupation->property->name, 'arrival' => $start->format('d.m.Y'), 'departure' => $end->format('d.m.Y'),
'nights' => (string) (int) $start->diffInDays($end),
'channel_name' => $booking ? null : ($occupation->originChannel?->name ?? $occupation->channel?->name)];
if ($booking) {
return [...$context, 'guest_first_name' => $occupation->guest?->first_name, 'guest_full_name' => $occupation->guest?->full_name, 'booking_reference' => $occupation->reference];
}
$fields = array_intersect_key($occupation->ical_interpretation['fields'] ?? [], self::FIELDS);
if ($occupation->guest !== null) {
$fields['guest_first_name'] = $occupation->guest->anonymized_at === null ? $occupation->guest->first_name : null;
$fields['guest_full_name'] = $occupation->guest->anonymized_at === null && filled($occupation->guest->last_name) ? $occupation->guest->full_name : null;
}
return [...$context, ...$fields];
}
}