diff --git a/app/Filament/Imports/ItemImporter.php b/app/Filament/Imports/ItemImporter.php index 659a5e9..53b0b4b 100644 --- a/app/Filament/Imports/ItemImporter.php +++ b/app/Filament/Imports/ItemImporter.php @@ -3,6 +3,7 @@ namespace App\Filament\Imports; use App\Models\Item; +use App\Models\Line; use App\Models\Plant; use Filament\Actions\Imports\Exceptions\RowImportFailedException; use Filament\Actions\Imports\ImportColumn; @@ -29,6 +30,13 @@ class ItemImporter extends Importer ->example('123456') ->label('Item Code') ->rules(['required']), + ImportColumn::make('line') + ->requiredMapping() + ->exampleHeader('Line Name') + ->example('4 inch pump line') + ->label('Line Name') + ->relationship(resolveUsing: 'name') // Lookup Plant by code column + ->rules(['required']), ImportColumn::make('description') ->requiredMapping() ->exampleHeader('Description') @@ -65,6 +73,7 @@ class ItemImporter extends Importer Log::info('ResolveRecord triggered', $this->data); $iCode = trim($this->data['code']); $description = trim($this->data['description']); + $lineName = trim($this->data['line']); if (Str::length($plantCod) < 4 || ! is_numeric($plantCod) || ! preg_match('/^[1-9]\d{3,}$/', $plantCod)) { $warnMsg[] = 'Invalid plant code found'; @@ -75,6 +84,12 @@ class ItemImporter extends Importer } } + $lineId = Line::where('plant_id',$plant->id)->where('name', $lineName)->first(); + + if (! $lineId) { + $warnMsg[] = 'Line name not found'; // '" . $plantCod . "' + } + if (Str::length($iCode) < 6 || ! ctype_alnum($iCode)) { $warnMsg[] = 'Invalid item code found'; } @@ -100,6 +115,7 @@ class ItemImporter extends Importer 'description' => $description, 'hourly_quantity' => $this->data['hourly_quantity'], 'uom' => trim($this->data['uom']), + 'line_id' => $lineId->id ?? null, ] ); // return new Item;