current()->parameters(); $item = Item::find((int) $parameters['item']); if (!$item) { return redirect($router->route('show-items')); } $stock = Stock::where('item_id', $item->id)->all(); $stock = array_filter($stock, fn($row) => $row->quantity > 0); foreach ($stock as $row) { $row->locationRoute = $router->route('view-location', ['location' => $row->location_id]); } $movements = StockMovement::where('item_id', $item->id)->all(); usort($movements, fn($a, $b) => $b->id <=> $a->id); $movements = array_slice($movements, 0, 20); return view('items/view', [ 'item' => $item, 'totalQuantity' => array_sum(array_map(fn($row) => $row->quantity, $stock)), 'stock' => $stock, 'movements' => $movements, 'receiveAction' => $router->route('show-receive-stock-form', ['item' => $item->id]), 'withdrawAction' => $router->route('show-withdraw-stock-form', ['item' => $item->id]), 'adjustAction' => $router->route('show-adjust-stock-form', ['item' => $item->id]), 'canManage' => session()->has('user_id'), ]); } }