Auto-deduct spice inventory when batch is created/updated/deleted
Deploy / deploy (push) Successful in 14s
Deploy / deploy (push) Successful in 14s
- Add size_id, units_produced, quantity_g to batches table - quantity_g auto-calculated from units × packing size on save - Batch model deducts spice quantities on create, reverses on delete, recalculates on update when relevant fields change - Batch form shows live total weight preview - Chargen table shows units + grams produced Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
1e93aaa7d8
commit
a34bb29620
4 files changed
+163
-1
No files matched your search
@@ -4,11 +4,13 @@ namespace App\Filament\User\Resources;
|
||||
|
||||
use App\Filament\User\Resources\BatchResource\Pages;
|
||||
use App\Models\Batch;
|
||||
use App\Models\ProductSize;
|
||||
use App\Models\Recipe;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Forms\Get;
|
||||
use Filament\Resources\Resource;
|
||||
use Illuminate\Support\HtmlString;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
@@ -38,6 +40,17 @@ class BatchResource extends Resource
|
||||
->searchable()
|
||||
->preload()
|
||||
->required()
|
||||
->live()
|
||||
->afterStateUpdated(fn ($set) => $set('size_id', null)),
|
||||
|
||||
Forms\Components\Select::make('size_id')
|
||||
->label('Variante (Verpackung)')
|
||||
->options(fn (Get $get) => ProductSize::with('packing')
|
||||
->where('product_id', $get('product_id'))
|
||||
->get()
|
||||
->mapWithKeys(fn ($s) => [$s->id => $s->packing->name . ' ' . $s->packing->size . 'g'])
|
||||
)
|
||||
->required()
|
||||
->live(),
|
||||
|
||||
Forms\Components\Select::make('recipe_id')
|
||||
@@ -48,6 +61,25 @@ class BatchResource extends Resource
|
||||
->required()
|
||||
->live(),
|
||||
|
||||
Forms\Components\TextInput::make('units_produced')
|
||||
->label('Anzahl Einheiten')
|
||||
->numeric()
|
||||
->required()
|
||||
->live(debounce: 400),
|
||||
|
||||
Forms\Components\Placeholder::make('quantity_g_preview')
|
||||
->label('Gesamtgewicht (berechnet)')
|
||||
->content(function (Get $get): HtmlString {
|
||||
$units = (int) $get('units_produced');
|
||||
$sizeId = $get('size_id');
|
||||
if (! $units || ! $sizeId) {
|
||||
return new HtmlString('<span class="text-gray-400">—</span>');
|
||||
}
|
||||
$size = ProductSize::with('packing')->find($sizeId);
|
||||
$totalG = $units * ($size?->packing?->size ?? 0);
|
||||
return new HtmlString("<strong>{$totalG} g</strong> ({$units} × {$size?->packing?->size}g)");
|
||||
}),
|
||||
|
||||
Forms\Components\DatePicker::make('produced_at')
|
||||
->label('Produktionsdatum'),
|
||||
|
||||
|
||||
Reference in new issue
Block a user