Warenwirtschaft: F-02 — getrennter Produktkatalog für Ergebniszeilen

Planung oben bleibt auf produktionsrelevante Produkte gefiltert (AP-47);
Ergebniszeilen bieten alle aktiven Einzelprodukte plus bereits gespeicherte
Output-Produkte an (Bearbeiten/Kopieren verliert keine Zuordnung mehr).

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
Kevin Adametz 2026-09-08 10:50:24 +00:00
parent 9e745d1441
commit 73512897ee
3 changed files with 89 additions and 9 deletions

View file

@ -10,6 +10,7 @@ use App\Models\Production;
use App\Repositories\ProductionRepository;
use App\Services\ProductionService;
use App\Services\ProductStockService;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
@ -46,7 +47,7 @@ class ProductionController extends Controller
$defaultProductId = (int) $request->query('product_id') ?: null;
return view('admin.inventory.productions.create', [
'products' => Product::query()->where('active', 1)->where('is_set', false)->where('production_relevant', true)->orderBy('name')->get(['id', 'name', 'batch_prefix']),
...$this->productCatalogs(null),
'locations' => Location::query()->where('active', true)->orderBy('name')->get(),
'defaultLocationId' => $defaultLocationId,
'defaultProductId' => $defaultProductId,
@ -159,10 +160,7 @@ class ProductionController extends Controller
return view('admin.inventory.productions.edit', [
'model' => $production,
'products' => Product::query()
->where(fn ($q) => $q->where('active', 1)->where('is_set', false)->where('production_relevant', true))
->orWhere('id', $production->product_id)
->orderBy('name')->get(['id', 'name', 'batch_prefix']),
...$this->productCatalogs($production),
'locations' => Location::query()->where('active', true)->orderBy('name')->get(),
'defaultLocationId' => $defaultLocationId,
]);
@ -219,12 +217,44 @@ class ProductionController extends Controller
return view('admin.inventory.productions.create', [
'model' => $production,
'products' => Product::query()->where('active', 1)->where('is_set', false)->where('production_relevant', true)->orderBy('name')->get(['id', 'name', 'batch_prefix']),
...$this->productCatalogs($production),
'locations' => Location::query()->where('active', true)->orderBy('name')->get(),
'defaultLocationId' => $defaultLocationId,
]);
}
/**
* Prüfung 08.09.2026 F-02: Zwei getrennte Kataloge.
* - `products`: Planungsprodukt oben — nur produktionsrelevante Produkte (AP-47),
* plus das bereits geplante Produkt einer bestehenden Produktion.
* - `outputProducts`: Ergebniszeilen — alle aktiven Einzelprodukte, unabhängig von
* der Produktionsrelevanz (z. B. 5-ml-Variante aus der 50-ml-Masse), plus alle
* bereits gespeicherten Ergebnisprodukte, damit sie beim Bearbeiten/Kopieren
* nicht still verloren gehen.
*
* @return array{products: Collection<int, Product>, outputProducts: Collection<int, Product>}
*/
private function productCatalogs(?Production $production): array
{
$columns = ['id', 'name', 'batch_prefix'];
$products = Product::query()
->where(fn ($q) => $q->where('active', 1)->where('is_set', false)->where('production_relevant', true))
->when($production !== null, fn ($q) => $q->orWhere('id', $production->product_id))
->orderBy('name')
->get($columns);
$existingOutputIds = $production?->outputs?->pluck('product_id')->map(fn ($id) => (int) $id)->all() ?? [];
$outputProducts = Product::query()
->where(fn ($q) => $q->where('active', 1)->where('is_set', false))
->when($existingOutputIds !== [], fn ($q) => $q->orWhereIn('id', $existingOutputIds))
->orderBy('name')
->get($columns);
return ['products' => $products, 'outputProducts' => $outputProducts];
}
/**
* Anforderung 15.07.2026: Produktionen löschbar (Soft-Delete).
* Der gebuchte Produktbestand wird per Gegenbuchung zurückgeführt;