authorizeIe('ie.items.view'); $businessId = $this->businessId(); if ($request->ajax()) { $query = ItemMaster::forBusiness($businessId)->with('manufacturer'); return DataTables::of($query) ->addColumn('manufacturer_name', fn ($row) => $row->manufacturer?->name ?? '—') ->addColumn('action', function ($row) { $html = ''; return $html; }) ->rawColumns(['action']) ->make(true); } return view('industrialengineering::item_masters.index'); } public function create() { $this->authorizeIe('ie.items.create'); return view('industrialengineering::item_masters.create', [ 'itemTypes' => $this->itemTypes(), 'suggestedCode' => $this->suggestCode('item'), ]); } public function store(Request $request) { $this->authorizeIe('ie.items.create'); $data = $request->validate([ 'item_code' => 'nullable|string|max:100', 'name' => 'required|string|max:255', 'item_type' => 'required|string', 'standard_cost' => 'nullable|numeric|min:0', 'is_serialized' => 'nullable|boolean', 'is_serviceable' => 'nullable|boolean', 'description' => 'nullable|string', 'variation_id' => 'nullable|integer', 'product_id' => 'nullable|integer', ]); $codes = $this->resolveCodes('item', $data['item_code'] ?? null, new ItemMaster(), 'item_code'); $data = array_merge($data, $codes); $data['business_id'] = $this->businessId(); $data['is_serialized'] = $request->boolean('is_serialized'); $data['is_serviceable'] = $request->boolean('is_serviceable', true); $item = ItemMaster::create($data); $this->erpItemLink->linkItem($item, $data); return redirect()->action([self::class, 'index'])->with('status', ['success' => true, 'msg' => __('industrialengineering::lang.saved')]); } public function show($id) { $this->authorizeIe('ie.items.view'); $item = ItemMaster::forBusiness($this->businessId()) ->with(['revisions', 'equivalents.equivalentItem', 'supplierPartNumbers.supplier']) ->findOrFail($id); return view('industrialengineering::item_masters.show', compact('item')); } protected function itemTypes(): array { return [ 'part' => __('industrialengineering::lang.type_part'), 'subassembly' => __('industrialengineering::lang.type_subassembly'), 'assembly' => __('industrialengineering::lang.type_assembly'), 'device' => __('industrialengineering::lang.type_device'), 'tool' => __('industrialengineering::lang.type_tool'), 'consumable' => __('industrialengineering::lang.type_consumable'), ]; } }