diff --git a/app/Livewire/ProductionSapData.php b/app/Livewire/ProductionSapData.php new file mode 100644 index 0000000..ffc8eca --- /dev/null +++ b/app/Livewire/ProductionSapData.php @@ -0,0 +1,106 @@ +plantId = $plantId; + $this->productionOrder = $productionOrder; + $this->refresh = true; + $this->attempted = false; + + if (!$plantId || !$productionOrder) { + $this->items = []; + return; + } + + $this->items = ProductionQuantity::where('plant_id', $plantId) + ->where('production_order', $productionOrder) + ->get() + ->map(function ($item) { + return [ + 'item_code' => optional($item->item)->code ?? 'N/A', + 'serial_number' => $item->serial_number, + 'created_at' => $item->created_at->format('Y-m-d H:i:s'), + 'sap_status' => $item->sap_msg_status, + 'sap_description' => $item->sap_msg_description, + ]; + }) + ->toArray(); + + $this->updateRowCount(); + } + + public function loadItems($plantId, $productionOrder) + { + $this->plantId = $plantId; + $this->productionOrder = $productionOrder; + $this->attempted = true; + $this->refresh = false; + + + if (!$plantId || !$productionOrder) { + $this->items = []; + return; + } + + $this->items = ProductionQuantity::where('plant_id', $plantId) + ->where('production_order', $productionOrder) + ->get() + ->map(function ($item) { + return [ + 'item_code' => optional($item->item)->code ?? 'N/A', + 'serial_number' => $item->serial_number, + 'created_at' => $item->created_at->format('Y-m-d H:i:s'), + 'sap_status' => $item->sap_msg_status, + 'sap_description' => $item->sap_msg_description, + ]; + }) + ->toArray(); + + $this->updateRowCount(); + } + + // Method to update row count based on scanned_quantity + public function updateRowCount() + { + $this->attempted = true; + + // Ensure scanned_quantity is a valid number and doesn't exceed the available rows + if ($this->scanned_quantity > 0 && $this->scanned_quantity <= count($this->items)) { + $this->items = array_slice($this->items, 0, $this->scanned_quantity); + } else { + $this->scanned_quantity = count($this->items); // Reset to show all items if invalid quantity + } + + $this->dispatch('updateScannedQuantity', $this->scanned_quantity); + } + public function render() + { + return view('livewire.production-sap-data'); + } +} diff --git a/resources/views/livewire/production-sap-data.blade.php b/resources/views/livewire/production-sap-data.blade.php new file mode 100644 index 0000000..f9d211d --- /dev/null +++ b/resources/views/livewire/production-sap-data.blade.php @@ -0,0 +1,40 @@ +
+ + + + + + + + + + + + + @forelse($items as $index => $item) + + + + + + + + + @empty + @if ($attempted) + + + + @elseif ($refresh) + + + + @endif + @endforelse + +
NoItem CodeSerial NumberCreated AtSAP StatusSAP Description
{{ $index + 1 }}{{ $item['item_code'] }}{{ $item['serial_number'] }}{{ $item['created_at'] }}{{ $item['sap_status'] }}{{ $item['sap_description'] }}
+ No data available for the selected plant and production order! +
+ Scan the valid production order and press enter! +
+