Phase 1: Wohnungen, Saisons & Preisberechnung
- 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>
This commit is contained in:
1 parent
bf4c1c0838
commit
2e9a391b37
35 files changed
+1766
-12
No files matched your search
@@ -0,0 +1,43 @@
|
||||
<?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];
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user