After change datatype from citext to text
This commit is contained in:
@@ -14,23 +14,38 @@ class ItemOverview extends ChartWidget
|
||||
protected function getData(): array
|
||||
{
|
||||
$activeFilter = $this->filter;
|
||||
|
||||
// Get selected values from the plant and line filter form inputs
|
||||
$selectedPlant = request()->input('plant'); // Assuming form input name is 'plant'
|
||||
$selectedLine = request()->input('line'); // Assuming form input name is 'line'
|
||||
|
||||
$query = \DB::table('production_quantities')
|
||||
->selectRaw('EXTRACT(HOUR FROM created_at) AS hour, SUM(hourly_quantity) AS total_quantity')
|
||||
->whereBetween('created_at', [now()->startOfDay(), now()->endOfDay()])
|
||||
->groupByRaw('EXTRACT(HOUR FROM created_at)')
|
||||
->selectRaw('EXTRACT(HOUR FROM created_at) AS hour, COUNT(*) AS total_quantity')
|
||||
->whereBetween('created_at', [now()->startOfDay(), now()->endOfDay()]);
|
||||
|
||||
// Apply filters only if values are selected
|
||||
if (!empty($selectedPlant)) {
|
||||
$query->where('plant', $selectedPlant);
|
||||
}
|
||||
|
||||
if (!empty($selectedLine)) {
|
||||
$query->where('line', $selectedLine);
|
||||
}
|
||||
|
||||
$query = $query->groupByRaw('EXTRACT(HOUR FROM created_at)')
|
||||
->orderByRaw('EXTRACT(HOUR FROM created_at)')
|
||||
->pluck('total_quantity', 'hour')
|
||||
->toArray();
|
||||
// Initialize data for each hour interval (8 AM - 7 PM)
|
||||
$data = array_fill(8, 12, 0); // 8 AM to 7 PM (indexes 8 to 19)
|
||||
|
||||
// Populate actual values
|
||||
// foreach ($query as $record) {
|
||||
// $hour = (int) $record->hour;
|
||||
// if ($hour >= 8 && $hour <= 19) {
|
||||
// $data[$hour] = $record->total_quantity; // Assign only the hourly production
|
||||
// }
|
||||
// }
|
||||
$data = array_fill(8, 12, 0);
|
||||
|
||||
// Populate actual values
|
||||
// foreach ($query as $record) {
|
||||
// $hour = (int) $record->hour;
|
||||
// if ($hour >= 8 && $hour <= 19) {
|
||||
// $data[$hour] = $record->total_quantity; // Assign only the hourly production
|
||||
// }
|
||||
// }
|
||||
|
||||
// Convert data to chart format
|
||||
return [
|
||||
@@ -47,44 +62,6 @@ class ItemOverview extends ChartWidget
|
||||
'labels' => array_map(fn($h) => ($h <= 11 ? "$h AM" : ($h == 12 ? "12 PM" : ($h - 12) . " PM")), array_keys($data)),
|
||||
];
|
||||
|
||||
// // Initialize data for each hour interval (8 AM - 7 PM)
|
||||
// $data = [
|
||||
// '8 AM - 9 AM' => 0, '9 AM - 10 AM' => 0, '10 AM - 11 AM' => 0, '11 AM - 12 PM' => 0,
|
||||
// '12 PM - 1 PM' => 0, '1 PM - 2 PM' => 0, '2 PM - 3 PM' => 0, '3 PM - 4 PM' => 0,
|
||||
// '4 PM - 5 PM' => 0, '5 PM - 6 PM' => 0, '6 PM - 7 PM' => 0, '7 PM - 8 PM' => 0,
|
||||
// ];
|
||||
|
||||
|
||||
// // Populate actual values
|
||||
// foreach ($query as $record) {
|
||||
// $hour = (int) $record->hour;
|
||||
// if ($hour >= 8 && $hour <= 19) {
|
||||
// $index = ($hour - 8); // Match hour to array index
|
||||
// $labels = array_keys($data); // Get labels
|
||||
|
||||
// // Store only the production for that specific hour
|
||||
// $data[$labels[$index]] = $record->total_quantity;
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
// // Debugging: Check if data exists
|
||||
// if (empty($query) || array_sum($data) === 0) {
|
||||
// \Log::info('No production data found for today.');
|
||||
// }
|
||||
|
||||
// return [
|
||||
// 'datasets' => [
|
||||
// [
|
||||
// 'label' => 'Production Quantities',
|
||||
// 'data' => array_values($data),
|
||||
// 'borderColor' => 'rgba(75, 192, 192, 1)',
|
||||
// 'backgroundColor' => 'rgba(75, 192, 192, 0.2)',
|
||||
// 'fill' => true,
|
||||
// ],
|
||||
// ],
|
||||
// 'labels' => array_keys($data),
|
||||
// ];
|
||||
}
|
||||
|
||||
protected function getType(): string
|
||||
|
||||
Reference in New Issue
Block a user