Added view rights against plant on import and export
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 10s

This commit is contained in:
dhanabalan
2026-01-13 16:04:11 +05:30
parent 3c4a09f571
commit 4705b3aebb
2 changed files with 29 additions and 23 deletions

View File

@@ -24,8 +24,8 @@ class GuardNameExporter extends Exporter
// Increment and return the row number // Increment and return the row number
return ++$rowNumber; return ++$rowNumber;
}), }),
ExportColumn::make('plant.name') ExportColumn::make('plant.code')
->label('PLANT'), ->label('PLANT CODE'),
ExportColumn::make('name') ExportColumn::make('name')
->label('GUARD NAME'), ->label('GUARD NAME'),
ExportColumn::make('identification1') ExportColumn::make('identification1')
@@ -46,10 +46,10 @@ class GuardNameExporter extends Exporter
public static function getCompletedNotificationBody(Export $export): string public static function getCompletedNotificationBody(Export $export): string
{ {
$body = 'Your guard name export has completed and ' . number_format($export->successful_rows) . ' ' . str('row')->plural($export->successful_rows) . ' exported.'; $body = 'Your guard name export has completed and '.number_format($export->successful_rows).' '.str('row')->plural($export->successful_rows).' exported.';
if ($failedRowsCount = $export->getFailedRowsCount()) { if ($failedRowsCount = $export->getFailedRowsCount()) {
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to export.'; $body .= ' '.number_format($failedRowsCount).' '.str('row')->plural($failedRowsCount).' failed to export.';
} }
return $body; return $body;

View File

@@ -20,10 +20,10 @@ class GuardNameImporter extends Importer
return [ return [
ImportColumn::make('plant') ImportColumn::make('plant')
->requiredMapping() ->requiredMapping()
->exampleHeader('Plant Name') ->exampleHeader('Plant Code')
->example('Ransar Industries-I') ->example('1000')
->label('Plant Name') ->label('Plant Code')
->relationship(resolveUsing: 'name') ->relationship(resolveUsing: 'code')
->rules(['required']), ->rules(['required']),
ImportColumn::make('name') ImportColumn::make('name')
->requiredMapping() ->requiredMapping()
@@ -54,32 +54,38 @@ class GuardNameImporter extends Importer
public function resolveRecord(): ?GuardName public function resolveRecord(): ?GuardName
{ {
$warnMsg = []; $warnMsg = [];
$plant = Plant::where('name', $this->data['plant'])->first(); $plantCod = $this->data['plant'];
if (!$plant) { $plant = null;
$warnMsg[] = "Plant not found"; // '" . $this->data['plant'] . "' if (Str::length($plantCod) < 4 || ! is_numeric($plantCod) || ! preg_match('/^[1-9]\d{3,}$/', $plantCod)) {
$warnMsg[] = 'Invalid plant code found';
} else {
$plant = Plant::where('code', $plantCod)->first();
if (! $plant) {
$warnMsg[] = 'Plant not found'; // '" . $plantCod . "'
}
} }
if (Str::length($this->data['name']) < 3) { // || !ctype_alnum($this->data['name']) if (Str::length($this->data['name']) < 3) { // || !ctype_alnum($this->data['name'])
$warnMsg[] = "Invalid guard name found"; $warnMsg[] = 'Invalid guard name found';
} }
if (Str::length($this->data['identification1']) < 5) { if (Str::length($this->data['identification1']) < 5) {
$warnMsg[] = "Invalid identification-1 found"; $warnMsg[] = 'Invalid identification-1 found';
} }
$createdBy = $this->data['created_by']; $createdBy = $this->data['created_by'];
if (Str::length($createdBy) < 3) { // || !ctype_alnum($createdBy) if (Str::length($createdBy) < 3) { // || !ctype_alnum($createdBy)
$warnMsg[] = "Invalid created by name found"; $warnMsg[] = 'Invalid created by name found';
} }
if (!empty($warnMsg)) { if (! empty($warnMsg)) {
throw new RowImportFailedException(implode(', ', $warnMsg)); throw new RowImportFailedException(implode(', ', $warnMsg));
} }
return GuardName::updateOrCreate([ return GuardName::updateOrCreate([
'name' => $this->data['name'], 'name' => $this->data['name'],
'plant_id' => $plant->id 'plant_id' => $plant->id,
], ],
[ [
'identification1' => $this->data['identification1'], 'identification1' => $this->data['identification1'],
'identification2' => $this->data['identification2'], 'identification2' => $this->data['identification2'],
'created_by' => $this->data['created_by'] 'created_by' => $this->data['created_by'],
] ]
); );
@@ -87,15 +93,15 @@ class GuardNameImporter extends Importer
// // // Update existing records, matching them by `$this->data['column_name']` // // // Update existing records, matching them by `$this->data['column_name']`
// // 'email' => $this->data['email'], // // 'email' => $this->data['email'],
// // ]); // // ]);
//return new GuardName(); // return new GuardName();
} }
public static function getCompletedNotificationBody(Import $import): string public static function getCompletedNotificationBody(Import $import): string
{ {
$body = 'Your guard name import has completed and ' . number_format($import->successful_rows) . ' ' . str('row')->plural($import->successful_rows) . ' imported.'; $body = 'Your guard name import has completed and '.number_format($import->successful_rows).' '.str('row')->plural($import->successful_rows).' imported.';
if ($failedRowsCount = $import->getFailedRowsCount()) { if ($failedRowsCount = $import->getFailedRowsCount()) {
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to import.'; $body .= ' '.number_format($failedRowsCount).' '.str('row')->plural($failedRowsCount).' failed to import.';
} }
return $body; return $body;