gruene-seele/app/Models/ProductionIngredient.php
Kevin Adametz b8180a06a1 Warenwirtschaft: AP-53 — Gramm-Mengen mit drei Nachkommastellen (Produktion, Wareneingang, Ausschuss)
Kundennachtrag 09.09.2026: Ist-Mengen je Charge in der Produktion sollen auf das Milligramm eingegeben werden können (z. B. 0,125 g). Bisher rundeten Datenbank (decimal 12,2), Bestandslogik, Anzeige und Toleranzsockel auf zwei Stellen; „0,125" wurde still zu 0,13, „0.125" nach der Punkt-Regel zu 125 g.

- Migration 2026_09_09_100000: production_ingredients.quantity_used, stock_entries.ordered_quantity/received_quantity, stock_disposals.quantity → decimal(12,3); Casts decimal:3. Auf der Dev-DB (Live-Kopie) ausgeführt, 53/78/7 Zeilen unverändert.
- InventoryService::QUANTITY_DECIMALS = 3; roundWawiQuantity() ersetzt alle round(…, 2) in InventoryService, ProductionService, StockDisposalController/-Request, StockEntryRepository/-Controller, RawMaterialStockController.
- formatWawiQuantity($v, $min = 2): bis drei Stellen, mindestens zwei — Produktionsdetail, Einkauf Liste/Detail/Formular, Ausschuss-Liste, Chargen-Rest im Rohstoff-Detail.
- Eingaberegel (reFormatWawiNumber, JS parseGerman/parseNumber): zusätzlich „0.xxx" als Dezimalzahl; „1.500" bleibt 1500. Produktions-JS: fmt() bis drei Stellen, fmtInput() schreibt gespeicherte Zahlen deutsch ins Feld (1,125 statt 1.125 = 1125).
- Soll-Ist-Toleranz: Sockel 0,05 → 0,005 g; Ausschuss min 0,001.
- Doku: Hinweise (Neu/geändert), Leitfaden Version 3.1 mit Abschnitt 26, Plan V7 AP-53, README (Deploy-Checkliste, Suite 378).

Tests: QuantityPrecisionTest (6) — Parsing, Anzeige, Produktion 0,125 g exakt + Rest 9,875 g, Entwurf 1,125 wiederöffnen, Toleranz Kleinmengen, Ausschuss 0,005 g.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-09 15:54:29 +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:3',
];
}
/**
* @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);
}
}