feat(laporan-admin-kredit): tambahkan filter tanggal pada laporan admin kredit
- Menambahkan input untuk tanggal awal dan tanggal akhir di tampilan laporan. - Memperbarui logika pencarian untuk mendukung filter berdasarkan rentang tanggal. - Menambahkan fungsi untuk menerapkan semua filter secara bersamaan.
This commit is contained in:
@@ -31,17 +31,29 @@
|
|||||||
// Retrieve data from the database
|
// Retrieve data from the database
|
||||||
$query = LaporanAdminKredit::query();
|
$query = LaporanAdminKredit::query();
|
||||||
|
|
||||||
|
if ($request->has('tanggal_awal') && $request->has('tanggal_akhir')) {
|
||||||
|
$query->whereBetween('tanggal_kunjungan', [$request->tanggal_awal, $request->tanggal_akhir]);
|
||||||
|
}
|
||||||
|
|
||||||
// Apply search filter if provided
|
// Apply search filter if provided
|
||||||
if ($request->has('search') && !empty($request->get('search'))) {
|
if ($request->has('search') && !empty($request->get('search'))) {
|
||||||
$search = $request->get('search');
|
$search = $request->get('search');
|
||||||
$query->where(function ($q) use ($search) {
|
$search_ = json_decode($search);
|
||||||
$q->where('kode_register_t24', 'LIKE', '%' . $search . '%')
|
|
||||||
->orWhere('jenis_agunan', 'LIKE', '%' . $search . '%')
|
if (isset($search_->search)) {
|
||||||
->orWhere('nama_pemilik', 'LIKE', '%' . $search . '%')
|
$query->where(function ($q) use ($search_) {
|
||||||
->orWhereHas('debiture', function ($query) use ($search) {
|
$q->where('kode_register_t24', 'LIKE', '%' . $search_->search . '%')
|
||||||
$query->where('name', 'LIKE', '%' . $search . '%');
|
->orWhere('jenis_agunan', 'LIKE', '%' . $search_->search . '%')
|
||||||
});
|
->orWhere('nama_pemilik', 'LIKE', '%' . $search_->search . '%')
|
||||||
});
|
->orWhereHas('debiture', function ($query) use ($search_) {
|
||||||
|
$query->where('name', 'LIKE', '%' . $search_->search . '%');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($search_->tanggal_awal) && isset($search_->tanggal_akhir)) {
|
||||||
|
$query->whereBetween('tanggal_kunjungan', [$search_->tanggal_awal, $search_->tanggal_akhir]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply sorting if provided
|
// Apply sorting if provided
|
||||||
|
|||||||
@@ -12,6 +12,19 @@
|
|||||||
Daftar Laporan Admin Kredit
|
Daftar Laporan Admin Kredit
|
||||||
</h3>
|
</h3>
|
||||||
<div class="flex flex-wrap gap-2 lg:gap-5">
|
<div class="flex flex-wrap gap-2 lg:gap-5">
|
||||||
|
<div class="flex">
|
||||||
|
<label class="input input-sm">
|
||||||
|
<input placeholder="Tanggal Awal" id="tanggal_awal" type="date">
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<div class="flex">
|
||||||
|
<label class="input input-sm">
|
||||||
|
<input placeholder="Tanggal Akhir" id="tanggal_akhir" type="date">
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<div class="flex">
|
||||||
|
<button class="btn btn-sm btn-primary" id="filter_tanggal">Filter</button>
|
||||||
|
</div>
|
||||||
<div class="flex">
|
<div class="flex">
|
||||||
<label class="input input-sm"> <i class="ki-filled ki-magnifier"> </i>
|
<label class="input input-sm"> <i class="ki-filled ki-magnifier"> </i>
|
||||||
<input placeholder="Search Laporan" id="search" type="text" value="">
|
<input placeholder="Search Laporan" id="search" type="text" value="">
|
||||||
@@ -105,6 +118,10 @@
|
|||||||
<script type="module">
|
<script type="module">
|
||||||
const element = document.querySelector('#laporan-admin-kredit-table');
|
const element = document.querySelector('#laporan-admin-kredit-table');
|
||||||
const searchInput = document.getElementById('search');
|
const searchInput = document.getElementById('search');
|
||||||
|
const tanggalAwalInput = document.getElementById('tanggal_awal');
|
||||||
|
const tanggalAkhirInput = document.getElementById('tanggal_akhir');
|
||||||
|
const filterTanggalButton = document.getElementById('filter_tanggal');
|
||||||
|
|
||||||
|
|
||||||
const apiUrl = element.getAttribute('data-api-url');
|
const apiUrl = element.getAttribute('data-api-url');
|
||||||
const dataTableOptions = {
|
const dataTableOptions = {
|
||||||
@@ -180,9 +197,31 @@
|
|||||||
|
|
||||||
let dataTable = new KTDataTable(element, dataTableOptions);
|
let dataTable = new KTDataTable(element, dataTableOptions);
|
||||||
|
|
||||||
searchInput.addEventListener('input', function() {
|
// Function to apply all filters
|
||||||
const searchValue = this.value.trim();
|
function applyFilters() {
|
||||||
dataTable.search(searchValue, true);
|
let filters = {};
|
||||||
});
|
const tanggalAwal = tanggalAwalInput.value;
|
||||||
|
const tanggalAkhir = tanggalAkhirInput.value;
|
||||||
|
|
||||||
|
console.table(tanggalAwal, tanggalAkhir);
|
||||||
|
|
||||||
|
if (searchInput.value) {
|
||||||
|
filters.search = searchInput.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tanggalAwal) {
|
||||||
|
filters.tanggal_awal = tanggalAwal
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tanggalAkhir) {
|
||||||
|
filters.tanggal_akhir = tanggalAkhir
|
||||||
|
}
|
||||||
|
|
||||||
|
dataTable.search(filters);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add event listeners for all inputs
|
||||||
|
searchInput.addEventListener('input', applyFilters);
|
||||||
|
filterTanggalButton.addEventListener('click', applyFilters);
|
||||||
</script>
|
</script>
|
||||||
@endpush
|
@endpush
|
||||||
|
|||||||
Reference in New Issue
Block a user