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:18:10 +05:30
parent 4de209841a
commit 1e57326e8e
2 changed files with 26 additions and 20 deletions

View File

@@ -24,8 +24,8 @@ class CheckPointNameExporter 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('CHECK POINT NAME'),
ExportColumn::make('created_at')
@@ -42,10 +42,10 @@ class CheckPointNameExporter extends Exporter
public static function getCompletedNotificationBody(Export $export): string
{
$body = 'Your check point name export has completed and ' . number_format($export->successful_rows) . ' ' . str('row')->plural($export->successful_rows) . ' exported.';
$body = 'Your check point name 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;

View File

@@ -20,10 +20,10 @@ class CheckPointNameImporter 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('name')
->requiredMapping()
@@ -43,27 +43,33 @@ class CheckPointNameImporter extends Importer
public function resolveRecord(): ?CheckPointName
{
$warnMsg = [];
$plant = Plant::where('name', $this->data['plant'])->first();
if (!$plant) {
$warnMsg[] = "Plant not found"; // '" . $this->data['plant'] . "'
$plantCod = $this->data['plant'];
$plant = 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'; // '" . $plantCod . "'
}
}
if (Str::length($this->data['name']) < 3) { // || !ctype_alnum($this->data['name'])
$warnMsg[] = "Invalid check point name found";
$warnMsg[] = 'Invalid check point name 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)) {
if (! empty($warnMsg)) {
throw new RowImportFailedException(implode(', ', $warnMsg));
}
return CheckPointName::updateOrCreate([
'name' => $this->data['name'],
'plant_id' => $plant->id
],
[
'created_by' => $this->data['created_by']
'plant_id' => $plant->id,
],
[
'created_by' => $this->data['created_by'],
]
);
// // return CheckPointName::firstOrNew([
@@ -76,10 +82,10 @@ class CheckPointNameImporter extends Importer
public static function getCompletedNotificationBody(Import $import): string
{
$body = 'Your check point name import has completed and ' . number_format($import->successful_rows) . ' ' . str('row')->plural($import->successful_rows) . ' imported.';
$body = 'Your check point name 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;