changed logic in invoice pending reason page
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 11s
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (pull_request) Successful in 10s
Gemini PR Review / Gemini PR Review (pull_request) Failing after 16s
Laravel Pint / pint (pull_request) Successful in 2m33s
Laravel Larastan / larastan (pull_request) Failing after 3m32s

This commit is contained in:
dhanabalan
2026-01-23 11:00:41 +05:30
parent b66216bb90
commit 2e6f27824c
2 changed files with 263 additions and 7 deletions

View File

@@ -2,6 +2,7 @@
namespace App\Filament\Pages;
use App\Imports\InvoicePendingReasonImport;
use App\Models\InvoiceDataValidation;
use App\Models\InvoiceOutValidation;
use App\Models\Plant;
@@ -10,12 +11,15 @@ use Filament\Forms\Contracts\HasForms;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Forms\Form;
use Filament\Facades\Filament;
use Filament\Forms\Components\FileUpload;
use Filament\Forms\Components\Hidden;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Notifications\Notification;
use Filament\Pages\Dashboard\Concerns\HasFiltersForm;
use Illuminate\Support\Facades\Auth;
use Maatwebsite\Excel\Facades\Excel;
use Storage;
class InvoicePendingReason extends Page
{
@@ -26,6 +30,13 @@ class InvoicePendingReason extends Page
protected static ?string $navigationGroup = 'Manufacturing SD';
public ?string $file = null;
public array $importErrors = [];
public array $invoicePending = [];
public function mount(): void
{
$this->filtersForm->fill([
@@ -40,7 +51,6 @@ class InvoicePendingReason extends Page
return $form
->statePath('filters')
->schema([
Select::make('plant_id')
->label('Plant')
->reactive()
@@ -52,6 +62,14 @@ class InvoicePendingReason extends Page
})
->afterStateUpdated(function ($state, $set, callable $get,$livewire) {
$plantId = $get('plant_id');
if($plantId){
$this->dispatch('loadData' ,$plantId);
}
else{
$this->dispatch('emptyData');
}
$set('document_number', null);
$set('customer_trade_name', null);
$set('location', null);
@@ -127,7 +145,7 @@ class InvoicePendingReason extends Page
->toArray();
})
->afterStateUpdated(function ($state, callable $set, callable $get) {
$plantId = $get('plant_id');
$plantId = $get('plant_id');
if (empty($plantId)) {
return [];
}
@@ -171,6 +189,28 @@ class InvoicePendingReason extends Page
])
->autofocus()
->required(),
FileUpload::make('file')
->label('Upload Excel File')
->required()
->disk('local')
->multiple(false)
->directory('invoice-pending')
->dehydrated(false)
//->preserveFilenames()
//->storeFiles()
//storeFileNamesIn('original_name')
// ->visibility('private')
->acceptedFileTypes([
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'application/vnd.ms-excel',
'text/csv',
])
->rules(['mimes:xlsx,xls,csv'])
->afterStateUpdated(function ($state, callable $set) {
if ($state instanceof \Livewire\Features\SupportFileUploads\TemporaryUploadedFile) {
$set('file', $state->store('invoice-pending'));
}
}),
])
->columns(3);
}
@@ -224,6 +264,202 @@ class InvoicePendingReason extends Page
->send();
}
// public function importPendingReason()
// {
// $file = $this->filters['file'] ?? null;
// $absolutePath = Storage::disk('local')->path($file);
// Excel::import(new InvoicePendingReasonImport, $absolutePath);
// $this->reset('filters.file');
// Notification::make()
// ->title('File processed and database updated successfully')
// ->success()
// ->send();
// }
public function importPendingReason()
{
$file = $this->filters['file'] ?? null;
$plantId = $this->filters['plant_id'] ?? null;
if (empty($file)) {
Notification::make()
->title('Please upload a file')
->danger()
->send();
return;
}
// if (
// empty($fileFilter) ||
// !is_array($fileFilter) ||
// empty($fileFilter[0])
// ) {
// Notification::make()
// ->title('Please upload a file')
// ->danger()
// ->send();
// return;
// }
// $filePath = $fileFilter[0];
// if (!is_string($filePath)) {
// Notification::make()
// ->title('Invalid file upload')
// ->danger()
// ->send();
// return;
// }
$absolutePath = Storage::disk('local')->path($file);
$import = new InvoicePendingReasonImport();
try {
Excel::import(
$import,
$absolutePath
);
if(!empty($import->plantCodeEmpty)) {
Notification::make()
->title('Import failed')
->body("Plant code can't be empty")
->danger()
->send();
$this->filtersForm->fill([
'file' => null,
]);
return;
}
else if(!empty($import->docNoEmpty)) {
Notification::make()
->title('Import failed')
->body("Document number can't be empty")
->danger()
->send();
$this->filtersForm->fill([
'file' => null,
]);
return;
}
// else if(!empty($import->remarkEmpty)) {
// Notification::make()
// ->title('Import failed')
// ->body("Remark can't be empty")
// ->danger()
// ->send();
// $this->filtersForm->fill([
// 'file' => null,
// ]);
// return;
// }
else if (! empty($import->duplicateExcelDocs)) {
$duplicates = collect($import->duplicateExcelDocs)
->map(function ($rows, $key) {
[$plant, $doc] = explode('|', $key);
return "{$plant}-{$doc}";
})
->implode(', ');
Notification::make()
->title('Import failed')
->body("Duplicate Document Numbers found in Excel: {$duplicates}")
->danger()
->send();
$this->filtersForm->fill([
'file' => null,
]);
return;
}
else if(!empty($import->missingPlantCodes)) {
$codes = implode(', ', array_keys($import->missingPlantCodes));
Notification::make()
->title('Import failed')
->body("Plant codes not found: {$codes}")
->danger()
->send();
$this->filtersForm->fill([
'file' => null,
]);
return;
}
else if(!empty($import->missingDocNo)) {
$docNo = implode(', ', array_keys($import->missingDocNo));
Notification::make()
->title('Import failed')
->body("Document numbers not found: {$docNo}")
->danger()
->send();
$this->filtersForm->fill([
'file' => null,
]);
return;
}
foreach ($import->validRows as $row) {
InvoiceDataValidation::where('plant_id', $row['plant_id'])
->where('document_number', $row['document_number'])
->update([
'remark' => $row['remark'],
'updated_at' => now(),
]);
}
Notification::make()
->title('Import successful')
->body('All records updated successfully.')
->success()
->send();
$this->dispatch('loadData' ,$plantId);
$this->filtersForm->fill([
'file' => null,
'plant_id' => $plantId,
]);
} catch (\Throwable $e) {
Notification::make()
->title('Import error')
->body($e->getMessage())
->danger()
->send();
}
}
public function exportPendingReason()
{
$plantId = $this->filters['plant_id'] ?? null;
if (! $plantId) {
Notification::make()
->title('Plant')
->body("please select plant to export data..!")
->danger()
->send();
return;
}
$this->dispatch('loadData1' ,$plantId);
}
public static function canAccess(): bool
{
return Auth::check() && Auth::user()->can('view invoice pending reason');