Added production data sap livewire page
This commit is contained in:
106
app/Livewire/ProductionSapData.php
Normal file
106
app/Livewire/ProductionSapData.php
Normal file
@@ -0,0 +1,106 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Livewire;
|
||||||
|
|
||||||
|
use App\Models\ProductionQuantity;
|
||||||
|
use App\Models\QualityValidation;
|
||||||
|
use Livewire\Component;
|
||||||
|
|
||||||
|
class ProductionSapData extends Component
|
||||||
|
{
|
||||||
|
public $plantId;
|
||||||
|
public $productionOrder;
|
||||||
|
|
||||||
|
|
||||||
|
public $items = [];
|
||||||
|
|
||||||
|
public bool $attempted = false;
|
||||||
|
|
||||||
|
public bool $refresh = false;
|
||||||
|
|
||||||
|
public $scanned_quantity;
|
||||||
|
|
||||||
|
protected $listeners = [
|
||||||
|
'loadItems',
|
||||||
|
'refreshed',
|
||||||
|
|
||||||
|
];
|
||||||
|
|
||||||
|
public function refreshed($plantId, $productionOrder)
|
||||||
|
{
|
||||||
|
$this->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');
|
||||||
|
}
|
||||||
|
}
|
||||||
40
resources/views/livewire/production-sap-data.blade.php
Normal file
40
resources/views/livewire/production-sap-data.blade.php
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
<div class="w-full px-2 py-2">
|
||||||
|
<table class="w-full divide-y divide-gray-200 border-1 rounded-lg overflow-hidden">
|
||||||
|
<thead class="bg-gray-100">
|
||||||
|
<tr>
|
||||||
|
<th class="px-2 py-2 text-center border text-xs font-bold text-gray-700 uppercase tracking-wider">No</th>
|
||||||
|
<th class="px-2 py-2 text-center border text-xs font-bold text-gray-700 uppercase tracking-wider">Item Code</th>
|
||||||
|
<th class="px-2 py-2 text-center border text-xs font-bold text-gray-700 uppercase tracking-wider">Serial Number</th>
|
||||||
|
<th class="px-2 py-2 text-center border text-xs font-bold text-gray-700 uppercase tracking-wider">Created At</th>
|
||||||
|
<th class="px-2 py-2 text-center border text-xs font-bold text-gray-700 uppercase tracking-wider">SAP Status</th>
|
||||||
|
<th class="px-2 py-2 text-center border text-xs font-bold text-gray-700 uppercase tracking-wider">SAP Description</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody class="bg-white divide-y divide-gray-200">
|
||||||
|
@forelse($items as $index => $item)
|
||||||
|
<tr>
|
||||||
|
<td class="px-3 py-2 border text-center text-xs whitespace-nowrap">{{ $index + 1 }}</td>
|
||||||
|
<td class="px-3 py-2 border text-center text-xs whitespace-nowrap">{{ $item['item_code'] }}</td>
|
||||||
|
<td class="px-3 py-2 border text-center text-xs whitespace-nowrap">{{ $item['serial_number'] }}</td>
|
||||||
|
<td class="px-3 py-2 border text-center text-xs whitespace-nowrap">{{ $item['created_at'] }}</td>
|
||||||
|
<td class="px-3 py-2 border text-center text-xs whitespace-nowrap">{{ $item['sap_status'] }}</td>
|
||||||
|
<td class="px-3 py-2 border text-center text-xs whitespace-nowrap">{{ $item['sap_description'] }}</td>
|
||||||
|
</tr>
|
||||||
|
@empty
|
||||||
|
@if ($attempted)
|
||||||
|
<tr>
|
||||||
|
<td colspan="6" class="px-3 py-4 border text-center text-sm text-gray-500">
|
||||||
|
No data available for the selected plant and production order!
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
@elseif ($refresh)
|
||||||
|
<tr>
|
||||||
|
<td colspan="6" class="px-3 py-4 border text-center text-sm text-gray-500">
|
||||||
|
Scan the valid production order and press enter!
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
@endif
|
||||||
|
@endforelse
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
Reference in New Issue
Block a user