Tambahkan fitur data untuk laporan datatables
- Menambahkan metode `dataForDatatables` di `LaporanController` untuk keperluan pencarian, pengurutan, dan paginasi data laporan. - Memperbarui view `laporan/index.blade.php` agar mendukung penggunaan datatables untuk menampilkan data laporan dengan kolom baru. - Menambahkan route baru untuk akses endpoint datatables laporan. - Memodifikasi `module.json` dengan menggabungkan menu "Resume" dan "Laporan" menjadi satu menu "Resume dan Laporan".
This commit is contained in:
@@ -4,6 +4,7 @@ namespace Modules\Lpj\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Modules\Lpj\Models\Permohonan;
|
||||
|
||||
class LaporanController extends Controller
|
||||
{
|
||||
@@ -37,4 +38,75 @@ class LaporanController extends Controller
|
||||
public function store(Request $request) {}
|
||||
|
||||
public function update(Request $request, $id) {}
|
||||
|
||||
public function dataForDatatables(Request $request)
|
||||
{
|
||||
if (is_null($this->user) || !$this->user->can('debitur.view')) {
|
||||
//abort(403, 'Sorry! You are not allowed to view users.');
|
||||
}
|
||||
|
||||
// Retrieve data from the database
|
||||
$query = Permohonan::query()->whereIn('status',['proses-laporan','done']);
|
||||
|
||||
$query = $query->orderBy('nomor_registrasi', 'desc');
|
||||
// Apply search filter if provided
|
||||
if ($request->has('search') && !empty($request->get('search'))) {
|
||||
$search = $request->get('search');
|
||||
$query->where(function ($q) use ($search) {
|
||||
$q->where('nomor_registrasi', 'LIKE', '%' . $search . '%');
|
||||
$q->orWhere('tanggal_permohonan', 'LIKE', '%' . $search . '%');
|
||||
$q->orWhereRelation('user', 'name', 'LIKE', '%' . $search . '%');
|
||||
$q->orWhereRelation('debiture', 'name', 'LIKE', '%' . $search . '%');
|
||||
$q->orWhereRelation('tujuanPenilaian', 'name', 'LIKE', '%' . $search . '%');
|
||||
$q->orWhereRelation('branch', 'name', 'LIKE', '%' . $search . '%');
|
||||
$q->orWhere('status', 'LIKE', '%' . $search . '%');
|
||||
});
|
||||
}
|
||||
|
||||
// Apply sorting if provided
|
||||
if ($request->has('sortOrder') && !empty($request->get('sortOrder'))) {
|
||||
$order = $request->get('sortOrder');
|
||||
$column = $request->get('sortField');
|
||||
$query->orderBy($column, $order);
|
||||
}
|
||||
|
||||
// Get the total count of records
|
||||
$totalRecords = $query->count();
|
||||
$size = $request->get('size', 10);
|
||||
if ($size == 0) {
|
||||
$size = 10;
|
||||
}
|
||||
|
||||
// Apply pagination if provided
|
||||
if ($request->has('page') && $request->has('size')) {
|
||||
$page = $request->get('page');
|
||||
$size = $request->get('size');
|
||||
$offset = ($page - 1) * $size; // Calculate the offset
|
||||
|
||||
$query->skip($offset)->take($size);
|
||||
}
|
||||
|
||||
// Get the filtered count of records
|
||||
$filteredRecords = $query->count();
|
||||
|
||||
// Get the data for the current page
|
||||
$data = $query->with(['user', 'debiture', 'branch', 'tujuanPenilaian', 'penilaian','jenisFasilitasKredit'])->get();
|
||||
|
||||
// Calculate the page count
|
||||
$pageCount = ceil($totalRecords / $size);
|
||||
|
||||
// Calculate the current page number
|
||||
$currentPage = max(1, $request->get('page', 1));
|
||||
|
||||
// Return the response data as a JSON object
|
||||
return response()->json([
|
||||
'draw' => $request->get('draw'),
|
||||
'recordsTotal' => $totalRecords,
|
||||
'recordsFiltered' => $filteredRecords,
|
||||
'pageCount' => $pageCount,
|
||||
'page' => $currentPage,
|
||||
'totalCount' => $totalRecords,
|
||||
'data' => $data,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
15
module.json
15
module.json
@@ -325,7 +325,7 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"title": "Laporan",
|
||||
"title": "Resume dan Laporan",
|
||||
"path": "laporan",
|
||||
"icon": "ki-filled ki-filter-tablet text-lg text-primary",
|
||||
"classes": "",
|
||||
@@ -338,19 +338,6 @@
|
||||
"admin",
|
||||
"senior-officer"
|
||||
]
|
||||
},
|
||||
{
|
||||
"title": "Resume",
|
||||
"path": "resume",
|
||||
"icon": "ki-filled ki-notepad text-lg text-primary",
|
||||
"classes": "",
|
||||
"attributes": [],
|
||||
"permission": "",
|
||||
"roles": [
|
||||
"administrator",
|
||||
"pemohon-ao",
|
||||
"pemohon-eo"
|
||||
]
|
||||
}
|
||||
],
|
||||
"master": [
|
||||
|
||||
@@ -7,10 +7,8 @@
|
||||
|
||||
@section('content')
|
||||
<div class="w-full grid gap-5 lg:gap-7.5 mx-auto">
|
||||
|
||||
|
||||
<div class="card card-grid min-w-full" data-datatable="false" data-datatable-page-size="10"
|
||||
data-datatable-state-save="false" id="penilai-table" data-api-url="{{ route('penilai.dataForTables') }}">
|
||||
data-datatable-state-save="false" id="laporan-table" data-api-url="{{ route('laporan.datatables') }}">
|
||||
<div class="card-header py-5 flex-wrap">
|
||||
<h3 class="card-title">
|
||||
Laporan
|
||||
@@ -69,7 +67,8 @@
|
||||
<span class="sort"> <span class="sort-label"> Due Date SLA </span>
|
||||
<span class="sort-icon"> </span> </span>
|
||||
</th>
|
||||
<th class="min-w-[50px] text-center" data-datatable-column="actions">Action</th>
|
||||
<th class="min-w-[50px] text-center" data-datatable-column="status">Status</th>
|
||||
<th class="min-w-[50px] text-center" data-datatable-column="actions">Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
</table>
|
||||
@@ -88,9 +87,124 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
@push('scripts')
|
||||
<script type="module">
|
||||
const element = document.querySelector('#laporan-table');
|
||||
const searchInput = document.getElementById('search');
|
||||
|
||||
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();
|
||||
},
|
||||
},
|
||||
nomor_registrasi: {
|
||||
title: 'Nomor Registrasi',
|
||||
},
|
||||
debitur_id: {
|
||||
title: 'Debitur',
|
||||
render: (item, data) => {
|
||||
if (data.debiture) {
|
||||
return `${data.debiture.name.toUpperCase()}`;
|
||||
}
|
||||
return "-";
|
||||
},
|
||||
},
|
||||
branch_id: {
|
||||
title: 'Cabang Pemohon',
|
||||
render: (item, data) => {
|
||||
return `${data.branch.name}`;
|
||||
},
|
||||
},
|
||||
user_id: {
|
||||
title: 'User Pemohon',
|
||||
render: (item, data) => {
|
||||
return `${data.user.name}`;
|
||||
},
|
||||
},
|
||||
tujuan_penilaian_id: {
|
||||
title: 'Tujuan Penilaian',
|
||||
render: (item, data) => {
|
||||
switch (data.tujuan_penilaian.code) {
|
||||
case "TP0001":
|
||||
return `<span class="badge badge-sm badge-primary">${data.tujuan_penilaian.name}</span>`;
|
||||
case "TP0002":
|
||||
return `<span class="badge badge-sm badge-info">${data.tujuan_penilaian.name}</span>`;
|
||||
case "TP0003":
|
||||
return `<span class="badge badge-sm badge-success">${data.tujuan_penilaian.name}</span>`;
|
||||
case "TP0004":
|
||||
return `<span class="badge badge-sm badge-danger">${data.tujuan_penilaian.name}</span>`;
|
||||
case "TP0005":
|
||||
return `<span class="badge badge-sm badge-warning">${data.tujuan_penilaian.name}</span>`;
|
||||
case "TP0006":
|
||||
return `<span class="badge badge-sm badge-dark">${data.tujuan_penilaian.name}</span>`;
|
||||
case "TP0007":
|
||||
return `<span class="badge badge-sm badge-outline badge-info">${data.tujuan_penilaian.name}</span>`;
|
||||
default:
|
||||
return `<span class="badge badge-sm badge-outline badge-default">${data.tujuan_penilaian.name}</span>`;
|
||||
}
|
||||
},
|
||||
},
|
||||
jenis_fasilitas_kredit_id:{
|
||||
title: 'Fasilitas Kredit',
|
||||
render: (item, data) => {
|
||||
return `${data.jenis_fasilitas_kredit.name}`;
|
||||
}
|
||||
},
|
||||
tanggal_survei:{
|
||||
title: 'Tanggal Survei',
|
||||
render: (item, data) => {
|
||||
return '-';
|
||||
}
|
||||
},
|
||||
due_date_sla: {
|
||||
title: 'Due Date SLA',
|
||||
render: (item, data) => {
|
||||
return '-';
|
||||
}
|
||||
},
|
||||
status: {
|
||||
title: 'Status',
|
||||
render: (item, data) => {
|
||||
return `<span class="badge badge-sm badge-default uppercase flex justify-center">${data.status}</span>`;
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
title: 'Actions',
|
||||
render: (item, data) => {
|
||||
return `
|
||||
<a href="" class="btn btn-sm btn-success">
|
||||
Resume
|
||||
</a>
|
||||
<a href="#" class="btn btn-sm btn-dark">
|
||||
Laporan
|
||||
</a>
|
||||
`;
|
||||
},
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
let dataTable = new KTDataTable(element, dataTableOptions);
|
||||
// Custom search functionality
|
||||
searchInput.addEventListener('input', function () {
|
||||
const searchValue = this.value.trim();
|
||||
dataTable.search(searchValue, true);
|
||||
|
||||
});
|
||||
</script>
|
||||
@endpush
|
||||
|
||||
@@ -349,6 +349,10 @@ Route::middleware(['auth'])->group(function () {
|
||||
});
|
||||
|
||||
Route::resource('debitur', DebitureController::class);
|
||||
|
||||
Route::name('laporan.')->prefix('laporan')->group(function () {
|
||||
Route::get('datatables', [LaporanController::class, 'dataForDatatables'])->name('datatables');
|
||||
});
|
||||
Route::resource('laporan', LaporanController::class);
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user