Warenwirtschaft: AP-43 — Produktion zwischenspeichern (Entwurf) + „abschließen"

Der Speicher-Button heißt jetzt „Produktion abschließen"; daneben gibt es
„Zwischenspeichern (Entwurf)". Ein Entwurf sichert den Stand ohne Pflichtfeld-
und ohne Bestandsprüfung und bucht KEINEN Bestand (Roh-/Produkt-/Verpackung).
Erst „abschließen" prüft vollständig und bucht.

- Migration: productions.status (default 'completed'; Bestand ist bereits gebucht).
- Production-Model: STATUS_DRAFT/COMPLETED, isDraft(), scopeBooked().
- InventoryService: Entwürfe fallen aus allen Verbrauchs-/Bestandsjoins heraus
  (status != draft an den 4 productions-Joins).
- ProductionService store()/updateProduction() bekommen $draft: Entwurf
  überspringt Rezeptur-/Mengen-/Bestandsprüfung + Buchungen, sichert nur
  vollständige Chargen-Zeilen (filterCompleteLines) und die angegebenen Outputs.
  Ein abgeschlossene Produktion kann NICHT zurück in den Entwurf (sonst
  verwaisen die Buchungen) — Guard wirft ValidationException.
- StoreProductionRequest: save_mode=draft => nur Kopfdaten Pflicht, Chargen/
  Ergebnis optional; validatedPayload filtert unvollständige Zeilen/Outputs.
- Controller: Entwurf löst Chargen tolerant auf (nicht auflösbare Chargen werden
  übersprungen, Entwurf ist immer speicherbar) und leitet zur Bearbeitung zurück.
- Views: create/edit „abschließen" + „Zwischenspeichern"-Button (nur solange
  Entwurf); Entwurf-Badge in Liste + Bearbeiten-Kopf.

Tests: 5 neue (kein Produktbestand, kein Rohstoffverbrauch, Abschluss bucht,
Rück-Entwurf verboten, HTTP-Entwurf ohne Ergebnis ok / Abschluss erzwingt
Ergebnis). Migration auf Dev-/Live-DB. Suite 336 grün.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Kevin Adametz 2026-08-28 09:59:42 +00:00
parent 3d19f743b1
commit abd202a02e
10 changed files with 445 additions and 44 deletions

View file

@ -57,13 +57,11 @@ class ProductionController extends Controller
public function store(StoreProductionRequest $request): RedirectResponse
{
$payload = $request->validatedPayload();
$isDraft = (bool) $payload['is_draft'];
try {
// AP-27: Chargen-Zeilen (batch_key) FEFO auf die Einzel-Wareneingänge der Charge auflösen.
$ingredientLines = $this->productionService->expandBatchLines(
$payload['ingredient_lines'],
$payload['location_id']
);
$ingredientLines = $this->expandLines($payload['ingredient_lines'], $payload['location_id'], null, $isDraft);
$production = $this->productionService->store(
[
@ -75,12 +73,50 @@ class ProductionController extends Controller
],
$ingredientLines,
(int) $request->user()->id,
$payload['outputs']
$payload['outputs'],
$isDraft
);
} catch (ValidationException $e) {
return redirect()->back()->withInput()->withErrors($e->errors());
}
return $this->afterSave($production, $isDraft);
}
/**
* AP-27/AP-43: Chargen-Zeilen auf Einzel-Wareneingänge auflösen. Im Entwurf
* darf das Auflösen scheitern (Charge nicht verfügbar) — dann bleiben nur die
* bereits konkret gewählten Wareneingänge erhalten, der Entwurf ist immer speicherbar.
*
* @param array<int, array<string, mixed>> $lines
* @return array<int, array<string, mixed>>
*/
private function expandLines(array $lines, int $locationId, ?int $excludeProductionId, bool $isDraft): array
{
if (! $isDraft) {
return $this->productionService->expandBatchLines($lines, $locationId, $excludeProductionId);
}
try {
return $this->productionService->expandBatchLines($lines, $locationId, $excludeProductionId);
} catch (ValidationException) {
return array_values(array_filter($lines, fn ($l) => (int) ($l['stock_entry_id'] ?? 0) > 0));
}
}
/**
* AP-43: Entwurf zurück in die Bearbeitung (Weiterarbeiten), abgeschlossene
* Produktion in die Detailansicht.
*/
private function afterSave(Production $production, bool $isDraft): RedirectResponse
{
if ($isDraft) {
\Session::flash('alert-save', '1');
return redirect()->route('admin.inventory.productions.edit', $production)
->with('alert-info', __('Entwurf zwischengespeichert. Die Produktion ist noch nicht gebucht.'));
}
if ($production->mhd_warning) {
\Session::flash('alert-warning', __('Hinweis: Mindestens eine Rohstoff-Charge hat ein kürzeres MHD als das geplante Produkt-MHD.'));
}
@ -135,14 +171,11 @@ class ProductionController extends Controller
public function update(StoreProductionRequest $request, Production $production): RedirectResponse
{
$payload = $request->validatedPayload();
$isDraft = (bool) $payload['is_draft'];
try {
// AP-27: Beim Bearbeiten die eigene Produktion aus der Rest-Berechnung ausnehmen.
$ingredientLines = $this->productionService->expandBatchLines(
$payload['ingredient_lines'],
$payload['location_id'],
$production->id
);
$ingredientLines = $this->expandLines($payload['ingredient_lines'], $payload['location_id'], $production->id, $isDraft);
$production = $this->productionService->updateProduction(
$production,
@ -155,18 +188,14 @@ class ProductionController extends Controller
],
$ingredientLines,
(int) $request->user()->id,
$payload['outputs']
$payload['outputs'],
$isDraft
);
} catch (ValidationException $e) {
return redirect()->back()->withInput()->withErrors($e->errors());
}
if ($production->mhd_warning) {
\Session::flash('alert-warning', __('Hinweis: Mindestens eine Rohstoff-Charge hat ein kürzeres MHD als das geplante Produkt-MHD.'));
}
\Session::flash('alert-save', '1');
return redirect()->route('admin.inventory.productions.show', $production);
return $this->afterSave($production, $isDraft);
}
public function copy(Production $production): View|RedirectResponse