- Datenmodell Property/Season/Extra (Beträge in Cent), Seeder mit Preisliste 2026 - PriceCalculator: Saison-Splitting, Mindestaufenthalt, Zusatzperson, Endreinigung, Extras, Anzahlung/Restzahlung - Filament-Verwaltung: Wohnungen, Saisons (Überschneidungsprüfung, Lückenwarnung, Kopie ins Folgejahr, Preisrechner), Zusatzleistungen - Tests für Preisberechnung und Saisonverwaltung Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
44 lines
1.1 KiB
PHP
44 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Actions;
|
|
|
|
use App\Models\Property;
|
|
|
|
/**
|
|
* Copies all seasons starting in a given year to the following year with the same calendar dates,
|
|
* so a new price year only needs adjusting instead of re-entering.
|
|
*/
|
|
class CopySeasonsToNextYear
|
|
{
|
|
/**
|
|
* @return array{created: int, skipped: int}
|
|
*/
|
|
public function handle(Property $property, int $year): array
|
|
{
|
|
$created = 0;
|
|
$skipped = 0;
|
|
|
|
$seasons = $property->seasons()->whereYear('starts_on', $year)->get();
|
|
|
|
foreach ($seasons as $season) {
|
|
$startsOn = $season->starts_on->addYearNoOverflow();
|
|
$endsOn = $season->ends_on->addYearNoOverflow();
|
|
|
|
if ($property->seasons()->overlapping($startsOn, $endsOn)->exists()) {
|
|
$skipped++;
|
|
|
|
continue;
|
|
}
|
|
|
|
$property->seasons()->create([
|
|
...$season->only(['name', 'nightly_rate', 'min_nights']),
|
|
'starts_on' => $startsOn,
|
|
'ends_on' => $endsOn,
|
|
]);
|
|
$created++;
|
|
}
|
|
|
|
return ['created' => $created, 'skipped' => $skipped];
|
|
}
|
|
}
|