Warenwirtschaft: AP-52 — Verpackungsvorschau mit Bestand, Differenz und Lagerort (Kundennachtrag 09.09.2026)
Je Verpackungsartikel Bestand (Stück), Differenz zu Bedarf (rot/grün wie bei Rohstoffen, AP-40) und Lagerplatz; Spalte einheitlich „Lagerort“ für Rohstoffe (INCI-Tabelle, vorher „Ablage“) und Verpackung. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
parent
22e218d570
commit
3abb9e644e
5 changed files with 103 additions and 16 deletions
|
|
@ -8,6 +8,7 @@ use App\Models\Location;
|
|||
use App\Models\Product;
|
||||
use App\Models\Production;
|
||||
use App\Repositories\ProductionRepository;
|
||||
use App\Services\InventoryService;
|
||||
use App\Services\ProductionService;
|
||||
use App\Services\ProductStockService;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
|
|
@ -160,7 +161,7 @@ class ProductionController extends Controller
|
|||
// (dieselbe Regel wie ProductionService::updateProduction, F-05).
|
||||
$production->loadMissing('productionPackagings.packagingItem');
|
||||
$packagingSnapshot = $production->isDraft() ? [] : $production->productionPackagings
|
||||
->map(fn ($row) => ['name' => $row->packagingItem?->name ?? ('#'.$row->packaging_item_id), 'pieces' => (int) $row->quantity_used])
|
||||
->map(fn ($row) => ['id' => (int) $row->packaging_item_id, 'name' => $row->packagingItem?->name ?? ('#'.$row->packaging_item_id), 'pieces' => (int) $row->quantity_used])
|
||||
->values()->all();
|
||||
$initialOutputTotals = [];
|
||||
foreach ($production->outputs as $output) {
|
||||
|
|
@ -300,7 +301,7 @@ class ProductionController extends Controller
|
|||
$existingOutputIds = $production?->outputs?->pluck('product_id')->map(fn ($id) => (int) $id)->all() ?? [];
|
||||
|
||||
$outputProducts = Product::query()
|
||||
->with('packagings:id,name')
|
||||
->with('packagings.storageRoom', 'packagings.storageShelf', 'packagings.storageSlot')
|
||||
->where(fn ($q) => $q->where('active', 1)->where('is_set', false))
|
||||
->when($existingOutputIds !== [], fn ($q) => $q->orWhereIn('id', $existingOutputIds))
|
||||
->orderBy('name')
|
||||
|
|
@ -316,7 +317,21 @@ class ProductionController extends Controller
|
|||
])->values()->all()])
|
||||
->all();
|
||||
|
||||
return ['products' => $products, 'outputProducts' => $outputProducts, 'packagingBom' => $packagingBom];
|
||||
// AP-52 (Kundennachtrag 09.09.2026): Bestand, Differenz und Lagerort je
|
||||
// Verpackungsartikel in der Vorschau — wie bei den Rohstoffen in der INCI-Tabelle.
|
||||
$packagingItems = $outputProducts->flatMap->packagings->unique('id');
|
||||
if ($production !== null) {
|
||||
$production->loadMissing('productionPackagings.packagingItem.storageRoom', 'productionPackagings.packagingItem.storageShelf', 'productionPackagings.packagingItem.storageSlot');
|
||||
$packagingItems = $packagingItems->merge($production->productionPackagings->map->packagingItem->filter())->unique('id');
|
||||
}
|
||||
$stockByItem = $packagingItems->isEmpty() ? [] : app(InventoryService::class)->remainingByPackagingItem($packagingItems->pluck('id')->map(fn ($id) => (int) $id)->all());
|
||||
$packagingInfo = $packagingItems->mapWithKeys(fn ($pk) => [(int) $pk->id => [
|
||||
'name' => $pk->name,
|
||||
'stock' => round((float) ($stockByItem[(int) $pk->id] ?? 0.0), 0),
|
||||
'storage_label' => $pk->storageLabel(),
|
||||
]])->all();
|
||||
|
||||
return ['products' => $products, 'outputProducts' => $outputProducts, 'packagingBom' => $packagingBom, 'packagingInfo' => $packagingInfo];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue