Added refresh chart while update plant, line
This commit is contained in:
@@ -10,60 +10,29 @@ class ItemOverview extends ChartWidget
|
||||
|
||||
protected int|string|array $columnSpan = 'full';
|
||||
|
||||
//protected $listeners = ['filtersUpdated' => '$refresh']; // Listen for filter updates
|
||||
protected $listeners = ['filtersUpdated' => '$refresh'];
|
||||
// public $plantId;
|
||||
// public $lineId;
|
||||
|
||||
// protected function getData(): array
|
||||
// {
|
||||
// $activeFilter = $this->filter;
|
||||
// // Get filter values from session
|
||||
// $selectedPlant = session('selected_plant');
|
||||
// $selectedLine = session('selected_line');
|
||||
|
||||
// $query = \DB::table('production_quantities')
|
||||
// ->join('plants', 'production_quantities.plant_id', '=', 'plants.id') // Join plants table
|
||||
// ->join('lines', 'production_quantities.line_id', '=', 'lines.id') // Join lines table
|
||||
// ->selectRaw('EXTRACT(HOUR FROM production_quantities.created_at) AS hour, count(*) AS total_quantity')
|
||||
// ->whereBetween('production_quantities.created_at', [now()->startOfDay(), now()->endOfDay()])
|
||||
// ->when($selectedPlant, function ($q) use ($selectedPlant) {
|
||||
// return $q->where('plants.id', $selectedPlant);
|
||||
// })
|
||||
// ->when($selectedLine, function ($q) use ($selectedLine) {
|
||||
// return $q->where('lines.id', $selectedLine);
|
||||
// })
|
||||
// ->groupByRaw('EXTRACT(HOUR FROM production_quantities.created_at)')
|
||||
// ->orderByRaw('EXTRACT(HOUR FROM production_quantities.created_at)')
|
||||
// ->pluck('total_quantity', 'hour')
|
||||
// ->toArray();
|
||||
|
||||
// $allHours = array_fill(0, 24, 0);
|
||||
// $data = array_replace($allHours, $query);
|
||||
|
||||
// $shiftedKeys = range(8, 23); // 8 AM to 11 PM
|
||||
// $shiftedKeys = array_merge($shiftedKeys, range(0, 8));
|
||||
|
||||
// $orderedData = array_map(fn($hour) => $data[$hour], $shiftedKeys);
|
||||
|
||||
// return [
|
||||
// 'datasets' => [
|
||||
// [
|
||||
// 'label' => 'Hourly Production',
|
||||
// 'data' => array_values($orderedData),
|
||||
// 'borderColor' => 'rgba(75, 192, 192, 1)',
|
||||
// 'backgroundColor' => 'rgba(75, 192, 192, 0.2)',
|
||||
// 'fill' => false,
|
||||
// 'tension' => 0.3,
|
||||
// ],
|
||||
// ],
|
||||
// // Correct label sequence from 8 AM to 7 AM
|
||||
// 'labels' => array_map(fn ($hour) => date("g A", strtotime("$hour:00")), $shiftedKeys),
|
||||
// ];
|
||||
|
||||
// }
|
||||
protected function getData(): array
|
||||
{
|
||||
$activeFilter = $this->filter;
|
||||
$selectedPlant = session('selected_plant');
|
||||
$selectedLine = session('selected_line');
|
||||
// $selectPlant = session('select_plant');
|
||||
// $selectLine = session('select_line');
|
||||
|
||||
// $selectedPlant = session('selected_plant');
|
||||
// $selectedLine = session('selected_line');
|
||||
|
||||
$selectedPlant = session('selected_plant') ?? session('select_plant');
|
||||
$selectedLine = session('selected_line') ?? session('select_line');
|
||||
|
||||
|
||||
if (!$selectedPlant || !$selectedLine) {
|
||||
return [
|
||||
'datasets' => [],
|
||||
'labels' => [],
|
||||
];
|
||||
}
|
||||
|
||||
if ($activeFilter === 'yesterday') {
|
||||
$startDate = now()->subDay()->startOfDay();
|
||||
@@ -90,7 +59,7 @@ class ItemOverview extends ChartWidget
|
||||
}
|
||||
|
||||
$query = \DB::table('production_quantities')
|
||||
->join('plants', 'production_quantities.plant_id', '=', 'plants.id')
|
||||
->join('plants', 'production_quantities.plant_id', '=', 'plants.id') //inner join
|
||||
->join('lines', 'production_quantities.line_id', '=', 'lines.id')
|
||||
->selectRaw("$groupBy AS time_unit, count(*) AS total_quantity")
|
||||
->whereBetween('production_quantities.created_at', [$startDate, $endDate])
|
||||
@@ -205,4 +174,6 @@ class ItemOverview extends ChartWidget
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user