Updated alignments on import
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:
@@ -23,7 +23,7 @@ class PlantImporter extends Importer
|
||||
->exampleHeader('Plant Code')
|
||||
->example('1000')
|
||||
->label('Plant Code')
|
||||
->rules(['required']), //, 'integer'
|
||||
->rules(['required']), // , 'integer'
|
||||
ImportColumn::make('name')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Plant Name')
|
||||
@@ -41,7 +41,7 @@ class PlantImporter extends Importer
|
||||
->exampleHeader('Company Name')
|
||||
->example('C.R.I. Pumps Private Limited')
|
||||
->label('Company Name')
|
||||
->relationship(resolveUsing:'name')
|
||||
->relationship(resolveUsing: 'name')
|
||||
->rules(['required']),
|
||||
];
|
||||
}
|
||||
@@ -50,41 +50,40 @@ class PlantImporter extends Importer
|
||||
{
|
||||
$warnMsg = [];
|
||||
$company = Company::where('name', $this->data['company'])->first();
|
||||
if (!$company) {
|
||||
$warnMsg[] = "Company name not found";
|
||||
if (! $company) {
|
||||
$warnMsg[] = 'Company name not found';
|
||||
}
|
||||
if (Str::length($this->data['name']) < 0) {
|
||||
$warnMsg[] = "Plant name not found";
|
||||
$warnMsg[] = 'Plant name not found';
|
||||
}
|
||||
if (Str::length($this->data['code']) < 4 || !is_numeric($this->data['code']) || !preg_match('/^[1-9]\d{3,}$/', $this->data['code'])) {
|
||||
$warnMsg[] = "Invalid plant code found";
|
||||
if (Str::length($this->data['code']) < 4 || ! is_numeric($this->data['code']) || ! preg_match('/^[1-9]\d{3,}$/', $this->data['code'])) {
|
||||
$warnMsg[] = 'Invalid plant code found';
|
||||
}
|
||||
if (Str::length($this->data['address']) < 3) {
|
||||
$warnMsg[] = "Invalid address found";
|
||||
$warnMsg[] = 'Invalid address found';
|
||||
}
|
||||
if (!empty($warnMsg)) {
|
||||
if (! empty($warnMsg)) {
|
||||
throw new RowImportFailedException(implode(', ', $warnMsg));
|
||||
}
|
||||
|
||||
$plantCN = Plant::where('code', $this->data['code'])->where('name', $this->data['name'])->first();
|
||||
if (!$plantCN) {
|
||||
if (! $plantCN) {
|
||||
$plantCode = Plant::where('code', $this->data['code'])->first();
|
||||
$plantName = Plant::where('name', $this->data['name'])->first();
|
||||
if ($plantName) {
|
||||
throw new RowImportFailedException("Duplicate plant name found");
|
||||
}
|
||||
else if ($plantCode) {
|
||||
throw new RowImportFailedException("Duplicate plant code found");
|
||||
throw new RowImportFailedException('Duplicate plant name found');
|
||||
} elseif ($plantCode) {
|
||||
throw new RowImportFailedException('Duplicate plant code found');
|
||||
}
|
||||
}
|
||||
|
||||
return Plant::updateOrCreate([
|
||||
'code' => $this->data['code'],
|
||||
'name' => $this->data['name'],
|
||||
],
|
||||
'code' => $this->data['code'],
|
||||
'name' => $this->data['name'],
|
||||
],
|
||||
[
|
||||
'address' => $this->data['address'],
|
||||
'company_id' => $company->id
|
||||
'company_id' => $company->id,
|
||||
]
|
||||
);
|
||||
// return Plant::firstOrNew([
|
||||
@@ -97,10 +96,10 @@ class PlantImporter extends Importer
|
||||
|
||||
public static function getCompletedNotificationBody(Import $import): string
|
||||
{
|
||||
$body = 'Your plant import has completed and ' . number_format($import->successful_rows) . ' ' . str('row')->plural($import->successful_rows) . ' imported.';
|
||||
$body = 'Your plant 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