From 76afd15b3ba8263c0274ce89382c6f84b5edf934 Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Tue, 20 Jan 2026 10:23:06 +0530 Subject: [PATCH] Added invoice pending reason page --- app/Filament/Pages/InvoicePendingReason.php | 179 ++++++++++++++++++ .../pages/invoice-pending-reason.blade.php | 6 + 2 files changed, 185 insertions(+) create mode 100644 app/Filament/Pages/InvoicePendingReason.php create mode 100644 resources/views/filament/pages/invoice-pending-reason.blade.php diff --git a/app/Filament/Pages/InvoicePendingReason.php b/app/Filament/Pages/InvoicePendingReason.php new file mode 100644 index 0000000..b87e403 --- /dev/null +++ b/app/Filament/Pages/InvoicePendingReason.php @@ -0,0 +1,179 @@ +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() + ->extraAttributes([ + 'wire:keydown.enter.prevent' => 'addRemark($event.target.value)', + ]) + ->autofocus() + ->required(), + ]) + ->columns(3); + } + + public function addRemark($value){ + $plantId = $this->filters['plant_id'] ?? null; + $documentNumber = $this->filters['document_number'] ?? null; + $remark = $value; + + if (! $plantId || ! $documentNumber || $remark == '') { + 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'); + } +} diff --git a/resources/views/filament/pages/invoice-pending-reason.blade.php b/resources/views/filament/pages/invoice-pending-reason.blade.php new file mode 100644 index 0000000..d4f36dd --- /dev/null +++ b/resources/views/filament/pages/invoice-pending-reason.blade.php @@ -0,0 +1,6 @@ + +
+ {{-- {{ $this->filtersForm($this->form) }} --}} + {{ $this->filtersForm($this->form) }} +
+
-- 2.49.1