Added line in item importer page
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 14s
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (pull_request) Successful in 13s
Gemini PR Review / Gemini PR Review (pull_request) Failing after 18s
Laravel Pint / pint (pull_request) Successful in 2m33s
Laravel Larastan / larastan (pull_request) Failing after 4m34s

This commit is contained in:
dhanabalan
2026-09-25 11:39:40 +05:30
parent b4f9ccc0d8
commit c2ed52d7fb

View File

@@ -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;