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 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;
\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),
]);
}
Spice::findOrFail($record->spice->id)->decrement('quantity', $record->amount);
}),
];
}