Import Fun Completed and Sticker Master

This commit is contained in:
dhanabalan
2025-03-28 16:52:40 +05:30
parent ef4504155a
commit e46f290fd1
47 changed files with 1317 additions and 335 deletions

View File

@@ -8,58 +8,73 @@ class ItemOverview extends ChartWidget
{
protected static ?string $heading = 'Chart';
protected int|string|array $columnSpan = 'full';
//protected $listeners = ['filtersUpdated' => '$refresh']; // Listen for filter updates
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'
// Get filter values from session
$selectedPlant = session('selected_plant');
$selectedLine = session('selected_line');
$query = \DB::table('production_quantities')
->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)')
->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();
$data = array_fill(8, 12, 0);
// // Ensure all 24 hours are covered, filling missing ones with zero
// $data = array_replace(array_fill(8, 24, 0), $query);
// 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
// }
// }
// return [
// 'datasets' => [
// [
// 'label' => 'Hourly Production',
// 'data' => array_values($data),
// 'borderColor' => 'rgba(75, 192, 192, 1)',
// 'backgroundColor' => 'rgba(75, 192, 192, 0.2)',
// 'fill' => false,
// 'tension' => 0.3,
// ],
// ],
// // 'labels' => array_map(fn ($hour) => ($hour == 0 ? '12 AM' : ($hour == 12 ? '12 PM' : ($hour < 12 ? "{$hour} AM" : ($hour - 12) . " PM"))), array_keys($data)),
// // Labels in 24-hour format
// 'labels' => array_map(fn ($hour) => date("g A", strtotime("$hour:00")), array_keys($data)), // Improved hour formatting
// ];
$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);
// Convert data to chart format
return [
'datasets' => [
[
'label' => 'Hourly Production',
'data' => array_values($data), // Values only
'data' => array_values($orderedData),
'borderColor' => 'rgba(75, 192, 192, 1)',
'backgroundColor' => 'rgba(75, 192, 192, 0.2)',
'fill' => false, // No area fill, just the line
'tension' => 0.3, // Smooth curve
'fill' => false,
'tension' => 0.3,
],
],
'labels' => array_map(fn($h) => ($h <= 11 ? "$h AM" : ($h == 12 ? "12 PM" : ($h - 12) . " PM")), array_keys($data)),
// Correct label sequence from 8 AM to 7 AM
'labels' => array_map(fn ($hour) => date("g A", strtotime("$hour:00")), $shiftedKeys),
];
}
@@ -69,13 +84,24 @@ class ItemOverview extends ChartWidget
return 'line';
}
protected function getOptions(): array
{
return [
'scales' => [
'y' => [
'beginAtZero' => true, //Start Y-axis from 0
'ticks' => [
'stepSize' => 0.5,
],
],
],
];
}
protected function getFilters(): ?array
{
return [
'today' => 'Today',
'week' => 'Last week',
'month' => 'Last month',
'year' => 'This year',
];
}