Added view rights against plant on import and export and Validation logic updated
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:39:23 +05:30
parent 2f8d7615a3
commit aa781ccc89
2 changed files with 86 additions and 75 deletions

View File

@@ -25,11 +25,11 @@ class ShiftExporter extends Exporter
return ++$rowNumber; return ++$rowNumber;
}), }),
ExportColumn::make('block.name') ExportColumn::make('block.name')
->label('BLOCK'), ->label('BLOCK NAME'),
ExportColumn::make('plant.name') ExportColumn::make('plant.code')
->label('PLANT'), ->label('PLANT CODE'),
ExportColumn::make('name') ExportColumn::make('name')
->label('NAME'), ->label('SHIFT NAME'),
ExportColumn::make('start_time') ExportColumn::make('start_time')
->label('START TIME'), ->label('START TIME'),
ExportColumn::make('duration') ExportColumn::make('duration')

View File

@@ -52,10 +52,10 @@ class ShiftImporter extends Importer
->rules(['required']), ->rules(['required']),
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('status') ImportColumn::make('status')
->requiredMapping() ->requiredMapping()
@@ -69,25 +69,35 @@ class ShiftImporter extends Importer
public function resolveRecord(): ?Shift public function resolveRecord(): ?Shift
{ {
$warnMsg = []; $warnMsg = [];
$plant = Plant::where('name', $this->data['plant'])->first(); $plantCod = $this->data['plant'];
if (!$plant) { $plant = null;
$warnMsg[] = "Plant not found"; $block = 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';
} else {
$block = Block::where('name', $this->data['block'])->where('plant_id', $plant->id)->first(); $block = Block::where('name', $this->data['block'])->where('plant_id', $plant->id)->first();
}
if (! $block) { if (! $block) {
$warnMsg[] = "Block not found"; $warnMsg[] = 'Block not found';
} }
if (Str::length($this->data['duration']) < 0 || ! is_numeric($this->data['duration'])) { if (Str::length($this->data['duration']) < 0 || ! is_numeric($this->data['duration'])) {
$warnMsg[] = "Invalid duration found"; $warnMsg[] = 'Invalid duration found';
} }
if (Str::length($this->data['start_time']) < 0) { if (Str::length($this->data['start_time']) < 0) {
$warnMsg[] = "Invalid start time found"; $warnMsg[] = 'Invalid start time found';
} }
if (Str::length($this->data['end_time']) < 0) { if (Str::length($this->data['end_time']) < 0) {
$warnMsg[] = "Invalid end time found"; $warnMsg[] = 'Invalid end time found';
} }
if (Str::length($this->data['status']) < 0 || $this->data['status'] != 'Active') { if (Str::length($this->data['status']) < 0 || $this->data['status'] != 'Active') {
$warnMsg[] = "Invalid shift status found"; $warnMsg[] = 'Invalid shift status found';
} }
if (! empty($warnMsg)) { if (! empty($warnMsg)) {
@@ -105,8 +115,9 @@ class ShiftImporter extends Importer
'start_time' => $this->data['start_time'], 'start_time' => $this->data['start_time'],
'duration' => $this->data['duration'], 'duration' => $this->data['duration'],
'end_time' => $this->data['end_time'], 'end_time' => $this->data['end_time'],
'status' => $this->data['status'] 'status' => $this->data['status'],
]); ]);
return $shift; return $shift;
} else { } else {
// Safe to create new // Safe to create new
@@ -117,7 +128,7 @@ class ShiftImporter extends Importer
'start_time' => $this->data['start_time'], 'start_time' => $this->data['start_time'],
'duration' => $this->data['duration'], 'duration' => $this->data['duration'],
'end_time' => $this->data['end_time'], 'end_time' => $this->data['end_time'],
'status' => $this->data['status'] 'status' => $this->data['status'],
]); ]);
} }
// return Shift::firstOrNew([ // return Shift::firstOrNew([