production_ingredients.recipe_phase_id; Formular sendet die Phase je Zeile, Vorbelegung je Rohstoff|Phase. Altbestand ohne Phase wird nur einmal eingesetzt. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
74 lines
1.8 KiB
PHP
74 lines
1.8 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;
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|