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
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 10s
This commit is contained in:
@@ -24,12 +24,12 @@ class LineExporter 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('NAME'),
|
||||
->label('LINE NAME'),
|
||||
ExportColumn::make('type')
|
||||
->label('TYPE'),
|
||||
->label('LINE TYPE'),
|
||||
ExportColumn::make('no_of_operation')
|
||||
->label('NO OF OPERATION'),
|
||||
ExportColumn::make('workGroup1.name')
|
||||
|
||||
@@ -87,10 +87,10 @@ class LineImporter extends Importer
|
||||
->label('Work Group Center 10'),
|
||||
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']),
|
||||
];
|
||||
}
|
||||
@@ -98,18 +98,24 @@ class LineImporter extends Importer
|
||||
public function resolveRecord(): ?Line
|
||||
{
|
||||
$warnMsg = [];
|
||||
$plantCod = $this->data['plant'];
|
||||
$plant = null;
|
||||
|
||||
$plant = Plant::where('name', $this->data['plant'])->first();
|
||||
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) {
|
||||
throw new RowImportFailedException("Plant '{$this->data['plant']}' not found");
|
||||
throw new RowImportFailedException('Plant not found');
|
||||
}
|
||||
}
|
||||
|
||||
if (Str::length($this->data['name'] ?? '') <= 0) {
|
||||
throw new RowImportFailedException("Line name not found");
|
||||
throw new RowImportFailedException('Line name not found');
|
||||
}
|
||||
|
||||
if (Str::length($this->data['type'] ?? '') <= 0) {
|
||||
throw new RowImportFailedException("Line type not found");
|
||||
throw new RowImportFailedException('Line type not found');
|
||||
}
|
||||
|
||||
$noOfOps = (int) ($this->data['no_of_operation'] ?? 0);
|
||||
@@ -118,8 +124,7 @@ class LineImporter extends Importer
|
||||
throw new RowImportFailedException("'No of Operation' is required and must be a number $noOfOps");
|
||||
}
|
||||
|
||||
if ($noOfOps > 10)
|
||||
{
|
||||
if ($noOfOps > 10) {
|
||||
throw new RowImportFailedException("Invalid 'No Of Operation' value: {$noOfOps}, maximum allowed is 10");
|
||||
}
|
||||
|
||||
@@ -132,7 +137,7 @@ class LineImporter extends Importer
|
||||
}
|
||||
if (! empty($missingGroups)) {
|
||||
throw new RowImportFailedException(
|
||||
"Invalid data: Required work groups missing values in: " . implode(', ', $missingGroups)
|
||||
'Invalid data: Required work groups missing values in: '.implode(', ', $missingGroups)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -160,7 +165,7 @@ class LineImporter extends Importer
|
||||
->first();
|
||||
|
||||
if (! $workGroupRecord) {
|
||||
throw new RowImportFailedException("Work group '{$workGroupName}' not found in plant '{$this->data['plant']}'");
|
||||
throw new RowImportFailedException("Work group '{$workGroupName}' not found in plant '{$plantCod}'");
|
||||
}
|
||||
|
||||
$existsInLines = Line::where('plant_id', $plant->id)
|
||||
@@ -169,21 +174,20 @@ class LineImporter extends Importer
|
||||
->first();
|
||||
|
||||
if ($existsInLines) {
|
||||
$warnMsg[] = "Work group '{$workGroupName}' is already assigned to another line in plant '{$this->data['plant']}'";
|
||||
$warnMsg[] = "Work group '{$workGroupName}' is already assigned to another line in plant '{$plantCod}'";
|
||||
}
|
||||
|
||||
$this->data["work_group{$i}_id"] = $workGroupRecord->id;
|
||||
}
|
||||
|
||||
if (!empty($warnMsg))
|
||||
{
|
||||
if (! empty($warnMsg)) {
|
||||
throw new RowImportFailedException(implode(', ', $warnMsg));
|
||||
}
|
||||
|
||||
Line::updateOrCreate(
|
||||
[
|
||||
'name' => $this->data['name'],
|
||||
'plant_id' => $plant->id
|
||||
'plant_id' => $plant->id,
|
||||
],
|
||||
[
|
||||
'type' => $this->data['type'],
|
||||
|
||||
Reference in New Issue
Block a user