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

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,19 +54,25 @@ 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'];
$plant = null;
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) { if (! $plant) {
$warnMsg[] = "Plant not found"; // '" . $this->data['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));
@@ -74,12 +80,12 @@ class GuardNameImporter extends Importer
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'],
] ]
); );