Nächster Schritt sofort sichtbar, Saisonkopie ohne Preislücke
Deploy FeWo mit PipelineManager / deploy (push) Successful in 4m34s

- Vorgang: Die Kopfaktionen werden nach jeder Aktion neu aufgebaut, damit der
  große Schalter gleich den nächsten Schritt zeigt (Filament baut sie vor der
  Aktion auf).
- In Folgejahr kopieren: Reicht eine bestehende Saison (z. B. Neujahr über den
  Jahreswechsel) nur über Beginn oder Ende der Kopie, wird die Kopie dort
  gekürzt statt ganz übersprungen; sonst blieb z. B. Januar bis März ohne Preis.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
LarsandClaude Opus 5.5 committed 2026-11-02 19:53:13 +01:00
1 parent 150a64e100
commit 2d2ffffa33
6 files changed
+90 -6

No files matched your search

+34 -3
View File
@@ -14,12 +14,13 @@ class CopySeasonsToNextYear
{
/**
* @param int|null $alignToWeekday ISO weekday (1 = Monday … 7 = Sunday) or null for the same calendar dates
* @return array{created: int, skipped: int}
* @return array{created: int, skipped: int, trimmed: int}
*/
public function handle(Property $property, int $year, ?int $alignToWeekday = null): array
{
$created = 0;
$skipped = 0;
$trimmed = 0;
$seasons = $property->seasons()->whereYear('starts_on', $year)->orderBy('starts_on')->get();
@@ -38,7 +39,8 @@ public function handle(Property $property, int $year, ?int $alignToWeekday = nul
continue;
}
if ($property->seasons()->overlapping($startsOn, $endsOn)->exists()) {
[$startsOn, $endsOn, $wasTrimmed] = $this->fitBetweenExisting($property, $startsOn, $endsOn);
if ($startsOn === null || $endsOn === null) {
$skipped++;
continue;
@@ -50,9 +52,38 @@ public function handle(Property $property, int $year, ?int $alignToWeekday = nul
'ends_on' => $endsOn,
]);
$created++;
$trimmed += $wasTrimmed ? 1 : 0;
}
return ['created' => $created, 'skipped' => $skipped];
return ['created' => $created, 'skipped' => $skipped, 'trimmed' => $trimmed];
}
/**
* Existing seasons win. One that only reaches over the start or the end of the copy shortens the copy there (e.g.
* a season over the turn of the year that ends a day after the moved start), so no nights stay without a price;
* the copy is left out only when an existing season lies within it or covers it completely.
*
* @return array{0: ?CarbonImmutable, 1: ?CarbonImmutable, 2: bool}
*/
private function fitBetweenExisting(Property $property, CarbonImmutable $startsOn, CarbonImmutable $endsOn): array
{
$originalStart = $startsOn;
$originalEnd = $endsOn;
foreach ($property->seasons()->overlapping($startsOn, $endsOn)->get() as $existing) {
if ($existing->starts_on->lessThanOrEqualTo($startsOn) && $existing->ends_on->greaterThan($startsOn)) {
$startsOn = $existing->ends_on;
}
if ($existing->ends_on->greaterThanOrEqualTo($endsOn) && $existing->starts_on->lessThan($endsOn)) {
$endsOn = $existing->starts_on;
}
}
if ($endsOn->lessThanOrEqualTo($startsOn) || $property->seasons()->overlapping($startsOn, $endsOn)->exists()) {
return [null, null, false];
}
return [$startsOn, $endsOn, ! $startsOn->equalTo($originalStart) || ! $endsOn->equalTo($originalEnd)];
}
/**
@@ -97,6 +97,24 @@ public function getSubheading(): string|Htmlable|null
return CaseActivities::situation($this->record);
}
/**
* Filament builds the header actions before an action runs; rebuild them afterwards so the large button already
* shows the next step instead of the one just done.
*/
protected function afterActionCalled(Action $action): void
{
parent::afterActionCalled($action);
$fresh = $this->record->exists ? $this->record->fresh() : null;
if ($fresh === null) {
return;
}
$this->record = $fresh;
$this->cachedHeaderActions = [];
$this->cacheInteractsWithHeaderActions();
}
protected function getHeaderActions(): array
{
$actions = collect([
@@ -213,7 +213,7 @@ private function copyToNextYearAction(): Action
->label('In Folgejahr kopieren')
->icon(Heroicon::OutlinedDocumentDuplicate)
->color('gray')
->modalDescription('Alle Saisons, die im gewählten Jahr beginnen, werden mit Preisen und Mindestnächten ins Folgejahr übernommen. Bereits belegte Zeiträume werden übersprungen.')
->modalDescription('Alle Saisons, die im gewählten Jahr beginnen, werden mit Preisen und Mindestnächten ins Folgejahr übernommen. Bestehende Saisons bleiben unverändert: Reicht eine davon in den neuen Zeitraum hinein, beginnt bzw. endet die Kopie an ihrer Grenze; liegt der Zeitraum ganz in bestehenden Saisons, wird er übersprungen.')
->schema([
Select::make('year')
->label('Jahr kopieren')
@@ -232,7 +232,11 @@ private function copyToNextYearAction(): Action
Notification::make()
->title("{$result['created']} Saisons nach ".((int) $data['year'] + 1).' kopiert')
->body($result['skipped'] > 0 ? "{$result['skipped']} übersprungen, da der Zeitraum bereits belegt ist." : 'Bitte Daten und Preise prüfen.')
->body(collect([
$result['trimmed'] > 0 ? "{$result['trimmed']} an bestehende Saisons angepasst (Beginn oder Ende verschoben)." : null,
$result['skipped'] > 0 ? "{$result['skipped']} übersprungen, da der Zeitraum bereits belegt ist." : null,
'Bitte Daten und Preise prüfen.',
])->filter()->implode(' '))
->success()
->send();
});