asset_status::get(), // 'peminjaman' => asset_status::orderBy('created_at', 'desc')->get(), // 'warehouse' => m_warehouse::get(), // 'active' => 'menu-peminjaman', // ]; // return view('dashboard.Peminjaman.index', $data); // } public function index(Request $request) { $perPage = $request->input('perPage', 5); $query = asset_status::orderBy('created_at', 'desc'); // $query = asset_status::select(['asset_statuses.*', 'Petis.code_customer', 'customers.lot_no', 'type_petis.type', 'type_petis.size_peti', 'm_warehouses.name as warehouse_name']) // ->join('Petis', 'peti.id', '=', 'asset_statuses.peti_id') // ->join('type_petis', 'type_petis.id', '=', 'petis.tipe_peti_id') // ->join('m_warehouses', 'm_warehouses.id', '=', 'petis.warehouse_id') // ->join('kondisi_petis', 'kondisipeti_id', '=', 'petis.kondisipeti_id') // ->orderBy('petis.created_at', 'desc'); // Tambahkan logika pencarian $search = $request->input('search') ?? ''; if ($search) { $query->where(function ($q) use ($search) { $q->where('mobile_id', 'like', "%$search%") ->orWhere('exit_at', 'like', "%$search%") ->orWhere('est_pengembalian', 'like', "%$search%") ->orWhere('exit_pic', 'like', "%$search%") ->orWhere('customer_id', 'like', "%$search%") ->orWhere('warehouse_id', 'like', "%$search%") ->orWhere('exit_warehouse', 'like', "%$search%") ->orWhere('enter_at', 'like', "%$search%") ->orWhere('enter_pic', 'like', "%$search%") ->orWhere('enter_warehouse', 'like', "%$search%") ->orWhere('kondisi_peti_id', 'like', "%$search%") ->orWhere('status', 'like', "%$search%") ->orWhere('created_by', 'like', "%$search%") ->orWhere('updated_by', 'like', "%$search%"); }); } $peminjaman = $query->paginate($perPage); $data = [ 'peminjaman' => $peminjaman, 'warehouse' => m_warehouse::get(), 'search' => $search, 'active' => 'menu-peminjaman', ]; return view('dashboard.Peminjaman.index', $data); } /** * Show the form for creating a new resource. */ public function create() { $petiWithStatusNotZeroOrEmptyAndActive = Peti::where(function ($query) { $query->whereHas('assetStatuses', function ($subquery) { $subquery->where('status', '!=', 0) ->where('created_at', '=', function ($maxQuery) { $maxQuery->selectRaw('MAX(created_at)') ->from('asset_statuses') ->whereColumn('peti_id', 'petis.id'); }); })->orWhereDoesntHave('assetStatuses'); })->where('status', 'AKTIF')->get(); $data = [ // 'peti' => Peti::all(), 'peminjaman' => asset_status::get(), 'warehouse' => m_warehouse::get(), 'peti_block' => $petiWithStatusNotZeroOrEmptyAndActive, 'customer' => Customer::get(), 'existingPeti' => asset_status::pluck('peti_id')->toArray(), 'active' => 'menu-peminjaman', ]; return view('dashboard.Peminjaman.create', $data); } /** * Store a newly created resource in storage. */ public function store(ValidasiCreatePeminjaman $request) { // dd($request->all()); // dd($request); try { $currentUser = Auth::user(); $validatedData = $request->except('_token'); $validatedData['exit_pic'] = $currentUser->fullname; // Menambahkan ID pengguna sebagai created_by $validatedData['mobile_id'] = Uuid::v4(); // Menambahkan ID Mobile $validatedData['created_by'] = $currentUser->fullname; // Menambahkan ID pengguna sebagai created_by $validatedData['updated_by'] = $currentUser->fullname; // Menambahkan ID pengguna sebagai updated_by // dd($validatedData); asset_status::create($validatedData); return redirect()->route('dashboard.peminjaman.index')->with('success', 'Data peminjaman berhasil ditambah.'); } catch (\Throwable $th) { dd($th->getMessage()); // Tampilkan pesan kesalahan return redirect()->back()->with('error', 'Data peminjaman gagal ditambah.'); } } /** * Display the specified resource. */ public function show($id) { // dd('oke'); } /** * Show the form for editing the specified resource. */ public function edit($id) { $data = [ 'peti' => Peti::all(), 'peminjaman' => asset_status::find($id), 'warehouse' => m_warehouse::get(), 'customer' => Customer::get(), 'active' => 'menu-peminjaman', ]; return view('dashboard.Peminjaman.edit', $data); } /** * Update the specified resource in storage. */ public function update(ValidasiUpdatePeminjaman $request, $id) { // dd($request->all()); // dd($request); try { $peminjaman = asset_status::findOrFail($id); $peminjaman['updated_by'] = Auth::user()->fullname; // Menambahkan ID pengguna sebagai updated_by $peminjaman->update($request->all()); return redirect()->route('dashboard.peminjaman.index')->with('success', 'Data peminjaman berhasil diperbaharui'); } catch (\Throwable $th) { return redirect()->back()->with('error', 'Data peminjaman gagal diperbaharui'); } } /** * Remove the specified resource from storage. */ public function destroy($id) { try { $peminjaman = asset_status::findOrFail($id); $peminjaman->delete(); return redirect()->back()->with('success', 'Data peminjaman berhasil dihapus'); } catch (\Throwable $th) { return redirect()->back()->with('error', 'Data peminjaman gagal dihapus'); } } /** * Show the form for editing the specified resource. */ public function pengembalian($id) { // dd('oke'); $data = [ 'peti' => Peti::get(), 'peminjaman' => asset_status::findOrFail($id), 'warehouse' => m_warehouse::get(), 'kondisiPeti' => Kondisi_Peti::get(), 'active' => 'menu-pengembalian', ]; return view('dashboard.Peminjaman.pengembalian', $data); } }