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

+21 -1
View File
@@ -18,7 +18,6 @@ class SpiceSupplier extends Model
'supplied_at',
];
// Beziehungen
public function spice()
{
return $this->belongsTo(Spice::class);
@@ -28,4 +27,25 @@ class SpiceSupplier extends Model
{
return $this->belongsTo(Supplier::class);
}
protected static function booted(): void
{
static::created(function (SpiceSupplier $ss) {
SpiceStockMovement::create([
'spice_id' => $ss->spice_id,
'amount' => $ss->amount,
'source_type' => 'delivery',
'source_id' => $ss->id,
'description' => 'Lieferung' . ($ss->supplier ? ' von ' . $ss->supplier->name : ''),
]);
$ss->spice->recalculateQuantity();
});
static::deleted(function (SpiceSupplier $ss) {
SpiceStockMovement::where('source_type', 'delivery')
->where('source_id', $ss->id)
->delete();
$ss->spice->recalculateQuantity();
});
}
}