gruene-seele/app/Models/ProductionIngredient.php
Kevin Adametz 313c6277ce Warenwirtschaft: N-01/N-03/N-05 — Entwurfsmenge ohne Charge, Snapshot-Signatur je Produkt, Alt-Ausschuss in Chargenverfügbarkeit
- N-01: Ist-Menge ohne gewählte Charge bleibt im Entwurf erhalten (Filter in
  Request und Service, formBatchKey liefert '' für chargenlose Zeilen).
- N-03: outputSignature summiert Stückzahlen je Produkt — ein Chargensplit
  ersetzt den historischen Verpackungs-Snapshot nicht mehr.
- N-05: Ausschuss ohne Chargenbezug (Altbestand) wird für die Verfügbarkeit je
  Standort FEFO auf die Chargen angerechnet (applyUnboundDisposals, lesend);
  Chargen-Ausschussprüfung nutzt dieselbe Verfügbarkeit.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-08 11:48:02 +00:00

78 lines
1.9 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class ProductionIngredient extends Model
{
protected $fillable = [
'production_id',
'ingredient_id',
'stock_entry_id',
'batch_key',
'recipe_phase_id',
'quantity_used',
];
/**
* F-04: Schlüssel für die Formular-Vorbelegung: Rohstoff + Rezeptur-Phase.
* Zeilen ohne Phase (Altbestand/Rezeptur ohne Phasen) enden auf „|“.
*/
public function formGroupKey(): string
{
return (int) $this->ingredient_id.'|'.($this->recipe_phase_id !== null ? (int) $this->recipe_phase_id : '');
}
/**
* F-03: Chargen-Schlüssel für das Formular — im Entwurf der roh gespeicherte
* batch_key, sonst aus dem aufgelösten Wareneingang abgeleitet.
*/
public function formBatchKey(): string
{
if (! empty($this->batch_key)) {
return (string) $this->batch_key;
}
if ($this->stock_entry_id === null) {
return ''; // N-01: Entwurfszeile ohne Charge — Menge bleibt, Charge wird später gewählt.
}
return $this->stockEntry?->batchGroupKey() ?? 'e:'.$this->stock_entry_id;
}
/**
* @return array<string, string>
*/
protected function casts(): array
{
return [
'quantity_used' => 'decimal:2',
];
}
/**
* @return BelongsTo<Production, $this>
*/
public function production(): BelongsTo
{
return $this->belongsTo(Production::class);
}
/**
* @return BelongsTo<Ingredient, $this>
*/
public function ingredient(): BelongsTo
{
return $this->belongsTo(Ingredient::class);
}
/**
* @return BelongsTo<StockEntry, $this>
*/
public function stockEntry(): BelongsTo
{
return $this->belongsTo(StockEntry::class);
}
}