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
|
// 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('NAME'),
|
->label('LINE NAME'),
|
||||||
ExportColumn::make('type')
|
ExportColumn::make('type')
|
||||||
->label('TYPE'),
|
->label('LINE TYPE'),
|
||||||
ExportColumn::make('no_of_operation')
|
ExportColumn::make('no_of_operation')
|
||||||
->label('NO OF OPERATION'),
|
->label('NO OF OPERATION'),
|
||||||
ExportColumn::make('workGroup1.name')
|
ExportColumn::make('workGroup1.name')
|
||||||
|
|||||||
@@ -87,10 +87,10 @@ class LineImporter extends Importer
|
|||||||
->label('Work Group Center 10'),
|
->label('Work Group Center 10'),
|
||||||
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']),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@@ -98,18 +98,24 @@ class LineImporter extends Importer
|
|||||||
public function resolveRecord(): ?Line
|
public function resolveRecord(): ?Line
|
||||||
{
|
{
|
||||||
$warnMsg = [];
|
$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) {
|
if (! $plant) {
|
||||||
throw new RowImportFailedException("Plant '{$this->data['plant']}' not found");
|
throw new RowImportFailedException('Plant not found');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Str::length($this->data['name'] ?? '') <= 0) {
|
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) {
|
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);
|
$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");
|
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");
|
throw new RowImportFailedException("Invalid 'No Of Operation' value: {$noOfOps}, maximum allowed is 10");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -132,7 +137,7 @@ class LineImporter extends Importer
|
|||||||
}
|
}
|
||||||
if (! empty($missingGroups)) {
|
if (! empty($missingGroups)) {
|
||||||
throw new RowImportFailedException(
|
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();
|
->first();
|
||||||
|
|
||||||
if (! $workGroupRecord) {
|
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)
|
$existsInLines = Line::where('plant_id', $plant->id)
|
||||||
@@ -169,21 +174,20 @@ class LineImporter extends Importer
|
|||||||
->first();
|
->first();
|
||||||
|
|
||||||
if ($existsInLines) {
|
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;
|
$this->data["work_group{$i}_id"] = $workGroupRecord->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($warnMsg))
|
if (! empty($warnMsg)) {
|
||||||
{
|
|
||||||
throw new RowImportFailedException(implode(', ', $warnMsg));
|
throw new RowImportFailedException(implode(', ', $warnMsg));
|
||||||
}
|
}
|
||||||
|
|
||||||
Line::updateOrCreate(
|
Line::updateOrCreate(
|
||||||
[
|
[
|
||||||
'name' => $this->data['name'],
|
'name' => $this->data['name'],
|
||||||
'plant_id' => $plant->id
|
'plant_id' => $plant->id,
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'type' => $this->data['type'],
|
'type' => $this->data['type'],
|
||||||
|
|||||||
Reference in New Issue
Block a user