Penambahan Menu Laporan per pintu pos
This commit is contained in:
@@ -17,7 +17,120 @@ public function byGate ()
|
||||
|
||||
public function gateData(Request $request)
|
||||
{
|
||||
Log::info($request->all());
|
||||
|
||||
$awal = $request->tanggal_mulai;
|
||||
$akhir = $request->tanggal_selesai;
|
||||
$isShift = $request->shift === 'on';
|
||||
$dateBy = $isShift ? 'pklogin' : 'waktu_keluar';
|
||||
$paymentMethod = $request->payment_method === 'null' ? null : $request->payment_method;
|
||||
|
||||
// 🔹 Base select
|
||||
$select = [
|
||||
'np.nama as gate',
|
||||
'tp.id_pintu_keluar',
|
||||
'p.nama as petugas',
|
||||
'tp.id_op_keluar',
|
||||
'jm.nama as kendaraan',
|
||||
'tp.status_transaksi',
|
||||
DB::raw('count(*) as jumlah_transaksi'),
|
||||
DB::raw('sum(tp.bayar_keluar) as income_transaksi'),
|
||||
];
|
||||
|
||||
// 🔹 Tambah shift kalau aktif
|
||||
if ($isShift) {
|
||||
$select[] = 'tp.id_shift_keluar';
|
||||
}
|
||||
|
||||
// 🔹 Base group
|
||||
$groupBy = [
|
||||
'tp.id_pintu_keluar',
|
||||
'np.nama',
|
||||
'p.nama',
|
||||
'tp.id_op_keluar',
|
||||
'jm.nama',
|
||||
'tp.status_transaksi',
|
||||
];
|
||||
|
||||
if ($isShift) {
|
||||
$groupBy[] = 'tp.id_shift_keluar';
|
||||
}
|
||||
|
||||
$query = DB::table('transaksi_parkir as tp')
|
||||
->leftJoin('pegawai as p','p.nomer','=','tp.id_op_keluar')
|
||||
->leftJoin('nama_pos as np','np.id','=','tp.id_pintu_keluar')
|
||||
->leftJoin('jenis_mobil as jm','jm.id','=','tp.id_kendaraan')
|
||||
->select($select)
|
||||
|
||||
// 🔹 Filter tanggal (dynamic field)
|
||||
->where('tp.status', 0)
|
||||
|
||||
->whereBetween($dateBy, [
|
||||
$awal . ' 00:00:00',
|
||||
$akhir . ' 23:59:59'
|
||||
])
|
||||
|
||||
// 🔹 STATUS
|
||||
->when($request->status_transaksi, fn($q, $v) =>
|
||||
$q->where('tp.status_transaksi', $v)
|
||||
)
|
||||
|
||||
// 🔹 PINTU
|
||||
->when($request->id_pintu_keluar, fn($q, $v) =>
|
||||
$q->whereIn('tp.id_pintu_keluar', (array) $v)
|
||||
)
|
||||
|
||||
// 🔹 CARA BAYAR
|
||||
->when($request->cara_bayar, function ($q) use ($request) {
|
||||
|
||||
return match ($request->cara_bayar) {
|
||||
'cash' => $q->where('tp.cara_bayar', '!=', 3),
|
||||
'cashless' => $q->where('tp.cara_bayar', 3),
|
||||
default => $q
|
||||
};
|
||||
|
||||
})
|
||||
|
||||
->when($paymentMethod, function ($q) use ($paymentMethod) {
|
||||
return $q->where('tp.rep_bank', $paymentMethod);
|
||||
|
||||
// return match ($request->payment_method) {
|
||||
// 2 => $q->where('tp.rep_bank', 2),
|
||||
// 3 => $q->where('tp.rep_bank', 3),
|
||||
// 4 => $q->where('tp.rep_bank', 4),
|
||||
// 5 => $q->where('tp.rep_bank', 5),
|
||||
// 9 => $q->where('tp.rep_bank', 9),
|
||||
// default => $q
|
||||
// };
|
||||
|
||||
})
|
||||
|
||||
|
||||
|
||||
// // 🔹 PETUGAS
|
||||
// ->when($request->id_op_keluar, fn($q, $v) =>
|
||||
// $q->whereIn('tp.id_op_keluar', (array) $v)
|
||||
// )
|
||||
|
||||
// // 🔹 KENDARAAN
|
||||
// ->when($request->id_kendaraan, fn($q, $v) =>
|
||||
// $q->whereIn('tp.id_kendaraan', (array) $v)
|
||||
// )
|
||||
|
||||
->groupBy($groupBy)
|
||||
|
||||
->orderBy('tp.id_pintu_keluar')
|
||||
->when($isShift, fn($q) =>
|
||||
$q->orderBy('tp.id_shift_keluar')
|
||||
)
|
||||
->orderBy('tp.id_op_keluar')
|
||||
->orderBy('jm.nama')
|
||||
->orderBy('tp.status_transaksi');
|
||||
|
||||
|
||||
return response()->json([
|
||||
'byGateData' => $query->get()
|
||||
]);
|
||||
}
|
||||
|
||||
public function allReport ()
|
||||
|
||||
Reference in New Issue
Block a user