Merge pull request 'Added line in item importer page' (#1093) from ranjith-dev into master
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 13s
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 13s
Reviewed-on: #1093
This commit was merged in pull request #1093.
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
namespace App\Filament\Imports;
|
namespace App\Filament\Imports;
|
||||||
|
|
||||||
use App\Models\Item;
|
use App\Models\Item;
|
||||||
|
use App\Models\Line;
|
||||||
use App\Models\Plant;
|
use App\Models\Plant;
|
||||||
use Filament\Actions\Imports\Exceptions\RowImportFailedException;
|
use Filament\Actions\Imports\Exceptions\RowImportFailedException;
|
||||||
use Filament\Actions\Imports\ImportColumn;
|
use Filament\Actions\Imports\ImportColumn;
|
||||||
@@ -29,6 +30,13 @@ class ItemImporter extends Importer
|
|||||||
->example('123456')
|
->example('123456')
|
||||||
->label('Item Code')
|
->label('Item Code')
|
||||||
->rules(['required']),
|
->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')
|
ImportColumn::make('description')
|
||||||
->requiredMapping()
|
->requiredMapping()
|
||||||
->exampleHeader('Description')
|
->exampleHeader('Description')
|
||||||
@@ -65,6 +73,7 @@ class ItemImporter extends Importer
|
|||||||
Log::info('ResolveRecord triggered', $this->data);
|
Log::info('ResolveRecord triggered', $this->data);
|
||||||
$iCode = trim($this->data['code']);
|
$iCode = trim($this->data['code']);
|
||||||
$description = trim($this->data['description']);
|
$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)) {
|
if (Str::length($plantCod) < 4 || ! is_numeric($plantCod) || ! preg_match('/^[1-9]\d{3,}$/', $plantCod)) {
|
||||||
$warnMsg[] = 'Invalid plant code found';
|
$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)) {
|
if (Str::length($iCode) < 6 || ! ctype_alnum($iCode)) {
|
||||||
$warnMsg[] = 'Invalid item code found';
|
$warnMsg[] = 'Invalid item code found';
|
||||||
}
|
}
|
||||||
@@ -100,6 +115,7 @@ class ItemImporter extends Importer
|
|||||||
'description' => $description,
|
'description' => $description,
|
||||||
'hourly_quantity' => $this->data['hourly_quantity'],
|
'hourly_quantity' => $this->data['hourly_quantity'],
|
||||||
'uom' => trim($this->data['uom']),
|
'uom' => trim($this->data['uom']),
|
||||||
|
'line_id' => $lineId->id ?? null,
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
// return new Item;
|
// return new Item;
|
||||||
|
|||||||
Reference in New Issue
Block a user