Merge pull request 'Added dynamic plant selection based on user permissions and updated file upload path for invoices' (#318) from ranjith-dev into master
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Has been cancelled

Reviewed-on: #318
This commit was merged in pull request #318.
This commit is contained in:
2026-02-06 08:54:44 +00:00
2 changed files with 33 additions and 27 deletions

View File

@@ -37,6 +37,11 @@ class InvoiceDataValidationResource extends Resource
Forms\Components\Select::make('plant_id') Forms\Components\Select::make('plant_id')
->label('Plant') ->label('Plant')
->relationship('plant', 'name') ->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(), ->required(),
Forms\Components\TextInput::make('distribution_channel_desc') Forms\Components\TextInput::make('distribution_channel_desc')
->label('Distribution Channel Description') ->label('Distribution Channel Description')
@@ -206,7 +211,7 @@ class InvoiceDataValidationResource extends Resource
$originalNameOnly = pathinfo($originalName, PATHINFO_FILENAME); $originalNameOnly = pathinfo($originalName, PATHINFO_FILENAME);
// Store manually using storeAs to keep original name // 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); $fullPath = Storage::disk('local')->path($path);

View File

@@ -41,6 +41,11 @@ class InvoiceOutValidationResource extends Resource
Forms\Components\Select::make('plant_id') Forms\Components\Select::make('plant_id')
->label('Plant') ->label('Plant')
->relationship('plant', 'name') ->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(), ->required(),
Forms\Components\TextInput::make('qr_code') Forms\Components\TextInput::make('qr_code')
->label('QR Code'), ->label('QR Code'),
@@ -169,7 +174,7 @@ class InvoiceOutValidationResource extends Resource
$originalNameOnly = pathinfo($originalName, PATHINFO_FILENAME); $originalNameOnly = pathinfo($originalName, PATHINFO_FILENAME);
// Store manually using storeAs to keep original name // 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); $fullPath = Storage::disk('local')->path($path);
@@ -402,8 +407,7 @@ class InvoiceOutValidationResource extends Resource
$insertCount = 0; $insertCount = 0;
$failedRecords = []; $failedRecords = [];
foreach ($rows as $index => $row) foreach ($rows as $index => $row) {
{
if ($index == 0) { if ($index == 0) {
continue; continue;
} }
@@ -444,13 +448,13 @@ class InvoiceOutValidationResource extends Resource
} }
$exists = InvoiceOutValidation::where('plant_id', $plant->id) $exists = InvoiceOutValidation::where('plant_id', $plant->id)
->where('qr_code', $qrcode) ->where('qr_code', $qrcode)
->first(); ->first();
InvoiceOutValidation::updateOrCreate( InvoiceOutValidation::updateOrCreate(
[ [
'plant_id' => $plant->id, 'plant_id' => $plant->id,
'qr_code' => $qrcode, 'qr_code' => $qrcode,
], ],
[ [
'scanned_at' => $formattedDate, 'scanned_at' => $formattedDate,
@@ -463,8 +467,7 @@ class InvoiceOutValidationResource extends Resource
$exists ? $updateCount++ : $insertCount++; $exists ? $updateCount++ : $insertCount++;
$successCount++; $successCount++;
} } catch (\Exception $e) {
catch (\Exception $e) {
$failedRecords[] = [ $failedRecords[] = [
'row' => $rowNumber, 'row' => $rowNumber,
'qrcode' => $qrcode ?? null, 'qrcode' => $qrcode ?? null,
@@ -474,24 +477,22 @@ class InvoiceOutValidationResource extends Resource
} }
if (count($failedRecords) > 0) { if (count($failedRecords) > 0) {
$failedSummary = collect($failedRecords) $failedSummary = collect($failedRecords)
->map(fn ($f) => "Row {$f['row']} ({$f['qrcode']}) : {$f['error']}") ->map(fn ($f) => "Row {$f['row']} ({$f['qrcode']}) : {$f['error']}")
->take(5) ->take(5)
->implode("\n"); ->implode("\n");
Notification::make() Notification::make()
->title('Partial Import Warning') ->title('Partial Import Warning')
->body( ->body(
"Total Success: {$successCount}\n" . "Total Success: {$successCount}\n".
"Inserted: {$insertCount}\n" . "Inserted: {$insertCount}\n".
"Updated: {$updateCount}\n" . "Updated: {$updateCount}\n".
"Failed: " . count($failedRecords) . "\n\n" . 'Failed: '.count($failedRecords)."\n\n".
$failedSummary $failedSummary
) )
->warning() ->warning()
->send(); ->send();
} } else {
else
{
Notification::make() Notification::make()
->title('Import Success') ->title('Import Success')
->body("Successfully imported '{$successCount}' records.") ->body("Successfully imported '{$successCount}' records.")