Introduce spice_stock_movements ledger for traceable stock changes
Deploy / deploy (push) Successful in 16s

Every delivery and batch now writes a signed movement entry instead of
directly incrementing/decrementing spice.quantity. The balance is always
the sum of all movements. Existing data is backfilled in the migration.
Rohstoff edit page shows the full movement history (Lagerbewegungen tab).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Malek TellissiandClaude Sonnet 4.6 committed 2026-09-12 22:34:10 +02:00
1 parent 7545aed494
commit fb19e9a579
9 files changed
+179 -43

No files matched your search

@@ -78,7 +78,7 @@ class SpiceResource extends Resource
public static function getRelations(): array
{
return [
//
RelationManagers\StockMovementsRelationManager::class,
];
}
@@ -0,0 +1,34 @@
<?php
namespace App\Filament\User\Resources\SpiceResource\RelationManagers;
use Filament\Resources\RelationManagers\RelationManager;
use Filament\Tables;
use Filament\Tables\Table;
class StockMovementsRelationManager extends RelationManager
{
protected static string $relationship = 'stockMovements';
protected static ?string $title = 'Lagerbewegungen';
public function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('created_at')
->label('Datum')
->dateTime('d.m.Y H:i')
->sortable(),
Tables\Columns\TextColumn::make('description')
->label('Beschreibung'),
Tables\Columns\TextColumn::make('amount')
->label('Menge')
->formatStateUsing(fn ($state) => ($state > 0 ? '+' : '') . number_format($state, 2, ',', '.') . 'g')
->color(fn ($state) => $state > 0 ? 'success' : 'danger'),
])
->defaultSort('created_at', 'desc')
->paginated([25, 50]);
}
}
@@ -4,17 +4,8 @@ namespace App\Filament\User\Resources\SpiceSupplierResource\Pages;
use App\Filament\User\Resources\SpiceSupplierResource;
use Filament\Resources\Pages\CreateRecord;
use Illuminate\Database\Eloquent\Model;
use App\Models\Spice;
class CreateSpiceSupplier extends CreateRecord
{
protected static string $resource = SpiceSupplierResource::class;
protected function handleRecordCreation(array $data): Model {
$record = static::getModel()::create($data);
Spice::findOrFail($data['spice_id'])->increment('quantity', $data['amount']);
return $record;
}
}
@@ -16,14 +16,9 @@ class EditSpiceSupplier extends EditRecord
->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?'
? 'Warnung: Nach dem Löschen wird der Bestand von ' . $record->spice->name . ' negativ.'
: 'Soll diese Lieferung wirklich gelöscht werden?'
)
->before(function ($record) {
if ($record->spice) {
$record->spice->decrement('quantity', $record->amount);
}
}),
),
];
}
}