Added panel pallet validation resource pages
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Has been cancelled

This commit is contained in:
dhanabalan
2026-11-30 14:21:07 +05:30
parent 148c720554
commit dc7d5333fa
5 changed files with 1266 additions and 0 deletions

View File

@@ -0,0 +1,339 @@
<?php
namespace App\Filament\Resources;
use App\Filament\Resources\PanelPalletValidationResource\Pages;
use App\Filament\Resources\PanelPalletValidationResource\RelationManagers;
use App\Models\PanelPalletValidation;
use App\Models\Plant;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
use Filament\Forms\Components\Section;
use Filament\Facades\Filament;
use Filament\Tables\Actions\ExportAction;
use Filament\Tables\Actions\ImportAction;
use App\Filament\Exports\PanelPalletValidationExporter;
use App\Filament\Imports\PanelPalletValidationImporter;
class PanelPalletValidationResource extends Resource
{
protected static ?string $model = PanelPalletValidation::class;
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
protected static ?string $navigationGroup = 'Panel Pallet Box';
public static function form(Form $form): Form
{
return $form
->schema([
Section::make('')
->schema([
Forms\Components\Select::make('plant_id')
->label('Plant')
->relationship('plant', 'name')
->required()
->reactive()
->options(function (callable $get) {
$userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
})
->afterStateUpdated(function ($state, callable $set) {
$set('pallet_number', null);
$set('serial_number', null);
$set('removeSno_number', null);
$set('Sno_quantity', 0);
$set('pending_pallet_list', null);
}),
Forms\Components\TextInput::make('pallet_number')
->label('Scan Pallet No')
->reactive()
->required()
->readonly() // fn ($get) => (bool)$get('pallet_number_locked') || $get('serial_number') || $get('removeSno_number')
->extraAttributes([
'x-data' => '{ value: "" }',
'x-model' => 'value',
'x-on:keydown.enter.prevent' => '$wire.processPalletNo()',
])
->suffixAction(fn ($get, $set) => Forms\Components\Actions\Action::make('addPallet')
->label('')
->button()
->icon('heroicon-o-plus')
->color('primary')
->extraAttributes([
'class' => 'p-1 w-7 h-7',
])
->action(function ($get, $set, $livewire) {
$plantId = $get('plant_id');
session(['pallet_clicked_time' => now()->toDateTimeString()]);
session(['pallet_created_by' => Filament::auth()->user()->name]);
$year = now()->format('y');
$month = now()->format('m');
$prefix = "PP-{$year}{$month}";
$lastPallet1 = PanelPalletValidation::where('pallet_number', 'like', "{$prefix}%")->orderByDesc('pallet_number')->first();
$newNumber = '001';
if ($lastPallet1) {
$serialPart1 = substr($lastPallet1->pallet_number, strlen($prefix));
$newNumber = str_pad(intval($serialPart1) + 1, strlen($serialPart1), '0', STR_PAD_LEFT);
}
$newPalletNumber = "{$prefix}{$newNumber}";
// dd($newPalletNumber);
$set('pallet_number', $newPalletNumber);
$set('pallet_number_locked', true);
$set('plant_id', $plantId);
$livewire->redirectToPanelQrPdf($newPalletNumber);
})
),
Forms\Components\TextInput::make('serial_number')
->label('Scan Serial No')
->reactive()
->minLength(9)
->readOnly(fn (callable $get) => ! $get('pallet_number') || $get('removeSno_number'))
->extraAttributes([
'x-on:keydown.enter.prevent' => '$wire.processPalletSNo()',
]),
Forms\Components\TextInput::make('removeSno_number')
->label('Remove Serial No')
->reactive()
->minLength(9)
->readOnly(fn (callable $get) => ! $get('pallet_number') || $get('serial_number'))
->extraAttributes([
'x-data' => '{ value: "" }',
'x-model' => 'value',
'x-on:keydown.enter.prevent' => '$wire.processRemoveSNo()',
]),
Forms\Components\TextInput::make('Sno_quantity')
->label('SNo. Quantity')
->readOnly()
->default('0'),
Forms\Components\Hidden::make('created_by')
->default(Filament::auth()->user()?->name),
Forms\Components\Hidden::make('scanned_by')
->default(Filament::auth()->user()?->name),
Forms\Components\Hidden::make('pallet_number_locked')
->default(false),
Forms\Components\Select::make('pending_pallet_list')
->label('Pending Pallet List')
->reactive()
->afterStateUpdated(function ($state, callable $set) {
$set('pallet_number', $state);
$set('pallet_number_locked', false);
})
->options(function ($get) {
$plantId = $get('plant_id');
if (! $plantId) {
return [];
}
return PanelPalletValidation::query()
->where('plant_id', $plantId)
->where(function ($query) {
$query->whereNull('pallet_status')
->orWhere('pallet_status', '');
})
->whereNotNull('pallet_number')
->orderBy('pallet_number', 'asc')
->pluck('pallet_number')
->unique()
->mapWithKeys(fn ($number) => [$number => $number])
->toArray();
}),
Forms\Components\View::make('forms.components.save-panel-pallet-button'),
])
->columns(5),
Forms\Components\TextInput::make('id')
->hidden()
->readOnly(),
]);
}
public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('No.')
->label('No.')
->alignCenter()
->getStateUsing(function ($record, $livewire, $column, $rowLoop) {
$paginator = $livewire->getTableRecords();
$perPage = method_exists($paginator, 'perPage') ? $paginator->perPage() : 10;
$currentPage = method_exists($paginator, 'currentPage') ? $paginator->currentPage() : 1;
return ($currentPage - 1) * $perPage + $rowLoop->iteration;
}),
Tables\Columns\TextColumn::make('plant.name')
->label('Plant')
->alignCenter()
->sortable(),
Tables\Columns\TextColumn::make('item.code')
->label('Item')
->alignCenter()
->sortable(),
Tables\Columns\TextColumn::make('pallet_number')
->label('Pallet Number')
->alignCenter()
->sortable(),
Tables\Columns\TextColumn::make('serial_number')
->label('Serial Number')
->alignCenter()
->sortable(),
Tables\Columns\TextColumn::make('panel_box_supplier')
->label('Panel Box Supplier')
->alignCenter()
->sortable(),
Tables\Columns\TextColumn::make('panel_box_serial_number')
->label('Panel Box Serial Number')
->alignCenter()
->sortable(),
Tables\Columns\TextColumn::make('panel_box_code')
->label('Panel Box Code')
->alignCenter()
->sortable(),
Tables\Columns\TextColumn::make('pallet_status')
->label('Pallet Status')
->alignCenter()
->sortable(),
Tables\Columns\TextColumn::make('created_at')
->label('Created At')
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
Tables\Columns\TextColumn::make('updated_at')
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
Tables\Columns\TextColumn::make('scanned_at')
->dateTime()
->sortable(),
Tables\Columns\TextColumn::make('deleted_at')
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
])
->filters([
Tables\Filters\TrashedFilter::make(),
])
->actions([
Tables\Actions\ViewAction::make(),
Tables\Actions\EditAction::make(),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
Tables\Actions\ForceDeleteBulkAction::make(),
Tables\Actions\RestoreBulkAction::make(),
]),
])
->headerActions([
Tables\Actions\Action::make('reprint_pallet')
->label('Re-Print Panel Pallet QR')
->form([
Forms\Components\Section::make()
->schema([
Forms\Components\Select::make('plant')
->label('Select Plant')
// ->options(Plant::pluck('name', 'id')->toArray())
->options(function (callable $get) {
$userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
})
->required()
->reactive()
->columnSpan(2),
Forms\Components\Select::make('pallet_list')
->label('Select Pallet')
->searchable()
->required()
->reactive()
->columnSpan(1)
// ->optionsLimit(500)
->options(function (callable $get) {
$plantId = $get('plant');
if (! $plantId) {
return [];
}
return PanelPalletValidation::query()->where('plant_id', $plantId)
// ->whereNotNull('pallet_number')
// ->where('pallet_number', '!=', '')
->where('pallet_number', 'like', 'PP-'.'%')
->select('pallet_number')
->distinct()
->orderBy('pallet_number', 'desc')
->pluck('pallet_number', 'pallet_number')
->toArray();
}),
])
->columns(['default' => 1, 'sm' => 3]),
])
->action(function (array $data) {
$selectedPalletNumber = $data['pallet_list'];
return redirect()->route('download-reprint-qr-pdf', ['palletNo' => $selectedPalletNumber]);
})
->visible(function () {
return Filament::auth()->user()->can('view reprint pallet number');
}),
ImportAction::make()
->importer(PanelPalletValidationImporter::class)
->label('Import Panel Pallet')
->color('warning')
->visible(function () {
return Filament::auth()->user()->can('view import panel pallet validation');
}),
ExportAction::make()
->exporter(PanelPalletValidationExporter::class)
->label('Export Panel Pallet')
->color('warning')
->visible(function () {
return Filament::auth()->user()->can('view export panel pallet validation');
}),
]);
}
public static function getRelations(): array
{
return [
//
];
}
public static function getPages(): array
{
return [
'index' => Pages\ListPanelPalletValidations::route('/'),
'create' => Pages\CreatePanelPalletValidation::route('/create'),
'view' => Pages\ViewPanelPalletValidation::route('/{record}'),
'edit' => Pages\EditPanelPalletValidation::route('/{record}/edit'),
];
}
public static function getEloquentQuery(): Builder
{
return parent::getEloquentQuery()
->withoutGlobalScopes([
SoftDeletingScope::class,
]);
}
}

View File

@@ -0,0 +1,867 @@
<?php
namespace App\Filament\Resources\PanelPalletValidationResource\Pages;
use App\Filament\Resources\PanelPalletValidationResource;
use Filament\Actions;
use Filament\Resources\Pages\CreateRecord;
use Illuminate\View\View;
use Filament\Facades\Filament;
use Filament\Notifications\Notification;
use App\Models\PanelPalletValidation;
use App\Models\InvoiceValidation;
use App\Models\PanelBoxValidation;
use App\Models\Item;
use App\Models\Plant;
class CreatePanelPalletValidation extends CreateRecord
{
public $plantId;
public $pallet_number;
public $palletNo;
public $pendingPallet;
public $snoCount = 0;
public $pallet_number_locked = false;
public $serial_number;
protected static string $view = 'filament.resources.panel-pallet-validation-resource.create-panel-pallet-validation';
protected static string $resource = PanelPalletValidationResource::class;
protected $listeners = [
'updateSnoQuantity' => 'handleUpdateSnoQuantity',
];
public ?array $data = null;
protected function getRedirectUrl(): string
{
return $this->getResource()::getUrl('create');
}
public function processPalletSNo()
{
$plantId = $this->form->getState()['plant_id'];
$plantId = trim($plantId) ?? null;
$pendingPallet = $this->form->getState()['pending_pallet_list'];
$palletNumber = trim($this->form->getState()['pallet_number'])?? null;
$palletNumber = trim($palletNumber) ?? null;
$serNo = trim($this->form->getState()['serial_number'])?? null;
$serNo = trim($serNo) ?? null;
$user = Filament::auth()->user();
$operatorName = $user->name;
$clickedAt = session('pallet_clicked_time');
$clickedBy = session('pallet_created_by');
$plantName = Plant::where('id', $plantId)->value('name');
if (!$palletNumber)
{
Notification::make()
->title("Pallet number can't be empty")
->danger()
->duration(5000)
->send();
$this->form->fill([
'serial_number' => null,
'plant_id' => $plantId,
'pallet_number' => $palletNumber,
'pending_pallet_list' => $pendingPallet,
'Sno_quantity' => 0,
'created_by' => $operatorName,
'scanned_by' => $operatorName,
]);
return;
}
$count = PanelPalletValidation::where('plant_id', $plantId)
->where('pallet_number', $palletNumber)
->count('pallet_number');
if (!preg_match('/^(\d+)\/(\d+)\/(\d+)\/(\d+)$/', $serNo, $matches)) {
Notification::make()
->title("Invalid Panel Box QR format: $serNo <br>Sample Format '1070107/398679/2611/000001'")
->danger()
->send();
$this->form->fill([
'plant_id' => $plantId,
'item_id' => null,
'pallet_number' => $palletNumber,
'pending_pallet_list' => $pendingPallet,
'serial_number' => null,
'panel_box_supplier' => null,
'panel_box_serial_number' => null,
'panel_box_code' => null,
'Sno_quantity' => 0,
]);
return;
}
if (preg_match('/^(\d+)\/(\d+)\/(\d+)\/(\d+)$/', $serNo, $matches)) {
$itemCode = $matches[2];
$serialNumber = $matches[1] . $matches[3] . $matches[4];
$supplierNo = $matches[1];
$supplierSNo = implode('/', array_slice($matches, 3));
$panelBoxCode = $matches[2];
$pBoxSNo = $matches[3] . '/' . $matches[4];
$itemExists = Item::where('code', $panelBoxCode)->first();
if (!$itemExists) {
Notification::make()
->title("Item code '$panelBoxCode' does not exist.")
->danger()
->duration(5000)
->send();
$this->form->fill([
'plant_id' => $plantId,
'item_id' => null,
'pallet_number' => $palletNumber,
'pending_pallet_list' => $pendingPallet,
'serial_number' => null,
'panel_box_supplier' => null,
'panel_box_serial_number' => null,
'panel_box_code' => null,
'Sno_quantity' => 0,
]);
return;
}
$itemExistsAgaPlant = Item::where('plant_id', $plantId)->where('code', $panelBoxCode)->first();
if (!$itemExistsAgaPlant) {
Notification::make()
->title("Item code '$panelBoxCode' does not exist against plant $plantName.")
->danger()
->duration(5000)
->send();
$this->form->fill([
'plant_id' => $plantId,
'item_id' => null,
'pallet_number' => $palletNumber,
'pending_pallet_list' => $pendingPallet,
'serial_number' => null,
'panel_box_supplier' => null,
'panel_box_serial_number' => null,
'panel_box_code' => null,
'Sno_quantity' => 0,
]);
return;
}
$panelBoxExist = PanelBoxValidation::where('plant_id', $plantId)->where('panel_box_supplier', $supplierNo)->where('panel_box_serial_number', $pBoxSNo)->where('panel_box_code', $panelBoxCode)->first();
if(!$panelBoxExist){
Notification::make()
->title('Unknwon : Serial Number')
->body("Scanned Panel Box Serial Number '$serNo' was not found in Panel Box Validation.<br>Please complete the testing process for this Panel Box before proceeding.")
->danger()
->seconds(3)
->send();
$this->dispatch('playWarnSound');
$this->form->fill([
'plant_id' => $plantId,
'item_id' => null,
'pallet_number' => $palletNumber,
'pending_pallet_list' => $pendingPallet,
'serial_number' => null,
'panel_box_supplier' => null,
'panel_box_serial_number' => null,
'panel_box_code' => null,
'Sno_quantity' => 0,
]);
return;
}
$panelBoxExistStatus = PanelBoxValidation::where('plant_id', $plantId)->where('panel_box_supplier', $supplierNo)->where('panel_box_serial_number', $pBoxSNo)->where('panel_box_code', $panelBoxCode)->first();
if($panelBoxExistStatus && $panelBoxExistStatus->status == 'NotOk'){
Notification::make()
->title('NotOk : Serial Number')
->body("Scanned Panel Box Serial Number '$serNo' was found in Panel Box Validation, but its status is Not OK.")
->danger()
->seconds(3)
->send();
$this->dispatch('playWarnSound');
$this->form->fill([
'plant_id' => $plantId,
'item_id' => null,
'pallet_number' => $palletNumber,
'pending_pallet_list' => $pendingPallet,
'serial_number' => null,
'panel_box_supplier' => null,
'panel_box_serial_number' => null,
'panel_box_code' => null,
'Sno_quantity' => 0,
]);
return;
}
}
try
{
$existingPallet = PanelPalletValidation::where('plant_id', $plantId)->where('pallet_number', $palletNumber)->first();
$createdAt = $existingPallet ? $existingPallet->created_at : $clickedAt ?? now();
$createdBy = $existingPallet ? $existingPallet->created_by : $clickedBy ?? $operatorName;
$record = PanelPalletValidation::create([
'plant_id' => $plantId,
'item_id' => $itemExistsAgaPlant->id,
'pallet_number' => $palletNumber,
'serial_number' => $serialNumber,
'panel_box_supplier' => $supplierNo,
'panel_box_serial_number' => $pBoxSNo,
'panel_box_code' => $panelBoxCode,
'created_by' => $createdBy,
'scanned_by' => $operatorName,
'created_at' => $createdAt,
'scanned_at' => now(),
'updated_by' => $operatorName,
]);
$count = PanelPalletValidation::where('plant_id', $plantId)
->where('pallet_number', $palletNumber)
->count('pallet_number');
if ($record)
{
$this->snoCount = PanelPalletValidation::where('plant_id', $plantId)
->where('pallet_number', $palletNumber)
->count();
$this->dispatch('loadData', $palletNumber, $plantId);
$this->form->fill([
'plant_id' => $plantId,
'pallet_number' => $palletNumber,
'serial_number' => null,
'pending_pallet_list' => $pendingPallet,
'Sno_quantity' => $count,
'created_by' => $operatorName,
'scanned_by' => $operatorName,
]);
}
else
{
Notification::make()
->title("Failed to insert scanned serial number '$serialNumber' into pallet table!")
->danger()
->duration(5000)
->send();
$this->dispatch('loadData', $palletNumber, $plantId);
$this->form->fill([
'plant_id' => $plantId,
'pallet_number' => $palletNumber,
'serial_number' => null,
'pending_pallet_list' => $pendingPallet,
'Sno_quantity' => $count,
'scanned_by' => $operatorName,
]);
return;
}
}
catch (\Exception $e)
{
Notification::make()
->title('Error: Serial not inserted.')
->body("Something went wrong while inserting serial number '{$serialNumber}' into pallet table!\nScan the new serial number to proceed...")
->danger()
->duration(5000)
->send();
$this->dispatch('loadData', $palletNumber, $plantId);
$this->form->fill([
'plant_id' => $plantId,
'pallet_number' => $palletNumber,
'serial_number' => null,
'pending_pallet_list' => $pendingPallet,
'Sno_quantity' => $count,
'created_by' => $operatorName,
'scanned_by' => $operatorName,
]);
return;
}
}
public function handleUpdateSnoQuantity($newValue)
{
// Update the form field
$this->form->fill([
'Sno_quantity' => $newValue,
]);
}
public function redirectToPanelQrPdf($palletNo)
{
$this->palletNo = $palletNo;
//return redirect()->route('download-qr-pdf', ['palletNo' => $this->palletNo]);
$url = route('download-qr-panel-pdf', ['panelPalletNo' => $this->palletNo]);
$this->js(<<<JS
window.dispatchEvent(new CustomEvent('open-pdf', {
detail: {
url: "{$url}"
}
}));
JS);
}
public function markAsComplete()
{
$plantId = $this->form->getState()['plant_id'];
$plantId = trim($plantId) ?? null;
$pendingPallet = $this->form->getState()['pending_pallet_list'];
$palletNumber = trim($this->form->getState()['pallet_number'])?? null;
$palletNumber = trim($palletNumber) ?? null;
$serialNumber = trim($this->form->getState()['serial_number'])?? null;
$serialNumber = trim($serialNumber) ?? null;
$user = Filament::auth()->user();
$operatorName = $user->name;
$isCompleted = $this->data['is_completed'] ?? false;
$this->pendingPallet = $this->form->getState()['pending_pallet_list'];
$palletExist = PanelPalletValidation::where('pallet_number', $palletNumber)
->where('plant_id', $plantId)
->first();
if (!$palletExist)
{
Notification::make()
->title("Pallet number '$palletNumber' does not have serial numbers to save!<br>Add the valid serial number into pallet number to proceed...")
->danger()
->duration(5000)
->send();
$this->dispatch('loadData', $palletNumber, $plantId);
$this->form->fill([
'serial_number' => null,
'plant_id' => $plantId,
'pallet_number' => $palletNumber,
'pending_pallet_list' => $pendingPallet,
'Sno_quantity' => 0,
'created_by' => $operatorName,
'scanned_by' => $operatorName,
]);
return;
}
$allCompleted = PanelPalletValidation::where('plant_id', $plantId)
->where('pallet_number', $palletNumber)
->where('pallet_status', '=','Completed')
->first();
if ($allCompleted)
{
Notification::make()
->title("Pallet number '$palletNumber' already completed the master packing!<br>Generate the new pallet number or choose from pending pallet list!")
->danger()
->duration(5000)
->send();
$this->dispatch('loadData', '', $plantId);
$this->form->fill([
'serial_number' => null,
'plant_id' => $plantId,
'pallet_number' => null,
'pending_pallet_list' => null,//$pendingPallet
'Sno_quantity' => 0,
'created_by' => $operatorName,
'scanned_by' => $operatorName,
]);
return;
}
// $count = PalletValidation::where('plant_id', $plantId)
// ->where('pallet_number', $palletNumber)
// ->count('pallet_number');
if (!$isCompleted)
{
$updated = PanelPalletValidation::where('pallet_number', $palletNumber)
->where('plant_id', $plantId)
->update([
'updated_at' => now(),
'updated_by' => $operatorName,
]);
if ($updated > 0)
{
Notification::make()
->title("Pallet number '$palletNumber' records saved successfully!")
->success()
->duration(800)
->send();
$this->dispatch('loadData', '', $plantId);
$this->form->fill([
'serial_number' => null,
'plant_id' => $plantId,
'pallet_number' => null,//$palletNumber
'pending_pallet_list' => null,//$pendingPallet
'Sno_quantity' => 0,//$count,
'created_by' => $operatorName,
'scanned_by' => $operatorName,
]);
return;
}
}
else
{
$updated = PanelPalletValidation::where('pallet_number', $palletNumber)
->where('plant_id', $plantId)
->update([
'pallet_status' => 'Completed',
'updated_at' => now(),
'updated_by' => $operatorName,
]);
if ($updated > 0)
{
Notification::make()
->title("Pallet number '$palletNumber' completed the master packing successfully!")
->success()
->duration(800)
->send();
$this->dispatch('loadData', '', $plantId);
$this->form->fill([
'serial_number' => null,
'plant_id' => $plantId,
'pallet_number' => null,//$palletNumber
'pending_pallet_list' => null,//$pendingPallet
'Sno_quantity' => 0,//$count
'created_by' => $operatorName,
'scanned_by' => $operatorName,
]);
return;
}
}
}
public function processRemoveSNo()
{
$plantId = $this->form->getState()['plant_id'];
$plantId = trim($plantId) ?? null;
$pendingPallet = $this->form->getState()['pending_pallet_list'];
$palletNumber = trim($this->form->getState()['pallet_number']) ?? null;
$palletNumber = trim($palletNumber) ?? null;
$serialNumber = trim($this->form->getState()['removeSno_number']) ?? null;
$serialNumber = trim($serialNumber) ?? null;
$user = Filament::auth()->user();
$operatorName = $user->name;
if (!$palletNumber)
{
Notification::make()
->title('Pallet number is required to remove.')
->danger()
->duration(5000)
->send();
return;
}
$count = PanelPalletValidation::where('plant_id', $plantId)
->where('pallet_number', $palletNumber)
->count('pallet_number');
if (!$serialNumber)
{
Notification::make()
->title('Serial number is required to remove.')
->danger()
->duration(5000)
->send();
$this->dispatch('loadData', $palletNumber, $plantId);
$this->form->fill([
'serial_number' => null,
'plant_id' => $plantId,
'pallet_number' => $palletNumber,
'pending_pallet_list' => $pendingPallet,
'Sno_quantity' => $count,
'created_by' => $operatorName,
'scanned_by' => $operatorName,
]);
return;
}
else if (strlen($serialNumber) < 9 || strlen($serialNumber) > 20)
{
Notification::make()
->title('Serial number should contain minimum 9 digits and maximum 20 digits.')
->danger()
->duration(5000)
->send();
$this->dispatch('loadData', $palletNumber, $plantId);
$this->form->fill([
'serial_number' => null,
'plant_id' => $plantId,
'pallet_number' => $palletNumber,
'pending_pallet_list' => $pendingPallet,
'Sno_quantity' => $count,
'created_by' => $operatorName,
'scanned_by' => $operatorName,
]);
return;
}
else if (!ctype_alnum($serialNumber))
{
Notification::make()
->title('Serial number must contain alpha-numeric values only.')
->danger()
->duration(5000)
->send();
$this->dispatch('loadData', $palletNumber, $plantId);
$this->form->fill([
'serial_number' => null,
'plant_id' => $plantId,
'pallet_number' => $palletNumber,
'pending_pallet_list' => $pendingPallet,
'Sno_quantity' => $count,
'created_by' => $operatorName,
'scanned_by' => $operatorName,
]);
return;
}
$invoiceExist = LocatorInvoiceValidation::where('plant_id', $plantId)
->where('serial_number', $serialNumber)
->where('scanned_status', '=', 'Scanned')
->first();
if ($invoiceExist)
{
Notification::make()
->title("Scanned serial number '{$serialNumber}' already completed the scanning process and exist in invoice number '{$invoiceExist->invoice_number}'.<br>Scan the valid exist serial number to remove!")
->danger()
->duration(5000)
->send();
$this->dispatch('loadData', $palletNumber, $plantId);
$this->form->fill([
'serial_number' => null,
'plant_id' => $plantId,
'pallet_number' => $palletNumber,
'pending_pallet_list' => $pendingPallet,
'Sno_quantity' => $count,
'created_by' => $operatorName,
'scanned_by' => $operatorName,
]);
return;
}
$serialexist = PanelPalletValidation::where('plant_id', $plantId)
->where('serial_number', $serialNumber)
->first();
if (!$serialexist)
{
Notification::make()
->title('Serial number not exists in pallet table.')
->danger()
->duration(5000)
->send();
$this->dispatch('loadData', $palletNumber, $plantId);
$this->form->fill([
'serial_number' => null,
'plant_id' => $plantId,
'pallet_number' => $palletNumber,
'pending_pallet_list' => $pendingPallet,
'Sno_quantity' => $count,
'created_by' => $operatorName,
'scanned_by' => $operatorName,
]);
return;
}
$palletExist = PanelPalletValidation::where('plant_id', $plantId)
->where('serial_number', $serialNumber)
->where('pallet_number', '!=', '')
->where('pallet_number', '!=', null)
->first();
if ($palletExist && $palletExist->pallet_number != $palletNumber)
{
Notification::make()
->title("Scanned serial number exist in pallet number '$palletExist->pallet_number'.<br>Scan the valid exist serial number to remove!")
->danger()
->duration(5000)
->send();
$this->dispatch('loadData', $palletNumber, $plantId);
$this->form->fill([
'serial_number' => null,
'plant_id' => $plantId,
'pallet_number' => $palletNumber,
'pending_pallet_list' => $pendingPallet,
'Sno_quantity' => $count,
'created_by' => $operatorName,
'scanned_by' => $operatorName,
]);
return;
}
$locatorExist = PanelPalletValidation::where('plant_id', $plantId)
->where('serial_number', $serialNumber)
->where('locator_number', '!=', '')
->where('locator_number', '!=', null)
->first();
if ($locatorExist && $locatorExist->locator_number)
{
Notification::make()
->title("Scanned serial number exist in locator number '$locatorExist->locator_number'.<br>Scan the valid exist serial number to remove!")
->danger()
->duration(5000)
->send();
$this->dispatch('loadData', $palletNumber, $plantId);
$this->form->fill([
'serial_number' => null,
'plant_id' => $plantId,
'pallet_number' => $palletNumber,
'pending_pallet_list' => $pendingPallet,
'Sno_quantity' => $count,
'created_by' => $operatorName,
'scanned_by' => $operatorName,
]);
return;
}
$deleted = PanelPalletValidation::where('plant_id', $plantId)
->where('pallet_number', $palletNumber)
->where('serial_number', $serialNumber)
->forceDelete();
if ($deleted)
{
// Notification::make()
// ->title("Scanned serial number '$serialNumber' successfully removed from pallet table!<br>Scan the next exist serial number to remove...")
// ->success()
// ->duration(600)
// ->send();
$this->snoCount = PanelPalletValidation::where('plant_id', $plantId)
->where('pallet_number', $palletNumber)
->count();
$this->form->fill([
'plant_id' => $plantId,
'pallet_number' => $palletNumber,
'removeSno_number' => null,
'pending_pallet_list' => $this->pendingPallet,
'Sno_quantity' => $this->snoCount,
'created_by' => $operatorName,
'scanned_by' => $operatorName,
]);
$this->dispatch('loadData', $palletNumber, $plantId);
}
else
{
Notification::make()
->title("Failed to remove scanned serial number '$serialNumber' from pallet table!")
->danger()
->duration(5000)
->send();
$this->dispatch('loadData', $palletNumber, $plantId);
$this->form->fill([
'serial_number' => null,
'plant_id' => $plantId,
'pallet_number' => $palletNumber,
'pending_pallet_list' => $pendingPallet,
'Sno_quantity' => $count,
'created_by' => $operatorName,
'scanned_by' => $operatorName,
]);
}
//$this->dispatch('removeSno', $serialNumber, $palletNumber, $plantId);
}
public function processPalletNo()
{
$plantId = $this->form->getState()['plant_id'];
$plantId = trim($plantId) ?? null;
$pendingPallet = $this->form->getState()['pending_pallet_list'];
$palletNumber = trim($this->form->getState()['pallet_number']) ?? null;
$palletNumber = trim($palletNumber) ?? null;
$serialNumber = trim($this->form->getState()['serial_number']) ?? null;
$serialNumber = trim($serialNumber) ?? null;
$user = Filament::auth()->user();
$operatorName = $user->name;
//$this->dispatch('loadData', $palletNumber, $plantId);
$this->form->fill([
'serial_number' => null,
'plant_id' => $plantId,
'pallet_number' => $palletNumber,
'pending_pallet_list' => $pendingPallet,
'Sno_quantity' => 0,
'created_by' => $operatorName,
'scanned_by' => $operatorName,
]);
if (!$palletNumber)
{
Notification::make()
->title('Pallet number is required.')
->danger()
->duration(5000)
->send();
$this->dispatch('loadData', '', $plantId);
$this->form->fill([
'serial_number' => null,
'plant_id' => $plantId,
'pallet_number' => $palletNumber,
'pending_pallet_list' => $pendingPallet,
'Sno_quantity' => 0,
'created_by' => $operatorName,
'scanned_by' => $operatorName,
]);
return;
}
if (strlen($palletNumber) < 10)
{
Notification::make()
->title("Pallet number '$palletNumber' must be at least 10 digits.")
->danger()
->duration(5000)
->send();
$this->dispatch('loadLocator' ,'',$plantId);
$this->form->fill([
'serial_number' => null,
'plant_id' => $plantId,
'pallet_number' => $palletNumber,
'pending_pallet_list' => $pendingPallet,
'Sno_quantity' => 0,
'created_by' => $operatorName,
'scanned_by' => $operatorName,
]);
return;
}
$count = PanelPalletValidation::where('plant_id', $plantId)
->where('pallet_number', $palletNumber)
->count('pallet_number');
$palletNotCompleted = PanelPalletValidation::where('plant_id', $plantId)
->where('pallet_number', $palletNumber)
->where('pallet_status', '=','')
->orWhere('pallet_status', '=',null)
->first();
if (!$palletNotCompleted)
{
Notification::make()
->title("Already completed for pallet number $palletNumber!")
->danger()
->duration(5000)
->send();
$this->dispatch('loadData', $palletNumber, $plantId);
$this->form->fill([
'serial_number' => null,
'plant_id' => $plantId,
'pallet_number' => $palletNumber,
'pending_pallet_list' => $pendingPallet,
'Sno_quantity' => $count,
'created_by' => $operatorName,
'scanned_by' => $operatorName,
]);
return;
}
$this->form->fill([
'serial_number' => null,
'plant_id' => $plantId,
'pallet_number' => $palletNumber,
'pending_pallet_list' => $pendingPallet,
'Sno_quantity' => $count,
'created_by' => $operatorName,
'scanned_by' => $operatorName,
]);
$this->dispatch('loadData', $palletNumber, $plantId);
}
public function getFormActions(): array
{
return [];
}
}

View File

@@ -0,0 +1,22 @@
<?php
namespace App\Filament\Resources\PanelPalletValidationResource\Pages;
use App\Filament\Resources\PanelPalletValidationResource;
use Filament\Actions;
use Filament\Resources\Pages\EditRecord;
class EditPanelPalletValidation extends EditRecord
{
protected static string $resource = PanelPalletValidationResource::class;
protected function getHeaderActions(): array
{
return [
Actions\ViewAction::make(),
Actions\DeleteAction::make(),
Actions\ForceDeleteAction::make(),
Actions\RestoreAction::make(),
];
}
}

View File

@@ -0,0 +1,19 @@
<?php
namespace App\Filament\Resources\PanelPalletValidationResource\Pages;
use App\Filament\Resources\PanelPalletValidationResource;
use Filament\Actions;
use Filament\Resources\Pages\ListRecords;
class ListPanelPalletValidations extends ListRecords
{
protected static string $resource = PanelPalletValidationResource::class;
protected function getHeaderActions(): array
{
return [
Actions\CreateAction::make(),
];
}
}

View File

@@ -0,0 +1,19 @@
<?php
namespace App\Filament\Resources\PanelPalletValidationResource\Pages;
use App\Filament\Resources\PanelPalletValidationResource;
use Filament\Actions;
use Filament\Resources\Pages\ViewRecord;
class ViewPanelPalletValidation extends ViewRecord
{
protected static string $resource = PanelPalletValidationResource::class;
protected function getHeaderActions(): array
{
return [
Actions\EditAction::make(),
];
}
}