fix(laporan-penilai-jaminan): perbaikkan filter tanggal dan stype llaporan

This commit is contained in:
majid
2025-03-26 15:01:19 +07:00
parent fcbf2ba979
commit b1aa7bf42c
2 changed files with 80 additions and 53 deletions

View File

@@ -89,13 +89,16 @@ class LaporanPenilaiJaminanController extends Controller
$userTeam = TeamsUsers::with('team')->firstWhere('user_id', $user->id); $userTeam = TeamsUsers::with('team')->firstWhere('user_id', $user->id);
$regionId = $userTeam?->team->regions_id; $regionId = $userTeam?->team->regions_id;
} }
$paramsSearch = null;
// dd($startDate);
// Retrieve data from the database // Retrieve data from the database
$query = Permohonan::query(); $query = Permohonan::query();
// 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');
$paramsSearch = json_decode($search);
$query->where(function ($q) use ($search) { $query->where(function ($q) use ($search) {
$q->where('nomor_registrasi', 'LIKE', '%' . $search . '%') $q->where('nomor_registrasi', 'LIKE', '%' . $search . '%')
->orWhere('tanggal_permohonan', 'LIKE', '%' . $search . '%') ->orWhere('tanggal_permohonan', 'LIKE', '%' . $search . '%')
@@ -104,10 +107,14 @@ class LaporanPenilaiJaminanController extends Controller
->orWhereRelation('tujuanPenilaian', 'name', 'LIKE', '%' . $search . '%') ->orWhereRelation('tujuanPenilaian', 'name', 'LIKE', '%' . $search . '%')
->orWhereRelation('branch', 'name', 'LIKE', '%' . $search . '%'); ->orWhereRelation('branch', 'name', 'LIKE', '%' . $search . '%');
// Split search term by comma to allow multiple statuses if (!empty($paramsSearch->tanggal_awal) && !empty($paramsSearch->tanggal_akhir)) {
$q->whereBetween('tanggal_permohonan', [$paramsSearch->tanggal_awal, $paramsSearch->tanggal_akhir]);
}
$statusKeywords = explode(',', $search); $statusKeywords = explode(',', $search);
foreach ($statusKeywords as $keyword) { foreach ($statusKeywords as $keyword) {
$q->orWhere('status', 'LIKE', '%' . trim($keyword) . '%'); $q->orWhereRelation('penilai', 'type_penilai', 'LIKE', '%' . trim($keyword) . '%');
} }
}); });
} }

View File

@@ -76,9 +76,8 @@
<div class="flex"> <div class="flex">
<!-- Custom dropdown for status filter --> <!-- Custom dropdown for status filter -->
<div class="dropdown" data-dropdown="true" data-dropdown-trigger="click"> <div class="dropdown" data-dropdown="true" data-dropdown-trigger="click">
<button <button class="dropdowns-toggle btn btn-light inline-flex justify-between w-full items-center">
class="dropdowns-toggle btn btn-light inline-flex justify-between w-full items-center"> Pilih Type Laporan
Pilih Status
<i class="ki-outline ki-down dropdown-open:hidden"> <i class="ki-outline ki-down dropdown-open:hidden">
</i> </i>
<i class="ki-outline ki-up hidden dropdown-open:block"> <i class="ki-outline ki-up hidden dropdown-open:block">
@@ -97,7 +96,14 @@
</div> </div>
<!-- Dinamis Status dari Backend --> <!-- Dinamis Status dari Backend -->
@php @php
$status_laporan = ['Standar', 'Sederhana', 'Memo', 'Resume', 'Call Report', 'RAP']; $status_laporan = [
'Standar',
'Sederhana',
'Memo',
'Resume',
'Call Report',
'RAP',
];
@endphp @endphp
@foreach ($status_laporan as $item) @foreach ($status_laporan as $item)
<div class="menu-item"> <div class="menu-item">
@@ -216,10 +222,15 @@
const dataTableOptions = { const dataTableOptions = {
apiEndpoint: apiUrl, apiEndpoint: apiUrl,
pageSize: 5, pageSize: 5,
params: {
startDate: '',
endDate: '',
},
order: [{ order: [{
column: 'nomor_registrasi', column: 'nomor_registrasi',
dir: 'asc' dir: 'asc'
}], }],
columns: { columns: {
select: { select: {
render: (item, data, context) => { render: (item, data, context) => {
@@ -292,7 +303,8 @@
}, },
}, },
} },
}; };
let dataTable = new KTDataTable(element, dataTableOptions); let dataTable = new KTDataTable(element, dataTableOptions);
@@ -312,14 +324,20 @@
const tanggalAwal = tanggalAwalInput.value; const tanggalAwal = tanggalAwalInput.value;
const tanggalAkhir = tanggalAkhirInput.value; const tanggalAkhir = tanggalAkhirInput.value;
if (tanggalAwal && tanggalAkhir) { let filters = {};
// Reload the table with date filters if (searchInput.value) {
dataTable.setParameter('tanggal_awal', tanggalAwal); filters.search = searchInput.value;
dataTable.setParameter('tanggal_akhir', tanggalAkhir);
dataTable.reload();
} else {
alert('Mohon isi tanggal awal dan tanggal akhir');
} }
if (tanggalAwal) {
filters.tanggal_awal = tanggalAwal
}
if (tanggalAkhir) {
filters.tanggal_akhir = tanggalAkhir
}
dataTable.search(filters);
} }
// Status filter functionality // Status filter functionality
@@ -342,9 +360,11 @@
.map(checkbox => checkbox.value); .map(checkbox => checkbox.value);
if (selectedStatuses.length === 0) { if (selectedStatuses.length === 0) {
dataTable.setParameter('status', null); dataTable.search('');
console.log(selectedStatuses);
} else { } else {
dataTable.setParameter('status', selectedStatuses); dataTable.search(selectedStatuses.join(','), true);
console.log(selectedStatuses);
} }
dataTable.reload(); dataTable.reload();