diff --git a/app/Http/Controllers/ModuleFilterDataController.php b/app/Http/Controllers/ModuleFilterDataController.php index f0415ad..9430176 100644 --- a/app/Http/Controllers/ModuleFilterDataController.php +++ b/app/Http/Controllers/ModuleFilterDataController.php @@ -227,10 +227,43 @@ class ModuleFilterDataController extends Controller ->whereBetween('created_at', [$startDate, $endDate]) ->count(); - return response()->json([ - 'status_code' => 'SUCCESS', - 'status_description' => $rowCount - ], 200); + // return response()->json([ + // 'status_code' => 'SUCCESS', + // 'status_description' => $rowCount + // ], 200); + $chartName = $request->header('chart-name'); + + if ($chartName == 'Production Hourly Count') { + $hourlyCounts = []; + + $hourStart = $startDate->copy(); + while ($hourStart < $endDate) { + $hourEnd = $hourStart->copy()->addHour(); + + $label = $hourStart->format('g:i A') . ' to ' . $hourEnd->format('g:i A'); + + $count = ProductionQuantity::where('plant_id', $plant->id) + ->where('line_id', $line->id) + ->whereBetween('created_at', [$hourStart, $hourEnd]) + ->count(); + + $hourlyCounts[$label] = $count; + + $hourStart = $hourEnd; + } + + return response()->json([ + 'status_code' => 'SUCCESS', + 'status_description' => $hourlyCounts + ], 200); + } + if ($chartName == 'Production Line Count') + { + return response()->json([ + 'status_code' => 'SUCCESS', + 'status_description' => $rowCount + ], 200); + } }