authorizeIe('ie.sourcing.view'); $businessId = $this->businessId(); if ($request->ajax()) { return DataTables::of(SupplierSourcingCase::forBusiness($businessId)->with('itemMaster')) ->addColumn('item_name', fn ($row) => $row->itemMaster?->name ?? '—') ->addColumn('action', fn ($row) => '') ->rawColumns(['action']) ->make(true); } return view('industrialengineering::sourcing.index'); } public function create() { $this->authorizeIe('ie.sourcing.create'); $items = ItemMaster::forBusiness($this->businessId())->pluck('name', 'id'); return view('industrialengineering::sourcing.create', compact('items')); } public function store(Request $request) { $this->authorizeIe('ie.sourcing.create'); $data = $request->validate([ 'item_master_id' => 'required|exists:ie_item_masters,id', 'required_quantity' => 'required|numeric|min:0.0001', 'needed_by' => 'nullable|date', 'priority' => 'nullable|string', 'installed_asset_id' => 'nullable|exists:ie_customer_installed_assets,id', ]); $case = $this->sourcingService->createSourcingCase( $this->businessId(), (int) $data['item_master_id'], (float) $data['required_quantity'], $data['installed_asset_id'] ?? null, $data['needed_by'] ?? null, $data['priority'] ?? 'medium' ); return redirect()->action([self::class, 'show'], $case->id) ->with('status', ['success' => true, 'msg' => __('industrialengineering::lang.sourcing_case_created')]); } public function show($id) { $this->authorizeIe('ie.sourcing.view'); $case = SupplierSourcingCase::forBusiness($this->businessId()) ->with(['itemMaster', 'quotes.supplier', 'procurementTasks', 'installedAsset']) ->findOrFail($id); $stock = $this->sourcingService->findStock($this->businessId(), $case->item_master_id); $suppliers = $this->sourcingService->findSuppliers($case->item_master_id); return view('industrialengineering::sourcing.show', compact('case', 'stock', 'suppliers')); } public function searchStock(Request $request) { $this->authorizeIe('ie.sourcing.view'); $itemId = (int) $request->input('item_master_id'); return response()->json([ 'stock' => $this->sourcingService->findStock($this->businessId(), $itemId), 'suppliers' => $this->sourcingService->findSuppliers($itemId), ]); } }