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