update api laporan
This commit is contained in:
@@ -17,10 +17,142 @@ private function getTrans() {
|
|||||||
return TransaksiParkir::query();
|
return TransaksiParkir::query();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function daily(Request $request)
|
||||||
|
{
|
||||||
|
$tanggal = $request->query('tanggal');
|
||||||
|
$shift = $request->query('shift');
|
||||||
|
$harian = $request->query('harian');
|
||||||
|
$report = $request->input('report');
|
||||||
|
|
||||||
|
Log::info($request->all());
|
||||||
|
// Tentukan field tanggal
|
||||||
|
$dateField = $this->resolveDateField($shift, $harian);
|
||||||
|
|
||||||
|
// Config jenis report
|
||||||
|
$reportConfig = [
|
||||||
|
'harian' => [
|
||||||
|
'select' => 'jm.id, jm.nama as vehicle, COUNT(*) as jml, SUM(bayar_keluar) as total_bayar',
|
||||||
|
'group' => 'jm.id, jm.nama',
|
||||||
|
'order' => 'jm.id, jm.nama',
|
||||||
|
'join' => [['jenis_mobil as jm', 'jm.id', 'transaksi_parkir.id_kendaraan']],
|
||||||
|
],
|
||||||
|
'vehicle' => [
|
||||||
|
'select' => 'jm.id, jm.nama as vehicle, COUNT(*) as jml, SUM(bayar_keluar) as total_bayar',
|
||||||
|
'group' => 'jm.id, jm.nama',
|
||||||
|
'order' => 'jm.id, jm.nama',
|
||||||
|
'join' => [['jenis_mobil as jm', 'jm.id', 'transaksi_parkir.id_kendaraan']],
|
||||||
|
],
|
||||||
|
'gate' => [
|
||||||
|
'select' => 'np.id, np.nama as gate, COUNT(*) as jml, SUM(bayar_keluar) as total_bayar',
|
||||||
|
'group' => 'np.id, np.nama',
|
||||||
|
'order' => 'np.id, np.nama',
|
||||||
|
'join' => [['nama_pos as np', 'np.id', 'transaksi_parkir.id_pintu_keluar']],
|
||||||
|
],
|
||||||
|
'operator' => [
|
||||||
|
'select' => 'p.nomer, p.nama as operator, COUNT(*) as jml, SUM(bayar_keluar) as total_bayar',
|
||||||
|
'group' => 'p.nomer, p.nama',
|
||||||
|
'order' => 'p.nomer, p.nama',
|
||||||
|
'join' => [['pegawai as p', 'p.nomer', 'transaksi_parkir.id_op_keluar']],
|
||||||
|
],
|
||||||
|
'payment' => [
|
||||||
|
'select' => 'rep_bank as payment, COUNT(*) as jml, SUM(bayar_keluar) as total_bayar',
|
||||||
|
'group' => 'rep_bank',
|
||||||
|
'order' => 'rep_bank',
|
||||||
|
'join' => [],
|
||||||
|
],
|
||||||
|
];
|
||||||
|
Log::info(json_encode($reportConfig[$report], JSON_PRETTY_PRINT));
|
||||||
|
|
||||||
|
if (!isset($reportConfig[$report])) {
|
||||||
|
return response()->json([
|
||||||
|
'status' => 'failed',
|
||||||
|
'desc' => 'Jenis report tidak valid'
|
||||||
|
], 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
$config = $reportConfig[$report];
|
||||||
|
// $koneKemana = $this->connecTo($parameter);
|
||||||
|
|
||||||
|
// Function helper bikin query dasar
|
||||||
|
$buildQuery = function ($paymentType) use ($config, $tanggal, $dateField) {
|
||||||
|
$query = $this->getTrans()
|
||||||
|
->selectRaw($config['select']);
|
||||||
|
|
||||||
|
// Apply join
|
||||||
|
foreach ($config['join'] as $join) {
|
||||||
|
$query->leftJoin($join[0], $join[1], '=', $join[2]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Filter tanggal
|
||||||
|
if ($tanggal) {
|
||||||
|
$query->whereDate($dateField, '=', $tanggal);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Filter cara bayar
|
||||||
|
$query->where(function ($q) use ($paymentType) {
|
||||||
|
if ($paymentType === 'cash') {
|
||||||
|
$q->whereRaw('cara_bayar <> 3')
|
||||||
|
->orWhereRaw('cara_bayar is null');
|
||||||
|
} else { // cashless
|
||||||
|
$q->where('cara_bayar', 3);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return $query
|
||||||
|
->groupByRaw($config['group'])
|
||||||
|
->orderByRaw($config['order']);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Eksekusi cash & cashless
|
||||||
|
$resultCash = $buildQuery('cash')->get();
|
||||||
|
$resultCashless = $buildQuery('cashless')->get();
|
||||||
|
|
||||||
|
// Hitung total
|
||||||
|
$jmlTotal = $resultCash->sum('jml') + $resultCashless->sum('jml');
|
||||||
|
$incomeTotal = $resultCash->sum('total_bayar') + $resultCashless->sum('total_bayar');
|
||||||
|
|
||||||
|
return response()->json([
|
||||||
|
'status' => 'success',
|
||||||
|
'result' => [
|
||||||
|
'cash' => $resultCash,
|
||||||
|
'cashless' => $resultCashless,
|
||||||
|
],
|
||||||
|
'total' => [
|
||||||
|
'jumlah' => $jmlTotal,
|
||||||
|
'income' => $incomeTotal,
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tentukan field tanggal yang dipakai
|
||||||
|
*/
|
||||||
|
private function resolveDateField($shift, $harian): string
|
||||||
|
{
|
||||||
|
$isShift = ($shift !== null && $shift !== 0 && $shift !== '0' && $shift !== false);
|
||||||
|
$isHarian = ($harian !== null && $harian !== 0 && $harian !== '0' && $harian !== false);
|
||||||
|
|
||||||
|
if ($isHarian) {
|
||||||
|
return 'waktu_keluar';
|
||||||
|
} elseif ($isShift) {
|
||||||
|
return 'pklogin';
|
||||||
|
}
|
||||||
|
return 'waktu_keluar';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public function harian(Request $request)
|
public function harian(Request $request)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
// $method = $request->input('tanggal');
|
||||||
|
|
||||||
|
if (!$request->input('tanggal')) {
|
||||||
|
return response()->json([
|
||||||
|
'status' => 'failed',
|
||||||
|
'desc' => 'harap masuk kan metode pencarian'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
$tanggal = $request->input('tanggal');
|
$tanggal = $request->input('tanggal');
|
||||||
$shift = $request->input('shift');
|
$shift = $request->input('shift');
|
||||||
$harian = $request->input('harian');
|
$harian = $request->input('harian');
|
||||||
@@ -142,6 +274,13 @@ public function harian(Request $request)
|
|||||||
|
|
||||||
public function payment(Request $request)
|
public function payment(Request $request)
|
||||||
{
|
{
|
||||||
|
if (!$request->input('tanggal')) {
|
||||||
|
return response()->json([
|
||||||
|
'status' => 'failed',
|
||||||
|
'desc' => 'harap masuk kan metode pencarian'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
$tanggal = $request->input('tanggal');
|
$tanggal = $request->input('tanggal');
|
||||||
$shift = $request->input('shift');
|
$shift = $request->input('shift');
|
||||||
$harian = $request->input('harian');
|
$harian = $request->input('harian');
|
||||||
@@ -229,6 +368,13 @@ public function payment(Request $request)
|
|||||||
|
|
||||||
public function operator(Request $request)
|
public function operator(Request $request)
|
||||||
{
|
{
|
||||||
|
if (!$request->input('tanggal')) {
|
||||||
|
return response()->json([
|
||||||
|
'status' => 'failed',
|
||||||
|
'desc' => 'harap masuk kan metode pencarian'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
$tanggal = $request->input('tanggal');
|
$tanggal = $request->input('tanggal');
|
||||||
$shift = $request->input('shift');
|
$shift = $request->input('shift');
|
||||||
$harian = $request->input('harian');
|
$harian = $request->input('harian');
|
||||||
@@ -319,6 +465,14 @@ public function operator(Request $request)
|
|||||||
|
|
||||||
public function gate(Request $request)
|
public function gate(Request $request)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
if (!$request->input('tanggal')) {
|
||||||
|
return response()->json([
|
||||||
|
'status' => 'failed',
|
||||||
|
'desc' => 'harap masuk kan metode pencarian'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
$tanggal = $request->input('tanggal');
|
$tanggal = $request->input('tanggal');
|
||||||
$shift = $request->input('shift');
|
$shift = $request->input('shift');
|
||||||
$harian = $request->input('harian');
|
$harian = $request->input('harian');
|
||||||
|
|||||||
16
resources/views/backend.blade.php
Normal file
16
resources/views/backend.blade.php
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="id">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Backend itcn.co.id</title>
|
||||||
|
<script src="https://cdn.tailwindcss.com"></script>
|
||||||
|
</head>
|
||||||
|
<body class="bg-white flex items-center justify-center min-h-screen">
|
||||||
|
|
||||||
|
<h1 class="text-5xl font-extrabold text-gray-800 animate-pulse">
|
||||||
|
Backend <span class="text-blue-600">itcn.co.id</span>
|
||||||
|
</h1>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -35,4 +35,5 @@
|
|||||||
Route::post('payment', [LaporanController::class, 'payment']);
|
Route::post('payment', [LaporanController::class, 'payment']);
|
||||||
Route::post('operator', [LaporanController::class, 'operator']);
|
Route::post('operator', [LaporanController::class, 'operator']);
|
||||||
Route::post('gate', [LaporanController::class, 'gate']);
|
Route::post('gate', [LaporanController::class, 'gate']);
|
||||||
|
Route::post('daily', [LaporanController::class, 'daily']);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
Route::get('/', function () {
|
Route::get('/', function () {
|
||||||
return view('welcome');
|
return view('backend');
|
||||||
});
|
});
|
||||||
|
|
||||||
Route::get('phpinformation', function () {
|
Route::get('phpinformation', function () {
|
||||||
|
|||||||
Reference in New Issue
Block a user