CRUD petugas/pegawai + filter-sort-rekap transaksi parkir + fix save member kartu + hilangkan alert ganti Swal-loading

This commit is contained in:
2026-10-14 11:21:07 +07:00
parent ee1f43977a
commit f3818f03f5
23 changed files with 747 additions and 53 deletions
@@ -27,10 +27,18 @@ public function index()
* - tgl_awal / tgl_akhir (Y-m-d): periode kolom tanggal
* - status_kendaraan: 1 = masuk, 0 = keluar
* - status_transaksi: 0 = casual, 3 = member, 32 = denda
* - sort_by + sort_dir (asc/desc): klik header kolom
* - export=csv: unduh hasil filter sebagai CSV
*/
public function data(Request $request)
{
$sortable = [
'id', 'no_pol', 'no_barcode', 'id_kendaraan', 'nama_kendaraan',
'waktu_masuk', 'waktu_keluar', 'tanggal',
'id_op_masuk', 'id_op_keluar', 'id_pintu_masuk', 'id_pintu_keluar',
'bayar_keluar', 'status', 'status_transaksi',
];
$request->validate([
'field' => 'nullable|in:id,no_pol,no_barcode',
'q' => 'nullable|string|max:100',
@@ -38,6 +46,8 @@ public function data(Request $request)
'tgl_akhir' => 'nullable|date_format:Y-m-d|after_or_equal:tgl_awal',
'status_kendaraan' => 'nullable|in:0,1',
'status_transaksi' => 'nullable|in:0,3,32',
'sort_by' => 'nullable|in:' . implode(',', $sortable),
'sort_dir' => 'nullable|in:asc,desc',
'per_page' => 'nullable|integer|min:1|max:500',
]);
@@ -53,6 +63,7 @@ public function data(Request $request)
return response()->json([
'status' => true,
'data' => $rows->items(),
'summary' => $this->summary($request),
'meta' => [
'current_page' => $rows->currentPage(),
'per_page' => $rows->perPage(),
@@ -62,6 +73,45 @@ public function data(Request $request)
]);
}
/**
* Rekap sedetail logic report (per segmen) dari filter yang sedang aktif.
* - keluar = status 0 ; tunai = cara_bayar null/0 ; cashless = cara_bayar 3
* - casual/member/denda/manual/masalah = subset tunai (ikut reportOfficer)
*/
protected function summary(Request $request): array
{
$tunai = "(tp.cara_bayar IS NULL OR tp.cara_bayar = 0)";
$keluar = "tp.status = 0";
$query = $this->filteredQuery($request);
$query->reorder();
$query->columns = [];
$row = $query
->selectRaw("
count(*) as total_rows,
coalesce(sum(tp.bayar_keluar), 0) as total_bayar,
count(case when {$keluar} then 1 end) as keluar_rows,
coalesce(sum(case when {$keluar} then tp.bayar_keluar end), 0) as keluar_bayar,
count(case when {$keluar} and {$tunai} then 1 end) as tunai_rows,
coalesce(sum(case when {$keluar} and {$tunai} then tp.bayar_keluar end), 0) as tunai_bayar,
count(case when {$keluar} and tp.cara_bayar = 3 then 1 end) as cashless_rows,
coalesce(sum(case when {$keluar} and tp.cara_bayar = 3 then tp.bayar_keluar end), 0) as cashless_bayar,
count(case when {$keluar} and {$tunai} and tp.status_transaksi = '0' and tp.id_op_masuk is not null then 1 end) as casual_rows,
coalesce(sum(case when {$keluar} and {$tunai} and tp.status_transaksi = '0' and tp.id_op_masuk is not null then tp.bayar_keluar end), 0) as casual_bayar,
count(case when {$keluar} and {$tunai} and tp.status_transaksi = '3' then 1 end) as member_rows,
coalesce(sum(case when {$keluar} and {$tunai} and tp.status_transaksi = '3' then tp.bayar_keluar end), 0) as member_bayar,
count(case when {$keluar} and {$tunai} and tp.status_transaksi = '32' then 1 end) as denda_rows,
coalesce(sum(case when {$keluar} and {$tunai} and tp.status_transaksi = '32' then tp.bayar_keluar end), 0) as denda_bayar,
count(case when {$keluar} and {$tunai} and tp.id_op_masuk is null then 1 end) as manual_rows,
coalesce(sum(case when {$keluar} and {$tunai} and tp.id_op_masuk is null then tp.bayar_keluar end), 0) as manual_bayar,
count(case when {$keluar} and {$tunai} and tp.status_transaksi = '-1' then 1 end) as masalah_rows,
coalesce(sum(case when {$keluar} and {$tunai} and tp.status_transaksi = '-1' then tp.bayar_keluar end), 0) as masalah_bayar
")
->first();
return (array) $row;
}
protected function filteredQuery(Request $request)
{
$query = DB::table('transaksi_parkir as tp')
@@ -76,7 +126,12 @@ protected function filteredQuery(Request $request)
'tp.status_transaksi',
'tp.waktu_masuk',
'tp.waktu_keluar',
'tp.tanggal'
'tp.tanggal',
'tp.id_op_masuk',
'tp.id_op_keluar',
'tp.id_pintu_masuk',
'tp.id_pintu_keluar',
'tp.bayar_keluar'
);
// 1. Pencarian: id / no_pol / no_barcode
@@ -103,7 +158,13 @@ protected function filteredQuery(Request $request)
$query->where('tp.status_transaksi', (int) $request->input('status_transaksi'));
}
return $query->orderBy('tp.tanggal', 'desc');
// 5. Sorting klik header (default: tanggal terbaru)
$sortMap = ['nama_kendaraan' => 'jm.nama'];
$sortBy = $request->input('sort_by', 'tanggal');
$sortDir = $request->input('sort_dir', 'desc');
$query->orderBy($sortMap[$sortBy] ?? "tp.{$sortBy}", $sortDir);
return $query;
}
protected function exportCsv($query): StreamedResponse
@@ -112,7 +173,7 @@ protected function exportCsv($query): StreamedResponse
return response()->streamDownload(function () use ($query) {
$out = fopen('php://output', 'w');
fputcsv($out, ['ID', 'No. Pol', 'Barcode', 'Kendaraan', 'Status Kendaraan', 'Status Transaksi', 'Waktu Masuk', 'Waktu Keluar']);
fputcsv($out, ['ID', 'No. Pol', 'Barcode', 'Kendaraan', 'Status Kendaraan', 'Status Transaksi', 'Waktu Masuk', 'Waktu Keluar', 'Op Masuk', 'Op Keluar', 'Pintu Masuk', 'Pintu Keluar', 'Bayar Keluar']);
$query->chunk(1000, function ($rows) use ($out) {
foreach ($rows as $r) {
fputcsv($out, [
@@ -124,6 +185,11 @@ protected function exportCsv($query): StreamedResponse
$r->status_transaksi,
$r->waktu_masuk,
$r->waktu_keluar,
$r->id_op_masuk,
$r->id_op_keluar,
$r->id_pintu_masuk,
$r->id_pintu_keluar,
$r->bayar_keluar,
]);
}
});