ranjith-dev #1566

Merged
jothi merged 5 commits from ranjith-dev into master 2026-11-30 08:56:03 +00:00
11 changed files with 1636 additions and 0 deletions

View File

@@ -0,0 +1,69 @@
<?php
namespace App\Filament\Exports;
use App\Models\PanelPalletValidation;
use Filament\Actions\Exports\ExportColumn;
use Filament\Actions\Exports\Exporter;
use Filament\Actions\Exports\Models\Export;
class PanelPalletValidationExporter extends Exporter
{
protected static ?string $model = PanelPalletValidation::class;
static $rowNumber = 0;
public static function getColumns(): array
{
return [
ExportColumn::make('no')
->label('NO')
->state(function ($record) use (&$rowNumber) {
// Increment and return the row number
return ++$rowNumber;
}),
ExportColumn::make('plant.name')
->label('PLANT'),
ExportColumn::make('item.code')
->label('ITEM'),
ExportColumn::make('pallet_number')
->label('PALLET NUMBER'),
ExportColumn::make('serial_number')
->label('SERIAL NUMBER'),
ExportColumn::make('panel_box_supplier')
->label('PANEL BOX SUPPLIER'),
ExportColumn::make('panel_box_code')
->label('PANEL BOX CODE'),
ExportColumn::make('panel_box_serial_number')
->label('PANEL BOX SERIAL NUMBER'),
ExportColumn::make('pallet_status')
->label('PALLET STATUS'),
ExportColumn::make('created_at')
->label('CREATED AT'),
ExportColumn::make('updated_at')
->label('UPDATED AT'),
ExportColumn::make('scanned_at')
->label('SCANNED AT'),
ExportColumn::make('created_by')
->label('CREATED BY'),
ExportColumn::make('updated_by')
->label('UPDATED BY'),
ExportColumn::make('scanned_by')
->label('SCANNED BY'),
ExportColumn::make('deleted_at')
->label('DELETED AT')
->enabledByDefault(false),
];
}
public static function getCompletedNotificationBody(Export $export): string
{
$body = 'Your panel pallet validation export has completed and ' . number_format($export->successful_rows) . ' ' . str('row')->plural($export->successful_rows) . ' exported.';
if ($failedRowsCount = $export->getFailedRowsCount()) {
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to export.';
}
return $body;
}
}

View File

@@ -0,0 +1,59 @@
<?php
namespace App\Filament\Imports;
use App\Models\PanelPalletValidation;
use Filament\Actions\Imports\ImportColumn;
use Filament\Actions\Imports\Importer;
use Filament\Actions\Imports\Models\Import;
class PanelPalletValidationImporter extends Importer
{
protected static ?string $model = PanelPalletValidation::class;
public static function getColumns(): array
{
return [
ImportColumn::make('plant')
->requiredMapping()
->relationship()
->rules(['required']),
ImportColumn::make('item')
->requiredMapping()
->relationship()
->rules(['required']),
ImportColumn::make('pallet_number'),
ImportColumn::make('serial_number'),
ImportColumn::make('panel_box_supplier'),
ImportColumn::make('panel_box_code'),
ImportColumn::make('panel_box_serial_number'),
ImportColumn::make('pallet_status'),
ImportColumn::make('scanned_at')
->rules(['datetime']),
ImportColumn::make('created_by'),
ImportColumn::make('scanned_by'),
ImportColumn::make('updated_by'),
];
}
public function resolveRecord(): ?PanelPalletValidation
{
// return PanelPalletValidation::firstOrNew([
// // Update existing records, matching them by `$this->data['column_name']`
// 'email' => $this->data['email'],
// ]);
return new PanelPalletValidation();
}
public static function getCompletedNotificationBody(Import $import): string
{
$body = 'Your panel pallet validation import has completed and ' . number_format($import->successful_rows) . ' ' . str('row')->plural($import->successful_rows) . ' imported.';
if ($failedRowsCount = $import->getFailedRowsCount()) {
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to import.';
}
return $body;
}
}

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(),
];
}
}

View File

@@ -0,0 +1,58 @@
<?php
namespace App\Livewire;
use App\Models\PanelPalletValidation;
use Livewire\Component;
class PanelPalletDataTable 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 = PanelPalletValidation::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,
'panel_box_supplier' => $record->panel_box_supplier,
'panel_box_code' => $record->panel_box_code,
'panel_box_serial_number' => $record->panel_box_serial_number,
'scanned_at' => $record->scanned_at,
'scanned_by' => $record->scanned_by ?? '',
];
})
->toArray();
}
public function render()
{
return view('livewire.panel-pallet-data-table');
}
}

View File

@@ -0,0 +1,106 @@
<?php
namespace App\Policies;
use Illuminate\Auth\Access\Response;
use App\Models\PanelPalletValidation;
use App\Models\User;
class PanelPalletValidationPolicy
{
/**
* Determine whether the user can view any models.
*/
public function viewAny(User $user): bool
{
return $user->checkPermissionTo('view-any PanelPalletValidation');
}
/**
* Determine whether the user can view the model.
*/
public function view(User $user, PanelPalletValidation $panelpalletvalidation): bool
{
return $user->checkPermissionTo('view PanelPalletValidation');
}
/**
* Determine whether the user can create models.
*/
public function create(User $user): bool
{
return $user->checkPermissionTo('create PanelPalletValidation');
}
/**
* Determine whether the user can update the model.
*/
public function update(User $user, PanelPalletValidation $panelpalletvalidation): bool
{
return $user->checkPermissionTo('update PanelPalletValidation');
}
/**
* Determine whether the user can delete the model.
*/
public function delete(User $user, PanelPalletValidation $panelpalletvalidation): bool
{
return $user->checkPermissionTo('delete PanelPalletValidation');
}
/**
* Determine whether the user can delete any models.
*/
public function deleteAny(User $user): bool
{
return $user->checkPermissionTo('delete-any PanelPalletValidation');
}
/**
* Determine whether the user can restore the model.
*/
public function restore(User $user, PanelPalletValidation $panelpalletvalidation): bool
{
return $user->checkPermissionTo('restore PanelPalletValidation');
}
/**
* Determine whether the user can restore any models.
*/
public function restoreAny(User $user): bool
{
return $user->checkPermissionTo('restore-any PanelPalletValidation');
}
/**
* Determine whether the user can replicate the model.
*/
public function replicate(User $user, PanelPalletValidation $panelpalletvalidation): bool
{
return $user->checkPermissionTo('replicate PanelPalletValidation');
}
/**
* Determine whether the user can reorder the models.
*/
public function reorder(User $user): bool
{
return $user->checkPermissionTo('reorder PanelPalletValidation');
}
/**
* Determine whether the user can permanently delete the model.
*/
public function forceDelete(User $user, PanelPalletValidation $panelpalletvalidation): bool
{
return $user->checkPermissionTo('force-delete PanelPalletValidation');
}
/**
* Determine whether the user can permanently delete any models.
*/
public function forceDeleteAny(User $user): bool
{
return $user->checkPermissionTo('force-delete-any PanelPalletValidation');
}
}

View File

@@ -0,0 +1,32 @@
<x-filament::page>
<div class="filament-form space-y-6">
{{ $this->form }}
</div>
<div class="bg-white shadow rounded-xl p-4">
<livewire:panel-pallet-data-table />
</div>
<div class="filament-actions mt-6">
<x-filament::actions>
@foreach ($this->getFormActions() as $action)
{{ $action }}
@endforeach
</x-filament::actions>
</div>
@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>

View File

@@ -0,0 +1,46 @@
<div class="p-4">
<h2 class="text-lg font-bold mb-4 text-gray-700 uppercase tracking-wider">
PANEL 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">Panel Box Supplier</th>
<th class="border px-4 py-2">Panel Box Code</th>
<th class="border px-4 py-2">Panel Box 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 whitespace-nowrap">{{ $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">{{ $record['panel_box_supplier'] ?? '-' }}</td>
<td class="border px-4 py-2">{{ $record['panel_box_code'] ?? '-' }}</td>
<td class="border px-4 py-2">{{ $record['panel_box_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 Panel pallet records found.
</td>
</tr>
@endforelse
</tbody>
</table>
</div>
</div>