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')
|
||||
@@ -84,10 +84,10 @@ class LineExporter extends Exporter
|
||||
|
||||
public static function getCompletedNotificationBody(Export $export): string
|
||||
{
|
||||
$body = 'Your line export has completed and ' . number_format($export->successful_rows) . ' ' . str('row')->plural($export->successful_rows) . ' exported.';
|
||||
$body = 'Your line export has completed and '.number_format($export->successful_rows).' '.str('row')->plural($export->successful_rows).' exported.';
|
||||
|
||||
if ($failedRowsCount = $export->getFailedRowsCount()) {
|
||||
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to export.';
|
||||
$body .= ' '.number_format($failedRowsCount).' '.str('row')->plural($failedRowsCount).' failed to export.';
|
||||
}
|
||||
|
||||
return $body;
|
||||
|
||||
@@ -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,28 +98,33 @@ class LineImporter extends Importer
|
||||
public function resolveRecord(): ?Line
|
||||
{
|
||||
$warnMsg = [];
|
||||
$plantCod = $this->data['plant'];
|
||||
$plant = null;
|
||||
|
||||
$plant = Plant::where('name', $this->data['plant'])->first();
|
||||
if (!$plant) {
|
||||
throw new RowImportFailedException("Plant '{$this->data['plant']}' not found");
|
||||
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 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);
|
||||
|
||||
if (($noOfOps == null || $noOfOps == '' || !is_numeric($noOfOps)) && $noOfOps != 0) {
|
||||
if (($noOfOps == null || $noOfOps == '' || ! is_numeric($noOfOps)) && $noOfOps != 0) {
|
||||
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");
|
||||
}
|
||||
|
||||
@@ -130,28 +135,28 @@ class LineImporter extends Importer
|
||||
$missingGroups[] = "work_group{$i}_id";
|
||||
}
|
||||
}
|
||||
if (!empty($missingGroups)) {
|
||||
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)
|
||||
);
|
||||
}
|
||||
|
||||
// Ensure no extra work groups are filled
|
||||
$invalidGroups = [];
|
||||
for ($i = $noOfOps + 1; $i <= 10; $i++) {
|
||||
if (!empty($this->data["work_group{$i}_id"])) {
|
||||
if (! empty($this->data["work_group{$i}_id"])) {
|
||||
$invalidGroups[] = "work_group{$i}_id";
|
||||
}
|
||||
}
|
||||
if (!empty($invalidGroups)) {
|
||||
if (! empty($invalidGroups)) {
|
||||
throw new RowImportFailedException(
|
||||
"Invalid data: Only first {$noOfOps} work groups should be filled, but values found in: " . implode(', ', $invalidGroups)
|
||||
"Invalid data: Only first {$noOfOps} work groups should be filled, but values found in: ".implode(', ', $invalidGroups)
|
||||
);
|
||||
}
|
||||
|
||||
for ($i = 1; $i <= 10; $i++) {
|
||||
$workGroupName = $this->data["work_group{$i}_id"] ?? null;
|
||||
if (!$workGroupName) {
|
||||
if (! $workGroupName) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -159,8 +164,8 @@ class LineImporter extends Importer
|
||||
->where('plant_id', $plant->id)
|
||||
->first();
|
||||
|
||||
if (!$workGroupRecord) {
|
||||
throw new RowImportFailedException("Work group '{$workGroupName}' not found in plant '{$this->data['plant']}'");
|
||||
if (! $workGroupRecord) {
|
||||
throw new RowImportFailedException("Work group '{$workGroupName}' not found in plant '{$plantCod}'");
|
||||
}
|
||||
|
||||
$existsInLines = Line::where('plant_id', $plant->id)
|
||||
@@ -169,35 +174,34 @@ 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'],
|
||||
'no_of_operation' => $noOfOps,
|
||||
'work_group1_id' => $this->data['work_group1_id'] ?? null,
|
||||
'work_group2_id' => $this->data['work_group2_id'] ?? null,
|
||||
'work_group3_id' => $this->data['work_group3_id'] ?? null,
|
||||
'work_group4_id' => $this->data['work_group4_id'] ?? null,
|
||||
'work_group5_id' => $this->data['work_group5_id'] ?? null,
|
||||
'work_group6_id' => $this->data['work_group6_id'] ?? null,
|
||||
'work_group7_id' => $this->data['work_group7_id'] ?? null,
|
||||
'work_group8_id' => $this->data['work_group8_id'] ?? null,
|
||||
'work_group9_id' => $this->data['work_group9_id'] ?? null,
|
||||
'work_group10_id' => $this->data['work_group10_id'] ?? null,
|
||||
'work_group1_id' => $this->data['work_group1_id'] ?? null,
|
||||
'work_group2_id' => $this->data['work_group2_id'] ?? null,
|
||||
'work_group3_id' => $this->data['work_group3_id'] ?? null,
|
||||
'work_group4_id' => $this->data['work_group4_id'] ?? null,
|
||||
'work_group5_id' => $this->data['work_group5_id'] ?? null,
|
||||
'work_group6_id' => $this->data['work_group6_id'] ?? null,
|
||||
'work_group7_id' => $this->data['work_group7_id'] ?? null,
|
||||
'work_group8_id' => $this->data['work_group8_id'] ?? null,
|
||||
'work_group9_id' => $this->data['work_group9_id'] ?? null,
|
||||
'work_group10_id' => $this->data['work_group10_id'] ?? null,
|
||||
]
|
||||
);
|
||||
|
||||
@@ -206,10 +210,10 @@ class LineImporter extends Importer
|
||||
|
||||
public static function getCompletedNotificationBody(Import $import): string
|
||||
{
|
||||
$body = 'Your line import has completed and ' . number_format($import->successful_rows) . ' ' . str('row')->plural($import->successful_rows) . ' imported.';
|
||||
$body = 'Your line import has completed and '.number_format($import->successful_rows).' '.str('row')->plural($import->successful_rows).' imported.';
|
||||
|
||||
if ($failedRowsCount = $import->getFailedRowsCount()) {
|
||||
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to import.';
|
||||
$body .= ' '.number_format($failedRowsCount).' '.str('row')->plural($failedRowsCount).' failed to import.';
|
||||
}
|
||||
|
||||
return $body;
|
||||
|
||||
Reference in New Issue
Block a user