diff --git a/app/Filament/Widgets/ItemOverview.php b/app/Filament/Widgets/ItemOverview.php index 2980107..15df2f1 100644 --- a/app/Filament/Widgets/ItemOverview.php +++ b/app/Filament/Widgets/ItemOverview.php @@ -49,11 +49,17 @@ class ItemOverview extends ChartWidget //dd($selectedPlant, $selectedLine); + // if ($activeFilter === 'yesterday') { + // $startDate = now()->subDay()->setTime(8, 0, 0); // yesterday 8:00 AM + // $endDate = now()->setTime(8, 0, 0); // today 8:00 AM + // $groupBy = 'EXTRACT(HOUR FROM production_quantities.created_at)'; + // } if ($activeFilter === 'yesterday') { - $startDate = now()->subDay()->setTime(8, 0, 0); // yesterday 8:00 AM - $endDate = now()->setTime(8, 0, 0); // today 8:00 AM + $startDate = now()->subDay()->setTime(8, 0, 0); // Yesterday 8:00 AM + $endDate = now()->setTime(8, 0, 0); // Today 8:00 AM $groupBy = 'EXTRACT(HOUR FROM production_quantities.created_at)'; } + else if ($activeFilter === 'this_week') { // Monday 8:00 AM of the current week $startDate = now()->startOfWeek()->setTime(8, 0, 0); @@ -133,7 +139,7 @@ class ItemOverview extends ChartWidget $data[0] ?? 0, // Sunday (move to last) ]; } - else + else if($activeFilter === 'yesterday') { // Hourly data (same as before) @@ -141,7 +147,21 @@ class ItemOverview extends ChartWidget $data = array_replace($allHours, $query); // Shift hours for proper display (8 AM to 7 AM) - $shiftedKeys = array_merge(range(8, 23), range(0, 8)); + $shiftedKeys = array_merge(range(8, 23), range(0, 7)); + $orderedData = array_map(fn($hour) => $data[$hour], $shiftedKeys); + + // Labels: ["8 AM", "9 AM", ..., "7 AM"] + $labels = array_map(fn ($hour) => date("g A", strtotime("$hour:00")), $shiftedKeys); + } + else + { + + // Hourly data (same as before) + $allHours = array_fill(0, 24, 0); + $data = array_replace($allHours, $query); + + // Shift hours for proper display (8 AM to 7 AM) + $shiftedKeys = array_merge(range(8, 23), range(0, 7)); $orderedData = array_map(fn($hour) => $data[$hour], $shiftedKeys); // Labels: ["8 AM", "9 AM", ..., "7 AM"]