diff --git a/app/Filament/Resources/ReworkLocatorInvoiceValidationResource.php b/app/Filament/Resources/ReworkLocatorInvoiceValidationResource.php new file mode 100644 index 000000000..ab4c167a7 --- /dev/null +++ b/app/Filament/Resources/ReworkLocatorInvoiceValidationResource.php @@ -0,0 +1,365 @@ +schema([ + Section::make('') + ->schema([ + Forms\Components\Select::make('plant_id') + ->label('Plant') + ->reactive() + ->relationship('plant', 'name') + ->disabled(fn (Get $get) => $get('rework_type')) + ->required() + ->afterStateUpdated(function ($state, callable $set, callable $get) { + $plantId = $get('plant_id'); + if ($plantId) + { + $set('plant', $plantId); + $set('invoice_number', null); + $set('scan_pallet_no', null); + $set('scan_serial_no', null); + $set('rework_type', null); + } + else + { + $set('plant', null); + $set('invoice_number', null); + $set('scan_pallet_no', null); + $set('scan_serial_no', null); + $set('rework_type', null); + } + }), + Forms\Components\Hidden::make('plant') + ->reactive(), + Forms\Components\TextInput::make('invoice_number') + ->label('Scan Invoice No') + ->required( fn ($get) => $get('rework_type') == 'invoice') + ->readOnly(fn (callable $get) => (!$get('plant') || $get('rework_type') != 'invoice' || $get('scan_pallet_no') || $get('scan_serial_no'))) + // ->readOnly(fn ($get) => $get('rework_type') == 'pallet') + ->reactive() + ->extraAttributes([ + 'wire:keydown.enter' => 'processInvoiceRework($event.target.value)', + ]), + Forms\Components\TextInput::make('scan_pallet_no') + ->label('Scan Pallet No') + ->required( fn ($get) => $get('rework_type') == 'pallet') + ->readOnly(fn ($get) => $get('rework_type') == 'invoice') + ->reactive() + ->readOnly(fn (callable $get) => (!$get('plant') || !$get('rework_type') || ($get('rework_type') == 'invoice' && !$get('invoice_number')) || $get('scan_serial_no'))) + ->extraAttributes([ + 'wire:keydown.enter' => 'processPalletno($event.target.value)', + ]), + Forms\Components\TextInput::make('scan_serial_no') + ->label('Scan Serial No') + ->reactive() + ->readOnly(fn (callable $get) => (!$get('plant') || !$get('rework_type') || ($get('rework_type') == 'invoice' && !$get('invoice_number')) || ($get('rework_type') == 'invoice' && $get('scan_pallet_no')) || ($get('rework_type') == 'pallet' && !$get('scan_pallet_no')))) + ->extraAttributes([ + 'wire:keydown.enter' => 'processSno($event.target.value)', + ]), + Forms\Components\Radio::make('rework_type') + ->label('Rework Type') + ->options([ + 'invoice' => 'Invoice', + 'pallet' => 'Pallet', + ]) + ->reactive() + ->required() + ->disabled(fn (Get $get) => ($get('invoice_number') || $get('scan_pallet_no') || $get('scan_serial_no'))) + ->hidden(fn (callable $get) => !$get('plant')) + ->inline() + ->inlineLabel(false) + // ->default('invoice') + ->afterStateUpdated(function ($state, callable $set) { + if ($state == 'pallet') { + $set('reworkType', $state); + $set('invoice_number', null); + $set('scan_pallet_no', null); + $set('scan_serial_no', null); + } elseif ($state == 'invoice') { + $set('reworkType', $state); + $set('invoice_number', null); + $set('scan_pallet_no', null); + $set('scan_serial_no', null); + } + else { + $set('reworkType', null); + $set('invoice_number', null); + $set('scan_pallet_no', null); + $set('scan_serial_no', null); + } + }), + Forms\Components\Hidden::make('reworkType') + ->reactive(), + + ToggleButtons::make('update_invoice') + ->label('Rework entire invoice?') + ->boolean() + ->grouped() + ->reactive() + ->hidden(fn (callable $get) => (!$get('plant') || $get('rework_type') != 'invoice' || !$get('invoice_number') || $get('update_invoice') == '0' || $get('scan_pallet_no') || $get('scan_serial_no'))) + ->afterStateUpdated(function ($state, callable $set, callable $get, $livewire) { + $plantId = $get('plant'); + + $invoiceNumber = $get('invoice_number'); + + $rows = LocatorInvoiceValidation::where('invoice_number', $invoiceNumber) + ->where('plant_id', $plantId) + ->get(); + + $notCompletedCount = LocatorInvoiceValidation::where('invoice_number', $invoiceNumber) + ->where('plant_id', $plantId) + ->where(function($query) { + $query->whereNull('scanned_status') + ->orWhere('scanned_status', ''); + }) + ->count(); + + $isScanningComplete = true; + foreach ($rows as $row) + { + if ($row->scanned_status !== 'Scanned') { + $isScanningComplete = false; + break; + } + } + + if (!$isScanningComplete) + { + Notification::make() + ->title("Scanned invoice number: '$invoiceNumber' does not completed the scanning process!
Has '$notCompletedCount' pending serial number to scan!
Please, scan the valid completed invoice number to proceed...") + ->danger() + ->send(); + return; + } + }), + + ToggleButtons::make('update_pallet') + ->label('Rework entire pallet?') + ->boolean() + ->grouped() + ->reactive() + ->hidden(fn (callable $get) => (!$get('plant') || $get('rework_type') != 'pallet' || $get('update_pallet') == '0' || !$get('scan_pallet_no') || $get('scan_serial_no'))) + ->afterStateUpdated(function ($state, callable $set, callable $get, $livewire) { + $plantId = $get('plant'); + + $invoiceNumber = $get('invoice_number'); + + $rows = LocatorInvoiceValidation::where('invoice_number', $invoiceNumber) + ->where('plant_id', $plantId) + ->get(); + + $notCompletedCount = LocatorInvoiceValidation::where('invoice_number', $invoiceNumber) + ->where('plant_id', $plantId) + ->where(function($query) { + $query->whereNull('scanned_status') + ->orWhere('scanned_status', ''); + }) + ->count(); + + $isScanningComplete = true; + foreach ($rows as $row) + { + if ($row->scanned_status !== 'Scanned') { + $isScanningComplete = false; + break; + } + } + + if (!$isScanningComplete) + { + Notification::make() + ->title("Scanned invoice number: '$invoiceNumber' does not completed the scanning process!
Has '$notCompletedCount' pending serial number to scan!
Please, scan the valid completed invoice number to proceed...") + ->danger() + ->send(); + return; + } + }), + Forms\Components\Hidden::make('created_by') + ->default(Filament::auth()->user()?->name), + Forms\Components\Hidden::make('scanned_by') + ->default(Filament::auth()->user()?->name), + Forms\Components\TextInput::make('id') + ->hidden() + ->readOnly(), + ]) + ->columns(5) + ]); + } + + 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') + ->sortable(), + Tables\Columns\TextColumn::make('invoice_number') + ->label('Invoice Number') + ->alignCenter() + ->sortable(), + Tables\Columns\TextColumn::make('serial_number') + ->label('Serial Number') + ->alignCenter() + ->sortable(), + Tables\Columns\TextColumn::make('pallet_number') + ->label('Pallet Number') + ->alignCenter() + ->sortable(), + Tables\Columns\TextColumn::make('locator_number') + ->label('Locator Number') + ->alignCenter() + ->sortable(), + Tables\Columns\TextColumn::make('scanned_status') + ->label('Scanned Status') + ->alignCenter() + ->sortable(), + Tables\Columns\TextColumn::make('upload_status') + ->label('Upload Status') + ->alignCenter() + ->sortable(), + Tables\Columns\TextColumn::make('created_by') + ->label('Created By') + ->alignCenter() + ->sortable(), + Tables\Columns\TextColumn::make('created_at') + ->label('Created At') + ->alignCenter() + ->dateTime() + ->sortable(), + Tables\Columns\TextColumn::make('updated_by') + ->label('Updated By') + ->alignCenter() + ->sortable() + ->toggleable(isToggledHiddenByDefault: true), + Tables\Columns\TextColumn::make('updated_at') + ->label('Updated At') + ->alignCenter() + ->dateTime() + ->sortable() + ->toggleable(isToggledHiddenByDefault: true), + Tables\Columns\TextColumn::make('scanned_by') + ->label('Scanned By') + ->alignCenter() + ->sortable(), + Tables\Columns\TextColumn::make('scanned_at') + ->label('Scanned At') + ->alignCenter() + ->dateTime() + ->sortable(), + Tables\Columns\TextColumn::make('reworked_by') + ->label('Reworked By') + ->alignCenter() + ->sortable(), + Tables\Columns\TextColumn::make('reworked_at') + ->label('Reworked At') + ->alignCenter() + ->dateTime() + ->sortable(), + Tables\Columns\TextColumn::make('deleted_at') + ->label('Deleted At') + ->alignCenter() + ->dateTime() + ->sortable() + ->toggleable(isToggledHiddenByDefault: true), + ]) + ->headerActions([ + ImportAction::make() + ->importer(ReworkLocatorInvoiceValidationImporter::class) + ->visible(function() { + return Filament::auth()->user()->can('view import rework invoice validation'); + }), + ExportAction::make() + ->exporter(ReworkLocatorInvoiceValidationExporter::class) + ->visible(function() { + return Filament::auth()->user()->can('view export rework invoice validation'); + }), + ]) + ->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(), + ]), + ]); + } + + public static function getRelations(): array + { + return [ + // + ]; + } + + public static function getPages(): array + { + return [ + 'index' => Pages\ListReworkLocatorInvoiceValidations::route('/'), + 'create' => Pages\CreateReworkLocatorInvoiceValidation::route('/create'), + 'view' => Pages\ViewReworkLocatorInvoiceValidation::route('/{record}'), + 'edit' => Pages\EditReworkLocatorInvoiceValidation::route('/{record}/edit'), + ]; + } + public static function getNavigationLabel(): string + { + return 'Rework Invoice / Pallet'; + } + + public static function getEloquentQuery(): Builder + { + return parent::getEloquentQuery() + ->withoutGlobalScopes([ + SoftDeletingScope::class, + ]); + } +} diff --git a/app/Filament/Resources/ReworkLocatorInvoiceValidationResource/Pages/CreateReworkLocatorInvoiceValidation.php b/app/Filament/Resources/ReworkLocatorInvoiceValidationResource/Pages/CreateReworkLocatorInvoiceValidation.php new file mode 100644 index 000000000..4620dc204 --- /dev/null +++ b/app/Filament/Resources/ReworkLocatorInvoiceValidationResource/Pages/CreateReworkLocatorInvoiceValidation.php @@ -0,0 +1,1448 @@ +form->getState()['plant']; + + $this->pId = $plantId; + + $invoiceNo = trim($this->form->getState()['invoice_number']); + $this->invoiceNo = $invoiceNo; + + $palletNo = trim($this->form->getState()['scan_pallet_no']); + $this->palletNo = $palletNo; + + $serialNo = trim($this->form->getState()['scan_serial_no']); + $this->serialNo = $serialNo; + + $operatorName = Filament::auth()->user()->name; + + $reworkType = $this->form->getState()['reworkType'] ?? null; + + $updateInvoiceStatus = $this->form->getState()['update_invoice'] ?? null; + + // $updatePalletStatus = $this->form->getState()['update_pallet'] ?? null; + + $InvoiceSerialNumbers = []; + + if ($reworkType == 'invoice') + { + if ($invoiceNo == '' || $invoiceNo == null) + { + Notification::make() + ->title("Invalid: Invoice Number") + ->body("Invoice number can't be empty!") + ->danger() + ->send(); + $this->dispatch('loadData', '', '', $plantId, $reworkType); + // $snoCount = LocatorInvoiceValidation::where('plant_id', $plantId)->where('invoice_number', $invoiceNo)->count(); + $this->form->fill([ + 'plant_id' => $plantId, + 'plant' => $plantId, + 'invoice_number' => null, + 'scan_pallet_no' => null, + 'scan_serial_no' => null, + 'rework_type' => $reworkType, + 'reworkType' => $reworkType, + 'update_invoice' => 0, + 'update_pallet' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + + $InvoiceSerialNumbers = LocatorInvoiceValidation::where('plant_id', $plantId)->where('invoice_number', $invoiceNo)->first(); + + if (!$InvoiceSerialNumbers) + { + Notification::make() + ->title('Invoice Not Found') + ->body("Invoice number '$invoiceNo' doesn't exist in invoice table!

Scan the valid exist 'Invoice Number' to proceed..!") + ->danger() + ->send(); + + $this->dispatch('loadData', '', '', $plantId, $reworkType); + $this->form->fill([ + 'plant_id' => $plantId, + 'plant' => $plantId, + 'invoice_number' => null, + 'scan_pallet_no' => null, + 'scan_serial_no' => null, + 'rework_type' => $reworkType, + 'reworkType' => $reworkType, + 'update_invoice' => 0, + 'update_pallet' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + + $notCompletedCount = LocatorInvoiceValidation::where('plant_id', $plantId)->where('invoice_number', $invoiceNo) + ->where(function($query) { + $query->whereNull('scanned_status') + ->orWhere('scanned_status', ''); + }) + ->count(); + + $records = LocatorInvoiceValidation::where('plant_id', $plantId)->where('invoice_number', $invoiceNo)->get(); + + $allScanned = true; + foreach ($records as $record) + { + if (($record->scanned_status == null) || trim($record->scanned_status) == '') { + $allScanned = false; + break; + } + } + + if (count($records) > 0 && $allScanned) + { + if (strlen($palletNo) > 0 && strlen($palletNo) < 10) + { + Notification::make() + ->title("Invalid: Pallet Number") + ->body("Pallet number '$palletNo' must be at least 10 digits.") + ->danger() + ->send(); + $this->dispatch('loadData', $invoiceNo, '', $plantId, $reworkType); + $this->form->fill([ + 'plant_id' => $plantId, + 'plant' => $plantId, + 'invoice_number' => $invoiceNo, + 'scan_pallet_no' => null, + 'scan_serial_no' => null, + 'rework_type' => $reworkType, + 'reworkType' => $reworkType, + 'update_invoice' => 0, + 'update_pallet' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + else if (strlen($serialNo) > 0 && strlen($serialNo) < 13) + { + Notification::make() + ->title("Invalid: Serial Number") + ->body("Serial number '$serialNo' must be at least 13 digits.") + ->danger() + ->send(); + $this->dispatch('loadData', $invoiceNo, '', $plantId, $reworkType); + $this->form->fill([ + 'plant_id' => $plantId, + 'plant' => $plantId, + 'invoice_number' => $invoiceNo, + 'scan_pallet_no' => null, + 'scan_serial_no' => null, + 'rework_type' => $reworkType, + 'reworkType' => $reworkType, + 'update_invoice' => 0, + 'update_pallet' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + + if ($updateInvoiceStatus == 1) + { + foreach ($records as $row) + { + ReworkLocatorInvoiceValidation::create([ + 'plant_id' => $row->plant_id, + 'invoice_number' => $row->invoice_number, + 'serial_number' => $row->serial_number, + 'pallet_number' => $row->pallet_number, + 'locator_number' => $row->locator_number, + 'scanned_status' => $row->scanned_status, + 'upload_status' => $row->upload_status, + 'created_by' => $row->created_by, + 'scanned_by' => $row->scanned_by, + 'updated_by' => $row->updated_by, + 'reworked_by' => $operatorName, + 'created_at' => $row->created_at, + 'scanned_at' => $row->scanned_at, + 'updated_at' => $row->updated_at, + 'reworked_at' => now(), + ]); + + $row->forceDelete(); // Delete the row from the original table + } + + Notification::make() + ->title('Completed: Rework Invoice') + ->body("Scanned invoice number '$invoiceNo' successfully moved into rework invoice table.

Please, scan the next completed invoice number to proceed..!") + ->success() + ->send(); + + $this->dispatch('loadData', '', '', $plantId, $reworkType); + $this->form->fill([ + 'plant_id' => $plantId, + 'plant' => $plantId, + 'invoice_number' => null, + 'scan_pallet_no' => null, + 'scan_serial_no' => null, + 'rework_type' => $reworkType, + 'reworkType' => $reworkType, + 'update_invoice' => 0, + 'update_pallet' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + } + else + { + Notification::make() + ->title('Completed: Invoice Found') + ->body("Press 'Yes' and Press 'Enter' in Scan Invoice No to do rework for entire invoice.

Press 'No' to do rework against 'Pallet or Serial Number'..!") + ->info() + ->send(); + + $this->dispatch('loadData', $invoiceNo, '', $plantId, $reworkType); + $this->form->fill([ + 'plant_id' => $plantId, + 'plant' => $plantId, + 'invoice_number' => $invoiceNo, + 'scan_pallet_no' => null, + 'scan_serial_no' => null, + 'rework_type' => $reworkType, + 'reworkType' => $reworkType, + 'update_invoice' => null, + 'update_pallet' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + } + return; + } + else + { + Notification::make() + ->title('Invoice Not Completed') + ->body("Scanned invoice number '$invoiceNo' doesn't completed the scanning process!

Has '$notCompletedCount' pending serial number to scan!

Please, scan the valid completed invoice number to proceed..!") + ->danger() + ->send(); + + $this->dispatch('loadData', '', '', $plantId, $reworkType); + $this->form->fill([ + 'plant_id' => $plantId, + 'plant' => $plantId, + 'invoice_number' => null, + 'scan_pallet_no' => null, + 'scan_serial_no' => null, + 'rework_type' => $reworkType, + 'reworkType' => $reworkType, + 'update_invoice' => 0, + 'update_pallet' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + } + else if ($reworkType == 'pallet') + { + Notification::make() + ->title("Choosed: Pallet Rework Type") + ->body("Scan valid pallet number to proceed..!") + ->danger() + ->send(); + return; + } + else + { + Notification::make() + ->title("Rework Type Not Found") + ->danger() + ->send(); + $this->dispatch('loadData', '', '', $plantId, $reworkType); + $this->form->fill([ + 'plant_id' => $plantId, + 'plant' => $plantId, + 'invoice_number' => null, + 'scan_pallet_no' => null, + 'scan_serial_no' => null, + 'rework_type' => null, + 'reworkType' => null, + 'update_invoice' => 0, + 'update_pallet' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + } + + public function processPalletno($palletNo) + { + $plantId = $this->form->getState()['plant']; + + $this->pId = $plantId; + + $invoiceNo = trim($this->form->getState()['invoice_number']); + $this->invoiceNo = $invoiceNo; + + $palletNo = trim($this->form->getState()['scan_pallet_no']); + $this->palletNo = $palletNo; + + $serialNo = trim($this->form->getState()['scan_serial_no']); + $this->serialNo = $serialNo; + + $operatorName = Filament::auth()->user()->name; + + $reworkType = $this->form->getState()['reworkType'] ?? null; + + // $updateInvoiceStatus = $this->form->getState()['update_invoice'] ?? null; + + $updatePalletStatus = $this->form->getState()['update_pallet'] ?? null; + + $InvoiceSerialNumbers = []; + + $PalletSerialNumbers = []; + + if ($reworkType == 'invoice') + { + if ($invoiceNo == '' || $invoiceNo == null) + { + Notification::make() + ->title("Invalid: Invoice Number") + ->body("Invoice number can't be empty!") + ->danger() + ->send(); + $this->dispatch('loadData', '', '', $plantId, $reworkType); + // $snoCount = LocatorInvoiceValidation::where('plant_id', $plantId)->where('invoice_number', $invoiceNo)->count(); + $this->form->fill([ + 'plant_id' => $plantId, + 'plant' => $plantId, + 'invoice_number' => null, + 'scan_pallet_no' => null, + 'scan_serial_no' => null, + 'rework_type' => $reworkType, + 'reworkType' => $reworkType, + 'update_invoice' => 0, + 'update_pallet' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + + $InvoiceSerialNumbers = LocatorInvoiceValidation::where('plant_id', $plantId)->where('invoice_number', $invoiceNo)->first(); + + if (!$InvoiceSerialNumbers) + { + Notification::make() + ->title('Invoice Not Found') + ->body("Invoice number '$invoiceNo' doesn't exist in invoice table!

Scan the valid exist 'Invoice Number' to proceed..!") + ->danger() + ->send(); + + $this->dispatch('loadData', '', '', $plantId, $reworkType); + $this->form->fill([ + 'plant_id' => $plantId, + 'plant' => $plantId, + 'invoice_number' => null, + 'scan_pallet_no' => null, + 'scan_serial_no' => null, + 'rework_type' => $reworkType, + 'reworkType' => $reworkType, + 'update_invoice' => 0, + 'update_pallet' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + + $notCompletedCount = LocatorInvoiceValidation::where('plant_id', $plantId)->where('invoice_number', $invoiceNo) + ->where(function($query) { + $query->whereNull('scanned_status') + ->orWhere('scanned_status', ''); + }) + ->count(); + + $records = LocatorInvoiceValidation::where('plant_id', $plantId)->where('invoice_number', $invoiceNo)->get(); + + $allScanned = true; + foreach ($records as $record) + { + if (($record->scanned_status == null) || trim($record->scanned_status) == '') { + $allScanned = false; + break; + } + } + + if (count($records) > 0 && $allScanned) + { + if ($palletNo == '' || $palletNo == null) + { + Notification::make() + ->title("Invalid: Pallet Number") + ->body("Pallet number can't be empty!") + ->danger() + ->send(); + $this->dispatch('loadData', $invoiceNo, '', $plantId, $reworkType); + // $snoCount = LocatorInvoiceValidation::where('plant_id', $plantId)->where('invoice_number', $invoiceNo)->count(); + $this->form->fill([ + 'plant_id' => $plantId, + 'plant' => $plantId, + 'invoice_number' => $invoiceNo, + 'scan_pallet_no' => null, + 'scan_serial_no' => null, + 'rework_type' => $reworkType, + 'reworkType' => $reworkType, + 'update_invoice' => 0, + 'update_pallet' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + else if (strlen($palletNo) < 10) + { + Notification::make() + ->title("Invalid: Pallet Number") + ->body("Pallet number '$palletNo' must be at least 10 digits.") + ->danger() + ->send(); + $this->dispatch('loadData', $invoiceNo, '', $plantId, $reworkType); + $this->form->fill([ + 'plant_id' => $plantId, + 'plant' => $plantId, + 'invoice_number' => $invoiceNo, + 'scan_pallet_no' => null, + 'scan_serial_no' => null, + 'rework_type' => $reworkType, + 'reworkType' => $reworkType, + 'update_invoice' => 0, + 'update_pallet' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + + $InvoiceSerialNumbers = LocatorInvoiceValidation::where('plant_id', $plantId)->where('invoice_number', $invoiceNo)->where('pallet_number', $palletNo)->first(); + + if (!$InvoiceSerialNumbers) + { + Notification::make() + ->title('Pallet Not Found') + ->body("Pallet number '$palletNo' doesn't exist in scanned invoice number '$invoiceNo'!

Scan the valid exist 'Pallet Number' to proceed..!") + ->danger() + ->send(); + + $this->dispatch('loadData', $invoiceNo, '', $plantId, $reworkType); + $this->form->fill([ + 'plant_id' => $plantId, + 'plant' => $plantId, + 'invoice_number' => $invoiceNo, + 'scan_pallet_no' => null, + 'scan_serial_no' => null, + 'rework_type' => $reworkType, + 'reworkType' => $reworkType, + 'update_invoice' => 0, + 'update_pallet' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + + if (strlen($serialNo) > 0 && strlen($serialNo) < 13) + { + Notification::make() + ->title("Invalid: Serial Number") + ->body("Serial number '$serialNo' must be at least 13 digits.") + ->danger() + ->send(); + $this->dispatch('loadData', $invoiceNo, $palletNo, $plantId, $reworkType); + $this->form->fill([ + 'plant_id' => $plantId, + 'plant' => $plantId, + 'invoice_number' => $invoiceNo, + 'scan_pallet_no' => $palletNo, + 'scan_serial_no' => null, + 'rework_type' => $reworkType, + 'reworkType' => $reworkType, + 'update_invoice' => 0, + 'update_pallet' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + + foreach ($records as $row) + { + if ($row->pallet_number != null && $row->pallet_number != '' && $row->pallet_number == $palletNo) + { + ReworkLocatorInvoiceValidation::create([ + 'plant_id' => $row->plant_id, + 'invoice_number' => $row->invoice_number, + 'serial_number' => $row->serial_number, + 'pallet_number' => $row->pallet_number, + 'locator_number' => $row->locator_number, + 'scanned_status' => $row->scanned_status, + 'upload_status' => $row->upload_status, + 'created_by' => $row->created_by, + 'scanned_by' => $row->scanned_by, + 'updated_by' => $row->updated_by, + 'reworked_by' => $operatorName, + 'created_at' => $row->created_at, + 'scanned_at' => $row->scanned_at, + 'updated_at' => $row->updated_at, + 'reworked_at' => now(), + ]); + + $row->forceDelete(); // Delete the row from the original table + } + } + + Notification::make() + ->title('Completed: Rework Pallet from Invoice') + ->body("Scanned pallet number '$palletNo' successfully moved into rework invoice table from invoice number '$invoiceNo'.

Please, scan the next pallet number to proceed..!") + ->success() + ->send(); + + $InvoiceSerialNumbers = LocatorInvoiceValidation::where('plant_id', $plantId)->where('invoice_number', $invoiceNo)->first(); + + if (!$InvoiceSerialNumbers) + { + Notification::make() + ->title("All available serial numbers are successfully moved into rework invoice table from invoice number '$invoiceNo'.

Please, scan the next invoice number to proceed..!") + ->success() + ->send(); + + $this->dispatch('loadData', '', '', $plantId, $reworkType); + $this->form->fill([ + 'plant_id' => $plantId, + 'plant' => $plantId, + 'invoice_number' => null, + 'scan_pallet_no' => null, + 'scan_serial_no' => null, + 'rework_type' => $reworkType, + 'reworkType' => $reworkType, + 'update_invoice' => 0, + 'update_pallet' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + } + else + { + $this->dispatch('loadData', $invoiceNo, '', $plantId, $reworkType); + $this->form->fill([ + 'plant_id' => $plantId, + 'plant' => $plantId, + 'invoice_number' => $invoiceNo, + 'scan_pallet_no' => null, + 'scan_serial_no' => null, + 'rework_type' => $reworkType, + 'reworkType' => $reworkType, + 'update_invoice' => 0, + 'update_pallet' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + } + } + else + { + Notification::make() + ->title('Invoice Not Completed') + ->body("Scanned invoice number '$invoiceNo' doesn't completed the scanning process!

Has '$notCompletedCount' pending serial number to scan!

Please, scan the valid completed invoice number to proceed..!") + ->danger() + ->send(); + + $this->dispatch('loadData', '', '', $plantId, $reworkType); + $this->form->fill([ + 'plant_id' => $plantId, + 'plant' => $plantId, + 'invoice_number' => null, + 'scan_pallet_no' => null, + 'scan_serial_no' => null, + 'rework_type' => $reworkType, + 'reworkType' => $reworkType, + 'update_invoice' => 0, + 'update_pallet' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + } + else if ($reworkType == 'pallet') + { + if ($palletNo == '' || $palletNo == null) + { + Notification::make() + ->title("Invalid: Pallet Number") + ->body("Pallet number can't be empty!") + ->danger() + ->send(); + $this->dispatch('loadData', '', '', $plantId, $reworkType); + // $snoCount = LocatorInvoiceValidation::where('plant_id', $plantId)->where('invoice_number', $invoiceNo)->count(); + $this->form->fill([ + 'plant_id' => $plantId, + 'plant' => $plantId, + 'invoice_number' => null, + 'scan_pallet_no' => null, + 'scan_serial_no' => null, + 'rework_type' => $reworkType, + 'reworkType' => $reworkType, + 'update_invoice' => 0, + 'update_pallet' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + else if (strlen($palletNo) < 10) + { + Notification::make() + ->title("Invalid: Pallet Number") + ->body("Pallet number '$palletNo' must be at least 10 digits.") + ->danger() + ->send(); + $this->dispatch('loadData', '', '', $plantId, $reworkType); + $this->form->fill([ + 'plant_id' => $plantId, + 'plant' => $plantId, + 'invoice_number' => null, + 'scan_pallet_no' => null, + 'scan_serial_no' => null, + 'rework_type' => $reworkType, + 'reworkType' => $reworkType, + 'update_invoice' => 0, + 'update_pallet' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + + $PalletSerialNumbers = PalletValidation::where('plant_id', $plantId)->where('pallet_number', $palletNo)->first(); + + if (!$PalletSerialNumbers) + { + Notification::make() + ->title('Pallet Not Found') + ->body("Pallet number '$palletNo' doesn't exist in pallet table!

Scan the valid exist 'Pallet Number' to proceed..!") + ->danger() + ->send(); + + $this->dispatch('loadData', '', '', $plantId, $reworkType); + $this->form->fill([ + 'plant_id' => $plantId, + 'plant' => $plantId, + 'invoice_number' => null, + 'scan_pallet_no' => null, + 'scan_serial_no' => null, + 'rework_type' => $reworkType, + 'reworkType' => $reworkType, + 'update_invoice' => 0, + 'update_pallet' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + + $records = PalletValidation::where('plant_id', $plantId)->where('pallet_number', $palletNo)->get(); + + $allScanned = true; + foreach ($records as $record) + { + if (($record->pallet_status == null) || trim($record->pallet_status) == '') { + $allScanned = false; + break; + } + } + + if (count($records) > 0 && $allScanned) + { + $locatExist = ($PalletSerialNumbers->locator_number != null && $PalletSerialNumbers->locator_number != '') ? $PalletSerialNumbers->locator_number : ''; + if ($locatExist) + { + Notification::make() + ->title('Locator Pallet Found') + ->body("Scanned pallet number '$palletNo' exist in locator number '$locatExist'.

Remove scanned 'Pallet' from 'Locator' to proceed re-master packing..!") + ->danger() + ->send(); + + $this->dispatch('loadData', '', '', $plantId, $reworkType); + $this->form->fill([ + 'plant_id' => $plantId, + 'plant' => $plantId, + 'invoice_number' => null, + 'scan_pallet_no' => null, + 'scan_serial_no' => null, + 'rework_type' => $reworkType, + 'reworkType' => $reworkType, + 'update_invoice' => 0, + 'update_pallet' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + else + { + if (strlen($serialNo) > 0 && strlen($serialNo) < 13) + { + Notification::make() + ->title("Invalid: Serial Number") + ->body("Serial number '$serialNo' must be at least 13 digits.") + ->danger() + ->send(); + $this->dispatch('loadData', '', $palletNo, $plantId, $reworkType); + $this->form->fill([ + 'plant_id' => $plantId, + 'plant' => $plantId, + 'invoice_number' => null, + 'scan_pallet_no' => $palletNo, + 'scan_serial_no' => null, + 'rework_type' => $reworkType, + 'reworkType' => $reworkType, + 'update_invoice' => 0, + 'update_pallet' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + + if ($updatePalletStatus == 1) + { + foreach ($records as $row) + { + $row->forceDelete(); // Delete the row from the original table + } + + Notification::make() + ->title('Completed: Rework Pallet') + ->body("Scanned pallet number '$palletNo' successfully removed from pallet table.

Please, scan the next pallet number to re-master packing..!") + ->success() + ->send(); + + $this->dispatch('loadData', '', '', $plantId, $reworkType); + $this->form->fill([ + 'plant_id' => $plantId, + 'plant' => $plantId, + 'invoice_number' => null, + 'scan_pallet_no' => null, + 'scan_serial_no' => null, + 'rework_type' => $reworkType, + 'reworkType' => $reworkType, + 'update_invoice' => 0, + 'update_pallet' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + else + { + Notification::make() + ->title('Completed: Pallet Found') + ->body("Press 'Yes' and Press 'Enter' in Scan Pallet No to do re-master packing for entire pallet.

Press 'No' to do partial re-master packing against 'Serial Number'..!") + ->info() + ->send(); + + $this->dispatch('loadData', '', $palletNo, $plantId, $reworkType); + $this->form->fill([ + 'plant_id' => $plantId, + 'plant' => $plantId, + 'invoice_number' => null, + 'scan_pallet_no' => $palletNo, + 'scan_serial_no' => null, + 'rework_type' => $reworkType, + 'reworkType' => $reworkType, + 'update_invoice' => 0, + 'update_pallet' => null, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + } + } + else + { + Notification::make() + ->title('Pallet Not Completed') + ->body("Scanned pallet number '$palletNo' doesn't completed the master packing!

Please, scan the valid completed pallet number to proceed..!") + ->danger() + ->send(); + + $this->dispatch('loadData', '', '', $plantId, $reworkType); + $this->form->fill([ + 'plant_id' => $plantId, + 'plant' => $plantId, + 'invoice_number' => null, + 'scan_pallet_no' => null, + 'scan_serial_no' => null, + 'rework_type' => $reworkType, + 'reworkType' => $reworkType, + 'update_invoice' => 0, + 'update_pallet' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + } + else + { + Notification::make() + ->title("Rework Type Not Found") + ->danger() + ->send(); + $this->dispatch('loadData', '', '', $plantId, $reworkType); + $this->form->fill([ + 'plant_id' => $plantId, + 'plant' => $plantId, + 'invoice_number' => null, + 'scan_pallet_no' => null, + 'scan_serial_no' => null, + 'rework_type' => null, + 'reworkType' => null, + 'update_invoice' => 0, + 'update_pallet' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + } + + public function processSno($serialNo) + { + $plantId = $this->form->getState()['plant']; + + $this->pId = $plantId; + + $invoiceNo = trim($this->form->getState()['invoice_number']); + $this->invoiceNo = $invoiceNo; + + $palletNo = trim($this->form->getState()['scan_pallet_no']); + $this->palletNo = $palletNo; + + $serialNo = trim($this->form->getState()['scan_serial_no']); + $this->serialNo = $serialNo; + + $operatorName = Filament::auth()->user()->name; + + $reworkType = $this->form->getState()['reworkType'] ?? null; + + // $updateInvoiceStatus = $this->form->getState()['update_invoice'] ?? null; + + // $updatePalletStatus = $this->form->getState()['update_pallet'] ?? null; + + $PalletSerialNumbers = []; + + $InvoiceSerialNumbers = []; + + if ($reworkType == 'invoice') + { + if ($invoiceNo == '' || $invoiceNo == null) + { + Notification::make() + ->title("Invalid: Invoice Number") + ->body("Invoice number can't be empty!") + ->danger() + ->send(); + $this->dispatch('loadData', '', '', $plantId, $reworkType); + // $snoCount = LocatorInvoiceValidation::where('plant_id', $plantId)->where('invoice_number', $invoiceNo)->count(); + $this->form->fill([ + 'plant_id' => $plantId, + 'plant' => $plantId, + 'invoice_number' => null, + 'scan_pallet_no' => null, + 'scan_serial_no' => null, + 'rework_type' => $reworkType, + 'reworkType' => $reworkType, + 'update_invoice' => 0, + 'update_pallet' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + + $InvoiceSerialNumbers = LocatorInvoiceValidation::where('plant_id', $plantId)->where('invoice_number', $invoiceNo)->first(); + + if (!$InvoiceSerialNumbers) + { + Notification::make() + ->title('Invoice Not Found') + ->body("Invoice number '$invoiceNo' doesn't exist in invoice table!

Scan the valid exist 'Invoice Number' to proceed..!") + ->danger() + ->send(); + + $this->dispatch('loadData', '', '', $plantId, $reworkType); + $this->form->fill([ + 'plant_id' => $plantId, + 'plant' => $plantId, + 'invoice_number' => null, + 'scan_pallet_no' => null, + 'scan_serial_no' => null, + 'rework_type' => $reworkType, + 'reworkType' => $reworkType, + 'update_invoice' => 0, + 'update_pallet' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + + $notCompletedCount = LocatorInvoiceValidation::where('plant_id', $plantId)->where('invoice_number', $invoiceNo) + ->where(function($query) { + $query->whereNull('scanned_status') + ->orWhere('scanned_status', ''); + }) + ->count(); + + $records = LocatorInvoiceValidation::where('plant_id', $plantId)->where('invoice_number', $invoiceNo)->get(); + + $allScanned = true; + foreach ($records as $record) + { + if (($record->scanned_status == null) || trim($record->scanned_status) == '') { + $allScanned = false; + break; + } + } + + if (count($records) > 0 && $allScanned) + { + if (strlen($palletNo) > 0 && strlen($palletNo) < 10) + { + Notification::make() + ->title("Invalid: Pallet Number") + ->body("Pallet number '$palletNo' must be at least 10 digits.") + ->danger() + ->send(); + $this->dispatch('loadData', $invoiceNo, '', $plantId, $reworkType); + $this->form->fill([ + 'plant_id' => $plantId, + 'plant' => $plantId, + 'invoice_number' => $invoiceNo, + 'scan_pallet_no' => null, + 'scan_serial_no' => null, + 'rework_type' => $reworkType, + 'reworkType' => $reworkType, + 'update_invoice' => 0, + 'update_pallet' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + else if ($serialNo == '' || $serialNo == null) + { + Notification::make() + ->title("Invalid: Serial Number") + ->body("Serial number can't be empty!") + ->danger() + ->send(); + $this->dispatch('loadData', $invoiceNo, '', $plantId, $reworkType); + // $snoCount = LocatorInvoiceValidation::where('plant_id', $plantId)->where('invoice_number', $invoiceNo)->count(); + $this->form->fill([ + 'plant_id' => $plantId, + 'plant' => $plantId, + 'invoice_number' => $invoiceNo, + 'scan_pallet_no' => null, + 'scan_serial_no' => null, + 'rework_type' => $reworkType, + 'reworkType' => $reworkType, + 'update_invoice' => 0, + 'update_pallet' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + else if (strlen($serialNo) < 13) + { + Notification::make() + ->title("Invalid: Serial Number") + ->body("Serial number '$serialNo' must be at least 13 digits.") + ->danger() + ->send(); + $this->dispatch('loadData', $invoiceNo, '', $plantId, $reworkType); + $this->form->fill([ + 'plant_id' => $plantId, + 'plant' => $plantId, + 'invoice_number' => $invoiceNo, + 'scan_pallet_no' => null, + 'scan_serial_no' => null, + 'rework_type' => $reworkType, + 'reworkType' => $reworkType, + 'update_invoice' => 0, + 'update_pallet' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + + $InvoiceSerialNumbers = LocatorInvoiceValidation::where('plant_id', $plantId)->where('invoice_number', $invoiceNo)->where('serial_number', $serialNo)->first(); + + if (!$InvoiceSerialNumbers) + { + Notification::make() + ->title('Serial Not Found') + ->body("Serial number '$serialNo' doesn't exist in scanned invoice number '$invoiceNo'!

Scan the valid exist 'Serial Number' to proceed..!") + ->danger() + ->send(); + + $this->dispatch('loadData', $invoiceNo, '', $plantId, $reworkType); + $this->form->fill([ + 'plant_id' => $plantId, + 'plant' => $plantId, + 'invoice_number' => $invoiceNo, + 'scan_pallet_no' => null, + 'scan_serial_no' => null, + 'rework_type' => $reworkType, + 'reworkType' => $reworkType, + 'update_invoice' => 0, + 'update_pallet' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + + foreach ($records as $row) + { + if ($row->serial_number != null && $row->serial_number != '' && $row->serial_number == $serialNo) + { + ReworkLocatorInvoiceValidation::create([ + 'plant_id' => $row->plant_id, + 'invoice_number' => $row->invoice_number, + 'serial_number' => $row->serial_number, + 'pallet_number' => $row->pallet_number, + 'locator_number' => $row->locator_number, + 'scanned_status' => $row->scanned_status, + 'upload_status' => $row->upload_status, + 'created_by' => $row->created_by, + 'scanned_by' => $row->scanned_by, + 'updated_by' => $row->updated_by, + 'reworked_by' => $operatorName, + 'created_at' => $row->created_at, + 'scanned_at' => $row->scanned_at, + 'updated_at' => $row->updated_at, + 'reworked_at' => now(), + ]); + + $row->forceDelete(); // Delete the row from the original table + } + } + + Notification::make() + ->title('Completed: Rework Serial from Invoice') + ->body("Scanned serial number '$serialNo' successfully moved into rework invoice table from invoice number '$invoiceNo'.

Please, scan the next serial number to proceed..!") + ->success() + ->send(); + + $InvoiceSerialNumbers = LocatorInvoiceValidation::where('plant_id', $plantId)->where('invoice_number', $invoiceNo)->first(); + + if (!$InvoiceSerialNumbers) + { + Notification::make() + ->title("All available serial numbers are successfully moved into rework invoice table from invoice number '$invoiceNo'.

Please, scan the next invoice number to proceed..!") + ->success() + ->send(); + + $this->dispatch('loadData', '', '', $plantId, $reworkType); + $this->form->fill([ + 'plant_id' => $plantId, + 'plant' => $plantId, + 'invoice_number' => null, + 'scan_pallet_no' => null, + 'scan_serial_no' => null, + 'rework_type' => $reworkType, + 'reworkType' => $reworkType, + 'update_invoice' => 0, + 'update_pallet' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + } + else + { + $this->dispatch('loadData', $invoiceNo, '', $plantId, $reworkType); + $this->form->fill([ + 'plant_id' => $plantId, + 'plant' => $plantId, + 'invoice_number' => $invoiceNo, + 'scan_pallet_no' => null, + 'scan_serial_no' => null, + 'rework_type' => $reworkType, + 'reworkType' => $reworkType, + 'update_invoice' => 0, + 'update_pallet' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + } + } + else + { + Notification::make() + ->title('Invoice Not Completed') + ->body("Scanned invoice number '$invoiceNo' doesn't completed the scanning process!

Has '$notCompletedCount' pending serial number to scan!

Please, scan the valid completed invoice number to proceed..!") + ->danger() + ->send(); + + $this->dispatch('loadData', '', '', $plantId, $reworkType); + $this->form->fill([ + 'plant_id' => $plantId, + 'plant' => $plantId, + 'invoice_number' => null, + 'scan_pallet_no' => null, + 'scan_serial_no' => null, + 'rework_type' => $reworkType, + 'reworkType' => $reworkType, + 'update_invoice' => 0, + 'update_pallet' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + } + else if ($reworkType == 'pallet') + { + if ($palletNo == '' || $palletNo == null) + { + Notification::make() + ->title("Invalid: Pallet Number") + ->body("Pallet number can't be empty!") + ->danger() + ->send(); + $this->dispatch('loadData', '', '', $plantId, $reworkType); + // $snoCount = LocatorInvoiceValidation::where('plant_id', $plantId)->where('invoice_number', $invoiceNo)->count(); + $this->form->fill([ + 'plant_id' => $plantId, + 'plant' => $plantId, + 'invoice_number' => null, + 'scan_pallet_no' => null, + 'scan_serial_no' => null, + 'rework_type' => $reworkType, + 'reworkType' => $reworkType, + 'update_invoice' => 0, + 'update_pallet' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + else if (strlen($palletNo) < 10) + { + Notification::make() + ->title("Invalid: Pallet Number") + ->body("Pallet number '$palletNo' must be at least 10 digits.") + ->danger() + ->send(); + $this->dispatch('loadData', '', '', $plantId, $reworkType); + $this->form->fill([ + 'plant_id' => $plantId, + 'plant' => $plantId, + 'invoice_number' => null, + 'scan_pallet_no' => null, + 'scan_serial_no' => null, + 'rework_type' => $reworkType, + 'reworkType' => $reworkType, + 'update_invoice' => 0, + 'update_pallet' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + + $PalletSerialNumbers = PalletValidation::where('plant_id', $plantId)->where('pallet_number', $palletNo)->first(); + + if (!$PalletSerialNumbers) + { + Notification::make() + ->title('Pallet Not Found') + ->body("Pallet number '$palletNo' doesn't exist in pallet table!

Scan the valid exist 'Pallet Number' to proceed..!") + ->danger() + ->send(); + + $this->dispatch('loadData', '', '', $plantId, $reworkType); + $this->form->fill([ + 'plant_id' => $plantId, + 'plant' => $plantId, + 'invoice_number' => null, + 'scan_pallet_no' => null, + 'scan_serial_no' => null, + 'rework_type' => $reworkType, + 'reworkType' => $reworkType, + 'update_invoice' => 0, + 'update_pallet' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + + $records = PalletValidation::where('plant_id', $plantId)->where('pallet_number', $palletNo)->get(); + + $allScanned = true; + foreach ($records as $record) + { + if (($record->pallet_status == null) || trim($record->pallet_status) == '') { + $allScanned = false; + break; + } + } + + if (count($records) > 0 && $allScanned) + { + $locatExist = ($PalletSerialNumbers->locator_number != null && $PalletSerialNumbers->locator_number != '') ? $PalletSerialNumbers->locator_number : ''; + if ($locatExist) + { + Notification::make() + ->title('Locator Pallet Found') + ->body("Scanned pallet number '$palletNo' exist in locator number '$locatExist'.

Remove scanned 'Pallet' from 'Locator' to proceed re-master packing..!") + ->danger() + ->send(); + + $this->dispatch('loadData', '' , '', $plantId, $reworkType); + $this->form->fill([ + 'plant_id' => $plantId, + 'plant' => $plantId, + 'invoice_number' => null, + 'scan_pallet_no' => null, + 'scan_serial_no' => null, + 'rework_type' => $reworkType, + 'reworkType' => $reworkType, + 'update_invoice' => 0, + 'update_pallet' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + else + { + if ($serialNo == '' || $serialNo == null) + { + Notification::make() + ->title("Invalid: Serial Number") + ->body("Serial number can't be empty!") + ->danger() + ->send(); + $this->dispatch('loadData', '', $palletNo, $plantId, $reworkType); + // $snoCount = LocatorInvoiceValidation::where('plant_id', $plantId)->where('invoice_number', $invoiceNo)->count(); + $this->form->fill([ + 'plant_id' => $plantId, + 'plant' => $plantId, + 'invoice_number' => null, + 'scan_pallet_no' => $palletNo, + 'scan_serial_no' => null, + 'rework_type' => $reworkType, + 'reworkType' => $reworkType, + 'update_invoice' => 0, + 'update_pallet' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + else if (strlen($serialNo) < 13) + { + Notification::make() + ->title("Invalid: Serial Number") + ->body("Serial number '$serialNo' must be at least 13 digits.") + ->danger() + ->send(); + $this->dispatch('loadData', '', $palletNo, $plantId, $reworkType); + $this->form->fill([ + 'plant_id' => $plantId, + 'plant' => $plantId, + 'invoice_number' => null, + 'scan_pallet_no' => $palletNo, + 'scan_serial_no' => null, + 'rework_type' => $reworkType, + 'reworkType' => $reworkType, + 'update_invoice' => 0, + 'update_pallet' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + + $PalletSerialNumbers = PalletValidation::where('plant_id', $plantId)->where('pallet_number', $palletNo)->where('serial_number', $serialNo)->first(); + + if (!$PalletSerialNumbers) + { + Notification::make() + ->title('Serial Not Found') + ->body("Serial number '$serialNo' doesn't exist in pallet number '$palletNo'!

Scan the valid exist 'Serial Number' to proceed..!") + ->danger() + ->send(); + + $this->dispatch('loadData', '', $palletNo, $plantId, $reworkType); + $this->form->fill([ + 'plant_id' => $plantId, + 'plant' => $plantId, + 'invoice_number' => null, + 'scan_pallet_no' => $palletNo, + 'scan_serial_no' => null, + 'rework_type' => $reworkType, + 'reworkType' => $reworkType, + 'update_invoice' => 0, + 'update_pallet' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + + foreach ($records as $row) + { + if ($PalletSerialNumbers->serial_number != null && $PalletSerialNumbers->serial_number != '' && $PalletSerialNumbers->serial_number != $serialNo) + { + $row->forceDelete(); + } + + $row->pallet_status = null; + $row->updated_at = now(); + $row->updated_by = $operatorName; + $row->save(); + } + + Notification::make() + ->title('Completed: Rework Serial from Pallet') + ->body("Scanned serial number '$serialNo' successfully removed from pallet number '$palletNo'.

Please, scan the next pallet number to re-master packing..!") + ->success() + ->send(); + + $PalletSerialNumbers = PalletValidation::where('plant_id', $plantId)->where('pallet_number', $palletNo)->first(); + + if (!$PalletSerialNumbers) + { + Notification::make() + ->title("Pallet number '$palletNo' successfully re-master packed.

Please, scan the next pallet number to re-master packing..!") + ->success() + ->send(); + + $this->dispatch('loadData', '', '', $plantId, $reworkType); + $this->form->fill([ + 'plant_id' => $plantId, + 'plant' => $plantId, + 'invoice_number' => null, + 'scan_pallet_no' => null, + 'scan_serial_no' => null, + 'rework_type' => $reworkType, + 'reworkType' => $reworkType, + 'update_invoice' => 0, + 'update_pallet' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + } + else + { + $this->dispatch('loadData', '', '', $plantId, $reworkType); + $this->form->fill([ + 'plant_id' => $plantId, + 'plant' => $plantId, + 'invoice_number' => null, + 'scan_pallet_no' => null, + 'scan_serial_no' => null, + 'rework_type' => $reworkType, + 'reworkType' => $reworkType, + 'update_invoice' => 0, + 'update_pallet' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + } + } + } + else + { + Notification::make() + ->title('Pallet Not Completed') + ->body("Pallet number '$palletNo' doesn't completed the master packing for scanned serial number '$serialNo'!

Please, scan the valid completed pallet number to proceed..!") + ->danger() + ->send(); + + $this->dispatch('loadData', '' , '', $plantId, $reworkType); + $this->form->fill([ + 'plant_id' => $plantId, + 'plant' => $plantId, + 'invoice_number' => null, + 'scan_pallet_no' => null, + 'scan_serial_no' => null, + 'rework_type' => $reworkType, + 'reworkType' => $reworkType, + 'update_invoice' => 0, + 'update_pallet' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + } + else + { + Notification::make() + ->title("Rework Type Not Found") + ->danger() + ->send(); + $this->dispatch('loadData', '', '', $plantId, $reworkType); + $this->form->fill([ + 'plant_id' => $plantId, + 'plant' => $plantId, + 'invoice_number' => null, + 'scan_pallet_no' => null, + 'scan_serial_no' => null, + 'rework_type' => null, + 'reworkType' => null, + 'update_invoice' => 0, + 'update_pallet' => 0, + 'created_by' => $operatorName, + 'scanned_by' => $operatorName, + ]); + return; + } + } + + public function getFormActions(): array + { + return []; + } +} diff --git a/app/Filament/Resources/ReworkLocatorInvoiceValidationResource/Pages/EditReworkLocatorInvoiceValidation.php b/app/Filament/Resources/ReworkLocatorInvoiceValidationResource/Pages/EditReworkLocatorInvoiceValidation.php new file mode 100644 index 000000000..685c96346 --- /dev/null +++ b/app/Filament/Resources/ReworkLocatorInvoiceValidationResource/Pages/EditReworkLocatorInvoiceValidation.php @@ -0,0 +1,22 @@ +