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
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:
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Filament\Pages;
|
namespace App\Filament\Pages;
|
||||||
|
|
||||||
|
use App\Imports\InvoicePendingReasonImport;
|
||||||
use App\Models\InvoiceDataValidation;
|
use App\Models\InvoiceDataValidation;
|
||||||
use App\Models\InvoiceOutValidation;
|
use App\Models\InvoiceOutValidation;
|
||||||
use App\Models\Plant;
|
use App\Models\Plant;
|
||||||
@@ -10,12 +11,15 @@ use Filament\Forms\Contracts\HasForms;
|
|||||||
use Filament\Forms\Concerns\InteractsWithForms;
|
use Filament\Forms\Concerns\InteractsWithForms;
|
||||||
use Filament\Forms\Form;
|
use Filament\Forms\Form;
|
||||||
use Filament\Facades\Filament;
|
use Filament\Facades\Filament;
|
||||||
|
use Filament\Forms\Components\FileUpload;
|
||||||
use Filament\Forms\Components\Hidden;
|
use Filament\Forms\Components\Hidden;
|
||||||
use Filament\Forms\Components\Select;
|
use Filament\Forms\Components\Select;
|
||||||
use Filament\Forms\Components\TextInput;
|
use Filament\Forms\Components\TextInput;
|
||||||
use Filament\Notifications\Notification;
|
use Filament\Notifications\Notification;
|
||||||
use Filament\Pages\Dashboard\Concerns\HasFiltersForm;
|
use Filament\Pages\Dashboard\Concerns\HasFiltersForm;
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
use Maatwebsite\Excel\Facades\Excel;
|
||||||
|
use Storage;
|
||||||
|
|
||||||
class InvoicePendingReason extends Page
|
class InvoicePendingReason extends Page
|
||||||
{
|
{
|
||||||
@@ -26,6 +30,13 @@ class InvoicePendingReason extends Page
|
|||||||
|
|
||||||
protected static ?string $navigationGroup = 'Manufacturing SD';
|
protected static ?string $navigationGroup = 'Manufacturing SD';
|
||||||
|
|
||||||
|
public ?string $file = null;
|
||||||
|
|
||||||
|
public array $importErrors = [];
|
||||||
|
|
||||||
|
public array $invoicePending = [];
|
||||||
|
|
||||||
|
|
||||||
public function mount(): void
|
public function mount(): void
|
||||||
{
|
{
|
||||||
$this->filtersForm->fill([
|
$this->filtersForm->fill([
|
||||||
@@ -40,7 +51,6 @@ class InvoicePendingReason extends Page
|
|||||||
return $form
|
return $form
|
||||||
->statePath('filters')
|
->statePath('filters')
|
||||||
->schema([
|
->schema([
|
||||||
|
|
||||||
Select::make('plant_id')
|
Select::make('plant_id')
|
||||||
->label('Plant')
|
->label('Plant')
|
||||||
->reactive()
|
->reactive()
|
||||||
@@ -52,6 +62,14 @@ class InvoicePendingReason extends Page
|
|||||||
})
|
})
|
||||||
->afterStateUpdated(function ($state, $set, callable $get,$livewire) {
|
->afterStateUpdated(function ($state, $set, callable $get,$livewire) {
|
||||||
$plantId = $get('plant_id');
|
$plantId = $get('plant_id');
|
||||||
|
|
||||||
|
if($plantId){
|
||||||
|
$this->dispatch('loadData' ,$plantId);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
$this->dispatch('emptyData');
|
||||||
|
}
|
||||||
|
|
||||||
$set('document_number', null);
|
$set('document_number', null);
|
||||||
$set('customer_trade_name', null);
|
$set('customer_trade_name', null);
|
||||||
$set('location', null);
|
$set('location', null);
|
||||||
@@ -127,7 +145,7 @@ class InvoicePendingReason extends Page
|
|||||||
->toArray();
|
->toArray();
|
||||||
})
|
})
|
||||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||||
$plantId = $get('plant_id');
|
$plantId = $get('plant_id');
|
||||||
if (empty($plantId)) {
|
if (empty($plantId)) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
@@ -171,6 +189,28 @@ class InvoicePendingReason extends Page
|
|||||||
])
|
])
|
||||||
->autofocus()
|
->autofocus()
|
||||||
->required(),
|
->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);
|
->columns(3);
|
||||||
}
|
}
|
||||||
@@ -224,6 +264,202 @@ class InvoicePendingReason extends Page
|
|||||||
->send();
|
->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
|
public static function canAccess(): bool
|
||||||
{
|
{
|
||||||
return Auth::check() && Auth::user()->can('view invoice pending reason');
|
return Auth::check() && Auth::user()->can('view invoice pending reason');
|
||||||
|
|||||||
@@ -1,15 +1,35 @@
|
|||||||
<x-filament-panels::page>
|
<x-filament-panels::page>
|
||||||
<div class="space-y-4">
|
<div class="space-y-4">
|
||||||
{{-- {{ $this->filtersForm($this->form) }} --}}
|
|
||||||
{{ $this->filtersForm($this->form) }}
|
{{ $this->filtersForm($this->form) }}
|
||||||
</div>
|
</div>
|
||||||
<div class="flex-row gap-2 mt-4">
|
<div class="flex-row gap-2 mt-4">
|
||||||
<button
|
<x-filament::button
|
||||||
type="button"
|
{{-- type="button" --}}
|
||||||
|
{{-- wire:click="addRemark"
|
||||||
|
class="px-3 py-1 border border-primary-500 text-primary-600 rounded hover:bg-primary-50 hover:border-primary-700 transition text-sm" --}}
|
||||||
wire:click="addRemark"
|
wire:click="addRemark"
|
||||||
class="px-3 py-1 border border-primary-500 text-primary-600 rounded hover:bg-primary-50 hover:border-primary-700 transition text-sm"
|
color="primary"
|
||||||
|
class="mt-4"
|
||||||
>
|
>
|
||||||
Save
|
Save
|
||||||
</button>
|
</x-filament::button>
|
||||||
|
|
||||||
|
<x-filament::button
|
||||||
|
wire:click="importPendingReason"
|
||||||
|
color="primary"
|
||||||
|
class="mt-4"
|
||||||
|
>
|
||||||
|
Import
|
||||||
|
</x-filament::button>
|
||||||
|
<x-filament::button
|
||||||
|
wire:click="exportPendingReason"
|
||||||
|
color="primary"
|
||||||
|
class="mt-4"
|
||||||
|
>
|
||||||
|
Export
|
||||||
|
</x-filament::button>
|
||||||
|
<div class="bg-white shadow rounded-xl p-4 mt-6">
|
||||||
|
<livewire:invoice-pending />
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</x-filament-panels::page>
|
</x-filament-panels::page>
|
||||||
|
|||||||
Reference in New Issue
Block a user