Allow deleting spice deliveries even with insufficient stock; warn instead of block
Deploy / deploy (push) Successful in 15s

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 <noreply@anthropic.com>
This commit is contained in:
Malek TellissiandClaude Sonnet 4.6 committed 2026-09-12 21:46:47 +02:00
1 parent a4f3254ebd
commit 70eb5170d1
1 file changed
+12 -14
@@ -4,29 +4,27 @@ namespace App\Filament\User\Resources\SpiceSupplierResource\Pages;
use App\Filament\User\Resources\SpiceSupplierResource; use App\Filament\User\Resources\SpiceSupplierResource;
use Filament\Resources\Pages\EditRecord; use Filament\Resources\Pages\EditRecord;
use Filament\Notifications\Notification;
use App\Models\Spice;
class EditSpiceSupplier extends EditRecord class EditSpiceSupplier extends EditRecord
{ {
protected static string $resource = SpiceSupplierResource::class; protected static string $resource = SpiceSupplierResource::class;
protected function getHeaderActions(): array protected function getHeaderActions(): array
{ {
return [ return [
\Filament\Actions\DeleteAction::make()->before(function ($record) { \Filament\Actions\DeleteAction::make()
if (!$record->spice || $record->spice->quantity < $record->amount) { ->requiresConfirmation()
Notification::make() ->modalHeading('Lieferung löschen')
->warning() ->modalDescription(fn ($record) => $record->spice && $record->spice->quantity < $record->amount
->title('Fehler!') ? 'Warnung: Nicht mehr genügend ' . $record->spice->name . ' im Lager. Der Bestand wird auf 0 gesetzt. Trotzdem löschen?'
->body('Nicht mehr genügend ' . htmlentities($record->spice->name) . ' im Lager (bräuchte mindestens Liefermenge um Lieferung rückgängig zu machen)') : 'Soll diese Lieferung wirklich gelöscht werden?'
->send(); )
$this->halt(); ->before(function ($record) {
return false; if ($record->spice) {
$record->spice->update([
'quantity' => max(0, $record->spice->quantity - $record->amount),
]);
} }
Spice::findOrFail($record->spice->id)->decrement('quantity', $record->amount);
}), }),
]; ];
} }