From b5a5a68620eef3c334d4966329101a56c5ef2d79 Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Sun, 27 Apr 2025 23:43:20 +0530 Subject: [PATCH] Designed report table for production quantity --- app/Livewire/SelectPlant.php | 82 +++++++++ .../views/livewire/select-plant.blade.php | 170 ++++++++++++++++++ 2 files changed, 252 insertions(+) create mode 100644 app/Livewire/SelectPlant.php create mode 100644 resources/views/livewire/select-plant.blade.php diff --git a/app/Livewire/SelectPlant.php b/app/Livewire/SelectPlant.php new file mode 100644 index 000000000..e1a807522 --- /dev/null +++ b/app/Livewire/SelectPlant.php @@ -0,0 +1,82 @@ + 'updatePlantLine', + 'productionUpdated' => '$refresh' + ]; + + public $plantId; + public $lineId; + + public $hourlyData = []; + + public function updatePlantLine($plantId, $lineId) + { + session(['plantId' => $plantId, 'lineId' => $lineId]); + $this->plantId = $plantId; + $this->lineId = $lineId; + $this->loadData(); + } + + // Method to load hourly production data + public function loadData() + { + // Define the time range from today 8:00 AM to the next day 8:00 AM + $today = now()->startOfDay()->addHours(8); // Today 8:00 AM + $nextDay = $today->copy()->addDay(); // Next day 8:00 AM + + // Initialize the array to hold the hourly data + $productionCounts = []; + + // Loop through each hour from today 8:00 AM to the next day 8:00 AM + for ($i = 0; $i < 24; $i++) { + // Define the start and end time for the current hour + $startOfHour = $today->copy()->addHours($i); // Start of the hour + $endOfHour = $startOfHour->copy()->addHour()->subSeconds(1); // End of the hour + + // Query the production counts for the current hour (between start and end time) + $count = ProductionQuantity::query() + ->where('plant_id', $this->plantId) + ->where('line_id', $this->lineId) + ->whereBetween('created_at', [$startOfHour, $endOfHour]) + ->count(); // Count the number of records in the current hour + + // Store the count for the current hour in the production counts array + $productionCounts[$i] = $count; + + } + + // Set the hourly data to be used in the component's view + $this->hourlyData = $productionCounts; + + } + + // public function render() + // { + // return view('livewire.select-plant', [ + // 'hourlyData' => $this->hourlyData, + // ]); + // } + + public function mount() + { + $this->plantId = session('plantId'); + $this->lineId = session('lineId'); + + if ($this->plantId && $this->lineId) { + $this->loadData(); + } + } + +} diff --git a/resources/views/livewire/select-plant.blade.php b/resources/views/livewire/select-plant.blade.php new file mode 100644 index 000000000..8d5ab9520 --- /dev/null +++ b/resources/views/livewire/select-plant.blade.php @@ -0,0 +1,170 @@ + + +
+ + +
+ + + + + + + + + + @php + // Static time range for the first 12 hours (08:00 AM to 07:00 PM) + $timeRanges = [ + '08:00 AM - 09:00 AM', + '09:00 AM - 10:00 AM', + '10:00 AM - 11:00 AM', + '11:00 AM - 12:00 PM', + '12:00 PM - 13:00 PM', + '13:00 PM - 14:00 PM', + '14:00 PM - 15:00 PM', + '15:00 PM - 16:00 PM', + '16:00 PM - 17:00 PM', + '17:00 PM - 18:00 PM', + '18:00 PM - 19:00 PM', + '19:00 PM - 20:00 PM', + ]; + @endphp + + @foreach ($timeRanges as $index => $timeRange) + + + + + + @endforeach + +
NoTime RangeProduction Quantity
{{ $index + 1 }}{{ $timeRange }} + {{ $hourlyData[$index] ?? 0 }} +
+
+ +
+ + + + + + + + + + @php + // Static time range for the first 12 hours (08:00 AM to 07:00 PM) + $timeRanges = [ + '20:00 PM - 21:00 PM', + '21:00 PM - 22:00 PM', + '22:00 PM - 23:00 PM', + '23:00 PM - 12:00 AM', + '12:00 AM - 01:00 AM', + '01:00 AM - 02:00 AM', + '02:00 AM - 03:00 AM', + '03:00 AM - 04:00 AM', + '04:00 AM - 05:00 AM', + '05:00 AM - 06:00 AM', + '06:00 AM - 07:00 AM', + '07:00 AM - 08:00 AM', + ]; + @endphp + + @foreach ($timeRanges as $index => $timeRange) + + + + + + @endforeach + +
NoTime RangeProduction Quantity
{{ $index + 13 }}{{ $timeRange }} + {{ $hourlyData[$index + 12] ?? 0 }} +
+
+ + + {{--
+ + + + + + + + + + + + + + + + + + + + + + +
NoTime RangeProduction Quantity
1308:00 PM - 09:00 PM{{ $productionQuantities[12] }}
1409:00 PM - 10:00 PM{{ $productionQuantities[13] }}
1510:00 PM - 11:00 PM{{ $productionQuantities[14] }}
1611:00 PM - 12:00 AM{{ $productionQuantities[15] }}
1712:00 AM - 01:00 AM{{ $productionQuantities[16] }}
1801:00 AM - 02:00 AM{{ $productionQuantities[17] }}
1902:00 AM - 03:00 AM{{ $productionQuantities[18] }}
2003:00 AM - 04:00 AM{{ $productionQuantities[19] }}
2104:00 AM - 05:00 AM{{ $productionQuantities[20] }}
2205:00 AM - 06:00 AM{{ $productionQuantities[21] }}
2306:00 AM - 07:00 AM{{ $productionQuantities[22] }}
2407:00 AM - 08:00 AM{{ $productionQuantities[23] }}
+
--}} +
+ + +{{-- //..perfect logic --}} + +{{--
+ +
+ + + + + + + + + + @foreach ($hourlyData as $index => $data) + @if ($index < 12) + + + + + + @endif + @endforeach + +
NoTime RangeProduction Quantity
{{ $index + 1 }}{{ $data['time'] }}{{ $data['quantity'] ?: '0' }}
+
+ + +
+ + + + + + + + + + @foreach ($hourlyData as $index => $data) + @if ($index >= 12) + + + + + + @endif + @endforeach + +
NoTime RangeProduction Quantity
{{ $index + 1 }}{{ $data['time'] }}{{ $data['quantity'] ?: '0' }}
+
+
--}} + + +