Added pallet data tables

This commit is contained in:
dhanabalan
2025-07-01 13:16:32 +05:30
parent c2b193c5b8
commit e083c0e4a5
4 changed files with 249 additions and 0 deletions

View 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');
}
}