updated chart logic for hourly production chart
This commit is contained in:
@@ -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,6 +139,20 @@ class ItemOverview extends ChartWidget
|
||||
$data[0] ?? 0, // Sunday (move to last)
|
||||
];
|
||||
}
|
||||
else if($activeFilter === 'yesterday')
|
||||
{
|
||||
|
||||
// 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"]
|
||||
$labels = array_map(fn ($hour) => date("g A", strtotime("$hour:00")), $shiftedKeys);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -141,7 +161,7 @@ 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"]
|
||||
|
||||
Reference in New Issue
Block a user