feat(laporan-pembatalan): tambahkan fitur laporan pembatalan
- Menambahkan controller LaporanPembatalanController untuk mengelola laporan pembatalan. - Menyediakan metode untuk menampilkan halaman laporan dan mengekspor data ke Excel. - Mengimplementasikan filter pencarian berdasarkan tanggal, cabang, dan status. - Menyediakan pagination dan sorting untuk data laporan. - Menambahkan tampilan blade untuk laporan pembatalan dengan elemen UI yang diperlukan.
This commit is contained in:
140
app/Http/Controllers/LaporanPembatalanController.php
Normal file
140
app/Http/Controllers/LaporanPembatalanController.php
Normal file
@@ -0,0 +1,140 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Lpj\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use Modules\Lpj\Exports\LaporanPembatalanExport;
|
||||
use Modules\Lpj\Models\PermohonanPembatalan;
|
||||
|
||||
class LaporanPembatalanController extends Controller
|
||||
{
|
||||
public $user;
|
||||
|
||||
public function index()
|
||||
{
|
||||
return view('lpj::laporan_pembatalan.index');
|
||||
}
|
||||
|
||||
public function export(Request $request)
|
||||
{
|
||||
return Excel::download(new LaporanPembatalanExport($request), 'laporan_pembatalan.xlsx');
|
||||
}
|
||||
|
||||
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 = PermohonanPembatalan::query();
|
||||
|
||||
|
||||
if (!Auth::user()->hasAnyRole(['administrator'])) {
|
||||
$query = $query->whereHas('permohonan', function ($q) {
|
||||
$q->where('branch_id', Auth::user()->branch_id);
|
||||
});
|
||||
}
|
||||
|
||||
$query = $query->orderBy('created_at', 'desc');
|
||||
|
||||
// Apply search filter if provided
|
||||
if ($request->has('search') && !empty($request->get('search'))) {
|
||||
$search = json_decode($request->get('search'));
|
||||
|
||||
if (isset($search->start_date) || isset($search->end_date)) {
|
||||
$query->whereBetween('created_at', [
|
||||
$search->start_date ?? '1900-01-01',
|
||||
$search->end_date ?? now()->toDateString()
|
||||
]);
|
||||
}
|
||||
|
||||
// Filter by branch if provided
|
||||
if (isset($search->branch_id) && !empty($search->branch_id)) {
|
||||
$query->whereHas('permohonan', function ($q) use ($search) {
|
||||
$q->where('branch_id', $search->branch_id);
|
||||
});
|
||||
}
|
||||
|
||||
if (isset($search->search)) {
|
||||
$query->where(function ($q) use ($search) {
|
||||
$q->whereHas('permohonan', function ($subq) use ($search) {
|
||||
$subq->where('nomor_registrasi', 'LIKE', '%' . $search->search . '%');
|
||||
$subq->orWhereRelation('user', 'name', 'LIKE', '%' . $search->search . '%');
|
||||
$subq->orWhereRelation('branch', 'name', 'LIKE', '%' . $search->search . '%');
|
||||
});
|
||||
$q->orWhere('alasan_pembatalan', 'LIKE', '%' . $search->search . '%');
|
||||
$q->orWhere('status', 'LIKE', '%' . $search->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->get();
|
||||
|
||||
$data = $data->map(function ($item) {
|
||||
return [
|
||||
'id' => $item->id,
|
||||
'nomor_registrasi' => $item->permohonan->nomor_registrasi ?? '-',
|
||||
'tanggal_permohonan' => $item->permohonan->tanggal_permohonan ? date('d-m-Y', strtotime($item->permohonan->tanggal_permohonan)) : '-',
|
||||
'tanggal_pembatalan' => date('d-m-Y', strtotime($item->created_at)),
|
||||
'cabang' => $item->permohonan->branch->name ?? '-',
|
||||
'pemohon' => $item->permohonan->user->name ?? '-',
|
||||
'debitur' => $item->permohonan->debiture->name ?? '-',
|
||||
'alasan_pembatalan' => $item->alasan_pembatalan,
|
||||
'status' => $item->status,
|
||||
'diajukan_oleh' => $item->user->name ?? '-',
|
||||
'disetujui_oleh' => $item->authorized_by ? $item->authorizedUser->name : '-',
|
||||
'tanggal_disetujui' => $item->authorized_at ? formatTanggalIndonesia(strtotime($item->authorized_at),1) : '-'
|
||||
];
|
||||
});
|
||||
|
||||
|
||||
// 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,
|
||||
]);
|
||||
}
|
||||
}
|
||||
283
resources/views/laporan_pembatalan/index.blade.php
Normal file
283
resources/views/laporan_pembatalan/index.blade.php
Normal file
@@ -0,0 +1,283 @@
|
||||
@extends('layouts.main')
|
||||
|
||||
@section('breadcrumbs')
|
||||
{{-- {{ Breadcrumbs::render('laporan-pembatalan') }}--}}
|
||||
@endsection
|
||||
|
||||
@section('content')
|
||||
<div class="w-full grid gap-5 lg:gap-7.5 mx-auto">
|
||||
<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-pembatalan-table" data-api-url="{{ route('laporan-pembatalan.data') }}">
|
||||
<div class="card-header bg-agi-50 py-5 flex-wrap">
|
||||
<h3 class="card-title">
|
||||
Laporan Pembatalan
|
||||
</h3>
|
||||
<div class="flex flex-wrap gap-2 lg:gap-5">
|
||||
<div class="flex">
|
||||
<label class="input input-sm">
|
||||
<input placeholder="Tanggal Awal" id="start_date" type="date">
|
||||
</label>
|
||||
</div>
|
||||
<div class="flex">
|
||||
<label class="input input-sm">
|
||||
<input placeholder="Tanggal Akhir" id="end_date" type="date">
|
||||
</label>
|
||||
</div>
|
||||
<div class="flex">
|
||||
<select class="select select-sm" id="branch_filter">
|
||||
<option value="">Semua Cabang</option>
|
||||
@foreach(\Modules\Basicdata\Models\Branch::where('status', 1)->get() as $branch)
|
||||
<option value="{{ $branch->id }}">{{ $branch->name }}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="flex">
|
||||
<button class="btn btn-sm btn-primary" id="filter_tanggal">Filter</button>
|
||||
</div>
|
||||
<div class="flex">
|
||||
<label class="input input-sm"> <i class="ki-filled ki-magnifier"> </i>
|
||||
<input placeholder="Search Pembatalan" id="search" type="text" value="">
|
||||
</label>
|
||||
</div>
|
||||
<div class="flex flex-wrap gap-2.5">
|
||||
<div class="h-[24px] border border-r-gray-200"></div>
|
||||
<a class="btn btn-sm btn-light" href="{{ route('laporan-pembatalan.export') }}" id="export-btn"> Export to Excel </a>
|
||||
</div>
|
||||
</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="nomor_registrasi">
|
||||
<span class="sort"> <span class="sort-label"> Nomor Registrasi </span>
|
||||
<span class="sort-icon"> </span> </span>
|
||||
</th>
|
||||
<th class="min-w-[150px]" data-datatable-column="tanggal_permohonan">
|
||||
<span class="sort"> <span class="sort-label"> Tanggal Permohonan </span>
|
||||
<span class="sort-icon"> </span> </span>
|
||||
</th>
|
||||
<th class="min-w-[150px]" data-datatable-column="tanggal_pembatalan">
|
||||
<span class="sort"> <span class="sort-label"> Tanggal Pembatalan </span>
|
||||
<span class="sort-icon"> </span> </span>
|
||||
</th>
|
||||
<th class="min-w-[150px]" data-datatable-column="cabang">
|
||||
<span class="sort"> <span class="sort-label"> Cabang </span>
|
||||
<span class="sort-icon"> </span> </span>
|
||||
</th>
|
||||
<th class="min-w-[150px]" data-datatable-column="pemohon">
|
||||
<span class="sort"> <span class="sort-label"> Pemohon </span>
|
||||
<span class="sort-icon"> </span> </span>
|
||||
</th>
|
||||
<th class="min-w-[150px]" data-datatable-column="debitur">
|
||||
<span class="sort"> <span class="sort-label"> Debitur </span>
|
||||
<span class="sort-icon"> </span> </span>
|
||||
</th>
|
||||
<th class="min-w-[150px]" data-datatable-column="alasan_pembatalan">
|
||||
<span class="sort"> <span class="sort-label"> Alasan Pembatalan </span>
|
||||
<span class="sort-icon"> </span> </span>
|
||||
</th>
|
||||
<th class="min-w-[150px]" data-datatable-column="status">
|
||||
<span class="sort"> <span class="sort-label"> Status </span>
|
||||
<span class="sort-icon"> </span> </span>
|
||||
</th>
|
||||
<th class="min-w-[150px]" data-datatable-column="diajukan_oleh">
|
||||
<span class="sort"> <span class="sort-label"> Diajukan Oleh </span>
|
||||
<span class="sort-icon"> </span> </span>
|
||||
</th>
|
||||
<th class="min-w-[150px]" data-datatable-column="disetujui_oleh">
|
||||
<span class="sort"> <span class="sort-label"> Disetujui Oleh </span>
|
||||
<span class="sort-icon"> </span> </span>
|
||||
</th>
|
||||
<th class="min-w-[150px]" data-datatable-column="tanggal_disetujui">
|
||||
<span class="sort"> <span class="sort-label"> Tanggal Disetujui </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-pembatalan-table');
|
||||
const searchInput = document.getElementById('search');
|
||||
const startDateInput = document.getElementById('start_date');
|
||||
const endDateInput = document.getElementById('end_date');
|
||||
const statusFilter = document.getElementById('status_filter');
|
||||
const branchFilter = document.getElementById('branch_filter');
|
||||
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();
|
||||
},
|
||||
},
|
||||
nomor_registrasi: {
|
||||
title: 'Nomor Registrasi',
|
||||
},
|
||||
tanggal_permohonan: {
|
||||
title: 'Tanggal Permohonan',
|
||||
},
|
||||
tanggal_pembatalan: {
|
||||
title: 'Tanggal Pembatalan',
|
||||
},
|
||||
cabang: {
|
||||
title: 'Cabang',
|
||||
},
|
||||
pemohon: {
|
||||
title: 'Pemohon',
|
||||
},
|
||||
debitur: {
|
||||
title: 'Debitur',
|
||||
},
|
||||
alasan_pembatalan: {
|
||||
title: 'Alasan Pembatalan',
|
||||
},
|
||||
status: {
|
||||
title: 'Status',
|
||||
render: (item, data) => {
|
||||
let statusClass = '';
|
||||
let statusText = '';
|
||||
|
||||
switch (data.status) {
|
||||
case 'batal':
|
||||
statusClass = 'badge-danger';
|
||||
statusText = 'Batal';
|
||||
break;
|
||||
default:
|
||||
statusClass = 'badge-secondary';
|
||||
statusText = data.status;
|
||||
}
|
||||
|
||||
return `<span class="badge ${statusClass}">${statusText}</span>`;
|
||||
},
|
||||
},
|
||||
diajukan_oleh: {
|
||||
title: 'Diajukan Oleh',
|
||||
},
|
||||
disetujui_oleh: {
|
||||
title: 'Disetujui Oleh',
|
||||
},
|
||||
tanggal_disetujui: {
|
||||
title: 'Tanggal Disetujui',
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
let dataTable = new KTDataTable(element, dataTableOptions);
|
||||
|
||||
// Function to apply all filters
|
||||
function applyFilters() {
|
||||
let filters = {};
|
||||
const startDate = startDateInput.value;
|
||||
const endDate = endDateInput.value;
|
||||
const branch = branchFilter.value;
|
||||
|
||||
if (searchInput.value) {
|
||||
filters.search = searchInput.value;
|
||||
}
|
||||
|
||||
if (startDate) {
|
||||
filters.start_date = startDate;
|
||||
}
|
||||
|
||||
if (endDate) {
|
||||
filters.end_date = endDate;
|
||||
}
|
||||
|
||||
if (status) {
|
||||
filters.status = status;
|
||||
}
|
||||
|
||||
if (branch) {
|
||||
filters.branch_id = branch;
|
||||
}
|
||||
|
||||
dataTable.search(filters);
|
||||
}
|
||||
|
||||
// Update export URL with filters
|
||||
function updateExportUrl() {
|
||||
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 (branchFilter.value) {
|
||||
url.searchParams.set('branch_id', branchFilter.value);
|
||||
} else {
|
||||
url.searchParams.delete('branch_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();
|
||||
});
|
||||
|
||||
|
||||
branchFilter.addEventListener('change', () => {
|
||||
applyFilters();
|
||||
updateExportUrl();
|
||||
});
|
||||
|
||||
filterTanggalButton.addEventListener('click', () => {
|
||||
applyFilters();
|
||||
updateExportUrl();
|
||||
});
|
||||
|
||||
// Initial update of export URL
|
||||
updateExportUrl();
|
||||
</script>
|
||||
@endpush
|
||||
Reference in New Issue
Block a user