Added plant code instead of plant name 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:17:03 +05:30
parent 5cba017b72
commit 4de209841a
2 changed files with 44 additions and 43 deletions

View File

@@ -24,8 +24,8 @@ class CheckPointTimeExporter 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('checkPointNames1.name')
->label('CHECK POINT 1'),
ExportColumn::make('checkPointNames2.name')

View File

@@ -21,10 +21,10 @@ class CheckPointTimeImporter 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('checkPointNames1')
->requiredMapping()
@@ -73,49 +73,50 @@ class CheckPointTimeImporter extends Importer
public function resolveRecord(): ?CheckPointTime
{
$warnMsg = [];
$plant = Plant::where('name', $this->data['plant'])->first();
$plantCod = $this->data['plant'];
$plant = null;
$checkPointNames1 = null;
$checkPointNames2 = 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'] . "'
}
else
{
$warnMsg[] = 'Plant not found'; // '" . $plantCod . "'
} else {
$checkPointNames1 = CheckPointName::where('name', $this->data['checkPointNames1'])->first();
if (! $checkPointNames1) {
$warnMsg[] = "Check point 1 not found";
}
else
{
$warnMsg[] = 'Check point 1 not found';
} else {
$checkPointNames2 = CheckPointName::where('name', $this->data['checkPointNames2'])->first();
if (! $checkPointNames2) {
$warnMsg[] = "Check point 2 not found";
}
else
{
$warnMsg[] = 'Check point 2 not found';
} else {
if ($checkPointNames1->id === $checkPointNames2->id) {
$warnMsg[] = "Check point 1 and 2 can't be the same";
}
}
}
}
}
if (Str::length($this->data['sequence_number']) < 1 || ! is_numeric($this->data['sequence_number']) || $this->data['sequence_number'] <= 0) {
$warnMsg[] = "Invalid sequence number found";
$warnMsg[] = 'Invalid sequence number found';
}
if (Str::length($this->data['time_lapse']) < 1 || ! is_numeric($this->data['time_lapse']) || $this->data['time_lapse'] <= 0) {
$warnMsg[] = "Invalid time lapse found";
$warnMsg[] = 'Invalid time lapse found';
}
if (Str::length($this->data['time_lapse_cushioning']) < 1 || ! is_numeric($this->data['time_lapse_cushioning']) || $this->data['time_lapse_cushioning'] <= 0) {
$warnMsg[] = "Invalid time lapse cushioning found";
$warnMsg[] = 'Invalid time lapse cushioning 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));
}
@@ -124,12 +125,12 @@ class CheckPointTimeImporter extends Importer
'plant_id' => $plant->id,
'check_point1_id' => $checkPointNames1->id,
'check_point2_id' => $checkPointNames2->id,
'sequence_number' => $this->data['sequence_number']
'sequence_number' => $this->data['sequence_number'],
],
[
'time_lapse' => $this->data['time_lapse'],
'time_lapse_cushioning' => $this->data['time_lapse_cushioning'],
'created_by' => $this->data['created_by']
'created_by' => $this->data['created_by'],
]
);
// // return CheckPointTime::firstOrNew([