filtersForm->fill([ 'plant_id' => null, 'document_number' => null, 'remark' => null, ]); } public function filtersForm(Form $form): Form { return $form ->statePath('filters') ->schema([ Select::make('plant_id') ->label('Plant') ->reactive() ->required() ->columnSpan(1) ->options(function (callable $get) { $userHas = Filament::auth()->user()->plant_id; return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray(); }) ->afterStateUpdated(function ($state, $set, callable $get,$livewire) { $plantId = $get('plant_id'); $set('document_number', null); }) ->hint(fn ($get) => $get('pqPlantError') ? $get('pqPlantError') : null) ->hintColor('danger'), Select::make('document_number') ->label('Document Number') ->required() ->reactive() ->columnSpan(1) ->options(function (callable $get) { $plantId = $get('plant_id'); if (empty($plantId)) { return []; } $distributions = InvoiceDataValidation::whereNotNull('distribution_channel_desc') ->distinct() ->pluck('distribution_channel_desc') ->filter(fn ($v) => trim($v) !== '') ->values() ->toArray(); $distributions[] = ''; $pendingInvoices = collect(); foreach ($distributions as $distribution) { $invoices = InvoiceDataValidation::where('plant_id', $plantId) ->where('distribution_channel_desc', $distribution) ->select('id', 'document_number') ->get() ->unique('document_number') ->filter(fn ($inv) => ! empty($inv->document_number) && ! str_contains($inv->document_number, '-') ); if (trim($distribution) == '') { $invoices = $invoices->filter(fn ($inv) => str_starts_with($inv->document_number, '7') ); } if ($invoices->isEmpty()) { continue; } $invoiceNumbers = $invoices->pluck('document_number') ->map(fn ($n) => preg_replace('/\s+/', '', strtoupper($n))) ->toArray(); $wentOut = InvoiceOutValidation::whereIn('qr_code', $invoiceNumbers) ->distinct() ->pluck('qr_code') ->map(fn ($n) => preg_replace('/\s+/', '', strtoupper($n))) ->toArray(); $pending = $invoices->filter(function ($inv) use ($wentOut) { $doc = preg_replace('/\s+/', '', strtoupper($inv->document_number)); return ! in_array($doc, $wentOut, true); }); $pendingInvoices = $pendingInvoices->merge($pending); } return $pendingInvoices ->unique('document_number') ->pluck('document_number', 'document_number') ->toArray(); }) ->afterStateUpdated(function ($state, callable $set, callable $get) { }) ->extraAttributes(fn ($get) => [ 'class' => $get('pqBlockError') ? 'border-red-500' : '', ]) ->hint(fn ($get) => $get('pqBlockError') ? $get('pqBlockError') : null) ->hintColor('danger'), TextInput::make('remark') ->label('Remark') ->reactive() ->maxLength(40) ->helperText('Max 40 characters allowed.') ->extraAttributes([ 'wire:keydown.enter.prevent' => 'addRemark($event.target.value)', ]) ->autofocus() ->required(), ]) ->columns(3); } public function addRemark(){ $plantId = $this->filters['plant_id'] ?? null; $documentNumber = $this->filters['document_number'] ?? null; $remark = $this->filters['remark'] ?? null; if (! $plantId) { Notification::make() ->title('Plant') ->body("please select plant first..!") ->danger() ->send(); return; } if (! $documentNumber) { Notification::make() ->title('Document Number') ->body("please select document number..!") ->danger() ->send(); return; } if ($remark == '') { Notification::make() ->title('Remark') ->body("Remark can't be empty..!") ->danger() ->send(); return; } InvoiceDataValidation::where('plant_id', $plantId) ->where('document_number', $documentNumber) ->update([ 'remark' => $remark, 'updated_at' => now(), ]); $this->filtersForm->fill([ 'plant_id' => $plantId, 'document_number' => $documentNumber, 'remark' => null, ]); Notification::make() ->title('Remark updated successfully') ->success() ->send(); } public static function canAccess(): bool { return Auth::check() && Auth::user()->can('view invoice pending reason'); } }