Warenwirtschaft: OPT-3 Index-Limits + OPT-4 show()-Refactoring
- Wareneingang-/Produktions-Uebersicht: Eingegangene auf 500 gedeckelt (offene Bestellungen immer vollstaendig), ?all=1 + Hinweis-Link; ungenutzte User-Eager-Loads entfernt - RawMaterialStockController::show() entschlackt: Chargen-Restmengen (FEFO) und offene Bestellungen im InventoryService, letzter Netto-Preis je Lieferant als Window-Function-Query im StockEntryRepository Tests: RawMaterialStockTest +2, volle Suite 186 gruen, 663 Assertions Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
parent
209ea467eb
commit
e47d848d3d
10 changed files with 165 additions and 75 deletions
|
|
@ -120,12 +120,35 @@ class StockEntryRepository
|
|||
->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Letzter Netto-kg-Preis je Lieferant für einen Rohstoff (neuester Einkauf zählt).
|
||||
*
|
||||
* @return array<int, float> [supplier_id => price_per_kg_net]
|
||||
*/
|
||||
public function lastNetPricePerSupplier(int $ingredientId): array
|
||||
{
|
||||
$ranked = StockEntry::query()
|
||||
->selectRaw('supplier_id, price_per_kg, ROW_NUMBER() OVER (PARTITION BY supplier_id ORDER BY ordered_at DESC, id DESC) as rn')
|
||||
->where('entry_type', 'ingredient')
|
||||
->where('ingredient_id', $ingredientId)
|
||||
->whereNotNull('supplier_id')
|
||||
->whereNotNull('price_per_kg');
|
||||
|
||||
return StockEntry::query()
|
||||
->fromSub($ranked, 'ranked')
|
||||
->where('rn', 1)
|
||||
->pluck('price_per_kg', 'supplier_id')
|
||||
->map(fn ($price) => (float) $price)
|
||||
->all();
|
||||
}
|
||||
|
||||
/**
|
||||
* Liste: Pending zuerst (neuestes Bestelldatum), dann Received (neuester Eingang).
|
||||
* Eingegangene Einträge sind auf $receivedLimit gedeckelt (OPT-3); null = alle.
|
||||
*
|
||||
* @return Collection<int, StockEntry>
|
||||
*/
|
||||
public function listForIndex(): Collection
|
||||
public function listForIndex(?int $receivedLimit = 500): Collection
|
||||
{
|
||||
$with = [
|
||||
'ingredient',
|
||||
|
|
@ -133,12 +156,20 @@ class StockEntryRepository
|
|||
'supplier',
|
||||
'location',
|
||||
'quality',
|
||||
'orderedByUser',
|
||||
'receivedByUser',
|
||||
];
|
||||
|
||||
$pending = StockEntry::query()->with($with)->where('status', 'pending')->orderByDesc('ordered_at')->get();
|
||||
$received = StockEntry::query()->with($with)->where('status', 'received')->orderByDesc('received_at')->get();
|
||||
$pending = StockEntry::query()->with($with)
|
||||
->where('status', 'pending')
|
||||
->orderByDesc('ordered_at')
|
||||
->orderByDesc('id')
|
||||
->get();
|
||||
|
||||
$received = StockEntry::query()->with($with)
|
||||
->where('status', 'received')
|
||||
->orderByDesc('received_at')
|
||||
->orderByDesc('id')
|
||||
->when($receivedLimit !== null, fn ($q) => $q->limit($receivedLimit))
|
||||
->get();
|
||||
|
||||
return $pending->concat($received)->values();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue