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')
->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);

View File

@@ -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.")