選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

47 行
1.5KB

  1. <?php
  2. namespace App\Http\Controllers\Items;
  3. use App\Models\Item;
  4. use App\Models\Stock;
  5. use App\Models\StockMovement;
  6. use Framework\Routing\Router;
  7. class ShowItemController
  8. {
  9. public function handle(Router $router)
  10. {
  11. $parameters = $router->current()->parameters();
  12. $item = Item::find((int) $parameters['item']);
  13. if (!$item) {
  14. return redirect($router->route('show-items'));
  15. }
  16. $stock = Stock::where('item_id', $item->id)->all();
  17. $stock = array_filter($stock, fn($row) => $row->quantity > 0);
  18. foreach ($stock as $row) {
  19. $row->locationRoute = $router->route('view-location', ['location' => $row->location_id]);
  20. }
  21. $movements = StockMovement::where('item_id', $item->id)->all();
  22. usort($movements, fn($a, $b) => $b->id <=> $a->id);
  23. $movements = array_slice($movements, 0, 20);
  24. return view('items/view', [
  25. 'item' => $item,
  26. 'totalQuantity' => array_sum(array_map(fn($row) => $row->quantity, $stock)),
  27. 'stock' => $stock,
  28. 'movements' => $movements,
  29. 'receiveAction' => $router->route('show-receive-stock-form', ['item' => $item->id]),
  30. 'withdrawAction' => $router->route('show-withdraw-stock-form', ['item' => $item->id]),
  31. 'adjustAction' => $router->route('show-adjust-stock-form', ['item' => $item->id]),
  32. 'canManage' => session()->has('user_id'),
  33. ]);
  34. }
  35. }

Powered by TurnKey Linux.