Changed plant name as plant code in item importer and exporter
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 10s
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (pull_request) Successful in 10s
Gemini PR Review / review (pull_request) Failing after 26s
Laravel Pint / pint (pull_request) Successful in 3m19s
Laravel Larastan / larastan (pull_request) Failing after 4m41s
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 10s
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (pull_request) Successful in 10s
Gemini PR Review / review (pull_request) Failing after 26s
Laravel Pint / pint (pull_request) Successful in 3m19s
Laravel Larastan / larastan (pull_request) Failing after 4m41s
This commit is contained in:
@@ -24,8 +24,8 @@ class ItemExporter 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('category')
|
ExportColumn::make('category')
|
||||||
->label('CATEGORY'),
|
->label('CATEGORY'),
|
||||||
ExportColumn::make('code')
|
ExportColumn::make('code')
|
||||||
|
|||||||
@@ -8,7 +8,8 @@ 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 Str;
|
use Illuminate\Support\Facades\Log;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
class ItemImporter extends Importer
|
class ItemImporter extends Importer
|
||||||
{
|
{
|
||||||
@@ -48,10 +49,10 @@ class ItemImporter extends Importer
|
|||||||
->label('Unit of Measure'),
|
->label('Unit of Measure'),
|
||||||
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') // Lookup Plant by code column
|
||||||
->rules(['required']),
|
->rules(['required']),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@@ -59,36 +60,46 @@ class ItemImporter extends Importer
|
|||||||
public function resolveRecord(): ?Item
|
public function resolveRecord(): ?Item
|
||||||
{
|
{
|
||||||
$warnMsg = [];
|
$warnMsg = [];
|
||||||
|
$plantCod = $this->data['plant'];
|
||||||
|
$plant = null;
|
||||||
|
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']);
|
||||||
$plant = Plant::where('name', $this->data['plant'])->first();
|
|
||||||
if (!$plant) {
|
if (Str::length($plantCod) < 4 || ! is_numeric($plantCod) || ! preg_match('/^[1-9]\d{3,}$/', $plantCod)) {
|
||||||
$warnMsg[] = "Plant not found"; // '" . $this->data['plant'] . "'
|
$warnMsg[] = 'Invalid plant code found';
|
||||||
|
} else {
|
||||||
|
$plant = Plant::where('code', $plantCod)->first();
|
||||||
|
if (! $plant) {
|
||||||
|
$warnMsg[] = 'Plant not found'; // '" . $plantCod . "'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (Str::length($iCode) < 6 || !ctype_alnum($iCode)) {
|
|
||||||
$warnMsg[] = "Invalid item code found";
|
if (Str::length($iCode) < 6 || ! ctype_alnum($iCode)) {
|
||||||
|
$warnMsg[] = 'Invalid item code found';
|
||||||
}
|
}
|
||||||
// if (Str::length($this->data['uom']) <= 0) {
|
// if (Str::length($this->data['uom']) <= 0) {
|
||||||
// $warnMsg[] = "Invalid unit of measure found";
|
// $warnMsg[] = "Invalid unit of measure found";
|
||||||
// }
|
// }
|
||||||
if (Str::length($description) < 5) {
|
if (Str::length($description) < 5) {
|
||||||
$warnMsg[] = "Invalid description found";
|
$warnMsg[] = 'Invalid description found';
|
||||||
}
|
}
|
||||||
if (Str::length($this->data['hourly_quantity']) < 0 || !is_numeric($this->data['hourly_quantity']) || $this->data['hourly_quantity'] <= 0) {
|
if (Str::length($this->data['hourly_quantity']) < 0 || ! is_numeric($this->data['hourly_quantity']) || $this->data['hourly_quantity'] <= 0) {
|
||||||
$warnMsg[] = "Invalid hourly quantity found";
|
$warnMsg[] = 'Invalid hourly quantity found';
|
||||||
}
|
}
|
||||||
if (!empty($warnMsg)) {
|
if (! empty($warnMsg)) {
|
||||||
throw new RowImportFailedException(implode(', ', $warnMsg));
|
throw new RowImportFailedException(implode(', ', $warnMsg));
|
||||||
}
|
}
|
||||||
|
|
||||||
return Item::updateOrCreate([
|
return Item::updateOrCreate([
|
||||||
'code' => $iCode,
|
'code' => $iCode,
|
||||||
'plant_id' => $plant->id
|
'plant_id' => $plant->id,
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'category' => trim($this->data['category']),
|
'category' => trim($this->data['category']),
|
||||||
'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']),
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
// return new Item;
|
// return new Item;
|
||||||
|
|||||||
Reference in New Issue
Block a user