Introduce spice_stock_movements ledger for traceable stock changes
Deploy / deploy (push) Successful in 16s
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:
1 parent
7545aed494
commit
fb19e9a579
9 files changed
+179
-43
No files matched your search
@@ -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();
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user