asset_status::withTrashed()->orderBy('created_at', 'desc')->get(), // 'warehouse' => m_warehouse::get(), // 'active' => 'history-peminjaman', // ]; // return view('dashboard.History.Peminjaman.index', $data); // } public function historyPeminjaman(Request $request) { $perPage = $request->input('perPage', 5); $query = asset_status::with(['customer', 'warehouseId', 'warehouse', 'warehouseEnter', 'kondisi_peti']) ->orderBy('created_at', 'desc'); //logika pencarian $search = $request->input('search') ?? ''; if ($search) { $query->where(function ($q) use ($search) { $q->where('mobile_id', 'like', "%$search%") ->orWhereHas('peti', function ($warehouseQuery) use ($search) { $warehouseQuery->where('fix_lot', 'like', "%$search%"); }) ->orWhereHas('customer', function ($warehouseQuery) use ($search) { $warehouseQuery->where('name', 'like', "%$search%"); }) // ->orWhereHas('peti.customer', function ($customerQuery) use ($search) { // $customerQuery->where('code_customer', 'like', "%$search%"); // }) // ->orWhereHas('peti.tipe_peti', function ($tipePetiQuery) use ($search) { // $tipePetiQuery->where('type', 'like', "%$search%"); // }) // ->orWhere(function ($combinedQuery) use ($search) { // // Pisahkan code customer dan tipe peti dari pencarian // list($codeCustomer, $typePeti) = explode(' - ', $search); // // Cek kesamaan code customer dan tipe peti // $combinedQuery->whereHas('peti.customer', function ($customerQuery) use ($codeCustomer) { // $customerQuery->where('code_customer', 'like', "%$codeCustomer%"); // })->whereHas('peti.tipe_peti', function ($tipePetiQuery) use ($typePeti) { // $tipePetiQuery->where('type', 'like', "%$typePeti%"); // }); // }) ->orWhere(function ($dateQuery) use ($search) { try { // Format tanggal yang diharapkan dari input pengguna $formattedDate = \Carbon\Carbon::createFromFormat('d-m-Y', $search)->format('Y-m-d'); // Cek kesamaan tanggal $dateQuery->whereDate('exit_at', $formattedDate); } catch (\Exception $e) { Log::error('Error parsing date: ' . $e->getMessage()); } }) ->orWhere(function ($dateQuery) use ($search) { try { // Format tanggal yang diharapkan dari input pengguna $formattedDate = \Carbon\Carbon::createFromFormat('d-m-Y', $search)->format('Y-m-d'); // Cek kesamaan tanggal $dateQuery->whereDate('est_pengembalian', $formattedDate); } catch (\Exception $e) { Log::error('Error parsing date: ' . $e->getMessage()); } }) ->orWhere('exit_pic', 'like', "%$search%") ->orWhereHas('warehouse', function ($warehouseQuery) use ($search) { $warehouseQuery->where('name', 'like', "%$search%") ->orWhere('address', 'like', "%$search%"); }); }); } if ($perPage == 'Semua') { $chunkSize = 100; $stores = new Collection(); $currentPage = 1; $query->chunk($chunkSize, function ($storesChunk) use ($stores, &$currentPage) { foreach ($storesChunk as $store) { $store->setAttribute('i', ($currentPage - 1) * $storesChunk->perPage() + 1); $stores->push($store); $currentPage++; } }); } else { $stores = $query->paginate($perPage); } $data = [ 'peminjaman' => $stores, 'warehouse' => m_warehouse::get(), 'i' => ($stores->currentPage() - 1) * $stores->perPage() + 1, 'search' => $search, 'active' => 'history-peminjaman', ]; return view('dashboard.History.Peminjaman.index', $data); } public function historyPengembalian() { $data = [ 'peminjaman' => asset_status::withTrashed()->orderBy('created_at', 'desc')->get(), 'active' => 'history-pengembalian', ]; return view('dashboard.History.Pengembalian.index', $data); } public function historyTransfer() { $data = [ 'transfer' => Transfer::withTrashed()->orderBy('created_at', 'desc')->get(), 'active' => 'history-transfer', ]; return view('dashboard.History.Transfer.index', $data); } }