- Change data source from Permohonan to User model - Simplify search functionality to only search by name and NIK - Update table columns to show user information (NIK, name, roles) - Remove date range filters and complex search conditions - Add helper function getFilePath to handle storage paths
235 lines
8.7 KiB
PHP
235 lines
8.7 KiB
PHP
@extends('layouts.main')
|
|
|
|
@section('breadcrumbs')
|
|
{{ Breadcrumbs::render('laporan-user') }}
|
|
@endsection
|
|
|
|
@section('content')
|
|
<div class="w-full grid gap-5 lg:gap-7.5 mx-auto">
|
|
|
|
<!-- Data Table Card -->
|
|
<div class="card border border-agi-100 card-grid min-w-full" data-datatable="false" data-datatable-page-size="10" data-datatable-state-save="false" id="laporan-user-table" data-api-url="{{ route('laporan-user.datatables') }}">
|
|
<div class="card-header bg-agi-50 py-5 flex-wrap">
|
|
|
|
<h3 class="card-title">
|
|
Laporan User
|
|
</h3>
|
|
<div class="flex flex-wrap gap-2 lg:gap-5">
|
|
<div class="flex flex-wrap gap-2 lg:gap-5">
|
|
<label class="input input-sm">
|
|
<i class="ki-filled ki-magnifier"></i>
|
|
<input placeholder="Search Laporan User" id="search" type="text" value="">
|
|
</label>
|
|
</div>
|
|
<a class="btn btn-sm btn-light" href="{{ route('laporan-user.export') }}" id="export-btn">
|
|
<i class="ki-outline ki-file-down fs-2 me-1"></i>
|
|
Export to Excel
|
|
</a>
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="card-body">
|
|
<div class="scrollable-x-auto">
|
|
<table class="table table-auto table-border align-middle text-gray-700 font-medium text-sm" data-datatable-table="true">
|
|
<thead>
|
|
<tr>
|
|
<th class="w-14">
|
|
<input class="checkbox checkbox-sm" data-datatable-check="true" type="checkbox"/>
|
|
</th>
|
|
<th class="min-w-[150px]" data-datatable-column="nik">
|
|
<span class="sort"> <span class="sort-label"> NIK</span>
|
|
<span class="sort-icon"> </span> </span>
|
|
</th>
|
|
<th class="min-w-[150px]" data-datatable-column="name">
|
|
<span class="sort"> <span class="sort-label"> Nama User</span>
|
|
<span class="sort-icon"> </span> </span>
|
|
</th>
|
|
<th class="min-w-[150px]" data-datatable-column="level">
|
|
<span class="sort"> <span class="sort-label"> Level Group </span>
|
|
<span class="sort-icon"> </span> </span>
|
|
</th>
|
|
<th class="min-w-[150px]" data-datatable-column="approval_limit">
|
|
<span class="sort"> <span class="sort-label"> Approval Limit </span>
|
|
<span class="sort-icon"> </span> </span>
|
|
</th>
|
|
</tr>
|
|
</thead>
|
|
</table>
|
|
</div>
|
|
<div class="card-footer justify-center md:justify-between flex-col md:flex-row gap-3 text-gray-600 text-2sm font-medium">
|
|
<div class="flex items-center gap-2">
|
|
Show
|
|
<select class="select select-sm w-16" data-datatable-size="true" name="perpage"> </select> per page
|
|
</div>
|
|
<div class="flex items-center gap-4">
|
|
<span data-datatable-info="true"> </span>
|
|
<div class="pagination" data-datatable-pagination="true">
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
@endsection
|
|
|
|
@push('scripts')
|
|
<script type="module">
|
|
const element = document.querySelector('#laporan-user-table');
|
|
const searchInput = document.getElementById('search');
|
|
const startDateInput = document.getElementById('start_date');
|
|
const endDateInput = document.getElementById('end_date');
|
|
const userFilter = document.getElementById('user_id');
|
|
const filterTanggalButton = document.getElementById('filter_tanggal');
|
|
const exportBtn = document.getElementById('export-btn');
|
|
|
|
const apiUrl = element.getAttribute('data-api-url');
|
|
const dataTableOptions = {
|
|
apiEndpoint: apiUrl,
|
|
pageSize: 5,
|
|
columns: {
|
|
select: {
|
|
render: (item, data, context) => {
|
|
const checkbox = document.createElement('input');
|
|
checkbox.className = 'checkbox checkbox-sm';
|
|
checkbox.type = 'checkbox';
|
|
checkbox.value = data.id.toString();
|
|
checkbox.setAttribute('data-datatable-row-check', 'true');
|
|
return checkbox.outerHTML.trim();
|
|
},
|
|
},
|
|
nik: {
|
|
title: 'Nomor Registrasi',
|
|
},
|
|
name: {
|
|
title: 'Nama',
|
|
},
|
|
level: {
|
|
title: 'level',
|
|
},
|
|
approval_limit: {
|
|
title: 'Approval Limit',
|
|
render: (item, data) => {
|
|
return data.tanggal_permohonan ? window.formatTanggalIndonesia(data.tanggal_permohonan) : '-';
|
|
},
|
|
},
|
|
}
|
|
};
|
|
|
|
let dataTable = new KTDataTable(element, dataTableOptions);
|
|
|
|
// Function to apply all filters
|
|
function applyFilters() {
|
|
let filters = {};
|
|
const startDate = startDateInput.value;
|
|
const endDate = endDateInput.value;
|
|
const user_id = userFilter.value;
|
|
|
|
|
|
if (searchInput.value) {
|
|
filters.search = searchInput.value;
|
|
}
|
|
|
|
if (startDate) {
|
|
filters.start_date = startDate;
|
|
}
|
|
if (endDate) {
|
|
filters.end_date = endDate;
|
|
}
|
|
|
|
if (user_id) {
|
|
filters.user_id = user_id;
|
|
}
|
|
|
|
|
|
dataTable.search(filters);
|
|
}
|
|
|
|
// Update export URL with filters
|
|
function updateExportUrl() {
|
|
dataTable.goPage(1);
|
|
let url = new URL(exportBtn.href);
|
|
|
|
if (startDateInput.value) {
|
|
url.searchParams.set('start_date', startDateInput.value);
|
|
} else {
|
|
url.searchParams.delete('start_date');
|
|
}
|
|
|
|
if (endDateInput.value) {
|
|
url.searchParams.set('end_date', endDateInput.value);
|
|
} else {
|
|
url.searchParams.delete('end_date');
|
|
}
|
|
|
|
if (userFilter.value) {
|
|
url.searchParams.set('user_id', userFilter.value);
|
|
} else {
|
|
url.searchParams.delete('user_id');
|
|
}
|
|
|
|
|
|
if (searchInput.value) {
|
|
url.searchParams.set('search', searchInput.value);
|
|
} else {
|
|
url.searchParams.delete('search');
|
|
}
|
|
|
|
exportBtn.href = url.toString();
|
|
}
|
|
|
|
// Add event listeners for all inputs
|
|
searchInput.addEventListener('input', () => {
|
|
applyFilters();
|
|
updateExportUrl();
|
|
});
|
|
|
|
filterTanggalButton.addEventListener('click', () => {
|
|
applyFilters();
|
|
updateExportUrl();
|
|
});
|
|
|
|
// Initial update of export URL
|
|
updateExportUrl();
|
|
</script>
|
|
|
|
<script>
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
let userSelect = document.querySelector('#user_id');
|
|
|
|
if (userSelect) {
|
|
// Jika sudah ada instance TomSelect, destroy dulu
|
|
if (userSelect.tomselect) {
|
|
userSelect.tomselect.destroy();
|
|
}
|
|
|
|
// Inisialisasi TomSelect dengan konfigurasi yang benar
|
|
new TomSelect(userSelect, {
|
|
valueField: 'id',
|
|
labelField: 'name',
|
|
searchField: 'name',
|
|
placeholder: 'Pilih User',
|
|
load: function(query, callback) {
|
|
if (!query.length) return callback();
|
|
|
|
$.ajax({
|
|
url: "{{ route('laporan-user.api.user-pemohon') }}",
|
|
method: 'GET',
|
|
data: {
|
|
search: query
|
|
},
|
|
success: function(response) {
|
|
console.log('Response data:', response);
|
|
callback(response);
|
|
},
|
|
error: function() {
|
|
callback();
|
|
}
|
|
});
|
|
}
|
|
});
|
|
}
|
|
});
|
|
</script>
|
|
@endpush
|