get(); return view('staff.list-vendor', compact('vendorKategoris', 'menu_master')); } /** * Show the form for creating a new resource. * * @return \Illuminate\Http\Response */ public function create() { } /** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { if ($request->act == 'create-category') { VendorKategori::create([ 'nama_kategori' => preg_replace("/[^a-zA-Z0-9\s\.,]/", "", $request->nama_kategori), 'urutan' => VendorKategori::orderBy('urutan','desc')->first()?VendorKategori::orderBy('urutan','desc')->first()->urutan + 1:0, ]); return redirect()->route('vendor.index')->with('msg', 'data kategori berhasil ditambahkan'); }elseif ($request->act == 'create-subcategory') { VendorSubkategori::create([ 'nama_subkategori' => preg_replace("/[^a-zA-Z0-9\s\.,]/", "", $request->nama_subkategori), 'id_vendor_kategori' => $request->id, ]); return redirect()->route('vendor.index')->with('msg', 'data subkategori berhasil ditambahkan'); }elseif ($request->act == 'create-vendor') { Vendor::create([ 'nama_pekerjaan' => preg_replace("/[^a-zA-Z0-9\s\.,]/", "", $request->nama_pekerjaan), 'dimensi_spesifikasi' => preg_replace("/[^a-zA-Z0-9\s\.,]/", "", $request->dimensi_spesifikasi), 'satuan' => preg_replace("/[^a-zA-Z0-9\s\.,]/", "", $request->satuan), 'harga_modal' => str_replace('.', '', $request->harga_modal), 'id_vendor_subkategori' => $request->id_vendor_subkategori, ]); return redirect()->route('vendor.index')->with('msg', 'data vendor berhasil ditambahkan'); }elseif ($request->act == 'add-vendor') { Vendor::create([ 'nama_pekerjaan' => preg_replace("/[^a-zA-Z0-9\s\.,]/", "", $request->nama_pekerjaan), 'dimensi_spesifikasi' => preg_replace("/[^a-zA-Z0-9\s\.,]/", "", $request->dimensi_spesifikasi), 'satuan' => preg_replace("/[^a-zA-Z0-9\s\.,]/", "", $request->satuan), 'harga_modal' => str_replace('.', '', $request->harga_modal), 'id_vendor_subkategori' => $request->id, ]); return redirect()->route('vendor.index')->with('msg', 'data vendor berhasil ditambahkan'); }elseif ($request->act == 'change-sort-kategori') { foreach ($request->id_kategori as $key => $value) { $row = VendorKategori::findOrFail($value); $row->urutan = $key+1; $row->save(); } return redirect()->route('vendor.index')->with('msg', 'urutan kategori berhasil disesuaikan'); }elseif ($request->act == 'change-sort-subkategori') { foreach ($request->id_subkategori as $key => $value) { $row = VendorSubkategori::findOrFail($value); $row->urutan = $key+1; $row->save(); } return redirect()->route('vendor.index')->with('msg', 'urutan sub-kategori berhasil disesuaikan'); }elseif ($request->act == 'change-sort-vendor') { foreach ($request->id_vendor as $key => $value) { $row = Vendor::findOrFail($value); $row->urutan = $key+1; $row->save(); } return redirect()->route('vendor.index')->with('msg', 'urutan Vendor berhasil disesuaikan'); }elseif ($request->act == 'paste-vendor') { $subK = vendorSubkategori::where('id',$request->id)->first(); foreach ($subK->vendorS as $row) { $vendor = vendor::create([ 'nama_pekerjaan' => preg_replace("/[^a-zA-Z0-9\s\.,]/", "", $row->nama_pekerjaan), 'dimensi_spesifikasi' => preg_replace("/[^a-zA-Z0-9\s\.,]/", "", $row->dimensi_spesifikasi), 'satuan' => preg_replace("/[^a-zA-Z0-9\s\.,]/", "", $row->satuan), 'harga_modal' => str_replace('.', '', $request->harga_modal), 'id_vendor_subkategori' => $request->paste_to, ]); } return redirect()->route('vendor.index')->with('msg', 'vendor berhasil dicopy'); }else{ abort('404'); } } /** * Display the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function show($id) { if ($_GET['act'] == 'subcategoryData') { if (\Request::ajax()) { $subkategori = VendorSubkategori::where('id_vendor_kategori',$id)->orderBy('urutan','asc')->get(); return response()->json([ 'subkategori' => $subkategori, ]); } else { abort('404'); } }elseif ($_GET['act'] == 'vendorData') { if (\Request::ajax()) { $vendor = Vendor::where('id_vendor_subkategori',$id)->orderBy('urutan','asc')->get(); return response()->json([ 'vendor' => $vendor, ]); } else { abort('404'); } }elseif ($_GET['act'] == 'subcategoryDataExcept') { if (\Request::ajax()) { $subkategori = VendorSubkategori::where('id','<>',$id)->get(); return response()->json([ 'subkategori' => $subkategori, ]); } else { abort('404'); } } } /** * Show the form for editing the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function edit($id) { // } /** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, $id) { if ($request->act == 'update-category') { VendorKategori::where('id',$id)->update([ 'nama_kategori' => preg_replace("/[^a-zA-Z0-9\s\.,]/", "", $request->nama_kategori), ]); return redirect()->route('vendor.index')->with('msg', 'kategori berhasil dirubah'); }elseif ($request->act == 'update-subcategory') { VendorSubkategori::where('id',$id)->update([ 'nama_subkategori' => preg_replace("/[^a-zA-Z0-9\s\.,]/", "", $request->nama_subkategori), ]); return redirect()->route('vendor.index')->with('msg', 'sub-kategori berhasil dirubah'); }elseif ($request->act == 'update-vendor') { Vendor::where('id',$id)->update([ 'nama_pekerjaan' => preg_replace("/[^a-zA-Z0-9\s\.,]/", "", $request->nama_pekerjaan), 'dimensi_spesifikasi' => preg_replace("/[^a-zA-Z0-9\s\.,]/", "", $request->dimensi_spesifikasi), 'satuan' => preg_replace("/[^a-zA-Z0-9\s\.,]/", "", $request->satuan), 'harga_modal' => str_replace('.', '', $request->harga_modal), ]); return redirect()->route('vendor.index')->with('msg', 'vendor berhasil dirubah'); } } /** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy(Request $request,$id) { if ($request->act == 'delete-category') { VendorKategori::destroy($id); return redirect()->route('vendor.index')->with('msg', 'Vendor Kategori berhasil dihapus dari list'); }elseif ($request->act == 'delete-subcategory') { VendorSubkategori::destroy($id); return redirect()->route('vendor.index')->with('msg', 'Vendor SubKategori berhasil dihapus dari list'); }elseif ($request->act == 'delete-vendor') { Vendor::destroy($id); return redirect()->route('vendor.index')->with('msg', 'Vendor berhasil dihapus dari list'); }else{ abort('404'); } } }