Added pallet data tables
This commit is contained in:
120
app/Livewire/PalletDataTable.php
Normal file
120
app/Livewire/PalletDataTable.php
Normal file
@@ -0,0 +1,120 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Livewire;
|
||||||
|
|
||||||
|
use App\Models\PalletValidation;
|
||||||
|
use Filament\Facades\Filament;
|
||||||
|
use Filament\Notifications\Notification;
|
||||||
|
use Livewire\Component;
|
||||||
|
|
||||||
|
|
||||||
|
class PalletDataTable extends Component
|
||||||
|
{
|
||||||
|
public $plantId;
|
||||||
|
|
||||||
|
public $palletNumber;
|
||||||
|
|
||||||
|
public $snoCount = 0;
|
||||||
|
|
||||||
|
public $records = [];
|
||||||
|
|
||||||
|
protected $listeners = [
|
||||||
|
//'removeSno' => 'requestRemoveSerialNumber',
|
||||||
|
'loadData' => 'loadPalletData',
|
||||||
|
];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public function loadPalletData($palletNumber, $plantId)
|
||||||
|
{
|
||||||
|
$this->plantId = $plantId;
|
||||||
|
$this->palletNumber = $palletNumber;
|
||||||
|
$this->records = [];
|
||||||
|
|
||||||
|
$this->records = PalletValidation::query()
|
||||||
|
->where('plant_id', $this->plantId)
|
||||||
|
->where('pallet_number', $this->palletNumber)
|
||||||
|
->orderBy('scanned_at')
|
||||||
|
->get()
|
||||||
|
->map(function ($record) {
|
||||||
|
return [
|
||||||
|
'created_at' => $record->created_at,
|
||||||
|
'created_by' => $record->created_by ?? '',
|
||||||
|
'pallet_number' => $record->pallet_number,
|
||||||
|
'serial_number' => $record->serial_number,
|
||||||
|
'scanned_at' => $record->scanned_at,
|
||||||
|
'scanned_by' => $record->scanned_by ?? '',
|
||||||
|
];
|
||||||
|
})
|
||||||
|
->toArray();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// public function requestRemoveSerialNumber($serialNumber, $palletNumber,$plantId)
|
||||||
|
// {
|
||||||
|
|
||||||
|
// $user = Filament::auth()->user();
|
||||||
|
|
||||||
|
// $operatorName = $user->name;
|
||||||
|
|
||||||
|
// $found = collect($this->records)->contains(function ($record) use ($serialNumber) {
|
||||||
|
// return $record['serial_number'] == $serialNumber;
|
||||||
|
// });
|
||||||
|
|
||||||
|
// if (!$found) {
|
||||||
|
// Notification::make()
|
||||||
|
// ->title('Serial number not found in the pallet data table. Cannot delete.')
|
||||||
|
// ->danger()
|
||||||
|
// ->send();
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// // Proceed to delete from the database
|
||||||
|
// $deleted = PalletValidation::where('plant_id', $plantId)
|
||||||
|
// ->where('pallet_number', $palletNumber)
|
||||||
|
// ->where('serial_number', $serialNumber)
|
||||||
|
// ->forceDelete();
|
||||||
|
|
||||||
|
// if ($deleted)
|
||||||
|
// {
|
||||||
|
// Notification::make()
|
||||||
|
// ->title('Serial number deleted successfully.')
|
||||||
|
// ->success()
|
||||||
|
// ->send();
|
||||||
|
|
||||||
|
// $this->form->fill([
|
||||||
|
// 'plant_id' => $this->plantId,
|
||||||
|
// 'pallet_number' => $palletNumber,
|
||||||
|
// 'removeSno_number' => null,
|
||||||
|
// 'pending_pallet_list' => $this->pendingPallet,
|
||||||
|
// 'Sno_quantity' => $this->snoCount,
|
||||||
|
// 'created_by' => $operatorName,
|
||||||
|
// 'scanned_by' => $operatorName,
|
||||||
|
// ]);
|
||||||
|
|
||||||
|
// $this->snoCount = PalletValidation::where('plant_id', $plantId)
|
||||||
|
// ->where('pallet_number', $palletNumber)
|
||||||
|
// ->count();
|
||||||
|
|
||||||
|
// $this->dispatch('updateSnoQuantity', $this->snoCount);
|
||||||
|
|
||||||
|
// //reload the data table
|
||||||
|
// $this->loadPalletData($this->palletNumber, $this->plantId);
|
||||||
|
// }
|
||||||
|
// else
|
||||||
|
// {
|
||||||
|
// Notification::make()
|
||||||
|
// ->title('Failed to delete serial number.')
|
||||||
|
// ->danger()
|
||||||
|
// ->send();
|
||||||
|
// }
|
||||||
|
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
public function render()
|
||||||
|
{
|
||||||
|
return view('livewire.pallet-data-table');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
|
||||||
|
|
||||||
|
<x-filament::page>
|
||||||
|
<form wire:submit.prevent="create" class="space-y-6 mt-4"> <!-- Added mt-4 (16px) -->
|
||||||
|
<div class="filament-page-header space-y-2 mb-6">
|
||||||
|
{{-- Breadcrumbs --}}
|
||||||
|
<div class="filament-breadcrumbs flex items-center gap-2 text-sm">
|
||||||
|
<a href="{{ route('filament.admin.resources.pallet-validations.index') }}"
|
||||||
|
class="text-primary-500 hover:underline">
|
||||||
|
Pallet Validations
|
||||||
|
</a>
|
||||||
|
<span class="text-gray-500"> > </span>
|
||||||
|
<span class="text-gray-600">Create</span>
|
||||||
|
</div>
|
||||||
|
<h1 class="text-3xl font-bold tracking-tight">Scan Pallet</h1>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="filament-form space-y-6">
|
||||||
|
{{ $this->form }}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="bg-white shadow rounded-xl p-4">
|
||||||
|
<livewire:pallet-data-table />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="filament-actions mt-6">
|
||||||
|
<x-filament::actions>
|
||||||
|
@foreach ($this->getFormActions() as $action)
|
||||||
|
{{ $action }}
|
||||||
|
@endforeach
|
||||||
|
</x-filament::actions>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
@push('scripts')
|
||||||
|
<script>
|
||||||
|
window.addEventListener('open-pdf', event => {
|
||||||
|
const url = event.detail.url;
|
||||||
|
const win = window.open(url, '_blank');
|
||||||
|
if (!win || win.closed || typeof win.closed == 'undefined') {
|
||||||
|
alert('Popup blocked. Please allow popups for this site.');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
@endpush
|
||||||
|
</x-filament::page>
|
||||||
43
resources/views/forms/components/save-pallet-button.php
Normal file
43
resources/views/forms/components/save-pallet-button.php
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
|
||||||
|
<div class="flex flex-col items-start space-y-2">
|
||||||
|
<div class="flex items-center">
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
id="is_completed"
|
||||||
|
wire:model.defer="data.is_completed"
|
||||||
|
class="focus:outline-none focus:ring-0 focus:border-transparent border-gray-300"
|
||||||
|
>
|
||||||
|
<label for="is_completed" style="margin-left:2mm;" class="whitespace-nowrap mb-0">
|
||||||
|
Is Completed!
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
wire:click="markAsComplete"
|
||||||
|
class="px-2 py-1 border border-primary-500 text-primary-600 rounded hover:bg-primary-50 hover:border-primary-700 transition text-sm"
|
||||||
|
>
|
||||||
|
Save Pallet
|
||||||
|
</button>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<!-- <div class="flex flex-col items-start space-y-2">
|
||||||
|
<div class="flex items-center space-x-8">
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
id="is_completed"
|
||||||
|
wire:model.defer="data.is_completed"
|
||||||
|
class="focus:outline-none focus:ring-0 focus:border-transparent border-gray-300"
|
||||||
|
>
|
||||||
|
<label for="is_completed" class="whitespace-nowrap mb-0">
|
||||||
|
Is Completed!
|
||||||
|
</label>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
wire:click="markAsComplete"
|
||||||
|
class="py-1 px-6 border border-primary-500 text-primary-600 rounded hover:bg-primary-50 hover:border-primary-700 transition text-sm whitespace-nowrap"
|
||||||
|
>
|
||||||
|
Save Pallet
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div> -->
|
||||||
40
resources/views/livewire/pallet-data-table.blade.php
Normal file
40
resources/views/livewire/pallet-data-table.blade.php
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
<div class="p-4">
|
||||||
|
<h2 class="text-lg font-bold mb-4 text-gray-700 uppercase tracking-wider">
|
||||||
|
PALLET DATA TABLE:
|
||||||
|
</h2>
|
||||||
|
<div class="overflow-x-auto rounded-lg shadow">
|
||||||
|
<table class="w-full divide-y divide-gray-200 text-sm text-center">
|
||||||
|
<thead class="bg-gray-100 text-s font-semibold uppercase text-gray-700">
|
||||||
|
<tr>
|
||||||
|
<th class="border px-4 py-2">No</th>
|
||||||
|
<th class="border px-4 py-2">Created Datetime</th>
|
||||||
|
<th class="border px-4 py-2">Created By</th>
|
||||||
|
<th class="border px-4 py-2">Pallet Number</th>
|
||||||
|
<th class="border px-4 py-2">Serial Number</th>
|
||||||
|
<th class="border px-4 py-2">Scanned Datetime</th>
|
||||||
|
<th class="border px-4 py-2">Scanned By</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody class="divide-y divide-gray-100">
|
||||||
|
@forelse ($records as $index => $record)
|
||||||
|
<tr class="hover:bg-gray-50">
|
||||||
|
<td class="border px-4 py-2">{{ $index + 1 }}</td>
|
||||||
|
<td class="border px-4 py-2 whitespace-nowrap">{{ $record['created_at'] ?? '-' }}</td>
|
||||||
|
<td class="border px-4 py-2">{{ $record['created_by'] ?? '-' }}</td>
|
||||||
|
<td class="border px-4 py-2 whitespace-nowrap">{{ $record['pallet_number'] ?? '-' }}</td>
|
||||||
|
<td class="border px-4 py-2">{{ $record['serial_number'] ?? '-' }}</td>
|
||||||
|
<td class="border px-4 py-2 whitespace-nowrap">{{ $record['scanned_at'] ?? '-' }}</td>
|
||||||
|
<td class="border px-4 py-2">{{ $record['scanned_by'] ?? '-' }}</td>
|
||||||
|
</tr>
|
||||||
|
@empty
|
||||||
|
<tr>
|
||||||
|
<td colspan="7" class="px-4 py-4 text-center text-gray-500">
|
||||||
|
No pallet records found.
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
@endforelse
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
Reference in New Issue
Block a user