diff --git a/app/Filament/Resources/InvoiceDataValidationResource.php b/app/Filament/Resources/InvoiceDataValidationResource.php index e0ce08e..df854c4 100644 --- a/app/Filament/Resources/InvoiceDataValidationResource.php +++ b/app/Filament/Resources/InvoiceDataValidationResource.php @@ -37,6 +37,11 @@ class InvoiceDataValidationResource extends Resource Forms\Components\Select::make('plant_id') ->label('Plant') ->relationship('plant', 'name') + ->options(function (callable $get) { + $userHas = Filament::auth()->user()->plant_id; + + return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray(); + }) ->required(), Forms\Components\TextInput::make('distribution_channel_desc') ->label('Distribution Channel Description') @@ -206,7 +211,7 @@ class InvoiceDataValidationResource extends Resource $originalNameOnly = pathinfo($originalName, PATHINFO_FILENAME); // Store manually using storeAs to keep original name - $path = $uploadedFile->storeAs('uploads/temp', $originalName, 'local'); // returns relative path + $path = $uploadedFile->storeAs('uploads/InvoiceOut', $originalName, 'local'); // returns relative path $fullPath = Storage::disk('local')->path($path); diff --git a/app/Filament/Resources/InvoiceOutValidationResource.php b/app/Filament/Resources/InvoiceOutValidationResource.php index 6b9c275..322f4e5 100644 --- a/app/Filament/Resources/InvoiceOutValidationResource.php +++ b/app/Filament/Resources/InvoiceOutValidationResource.php @@ -41,6 +41,11 @@ class InvoiceOutValidationResource extends Resource Forms\Components\Select::make('plant_id') ->label('Plant') ->relationship('plant', 'name') + ->options(function (callable $get) { + $userHas = Filament::auth()->user()->plant_id; + + return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray(); + }) ->required(), Forms\Components\TextInput::make('qr_code') ->label('QR Code'), @@ -169,7 +174,7 @@ class InvoiceOutValidationResource extends Resource $originalNameOnly = pathinfo($originalName, PATHINFO_FILENAME); // Store manually using storeAs to keep original name - $path = $uploadedFile->storeAs('uploads/temp', $originalName, 'local'); // returns relative path + $path = $uploadedFile->storeAs('uploads/InvoiceOut', $originalName, 'local'); // returns relative path $fullPath = Storage::disk('local')->path($path); @@ -402,8 +407,7 @@ class InvoiceOutValidationResource extends Resource $insertCount = 0; $failedRecords = []; - foreach ($rows as $index => $row) - { + foreach ($rows as $index => $row) { if ($index == 0) { continue; } @@ -444,13 +448,13 @@ class InvoiceOutValidationResource extends Resource } $exists = InvoiceOutValidation::where('plant_id', $plant->id) - ->where('qr_code', $qrcode) - ->first(); + ->where('qr_code', $qrcode) + ->first(); InvoiceOutValidation::updateOrCreate( [ 'plant_id' => $plant->id, - 'qr_code' => $qrcode, + 'qr_code' => $qrcode, ], [ 'scanned_at' => $formattedDate, @@ -463,8 +467,7 @@ class InvoiceOutValidationResource extends Resource $exists ? $updateCount++ : $insertCount++; $successCount++; - } - catch (\Exception $e) { + } catch (\Exception $e) { $failedRecords[] = [ 'row' => $rowNumber, 'qrcode' => $qrcode ?? null, @@ -474,24 +477,22 @@ class InvoiceOutValidationResource extends Resource } if (count($failedRecords) > 0) { - $failedSummary = collect($failedRecords) - ->map(fn ($f) => "Row {$f['row']} ({$f['qrcode']}) : {$f['error']}") - ->take(5) - ->implode("\n"); - Notification::make() - ->title('Partial Import Warning') - ->body( - "Total Success: {$successCount}\n" . - "Inserted: {$insertCount}\n" . - "Updated: {$updateCount}\n" . - "Failed: " . count($failedRecords) . "\n\n" . - $failedSummary - ) - ->warning() - ->send(); - } - else - { + $failedSummary = collect($failedRecords) + ->map(fn ($f) => "Row {$f['row']} ({$f['qrcode']}) : {$f['error']}") + ->take(5) + ->implode("\n"); + Notification::make() + ->title('Partial Import Warning') + ->body( + "Total Success: {$successCount}\n". + "Inserted: {$insertCount}\n". + "Updated: {$updateCount}\n". + 'Failed: '.count($failedRecords)."\n\n". + $failedSummary + ) + ->warning() + ->send(); + } else { Notification::make() ->title('Import Success') ->body("Successfully imported '{$successCount}' records.")