1
0
forked from poc/pds

Added view rights against plant on import and export

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
return ++$rowNumber;
}),
ExportColumn::make('plant.name')
->label('PLANT'),
ExportColumn::make('plant.code')
->label('PLANT CODE'),
ExportColumn::make('name')
->label('GUARD NAME'),
ExportColumn::make('identification1')

View File

@@ -20,10 +20,10 @@ class GuardNameImporter extends Importer
return [
ImportColumn::make('plant')
->requiredMapping()
->exampleHeader('Plant Name')
->example('Ransar Industries-I')
->label('Plant Name')
->relationship(resolveUsing: 'name')
->exampleHeader('Plant Code')
->example('1000')
->label('Plant Code')
->relationship(resolveUsing: 'code')
->rules(['required']),
ImportColumn::make('name')
->requiredMapping()
@@ -54,19 +54,25 @@ class GuardNameImporter extends Importer
public function resolveRecord(): ?GuardName
{
$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) {
$warnMsg[] = "Plant not found"; // '" . $this->data['plant'] . "'
$warnMsg[] = 'Plant not found'; // '" . $plantCod . "'
}
}
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) {
$warnMsg[] = "Invalid identification-1 found";
$warnMsg[] = 'Invalid identification-1 found';
}
$createdBy = $this->data['created_by'];
if (Str::length($createdBy) < 3) { // || !ctype_alnum($createdBy)
$warnMsg[] = "Invalid created by name found";
$warnMsg[] = 'Invalid created by name found';
}
if (! empty($warnMsg)) {
throw new RowImportFailedException(implode(', ', $warnMsg));
@@ -74,12 +80,12 @@ class GuardNameImporter extends Importer
return GuardName::updateOrCreate([
'name' => $this->data['name'],
'plant_id' => $plant->id
'plant_id' => $plant->id,
],
[
'identification1' => $this->data['identification1'],
'identification2' => $this->data['identification2'],
'created_by' => $this->data['created_by']
'created_by' => $this->data['created_by'],
]
);