|
|
|
@ -11,18 +11,7 @@ use Illuminate\Support\Facades\Log;
|
|
|
|
|
|
|
|
|
|
class HistoryController extends Controller |
|
|
|
|
{ |
|
|
|
|
// public function historyPeminjaman() |
|
|
|
|
// { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// $data = [ |
|
|
|
|
// 'peminjaman' => asset_status::withTrashed()->orderBy('created_at', 'desc')->get(), |
|
|
|
|
// 'warehouse' => m_warehouse::get(), |
|
|
|
|
// 'active' => 'history-peminjaman', |
|
|
|
|
// ]; |
|
|
|
|
|
|
|
|
|
// return view('dashboard.History.Peminjaman.index', $data); |
|
|
|
|
// } |
|
|
|
|
// Halaman index history peminjaman |
|
|
|
|
public function historyPeminjaman(Request $request) |
|
|
|
|
{ |
|
|
|
|
$perPage = $request->input('perPage', 5); |
|
|
|
@ -33,6 +22,19 @@ class HistoryController extends Controller
|
|
|
|
|
//logika pencarian |
|
|
|
|
$search = $request->input('search') ?? ''; |
|
|
|
|
if ($search) { |
|
|
|
|
$searchArray = explode(' - ', $search); |
|
|
|
|
|
|
|
|
|
if (count($searchArray) === 2) { |
|
|
|
|
// Case: DPM - B100X63 |
|
|
|
|
list($codeCustomer, $typePeti) = $searchArray; |
|
|
|
|
|
|
|
|
|
$query->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%"); |
|
|
|
|
}); |
|
|
|
|
} else { |
|
|
|
|
// Case: Other scenarios |
|
|
|
|
$query->where(function ($q) use ($search) { |
|
|
|
|
$q->where('mobile_id', 'like', "%$search%") |
|
|
|
|
->orWhereHas('peti', function ($warehouseQuery) use ($search) { |
|
|
|
@ -41,23 +43,12 @@ class HistoryController extends Controller
|
|
|
|
|
->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%"); |
|
|
|
|
// }); |
|
|
|
|
// }) |
|
|
|
|
->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 ($dateQuery) use ($search) { |
|
|
|
|
try { |
|
|
|
|
// Format tanggal yang diharapkan dari input pengguna |
|
|
|
@ -87,6 +78,7 @@ class HistoryController extends Controller
|
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if ($perPage == 'Semua') { |
|
|
|
|
$chunkSize = 100; |
|
|
|
@ -114,15 +106,117 @@ class HistoryController extends Controller
|
|
|
|
|
return view('dashboard.History.Peminjaman.index', $data); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function historyPengembalian() |
|
|
|
|
// Halaman index history pengembalian |
|
|
|
|
public function historyPengembalian(Request $request) |
|
|
|
|
{ |
|
|
|
|
$perPage = $request->input('perPage', 5); |
|
|
|
|
$query = asset_status::with(['customer', 'warehouseId', 'warehouse', 'warehouseEnter', 'kondisi_peti']) |
|
|
|
|
->where('status', '=', 1) |
|
|
|
|
->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%"); |
|
|
|
|
}) // sudah cari fix lot |
|
|
|
|
->orWhereHas('customer', function ($warehouseQuery) use ($search) { |
|
|
|
|
$warehouseQuery->where('name', 'like', "%$search%"); |
|
|
|
|
}) // sudah cari nama customer |
|
|
|
|
->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()); |
|
|
|
|
} |
|
|
|
|
}) // sudah cari est pengembalian (tanggal pengembalian) |
|
|
|
|
->orWhere('exit_pic', 'like', "%$search%") // sudah cari exit pic (nama peminjam) |
|
|
|
|
->orWhereHas('warehouse', function ($warehouseQuery) use ($search) { |
|
|
|
|
$warehouseQuery->where('name', 'like', "%$search%") |
|
|
|
|
->orWhere('address', 'like', "%$search%"); |
|
|
|
|
}) // sudah cari warehouse (lokasi peminjaman) |
|
|
|
|
->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('enter_at', $formattedDate); |
|
|
|
|
} catch (\Exception $e) { |
|
|
|
|
Log::error('Error parsing date: ' . $e->getMessage()); |
|
|
|
|
} |
|
|
|
|
}) // sudah cari enter at (tanggal pengembalian) |
|
|
|
|
->orWhere('enter_pic', 'like', "%$search%") // sudah cari enter pic (nama pengembali) |
|
|
|
|
->orWhereHas('warehouseEnter', function ($warehouseQuery) use ($search) { |
|
|
|
|
$warehouseQuery->where('name', 'like', "%$search%"); |
|
|
|
|
}) // sudah cari warehouse enter (lokasi pengembalian) |
|
|
|
|
->orWhereHas('kondisi_peti', function ($warehouseQuery) use ($search) { |
|
|
|
|
$warehouseQuery->where('nama_kondisi', 'like', "%$search%"); |
|
|
|
|
}) // sudah cari kondisi peti |
|
|
|
|
->orWhere(function ($statusQuery) use ($search) { |
|
|
|
|
if (strtolower($search) === 'return') { |
|
|
|
|
$statusQuery->where('status', 1); |
|
|
|
|
} else { |
|
|
|
|
$statusQuery->where('status', 'like', "%$search%"); |
|
|
|
|
} |
|
|
|
|
}); // sudah cari status |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Periksa apakah perPage adalah 'Semua' |
|
|
|
|
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() + $store->getQueueableId()); |
|
|
|
|
$stores->push($store); |
|
|
|
|
$currentPage++; |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} else { |
|
|
|
|
// Hitung halaman berdasarkan parameter halaman yang diberikan atau default ke halaman pertama |
|
|
|
|
$page = $request->input('page') ?? 1; |
|
|
|
|
|
|
|
|
|
// Paginasi dengan parameter halaman |
|
|
|
|
$stores = $query->paginate($perPage, ['*'], 'page', $page); |
|
|
|
|
|
|
|
|
|
// Hitung nomor urutan untuk setiap item di halaman |
|
|
|
|
$stores->each(function ($store) use ($page, $perPage) { |
|
|
|
|
$store->setAttribute('i', ($page - 1) * $perPage + $store->getQueueableId()); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$data = [ |
|
|
|
|
'peminjaman' => asset_status::withTrashed()->orderBy('created_at', 'desc')->get(), |
|
|
|
|
'peminjaman' => $stores, |
|
|
|
|
'warehouse' => m_warehouse::get(), |
|
|
|
|
'i' => ($stores->currentPage() - 1) * $stores->perPage() + 1, |
|
|
|
|
'search' => $search, |
|
|
|
|
'active' => 'history-pengembalian', |
|
|
|
|
]; |
|
|
|
|
return view('dashboard.History.Pengembalian.index', $data); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Halaman index history transfer |
|
|
|
|
public function historyTransfer() |
|
|
|
|
{ |
|
|
|
|
$data = [ |
|
|
|
|