Added uom column and updated validation func. on import
This commit is contained in:
@@ -3,9 +3,12 @@
|
||||
namespace App\Filament\Imports;
|
||||
|
||||
use App\Models\Item;
|
||||
use App\Models\Plant;
|
||||
use Filament\Actions\Imports\Exceptions\RowImportFailedException;
|
||||
use Filament\Actions\Imports\ImportColumn;
|
||||
use Filament\Actions\Imports\Importer;
|
||||
use Filament\Actions\Imports\Models\Import;
|
||||
use Str;
|
||||
|
||||
class ItemImporter extends Importer
|
||||
{
|
||||
@@ -33,6 +36,11 @@ class ItemImporter extends Importer
|
||||
->label('Hourly Quantity')
|
||||
->numeric()
|
||||
->rules(['required', 'integer']),
|
||||
ImportColumn::make('uom')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Unit of Measure')
|
||||
->example('EA')
|
||||
->label('Unit of Measure'),
|
||||
ImportColumn::make('plant')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Plant Name')
|
||||
@@ -45,9 +53,25 @@ class ItemImporter extends Importer
|
||||
|
||||
public function resolveRecord(): ?Item
|
||||
{
|
||||
$plant = \App\Models\Plant::where('name', $this->data['plant'])->first();
|
||||
$warnMsg = [];
|
||||
$plant = Plant::where('name', $this->data['plant'])->first();
|
||||
if (!$plant) {
|
||||
return null;
|
||||
$warnMsg[] = "Plant not found"; // '" . $this->data['plant'] . "'
|
||||
}
|
||||
if (Str::length($this->data['code']) < 6 || !ctype_alnum($this->data['code'])) {
|
||||
$warnMsg[] = "Invalid item code found";
|
||||
}
|
||||
// if (Str::length($this->data['uom']) <= 0) {
|
||||
// $warnMsg[] = "Invalid unit of measure found";
|
||||
// }
|
||||
if (Str::length($this->data['description']) < 5) {
|
||||
$warnMsg[] = "Invalid description found";
|
||||
}
|
||||
if (Str::length($this->data['hourly_quantity']) < 0 || !is_numeric($this->data['hourly_quantity']) || $this->data['hourly_quantity'] <= 0) {
|
||||
$warnMsg[] = "Invalid hourly quantity found";
|
||||
}
|
||||
if (!empty($warnMsg)) {
|
||||
throw new RowImportFailedException(implode(', ', $warnMsg));
|
||||
}
|
||||
return Item::updateOrCreate([
|
||||
'code' => $this->data['code'],
|
||||
@@ -55,7 +79,8 @@ class ItemImporter extends Importer
|
||||
],
|
||||
[
|
||||
'description' => $this->data['description'],
|
||||
'hourly_quantity' => $this->data['hourly_quantity']
|
||||
'hourly_quantity' => $this->data['hourly_quantity'],
|
||||
'uom' => $this->data['uom']
|
||||
]
|
||||
);
|
||||
// return new Item;
|
||||
|
||||
Reference in New Issue
Block a user