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,17 +24,18 @@ class BlockExporter 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('BLOCK NAME'),
|
||||||
ExportColumn::make('created_at')
|
ExportColumn::make('created_at')
|
||||||
->label('CREATED AT'),
|
->label('CREATED AT'),
|
||||||
ExportColumn::make('updated_at')
|
ExportColumn::make('updated_at')
|
||||||
->label('UPDATED AT'),
|
->label('UPDATED AT')
|
||||||
|
->enabledByDefault(true),
|
||||||
ExportColumn::make('deleted_at')
|
ExportColumn::make('deleted_at')
|
||||||
->enabledByDefault(false)
|
->label('DELETED AT')
|
||||||
->label('DELETED AT'),
|
->enabledByDefault(false),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ use Filament\Actions\Imports\Exceptions\RowImportFailedException;
|
|||||||
use Filament\Actions\Imports\ImportColumn;
|
use Filament\Actions\Imports\ImportColumn;
|
||||||
use Filament\Actions\Imports\Importer;
|
use Filament\Actions\Imports\Importer;
|
||||||
use Filament\Actions\Imports\Models\Import;
|
use Filament\Actions\Imports\Models\Import;
|
||||||
use Notification;
|
|
||||||
use Str;
|
use Str;
|
||||||
|
|
||||||
class BlockImporter extends Importer
|
class BlockImporter extends Importer
|
||||||
@@ -20,16 +19,16 @@ class BlockImporter extends Importer
|
|||||||
return [
|
return [
|
||||||
ImportColumn::make('name')
|
ImportColumn::make('name')
|
||||||
->requiredMapping()
|
->requiredMapping()
|
||||||
->exampleHeader('Block Name')
|
->exampleHeader('BLOCK NAME')
|
||||||
->example('Block A')
|
->example('Block A')
|
||||||
->label('Block Name')
|
->label('BLOCK NAME')
|
||||||
->rules(['required']),
|
->rules(['required']),
|
||||||
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']),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@@ -37,21 +36,28 @@ class BlockImporter extends Importer
|
|||||||
public function resolveRecord(): ?Block
|
public function resolveRecord(): ?Block
|
||||||
{
|
{
|
||||||
$warnMsg = [];
|
$warnMsg = [];
|
||||||
$plant = Plant::where('name', $this->data['plant'])->first();
|
$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) {
|
if (! $plant) {
|
||||||
$warnMsg[] = "Plant not found";
|
$warnMsg[] = 'Plant not found';
|
||||||
// $warnMsg[] = "Plant '" . $this->data['plant'] . "' not found";
|
// $warnMsg[] = "Plant '" . $plantCod . "' not found";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (Str::length($this->data['name']) < 0) {
|
if (Str::length($this->data['name']) < 0) {
|
||||||
$warnMsg[] = "Block name not found";
|
$warnMsg[] = 'Block name not found';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! empty($warnMsg)) {
|
if (! empty($warnMsg)) {
|
||||||
throw new RowImportFailedException(implode(', ', $warnMsg));
|
throw new RowImportFailedException(implode(', ', $warnMsg));
|
||||||
}
|
}
|
||||||
|
|
||||||
return Block::updateOrCreate([
|
return Block::updateOrCreate([
|
||||||
'name' => $this->data['name'],
|
'name' => $this->data['name'],
|
||||||
'plant_id' => $plant->id
|
'plant_id' => $plant->id,
|
||||||
]);
|
]);
|
||||||
// return Block::firstOrNew([
|
// return Block::firstOrNew([
|
||||||
// // Update existing records, matching them by `$this->data['column_name']`
|
// // Update existing records, matching them by `$this->data['column_name']`
|
||||||
|
|||||||
Reference in New Issue
Block a user