Sperrzeiten um Eigenbelegung und privaten Buchungskanal erweitern
Deploy FeWo mit PipelineManager / deploy (push) Successful in 2m49s
Deploy FeWo mit PipelineManager / deploy (push) Successful in 2m49s
This commit is contained in:
1 parent
2b2e732612
commit
4389894959
12 files changed
+305
-28
No files matched your search
@@ -2,19 +2,34 @@
|
||||
|
||||
namespace App\Actions;
|
||||
|
||||
use App\Enums\BlockedPeriodPurpose;
|
||||
use App\Enums\OccupationKind;
|
||||
use App\Models\BlockedPeriod;
|
||||
use App\Models\Channel;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
class ClassifyPortalOccupation
|
||||
{
|
||||
public function handle(BlockedPeriod $occupation, OccupationKind $kind, ?int $originId = null): void
|
||||
/** @param array{block_purpose?: BlockedPeriodPurpose|string|null, block_note?: string|null, is_private?: bool} $details */
|
||||
public function handle(BlockedPeriod $occupation, OccupationKind $kind, ?int $originId = null, array $details = []): void
|
||||
{
|
||||
Gate::authorize('update', $occupation);
|
||||
DB::transaction(function () use ($occupation, $kind, $originId): void {
|
||||
if (($details['block_purpose'] ?? null) instanceof BlockedPeriodPurpose) {
|
||||
$details['block_purpose'] = $details['block_purpose']->value;
|
||||
}
|
||||
$details = Validator::make($details, [
|
||||
'block_purpose' => ['nullable', Rule::enum(BlockedPeriodPurpose::class)],
|
||||
'block_note' => ['nullable', 'string', 'max:255'],
|
||||
'is_private' => ['sometimes', 'boolean'],
|
||||
])->validate();
|
||||
if (($details['is_private'] ?? false) && $originId !== null) {
|
||||
throw ValidationException::withMessages(['origin_channel_id' => 'Privat und ein externer Buchungskanal können nicht gleichzeitig gewählt werden.']);
|
||||
}
|
||||
DB::transaction(function () use ($occupation, $kind, $originId, $details): void {
|
||||
$record = BlockedPeriod::query()->whereKey($occupation->id)->lockForUpdate()->firstOrFail();
|
||||
if (! in_array($record->source, ['channel', 'email'], true) || $record->is_representation) {
|
||||
throw ValidationException::withMessages(['occupation_kind' => 'Nur eigenständige Portalereignisse können hier eingeordnet werden.']);
|
||||
@@ -22,7 +37,13 @@ public function handle(BlockedPeriod $occupation, OccupationKind $kind, ?int $or
|
||||
if ($originId !== null && ! Channel::query()->where('property_id', $record->property_id)->whereKey($originId)->exists()) {
|
||||
throw ValidationException::withMessages(['origin_channel_id' => 'Der Ursprungskanal muss zur selben Wohnung gehören.']);
|
||||
}
|
||||
$record->forceFill(['occupation_kind' => $kind, 'origin_channel_id' => $originId])->save();
|
||||
$record->forceFill([
|
||||
'occupation_kind' => $kind,
|
||||
'origin_channel_id' => $originId,
|
||||
'is_private' => $details['is_private'] ?? false,
|
||||
'block_purpose' => $kind === OccupationKind::Block ? (array_key_exists('block_purpose', $details) ? $details['block_purpose'] : $record->block_purpose) : null,
|
||||
'block_note' => $kind === OccupationKind::Block ? (array_key_exists('block_note', $details) ? $details['block_note'] : $record->block_note) : null,
|
||||
])->save();
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user