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>
This commit is contained in:
Kevin Adametz 2026-09-09 15:54:29 +00:00
parent 021edbfcc7
commit b8180a06a1
25 changed files with 378 additions and 71 deletions

View file

@ -110,7 +110,7 @@ class RawMaterialStockController extends Controller
$remainingByLocation = $this->inventoryService->remainingByLocationForIngredient($ingredient->id);
$openOrders = $this->inventoryService->openOrdersForIngredient($ingredient->id);
$openTotal = round((float) $openOrders->sum('ordered_quantity'), 2);
$openTotal = roundWawiQuantity((float) $openOrders->sum('ordered_quantity'));
$daily = ($this->inventoryService->dailyConsumptionByIngredient([$ingredient->id]))[$ingredient->id] ?? null;
$minAlert = $ingredient->min_stock_alert !== null ? (float) $ingredient->min_stock_alert : null;
@ -128,7 +128,7 @@ class RawMaterialStockController extends Controller
'ingredient' => $ingredient,
'productStock' => $productStock,
'chargeGroups' => $chargeGroups,
'remaining' => round($remaining, 2),
'remaining' => roundWawiQuantity($remaining),
'remainingByLocation' => $remainingByLocation,
'locations' => Location::query()->where('active', true)->orderBy('name')->get(),
'openOrders' => $openOrders,
@ -169,8 +169,8 @@ class RawMaterialStockController extends Controller
$usage[(int) $productId] = [
'percent' => round($percent, 3),
'grams_per_piece' => $hasMassBasis ? round($percent * $scale, 2) : null,
'consumption_per_piece' => $hasMassBasis ? round($withFactor * $scale, 2) : null,
'grams_per_piece' => $hasMassBasis ? roundWawiQuantity($percent * $scale) : null,
'consumption_per_piece' => $hasMassBasis ? roundWawiQuantity($withFactor * $scale) : null,
];
}

View file

@ -109,19 +109,19 @@ class StockDisposalController extends Controller
}
$ingredientId = (int) $data['ingredient_id'];
$quantity = round((float) $data['quantity'], 2);
$quantity = roundWawiQuantity((float) $data['quantity']);
if (! empty($data['stock_entry_id'])) {
$entry = StockEntry::query()->lockForUpdate()->findOrFail((int) $data['stock_entry_id']);
$available = $productionService->availableStockEntriesForIngredient($ingredientId, (int) $entry->location_id)->firstWhere('id', $entry->id);
$remaining = $available !== null ? round((float) $available->getAttribute('remaining_quantity'), 2) : 0.0;
$remaining = $available !== null ? roundWawiQuantity((float) $available->getAttribute('remaining_quantity')) : 0.0;
} else {
// Alle Eingänge des Rohstoffs am Standort sperren, dann Standortrest neu berechnen.
StockEntry::query()->lockForUpdate()
->where('entry_type', 'ingredient')->where('ingredient_id', $ingredientId)
->where('location_id', (int) $data['location_id'])
->get();
$remaining = round((float) ($this->inventoryService->remainingByLocationForIngredient($ingredientId)[(int) $data['location_id']] ?? 0.0), 2);
$remaining = roundWawiQuantity((float) ($this->inventoryService->remainingByLocationForIngredient($ingredientId)[(int) $data['location_id']] ?? 0.0));
}
if ($quantity > $remaining) {
@ -156,15 +156,15 @@ class StockDisposalController extends Controller
}
$rows = [];
$needed = round((float) $data['quantity'], 2);
$needed = roundWawiQuantity((float) $data['quantity']);
$lastIndex = $entries->count() - 1;
foreach ($entries as $index => $entry) {
$capacity = (float) $entry->getAttribute('remaining_quantity');
$take = $index === $lastIndex ? $needed : round(min($needed, $capacity), 2);
$take = $index === $lastIndex ? $needed : roundWawiQuantity(min($needed, $capacity));
if ($take > 0) {
$rows[] = array_merge($data, ['stock_entry_id' => (int) $entry->id, 'quantity' => $take]);
}
$needed = round($needed - $take, 2);
$needed = roundWawiQuantity($needed - $take);
if ($needed <= 0) {
break;
}

View file

@ -165,7 +165,7 @@ class StockEntryController extends Controller
// die Kopie zur Gramm-Bestellung und ein Wareneingang „100“ bucht 100 g statt 79 g.
if ($stockEntry->purchase_unit === 'ml' && $stockEntry->density_used !== null && (float) $stockEntry->density_used > 0) {
$data['ordered_unit'] = 'ml';
$data['ordered_quantity'] = round((float) $stockEntry->ordered_quantity / (float) $stockEntry->density_used, 2);
$data['ordered_quantity'] = roundWawiQuantity((float) $stockEntry->ordered_quantity / (float) $stockEntry->density_used);
$data['density_used'] = (float) $stockEntry->density_used;
}
@ -270,7 +270,7 @@ class StockEntryController extends Controller
return response()->json([
'exists' => true,
'purchases' => $entries->count(),
'remaining' => round((float) $remaining, 2),
'remaining' => roundWawiQuantity((float) $remaining),
'best_before' => $latest->best_before?->format('d.m.Y'),
'location' => $latest->location?->name,
'quality_id' => $latest->quality_id,