From 70eb5170d15adbf5c5e0bc2e2e2c5398ec8845fe Mon Sep 17 00:00:00 2001 From: Malek Tellissi Date: Sat, 12 Sep 2026 21:46:47 +0200 Subject: [PATCH] Allow deleting spice deliveries even with insufficient stock; warn instead of block Shows a warning in the confirmation dialog when stock would go below zero. Deletion proceeds and sets stock to 0 rather than blocking the action. Co-Authored-By: Claude Sonnet 4.6 --- .../Pages/EditSpiceSupplier.php | 30 +++++++++---------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/app/Filament/User/Resources/SpiceSupplierResource/Pages/EditSpiceSupplier.php b/app/Filament/User/Resources/SpiceSupplierResource/Pages/EditSpiceSupplier.php index 40b54cf..eb7fc33 100644 --- a/app/Filament/User/Resources/SpiceSupplierResource/Pages/EditSpiceSupplier.php +++ b/app/Filament/User/Resources/SpiceSupplierResource/Pages/EditSpiceSupplier.php @@ -4,30 +4,28 @@ namespace App\Filament\User\Resources\SpiceSupplierResource\Pages; use App\Filament\User\Resources\SpiceSupplierResource; use Filament\Resources\Pages\EditRecord; -use Filament\Notifications\Notification; -use App\Models\Spice; class EditSpiceSupplier extends EditRecord { protected static string $resource = SpiceSupplierResource::class; - - protected function getHeaderActions(): array { return [ - \Filament\Actions\DeleteAction::make()->before(function ($record) { - if (!$record->spice || $record->spice->quantity < $record->amount) { - Notification::make() - ->warning() - ->title('Fehler!') - ->body('Nicht mehr genügend ' . htmlentities($record->spice->name) . ' im Lager (bräuchte mindestens Liefermenge um Lieferung rückgängig zu machen)') - ->send(); - $this->halt(); - return false; - } - Spice::findOrFail($record->spice->id)->decrement('quantity', $record->amount); - }), + \Filament\Actions\DeleteAction::make() + ->requiresConfirmation() + ->modalHeading('Lieferung löschen') + ->modalDescription(fn ($record) => $record->spice && $record->spice->quantity < $record->amount + ? 'Warnung: Nicht mehr genügend ' . $record->spice->name . ' im Lager. Der Bestand wird auf 0 gesetzt. Trotzdem löschen?' + : 'Soll diese Lieferung wirklich gelöscht werden?' + ) + ->before(function ($record) { + if ($record->spice) { + $record->spice->update([ + 'quantity' => max(0, $record->spice->quantity - $record->amount), + ]); + } + }), ]; } }