Added create pallet from locator page and livewire pages and table
This commit is contained in:
933
app/Filament/Pages/PalletFromLocator.php
Normal file
933
app/Filament/Pages/PalletFromLocator.php
Normal file
@@ -0,0 +1,933 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Pages;
|
||||
|
||||
use App\Models\Locator;
|
||||
use App\Models\PalletValidation;
|
||||
use App\Models\Plant;
|
||||
use Filament\Facades\Filament;
|
||||
use Filament\Forms\Components\Hidden;
|
||||
use Filament\Forms\Get;
|
||||
use Filament\Pages\Page;
|
||||
use Filament\Forms\Contracts\HasForms;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Forms\Components\Section;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Concerns\InteractsWithForms;
|
||||
use Filament\Notifications\Notification;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class PalletFromLocator extends Page implements HasForms
|
||||
{
|
||||
protected static ?string $navigationIcon = 'heroicon-o-document-text';
|
||||
|
||||
protected static string $view = 'filament.pages.pallet-from-locator';
|
||||
|
||||
protected static ?string $navigationGroup = 'Export Dispatch';
|
||||
|
||||
public $plantId;
|
||||
|
||||
public $locatorNo;
|
||||
|
||||
protected $latestPalletNumber = null;
|
||||
|
||||
public array $filters = [];
|
||||
|
||||
public $Checking = [];
|
||||
|
||||
public $records = [];
|
||||
|
||||
// public $locatorSno = [];
|
||||
|
||||
public function mount()
|
||||
{
|
||||
$this->Checking = [];
|
||||
// session()->forget('latestPalletSerials');
|
||||
session()->forget('latestPalletNumber');
|
||||
session()->forget('latestPalletDateTime');
|
||||
session()->forget('latestPalletCreatedBy');
|
||||
}
|
||||
|
||||
// use InteractsWithForms;
|
||||
|
||||
// public $form;
|
||||
|
||||
public function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->statePath('filters')
|
||||
->schema([
|
||||
Section::make('')
|
||||
->schema([
|
||||
Select::make('plant_id')
|
||||
->options(Plant::pluck('name', 'id'))
|
||||
->label('Plant')
|
||||
->reactive()
|
||||
->required()
|
||||
->columnSpan(1)
|
||||
->disabled(fn (Get $get) => $get('plant_id'))
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||
$plantId = $get('plant_id');
|
||||
if ($plantId)
|
||||
{
|
||||
$set('plant', $plantId);
|
||||
$set('scan_locator_number', null);
|
||||
$set('scan_serial_number', null);
|
||||
$set('scan_remove_sno', null);
|
||||
$set('sno_quantity', 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
$set('plant', null);
|
||||
$set('scan_locator_number', null);
|
||||
$set('scan_serial_number', null);
|
||||
$set('scan_remove_sno', null);
|
||||
$set('sno_quantity', 0);
|
||||
}
|
||||
}),
|
||||
Hidden::make('plant')
|
||||
->reactive(),
|
||||
TextInput::make('scan_locator_number')
|
||||
->label('Scan Locator Number')
|
||||
->reactive()
|
||||
->columnSpan(1)
|
||||
->readOnly(fn (callable $get) => !$get('plant') || $get('scan_serial_number') || $get('scan_remove_sno'))
|
||||
->extraAttributes([
|
||||
'wire:keydown.enter' => 'processLocatorNo($event.target.value)',
|
||||
]),
|
||||
TextInput::make('scan_serial_number')
|
||||
->label('Scan Serial Number')
|
||||
->reactive()
|
||||
->columnSpan(1)
|
||||
->readOnly(fn (callable $get) => !$get('plant') || $get('scan_locator_number') || $get('scan_remove_sno'))
|
||||
->extraAttributes([
|
||||
'wire:keydown.enter' => 'processSerialNo($event.target.value)',
|
||||
]),
|
||||
TextInput::make('scan_remove_sno')
|
||||
->label('Remove Serial Number')
|
||||
->reactive()
|
||||
->columnSpan(1)
|
||||
->readOnly(fn (callable $get) => !$get('plant') || $get('scan_locator_number') || $get('scan_serial_number') || count($this->records) <= 0)
|
||||
->extraAttributes([
|
||||
'wire:keydown.enter' => 'processremoveSNo($event.target.value)',
|
||||
]),
|
||||
TextInput::make('sno_quantity')
|
||||
->label('SNo. Quantity')
|
||||
->reactive()
|
||||
->readOnly()
|
||||
->columnSpan(1),
|
||||
])
|
||||
->columns(5)
|
||||
]);
|
||||
}
|
||||
|
||||
public function processLocatorNo($locatorNo)
|
||||
{
|
||||
$locatorNo = trim($locatorNo);
|
||||
$this->locatorNo = $locatorNo;
|
||||
|
||||
$plantId = trim($this->form->getState()['plant']) ?? null;
|
||||
$this->plantId = $plantId;
|
||||
$serialNo = trim($this->form->getState()['scan_serial_number']) ?? null;
|
||||
$removeSerial = trim($this->form->getState()['scan_remove_sno']) ?? null;
|
||||
//$operatorName = Filament::auth()->user()->name;
|
||||
$count = count($this->records);
|
||||
|
||||
if ($serialNo != null || $serialNo != '')
|
||||
{
|
||||
Notification::make()
|
||||
->title('Press enter on "Scan Serial Number" field to proceed..!')
|
||||
->danger()
|
||||
->send();
|
||||
$this->dispatch('loadData', $this->records, $plantId);
|
||||
$this->form->fill([
|
||||
'plant_id' => $plantId,
|
||||
'plant' => $plantId,
|
||||
'scan_locator_number' => null,
|
||||
'scan_serial_number' => $serialNo,
|
||||
'scan_remove_sno' => null,
|
||||
'sno_quantity' => $count,
|
||||
]);
|
||||
return;
|
||||
}
|
||||
else if ($removeSerial != null || $removeSerial != '')
|
||||
{
|
||||
Notification::make()
|
||||
->title('Press enter on "Remove Serial Number" field to proceed..!')
|
||||
->danger()
|
||||
->send();
|
||||
$this->dispatch('loadData', $this->records, $plantId);
|
||||
$this->form->fill([
|
||||
'plant_id' => $plantId,
|
||||
'plant' => $plantId,
|
||||
'scan_locator_number' => null,
|
||||
'scan_serial_number' => null,
|
||||
'scan_remove_sno' => $removeSerial,
|
||||
'sno_quantity' => $count,
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
if ($locatorNo == null || $locatorNo == '')
|
||||
{
|
||||
Notification::make()
|
||||
->title('Unknown: Locator')
|
||||
->body("Locator number can't be empty!")
|
||||
->danger()
|
||||
->send();
|
||||
$this->dispatch('loadData', $this->records, $plantId);
|
||||
$this->form->fill([
|
||||
'plant_id' => $plantId,
|
||||
'plant' => $plantId,
|
||||
'scan_locator_number' => null,
|
||||
'scan_serial_number' => null,
|
||||
'scan_remove_sno' => null,
|
||||
'sno_quantity' => $count,
|
||||
]);
|
||||
return;
|
||||
}
|
||||
if (strlen($locatorNo) < 7)
|
||||
{
|
||||
Notification::make()
|
||||
->title("Locator number '$locatorNo' must be at least 7 digits.")
|
||||
->danger()
|
||||
->send();
|
||||
$this->dispatch('loadData', $this->records, $plantId);
|
||||
$this->form->fill([
|
||||
'plant_id' => $plantId,
|
||||
'plant' => $plantId,
|
||||
'scan_locator_number' => null,
|
||||
'scan_serial_number' => null,
|
||||
'scan_remove_sno' => null,
|
||||
'sno_quantity' => $count,
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
$exists = Locator::where('locator_number', $locatorNo)
|
||||
->where('plant_id', $plantId)
|
||||
->first();
|
||||
|
||||
if (!$exists)
|
||||
{
|
||||
Notification::make()
|
||||
->title("Locator number '$locatorNo' does not exist in the master.")
|
||||
->danger()
|
||||
->send();
|
||||
$this->dispatch('loadData', $this->records, $plantId);
|
||||
$this->form->fill([
|
||||
'plant_id' => $plantId,
|
||||
'plant' => $plantId,
|
||||
'scan_locator_number' => null,
|
||||
'scan_serial_number' => null,
|
||||
'scan_remove_sno' => null,
|
||||
'sno_quantity' => $count,
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
$serialLocator = PalletValidation::query()
|
||||
->where('plant_id', $plantId)
|
||||
->where('locator_number', $locatorNo)
|
||||
->where(function($query) {
|
||||
$query->whereNull('pallet_number')
|
||||
->orWhere('pallet_number', '');
|
||||
})
|
||||
->get();
|
||||
|
||||
//$locatorSno = $serialLocator->pluck('serial_number')->toArray();
|
||||
|
||||
if ($serialLocator->count() <= 0)
|
||||
{
|
||||
Notification::make()
|
||||
->title('Serial Locator Number Not Found')
|
||||
->body("Scanned locator number '$locatorNo' does not have any locator serial numbers to store into the pallet.<br>
|
||||
Please scan a valid stored locator number to proceed.")
|
||||
->danger()
|
||||
->send();
|
||||
$this->dispatch('loadData', $this->records, $plantId);
|
||||
$this->form->fill([
|
||||
'plant_id' => $plantId,
|
||||
'plant' => $plantId,
|
||||
'scan_locator_number' => null,
|
||||
'scan_serial_number' => null,
|
||||
'scan_remove_sno' => null,
|
||||
'sno_quantity' => $count,
|
||||
]);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
Notification::make()
|
||||
->title('Add: Locator Serial Numbers')
|
||||
->body("Scanned locator number '$locatorNo' has '".$serialLocator->count()."' locator serial numbers!<br>Do you want to store it into 'PALLET DATA' table?")
|
||||
->info()
|
||||
->seconds(2)
|
||||
->send();
|
||||
$this->dispatch('open-confirm-modal', locatorNo: $locatorNo, plantId: $plantId);
|
||||
}
|
||||
}
|
||||
|
||||
public function loadlocatorData($locatorNo, $serialNo, $removeserial, $plantId)
|
||||
{
|
||||
$operatorName = Filament::auth()->user()->name;
|
||||
|
||||
if(count($this->records) <= 0)
|
||||
{
|
||||
session(['latestPalletDateTime' => now()->format('Y-m-d H:i:s')]);
|
||||
session(['latestPalletCreatedBy' => $operatorName]);
|
||||
}
|
||||
|
||||
if ($locatorNo != null && $locatorNo != '')
|
||||
{
|
||||
$serialNumbers = PalletValidation::query()
|
||||
->where('plant_id', $plantId)
|
||||
->where(function($query) {
|
||||
$query->whereNull('pallet_number')
|
||||
->orWhere('pallet_number', '');
|
||||
})
|
||||
->where('locator_number', $locatorNo)
|
||||
->get()
|
||||
->map(function ($record) use($operatorName) {
|
||||
return [
|
||||
'created_at' => session('latestPalletDateTime') ?? '',
|
||||
'created_by' => session('latestPalletCreatedBy') ?? '',
|
||||
// 'pallet_number' => '',
|
||||
'serial_number' => $record->serial_number,
|
||||
'scanned_at' => now()->format('Y-m-d H:i:s'),
|
||||
'scanned_by' => $operatorName ?? '',
|
||||
];
|
||||
})
|
||||
->toArray();
|
||||
|
||||
if (count($this->records) > 0)
|
||||
{
|
||||
// $this->records = array_values(array_filter($this->records, function ($record) use ($serialNumbers) {
|
||||
// return !in_array($record['serial_number'], $serialNumbers);
|
||||
// }));
|
||||
foreach ($serialNumbers as $serial)
|
||||
{
|
||||
$serialNo = $serial['serial_number'];
|
||||
$this->records = array_values(array_filter($this->records, function ($record) use ($serialNo) {
|
||||
return $record['serial_number'] != $serialNo;
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
$newRecords = PalletValidation::query()
|
||||
->where('plant_id', $plantId)
|
||||
->where(function($query) {
|
||||
$query->whereNull('pallet_number')
|
||||
->orWhere('pallet_number', '');
|
||||
})
|
||||
->where('locator_number', $locatorNo)
|
||||
->orderByDesc('created_at')
|
||||
->get()
|
||||
->map(function ($record) use($operatorName) {
|
||||
return [
|
||||
'created_at' => session('latestPalletDateTime') ?? '',
|
||||
'created_by' => session('latestPalletCreatedBy') ?? '',
|
||||
// 'pallet_number' => '',
|
||||
'serial_number' => $record->serial_number,
|
||||
'scanned_at' => now()->format('Y-m-d H:i:s'),
|
||||
'scanned_by' => $operatorName ?? '',
|
||||
];
|
||||
})
|
||||
->toArray();
|
||||
|
||||
$this->records = array_merge($this->records, $newRecords);
|
||||
|
||||
$this->dispatch('loadData', $this->records, $plantId);
|
||||
$this->form->fill([
|
||||
'plant_id' => $plantId,
|
||||
'plant' => $plantId,
|
||||
'scan_locator_number' => $locatorNo,
|
||||
'scan_serial_number' => null,
|
||||
'scan_remove_sno' => null,
|
||||
'sno_quantity' => count($this->records),
|
||||
]);
|
||||
}
|
||||
else if ($serialNo != null && $serialNo != '')
|
||||
{
|
||||
if (count($this->records) > 0)
|
||||
{
|
||||
$this->records = array_values(array_filter($this->records, function ($record) use ($serialNo) {
|
||||
return $record['serial_number'] != $serialNo;
|
||||
}));
|
||||
}
|
||||
|
||||
$newRecords = PalletValidation::query()
|
||||
->where('plant_id', $plantId)
|
||||
->where('serial_number', $serialNo)
|
||||
->get()
|
||||
->map(function ($record) use($operatorName) {
|
||||
return [
|
||||
'created_at' => session('latestPalletDateTime') ?? '',
|
||||
'created_by' => session('latestPalletCreatedBy') ?? '',
|
||||
// 'pallet_number' => '',
|
||||
'serial_number' => $record->serial_number,
|
||||
'scanned_at' => now()->format('Y-m-d H:i:s'),
|
||||
'scanned_by' => $operatorName ?? '',
|
||||
];
|
||||
})
|
||||
->toArray();
|
||||
|
||||
$this->records = array_merge($this->records, $newRecords);
|
||||
|
||||
Notification::make()
|
||||
->title('Add: Locator Serial Number')
|
||||
->body(
|
||||
"Scanned locator serial number '$serialNo' successfully added into 'PALLET DATA' table."
|
||||
)
|
||||
->success()
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', $this->records, $plantId);
|
||||
$this->form->fill([
|
||||
'plant_id' => $plantId,
|
||||
'plant' => $plantId,
|
||||
'scan_locator_number' => null,
|
||||
'scan_serial_number' => null,
|
||||
'scan_remove_sno' => null,
|
||||
'sno_quantity' => count($this->records),
|
||||
]);
|
||||
}
|
||||
else if ($removeserial != null && $removeserial != '')
|
||||
{
|
||||
$this->records = array_values(array_filter($this->records, function ($record) use ($removeserial) {
|
||||
return $record['serial_number'] != $removeserial;
|
||||
}));
|
||||
|
||||
Notification::make()
|
||||
->title('Remove: Locator Serial Number')
|
||||
->body(
|
||||
"Scanned locator serial number '$removeserial' removed successfully from 'PALLET DATA' table."
|
||||
)
|
||||
->success()
|
||||
->send();
|
||||
|
||||
$this->dispatch('loadData', $this->records, $plantId);
|
||||
$this->form->fill([
|
||||
'plant_id' => $plantId,
|
||||
'plant' => $plantId,
|
||||
'scan_locator_number' => null,
|
||||
'scan_serial_number' => null,
|
||||
'scan_remove_sno' => null,
|
||||
'sno_quantity' => count($this->records),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function addToPalletValidation()
|
||||
{
|
||||
$plantId = $this->form->getState()['plant'];
|
||||
$locatorNo = trim($this->form->getState()['scan_locator_number']) ?? null;
|
||||
$serial = trim($this->form->getState()['scan_serial_number']) ?? null;
|
||||
$removeSno = trim($this->form->getState()['scan_remove_sno']) ?? null;
|
||||
|
||||
$serialLocator = PalletValidation::query()
|
||||
->where('plant_id', $plantId)
|
||||
->where('locator_number', $locatorNo)
|
||||
->where(function($query) {
|
||||
$query->whereNull('pallet_number')
|
||||
->orWhere('pallet_number', '');
|
||||
})
|
||||
->get()
|
||||
->count();
|
||||
|
||||
$this->loadlocatorData($locatorNo, $serial, $removeSno, $plantId);
|
||||
|
||||
$this->dispatch('close-modal', id: 'confirm-process-modal');
|
||||
|
||||
Notification::make()
|
||||
->title('Add: Locator Serial Numbers')
|
||||
->body("Scanned locator number '$locatorNo' has '$serialLocator' locator serial numbers!<br>Successfully added into 'PALLET DATA' table.")
|
||||
->success()
|
||||
->send();
|
||||
$this->dispatch('loadData', $this->records, $plantId);
|
||||
$this->form->fill([
|
||||
'plant_id' => $plantId,
|
||||
'plant' => $plantId,
|
||||
'scan_locator_number' => null,
|
||||
'scan_serial_number' => null,
|
||||
'scan_remove_sno' => null,
|
||||
'sno_quantity' => count($this->records),
|
||||
]);
|
||||
}
|
||||
|
||||
public function skipAddToPalletValidation()
|
||||
{
|
||||
$plantId = $this->form->getState()['plant'];
|
||||
Notification::make()
|
||||
->title('Scan the new locator number to proceed..!')
|
||||
->info()
|
||||
->send();
|
||||
$this->dispatch('loadData', $this->records, $plantId);
|
||||
$this->form->fill([
|
||||
'plant_id' => $plantId,
|
||||
'plant' => $plantId,
|
||||
'scan_locator_number' => null,
|
||||
'scan_serial_number' => null,
|
||||
'scan_remove_sno' => null,
|
||||
'sno_quantity' => count($this->records),
|
||||
]);
|
||||
}
|
||||
|
||||
public function processSerialNo($serialNo)
|
||||
{
|
||||
$serialNo = trim($serialNo);
|
||||
|
||||
$plantId = $this->form->getState()['plant'];
|
||||
|
||||
$locatorNo = trim($this->form->getState()['scan_locator_number']) ?? null;
|
||||
|
||||
$removeSerial = trim($this->form->getState()['scan_remove_sno']) ?? null;
|
||||
//$operatorName = Filament::auth()->user()->name;
|
||||
$count = count($this->records);
|
||||
|
||||
if ($locatorNo != null || $locatorNo != '')
|
||||
{
|
||||
Notification::make()
|
||||
->title('Press enter on "Scan Locator Number" field to proceed..!')
|
||||
->danger()
|
||||
->send();
|
||||
$this->dispatch('loadData', $this->records, $plantId);
|
||||
$this->form->fill([
|
||||
'plant_id' => $plantId,
|
||||
'plant' => $plantId,
|
||||
'scan_locator_number' => $locatorNo,
|
||||
'scan_serial_number' => null,
|
||||
'scan_remove_sno' => null,
|
||||
'sno_quantity' => $count,
|
||||
]);
|
||||
return;
|
||||
}
|
||||
else if ($removeSerial != null || $removeSerial != '')
|
||||
{
|
||||
Notification::make()
|
||||
->title('Press enter on "Remove Serial Number" field to proceed..!')
|
||||
->danger()
|
||||
->send();
|
||||
$this->dispatch('loadData', $this->records, $plantId);
|
||||
$this->form->fill([
|
||||
'plant_id' => $plantId,
|
||||
'plant' => $plantId,
|
||||
'scan_locator_number' => null,
|
||||
'scan_serial_number' => null,
|
||||
'scan_remove_sno' => $removeSerial,
|
||||
'sno_quantity' => $count,
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
if ($serialNo == '' || $serialNo == null)
|
||||
{
|
||||
Notification::make()
|
||||
->title("Serial number can't be empty!")
|
||||
->danger()
|
||||
->send();
|
||||
$this->dispatch('loadData', $this->records, $plantId);
|
||||
$this->form->fill([
|
||||
'plant_id' => $plantId,
|
||||
'plant' => $plantId,
|
||||
'scan_locator_number' => null,
|
||||
'scan_serial_number' => null,
|
||||
'scan_remove_sno' => null,
|
||||
'sno_quantity' => $count,
|
||||
]);
|
||||
return;
|
||||
}
|
||||
else if (strlen($serialNo) < 13)
|
||||
{
|
||||
Notification::make()
|
||||
->title("Serial number '$serialNo' must be at least 13 digits.")
|
||||
->danger()
|
||||
->send();
|
||||
$this->dispatch('loadData', $this->records, $plantId);
|
||||
$this->form->fill([
|
||||
'plant_id' => $plantId,
|
||||
'plant' => $plantId,
|
||||
'scan_locator_number' => null,
|
||||
'scan_serial_number' => null,
|
||||
'scan_remove_sno' => null,
|
||||
'sno_quantity' => $count,
|
||||
]);
|
||||
return;
|
||||
}
|
||||
else if (!ctype_alnum($serialNo))
|
||||
{
|
||||
Notification::make()
|
||||
->title("Serial number '$serialNo' must contain alpha-numeric values only.")
|
||||
->danger()
|
||||
->send();
|
||||
$this->dispatch('loadData', $this->records, $plantId);
|
||||
$this->form->fill([
|
||||
'plant_id' => $plantId,
|
||||
'plant' => $plantId,
|
||||
'scan_locator_number' => null,
|
||||
'scan_serial_number' => null,
|
||||
'scan_remove_sno' => null,
|
||||
'sno_quantity' => $count,
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
$serialLocator = PalletValidation::query()
|
||||
->where('plant_id', $plantId)
|
||||
// ->where(function($query) {
|
||||
// $query->whereNull('pallet_number')
|
||||
// ->orWhere('pallet_number', '');
|
||||
// })
|
||||
->where('serial_number', $serialNo)
|
||||
->first();
|
||||
|
||||
if ($serialLocator == '' || $serialLocator == null)
|
||||
{
|
||||
Notification::make()
|
||||
->title('UNKNOWN SERIAL NUMBER')
|
||||
->body("Scanned serial number: '$serialNo' doesn't exist in database!<br>Scan the valid exist locator-serial number to proceed...")
|
||||
->danger()
|
||||
->send();
|
||||
$this->dispatch('loadData', $this->records, $plantId);
|
||||
$this->form->fill([
|
||||
'plant_id' => $plantId,
|
||||
'plant' => $plantId,
|
||||
'scan_locator_number' => null,
|
||||
'scan_serial_number' => null,
|
||||
'scan_remove_sno' => null,
|
||||
'sno_quantity' => null,
|
||||
]);
|
||||
return;
|
||||
}
|
||||
elseif ($serialLocator->pallet_number != '' && $serialLocator->pallet_number != null)
|
||||
{
|
||||
Notification::make()
|
||||
->title('INVALID SERIAL NUMBER')
|
||||
->body("Scanned serial number: '$serialNo' already exist in pallet number '$serialLocator->pallet_number'!<br>Scan the valid locator-serial number to proceed...")
|
||||
->danger()
|
||||
->send();
|
||||
$this->dispatch('loadData', $this->records, $plantId);
|
||||
$this->form->fill([
|
||||
'plant_id' => $plantId,
|
||||
'plant' => $plantId,
|
||||
'scan_locator_number' => null,
|
||||
'scan_serial_number' => null,
|
||||
'scan_remove_sno' => null,
|
||||
'sno_quantity' => null,
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
$this->loadlocatorData('', $serialNo, '', $plantId);
|
||||
}
|
||||
|
||||
public function generatePallet()
|
||||
{
|
||||
$plantId = $this->form->getState()['plant'];
|
||||
$locatorNo = trim($this->form->getState()['scan_locator_number']) ?? null;
|
||||
$serialNo = trim($this->form->getState()['scan_serial_number']) ?? null;
|
||||
$removeSerial = trim($this->form->getState()['scan_remove_sno']) ?? null;
|
||||
// $this->Checking = session('latestPalletSerials');
|
||||
$operatorName = Filament::auth()->user()->name;
|
||||
|
||||
$plantId = trim($plantId) ?? null;
|
||||
|
||||
$year = now()->format('y');
|
||||
$month = now()->format('m');
|
||||
$prefix = "EP-{$year}{$month}";
|
||||
|
||||
$lastPallet = PalletValidation::where('pallet_number', 'like', "{$prefix}%")
|
||||
->where('plant_id', $plantId)
|
||||
->orderByDesc('pallet_number')
|
||||
->first();
|
||||
|
||||
$newNumber = $lastPallet
|
||||
? str_pad(intval(substr($lastPallet->pallet_number, -3)) + 1, 3, '0', STR_PAD_LEFT)
|
||||
: '001';
|
||||
|
||||
$newPalletNumber = "{$prefix}{$newNumber}";
|
||||
|
||||
session(['latestPalletNumber' => $newPalletNumber]);
|
||||
$this->latestPalletNumber = session('latestPalletNumber');
|
||||
|
||||
$url = route('download-qr-pdf', ['palletNo' => $newPalletNumber]);
|
||||
$this->js(<<<JS
|
||||
window.dispatchEvent(new CustomEvent('open-pdf', {
|
||||
detail: {
|
||||
url: "{$url}"
|
||||
}
|
||||
}));
|
||||
JS);
|
||||
|
||||
if (count($this->records) <= 0)
|
||||
{
|
||||
Notification::make()
|
||||
->title('Locator Serials Not Found')
|
||||
->body("Add some locator serial numbers to proceed generate pallet..!")
|
||||
->danger()
|
||||
->send();
|
||||
$this->dispatch('loadData', $this->records, $plantId);
|
||||
$this->form->fill([
|
||||
'plant_id' => $plantId,
|
||||
'plant' => $plantId,
|
||||
'scan_locator_number' => $locatorNo,
|
||||
'scan_serial_number' => $serialNo,
|
||||
'scan_remove_sno' => $removeSerial,
|
||||
'sno_quantity' => 0,
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
// $affected = PalletValidation::where('locator_number', $locatorNo)
|
||||
// ->where('plant_id', $plantId)
|
||||
// ->whereIn('serial_number', $this->Checking)
|
||||
// ->update([
|
||||
// 'pallet_number' => $newPalletNumber,
|
||||
// 'locator_number' => null,
|
||||
// 'updated_at' => now()->format('Y-m-d H:i:s'),
|
||||
// 'updated_by' => $operatorName,
|
||||
// ]);
|
||||
|
||||
$newSerialNumbers = array_column($this->records, 'serial_number');
|
||||
|
||||
PalletValidation::where('plant_id', $plantId)->whereIn('serial_number', $newSerialNumbers)->forceDelete();
|
||||
|
||||
$rowsAdded = 0;
|
||||
|
||||
foreach ($this->records as &$record) {
|
||||
$rowsAdded++;
|
||||
$record['plant_id'] = $plantId;
|
||||
// $record['pallet_number'] = $newPalletNumber;
|
||||
// $record['pallet_status'] = 'Completed';
|
||||
$record['updated_by'] = $operatorName;
|
||||
|
||||
PalletValidation::updateOrCreate(
|
||||
[
|
||||
'plant_id' => $plantId,
|
||||
'serial_number' => $record['serial_number'],
|
||||
],
|
||||
[
|
||||
'pallet_number' => $newPalletNumber,
|
||||
'pallet_status' => 'Completed',
|
||||
'locator_number' => null,
|
||||
'locator_quantity' => 0,
|
||||
'created_at' => $record['created_at'],
|
||||
'created_by' => $record['created_by'],
|
||||
'scanned_at' => $record['scanned_at'],
|
||||
'scanned_by' => $record['scanned_by'],
|
||||
'updated_by' => $operatorName
|
||||
]
|
||||
);
|
||||
}
|
||||
unset($record);
|
||||
|
||||
// PalletValidation::insert($this->records);
|
||||
|
||||
if ($rowsAdded > 0)
|
||||
{
|
||||
$this->records = [];
|
||||
Notification::make()
|
||||
->title('Success: Pallet Generated')
|
||||
->body("Pallet number '$newPalletNumber' completed the master packing successfully!")
|
||||
->success()
|
||||
->send();
|
||||
$this->dispatch('loadData', $this->records, $plantId);
|
||||
$this->form->fill([
|
||||
'plant_id' => $plantId,
|
||||
'plant' => $plantId,
|
||||
'scan_locator_number' => $locatorNo,
|
||||
'scan_serial_number' => $serialNo,
|
||||
'scan_remove_sno' => $removeSerial,
|
||||
'sno_quantity' => 0,
|
||||
]);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->records = [];
|
||||
Notification::make()
|
||||
->title('Failed: Pallet Generated')
|
||||
->body("No locator serial number records found to generate pallet..!")
|
||||
->danger()
|
||||
->send();
|
||||
$this->dispatch('loadData', $this->records, $plantId);
|
||||
$this->form->fill([
|
||||
'plant_id' => $plantId,
|
||||
'plant' => $plantId,
|
||||
'scan_locator_number' => $locatorNo,
|
||||
'scan_serial_number' => $serialNo,
|
||||
'scan_remove_sno' => $removeSerial,
|
||||
'sno_quantity' => 0,
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
// $locator = Locator::where('locator_number', $locatorNo)
|
||||
// ->where('plant_id', $plantId)
|
||||
// ->first();
|
||||
|
||||
// if ($locator && $locator->locator_quantity > 0) {
|
||||
// $locator->update([
|
||||
// 'locator_quantity' => $locator->locator_quantity - 1,
|
||||
// 'updated_at' => now()->format('Y-m-d H:i:s'),
|
||||
// 'updated_by' => $operatorName
|
||||
// ]);
|
||||
// }
|
||||
|
||||
// Notification::make()
|
||||
// ->title('Pallet Generated')
|
||||
// ->body("Pallet number {$this->latestPalletNumber} assigned to all serials for locator {$locatorNo}")
|
||||
// ->success()
|
||||
// ->send();
|
||||
// $this->dispatch('loadData', $this->records, $plantId);
|
||||
// $this->form->fill([
|
||||
// 'plant_id' => $plantId,
|
||||
// 'plant' => $plantId,
|
||||
// 'scan_locator_number' => null,
|
||||
// 'scan_serial_number' => null,
|
||||
// 'scan_remove_sno' => null,
|
||||
// 'sno_quantity' => null,
|
||||
// ]);
|
||||
}
|
||||
|
||||
public function processremoveSNo($removeSno)
|
||||
{
|
||||
$plantId = $this->form->getState()['plant'];
|
||||
|
||||
$locatorNo = trim($this->form->getState()['scan_locator_number']) ?? null;
|
||||
|
||||
$removeSno = trim($removeSno);
|
||||
|
||||
$serialNo = trim($this->form->getState()['scan_serial_number']) ?? null;
|
||||
$count = count($this->records);
|
||||
|
||||
if ($locatorNo != null || $locatorNo != '')
|
||||
{
|
||||
Notification::make()
|
||||
->title('Press enter on "Scan Locator Number" field to proceed..!')
|
||||
->danger()
|
||||
->send();
|
||||
$this->dispatch('loadData', $this->records, $plantId);
|
||||
$this->form->fill([
|
||||
'plant_id' => $plantId,
|
||||
'plant' => $plantId,
|
||||
'scan_locator_number' => $locatorNo,
|
||||
'scan_serial_number' => null,
|
||||
'scan_remove_sno' => null,
|
||||
'sno_quantity' => $count,
|
||||
]);
|
||||
return;
|
||||
}
|
||||
else if ($serialNo != null || $serialNo != '')
|
||||
{
|
||||
Notification::make()
|
||||
->title('Press enter on "Scan Serial Number" field to proceed..!')
|
||||
->danger()
|
||||
->send();
|
||||
$this->dispatch('loadData', $this->records, $plantId);
|
||||
$this->form->fill([
|
||||
'plant_id' => $plantId,
|
||||
'plant' => $plantId,
|
||||
'scan_locator_number' => null,
|
||||
'scan_serial_number' => $serialNo,
|
||||
'scan_remove_sno' => null,
|
||||
'sno_quantity' => $count,
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if ($removeSno == '' || $removeSno == null)
|
||||
{
|
||||
Notification::make()
|
||||
->title("Serial number can't be empty!")
|
||||
->danger()
|
||||
->send();
|
||||
$this->dispatch('loadData', $this->records, $plantId);
|
||||
$this->form->fill([
|
||||
'plant_id' => $plantId,
|
||||
'plant' => $plantId,
|
||||
'scan_locator_number' => null,
|
||||
'scan_serial_number' => null,
|
||||
'scan_remove_sno' => null,
|
||||
'sno_quantity' => $count,
|
||||
]);
|
||||
return;
|
||||
}
|
||||
else if (strlen($removeSno) < 13)
|
||||
{
|
||||
Notification::make()
|
||||
->title("Serial number '$removeSno' must be at least 13 digits.")
|
||||
->danger()
|
||||
->send();
|
||||
$this->dispatch('loadData', $this->records, $plantId);
|
||||
$this->form->fill([
|
||||
'plant_id' => $plantId,
|
||||
'plant' => $plantId,
|
||||
'scan_locator_number' => null,
|
||||
'scan_serial_number' => null,
|
||||
'scan_remove_sno' => null,
|
||||
'sno_quantity' => $count,
|
||||
]);
|
||||
return;
|
||||
}
|
||||
else if (!ctype_alnum($removeSno))
|
||||
{
|
||||
Notification::make()
|
||||
->title("Serial number '$removeSno' must contain alpha-numeric values only.")
|
||||
->danger()
|
||||
->send();
|
||||
$this->dispatch('loadData', $this->records, $plantId);
|
||||
$this->form->fill([
|
||||
'plant_id' => $plantId,
|
||||
'plant' => $plantId,
|
||||
'scan_locator_number' => null,
|
||||
'scan_serial_number' => null,
|
||||
'scan_remove_sno' => null,
|
||||
'sno_quantity' => $count,
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
// $serialLocator = PalletValidation::query()
|
||||
// ->where('plant_id', $plantId)
|
||||
// ->where(function($query) {
|
||||
// $query->whereNull('pallet_number')
|
||||
// ->orWhere('pallet_number', '');
|
||||
// })
|
||||
// ->first();
|
||||
|
||||
$serialNumbers = array_column($this->records, 'serial_number');
|
||||
|
||||
$exists = in_array($removeSno, $serialNumbers);
|
||||
|
||||
if (!$exists)
|
||||
{
|
||||
Notification::make()
|
||||
->title('UNKNOWN SERIAL NUMBER')
|
||||
->body("Scanned serial number: '$removeSno' doesn't exist in 'PALLET DATA' table!<br>Scan the valid exist locator-serial number to proceed...")
|
||||
->danger()
|
||||
->send();
|
||||
$this->dispatch('loadData', $this->records, $plantId);
|
||||
$this->form->fill([
|
||||
'plant_id' => $plantId,
|
||||
'plant' => $plantId,
|
||||
'scan_locator_number' => null,
|
||||
'scan_serial_number' => null,
|
||||
'scan_remove_sno' => null,
|
||||
'sno_quantity' => $count,
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
$this->loadlocatorData('', '', $removeSno, $plantId);
|
||||
|
||||
}
|
||||
|
||||
public static function canAccess(): bool
|
||||
{
|
||||
return Auth::check() && Auth::user()->can('create pallet from locator page');
|
||||
}
|
||||
|
||||
}
|
||||
88
app/Livewire/PalletFromLocatorDataTable.php
Normal file
88
app/Livewire/PalletFromLocatorDataTable.php
Normal file
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire;
|
||||
|
||||
use App\Models\PalletValidation;
|
||||
use Filament\Facades\Filament;
|
||||
use Filament\Notifications\Notification;
|
||||
use Livewire\Component;
|
||||
|
||||
|
||||
class PalletFromLocatorDataTable extends Component
|
||||
{
|
||||
public $plantId;
|
||||
|
||||
public $locatorNo, $palletNumber, $newpallet;
|
||||
|
||||
public $showSessionRecords = false;
|
||||
|
||||
public $showRemovedRecords = false;
|
||||
|
||||
public $records = [];
|
||||
|
||||
public $scannedRecords = [];
|
||||
public $removeRecords = [];
|
||||
|
||||
public $latestPalletDateTime = null;
|
||||
public $createdBy;
|
||||
|
||||
protected $listeners = [
|
||||
'loadData' => 'loadlocatorData',
|
||||
'open-confirm-modal' => 'openConfirmModal',
|
||||
];
|
||||
|
||||
// public function generatePallet($plantId)
|
||||
// {
|
||||
// $year = now()->format('y');
|
||||
// $month = now()->format('m');
|
||||
// $prefix = "EP-{$year}{$month}";
|
||||
|
||||
// $lastPallet = PalletValidation::where('pallet_number', 'like', "{$prefix}%")
|
||||
// ->where('plant_id', $plantId)
|
||||
// ->orderByDesc('pallet_number')
|
||||
// ->first();
|
||||
|
||||
// $newNumber = $lastPallet
|
||||
// ? str_pad(intval(substr($lastPallet->pallet_number, -3)) + 1, 3, '0', STR_PAD_LEFT)
|
||||
// : '001';
|
||||
|
||||
// $newPalletNumber = "{$prefix}{$newNumber}";
|
||||
|
||||
|
||||
// session(['latestPalletNumber' => $newPalletNumber]);
|
||||
|
||||
// $url = route('download-qr-pdf', ['palletNo' => $newPalletNumber]);
|
||||
// $this->js(<<<JS
|
||||
// window.dispatchEvent(new CustomEvent('open-pdf', {
|
||||
// detail: {
|
||||
// url: "{$url}"
|
||||
// }
|
||||
// }));
|
||||
// JS);
|
||||
// }
|
||||
|
||||
public function openConfirmModal($locatorNo, $plantId)
|
||||
{
|
||||
$this->locatorNo = $locatorNo;
|
||||
$this->plantId = $plantId;
|
||||
$this->dispatch('open-modal', id: 'confirm-process-modal');
|
||||
}
|
||||
|
||||
public function loadlocatorData($records,$plantId)
|
||||
{
|
||||
$this->plantId = $plantId;
|
||||
$this->records = $records;
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.pallet-from-locator-data-table');
|
||||
}
|
||||
|
||||
|
||||
|
||||
// public function render()
|
||||
// {
|
||||
// return view('livewire.pallet-from-locator-data-table');
|
||||
// }
|
||||
}
|
||||
51
resources/views/filament/pages/pallet-from-locator.blade.php
Normal file
51
resources/views/filament/pages/pallet-from-locator.blade.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<x-filament-panels::page>
|
||||
<div class="space-y-4">
|
||||
{{-- Render the Select form fields --}}
|
||||
<div class="space-y-4">
|
||||
{{ $this->form }}
|
||||
</div>
|
||||
<div class="flex-row gap-2 mt-4">
|
||||
<button
|
||||
type="button"
|
||||
wire:click="generatePallet"
|
||||
class="px-3 py-1 border border-primary-500 text-primary-600 rounded hover:bg-primary-50 hover:border-primary-700 transition text-sm"
|
||||
>
|
||||
Generate Pallet
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="bg-white shadow rounded-xl p-4 mt-6">
|
||||
<livewire:pallet-from-locator-data-table />
|
||||
</div>
|
||||
|
||||
{{-- <div>
|
||||
<p>Locator No: {{ $locatorNo }}</p>
|
||||
</div> --}}
|
||||
|
||||
<x-filament::modal id="confirm-process-modal">
|
||||
<x-slot name="heading">
|
||||
ADD: CONFIRMATION
|
||||
</x-slot>
|
||||
<p>Scanned locator number has locator serial numbers!<br>Do you want to store it into 'Pallet Data' table?</p>
|
||||
<x-slot name="footer">
|
||||
<x-filament::button wire:click="addToPalletValidation" x-on:click="isOpen = false" color="success">
|
||||
Yes
|
||||
</x-filament::button>
|
||||
<x-filament::button wire:click="skipAddToPalletValidation" x-on:click="isOpen = false" color="danger">
|
||||
No
|
||||
</x-filament::button>
|
||||
</x-slot>
|
||||
</x-filament::modal>
|
||||
@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
|
||||
</div>
|
||||
</x-filament-panels::page>
|
||||
@@ -0,0 +1,42 @@
|
||||
<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">{{ $record['created_at'] ?? '' }}</td>
|
||||
<td class="border px-4 py-2">{{ $record['created_by'] ?? '' }}</td>
|
||||
<td class="border px-4 py-2">{{ $record['pallet_number'] ?? '' }}</td>
|
||||
<td class="border px-4 py-2">{{ $record['serial_number'] ?? '' }}</td>
|
||||
<td class="border px-4 py-2">{{ $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