Updated validation functionality on import
This commit is contained in:
@@ -59,17 +59,19 @@ class ItemImporter extends Importer
|
|||||||
public function resolveRecord(): ?Item
|
public function resolveRecord(): ?Item
|
||||||
{
|
{
|
||||||
$warnMsg = [];
|
$warnMsg = [];
|
||||||
|
$iCode = trim($this->data['code']);
|
||||||
|
$description = trim($this->data['description']);
|
||||||
$plant = Plant::where('name', $this->data['plant'])->first();
|
$plant = Plant::where('name', $this->data['plant'])->first();
|
||||||
if (!$plant) {
|
if (!$plant) {
|
||||||
$warnMsg[] = "Plant not found"; // '" . $this->data['plant'] . "'
|
$warnMsg[] = "Plant not found"; // '" . $this->data['plant'] . "'
|
||||||
}
|
}
|
||||||
if (Str::length($this->data['code']) < 6 || !ctype_alnum($this->data['code'])) {
|
if (Str::length($iCode) < 6 || !ctype_alnum($iCode)) {
|
||||||
$warnMsg[] = "Invalid item code found";
|
$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($this->data['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) {
|
||||||
@@ -79,14 +81,14 @@ class ItemImporter extends Importer
|
|||||||
throw new RowImportFailedException(implode(', ', $warnMsg));
|
throw new RowImportFailedException(implode(', ', $warnMsg));
|
||||||
}
|
}
|
||||||
return Item::updateOrCreate([
|
return Item::updateOrCreate([
|
||||||
'code' => $this->data['code'],
|
'code' => $iCode,
|
||||||
'plant_id' => $plant->id
|
'plant_id' => $plant->id
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'category' => $this->data['category'],
|
'category' => trim($this->data['category']),
|
||||||
'description' => $this->data['description'],
|
'description' => $description,
|
||||||
'hourly_quantity' => $this->data['hourly_quantity'],
|
'hourly_quantity' => $this->data['hourly_quantity'],
|
||||||
'uom' => $this->data['uom']
|
'uom' => trim($this->data['uom'])
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
// return new Item;
|
// return new Item;
|
||||||
|
|||||||
Reference in New Issue
Block a user