Updated validation functionality on import
This commit is contained in:
@@ -162,17 +162,19 @@ class StickerMasterImporter extends Importer
|
|||||||
public function resolveRecord(): ?StickerMaster
|
public function resolveRecord(): ?StickerMaster
|
||||||
{
|
{
|
||||||
$warnMsg = [];
|
$warnMsg = [];
|
||||||
|
$item = null;
|
||||||
$plant = Plant::where('name', $this->data['plant'])->first();
|
$plant = Plant::where('name', $this->data['plant'])->first();
|
||||||
if (!$plant) {
|
if (!$plant) {
|
||||||
$warnMsg[] = "Plant not found";
|
$warnMsg[] = "Plant not found";
|
||||||
}
|
}
|
||||||
$item = null;
|
else
|
||||||
if ($plant) {
|
{
|
||||||
$item = Item::where('code', $this->data['item'])->where('plant_id', $plant->id)->first();
|
$item = Item::where('code', $this->data['item'])->where('plant_id', $plant->id)->first();
|
||||||
}
|
|
||||||
if (!$item) {
|
if (!$item) {
|
||||||
$warnMsg[] = "Item code not found";
|
$warnMsg[] = "Item code not found";
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
if (Str::length($this->data['serial_number_motor']) > 0 && $this->data['serial_number_motor'] != '1') {
|
if (Str::length($this->data['serial_number_motor']) > 0 && $this->data['serial_number_motor'] != '1') {
|
||||||
$warnMsg[] = "Serial number motor must be 1 or empty";
|
$warnMsg[] = "Serial number motor must be 1 or empty";
|
||||||
}
|
}
|
||||||
@@ -215,7 +217,7 @@ class StickerMasterImporter extends Importer
|
|||||||
if (Str::length($this->data['panel_box_code']) > 0 && (Str::length($this->data['panel_box_code']) < 6 || !ctype_alnum($this->data['panel_box_code']))) {
|
if (Str::length($this->data['panel_box_code']) > 0 && (Str::length($this->data['panel_box_code']) < 6 || !ctype_alnum($this->data['panel_box_code']))) {
|
||||||
$warnMsg[] = "Invalid panel box code found";
|
$warnMsg[] = "Invalid panel box code found";
|
||||||
}
|
}
|
||||||
if (!is_numeric($this->data['load_rate']) || $this->data['load_rate'] < 0) {
|
if (Str::length($this->data['load_rate']) < 0 || !is_numeric($this->data['load_rate']) || $this->data['load_rate'] < 0) {
|
||||||
$warnMsg[] = "Load rate must be greater than or equal to 0";
|
$warnMsg[] = "Load rate must be greater than or equal to 0";
|
||||||
}
|
}
|
||||||
if (Str::length($this->data['bundle_quantity']) > 0 && (!is_numeric($this->data['bundle_quantity']) || $this->data['bundle_quantity'] <= 1)) {
|
if (Str::length($this->data['bundle_quantity']) > 0 && (!is_numeric($this->data['bundle_quantity']) || $this->data['bundle_quantity'] <= 1)) {
|
||||||
@@ -224,11 +226,14 @@ class StickerMasterImporter extends Importer
|
|||||||
if (Str::length($this->data['material_type']) > 0 && $this->data['material_type'] != '1' && $this->data['material_type'] != '2' && $this->data['material_type'] != '3') { //($this->data['material_type'] != null) &&
|
if (Str::length($this->data['material_type']) > 0 && $this->data['material_type'] != '1' && $this->data['material_type'] != '2' && $this->data['material_type'] != '3') { //($this->data['material_type'] != null) &&
|
||||||
$warnMsg[] = "Material type must be 1 or 2 or 3 or empty";
|
$warnMsg[] = "Material type must be 1 or 2 or 3 or empty";
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!empty($warnMsg)) {
|
if (!empty($warnMsg)) {
|
||||||
throw new RowImportFailedException(implode(', ', $warnMsg));
|
throw new RowImportFailedException(implode(', ', $warnMsg));
|
||||||
}
|
}
|
||||||
return StickerMaster::updateOrCreate([
|
|
||||||
|
StickerMaster::updateOrCreate([
|
||||||
'item_id' => $item->id,
|
'item_id' => $item->id,
|
||||||
'plant_id' => $plant->id
|
'plant_id' => $plant->id
|
||||||
],
|
],
|
||||||
@@ -251,11 +256,14 @@ class StickerMasterImporter extends Importer
|
|||||||
'part_validation3' => $this->data['part_validation3'],
|
'part_validation3' => $this->data['part_validation3'],
|
||||||
'part_validation4' => $this->data['part_validation4'],
|
'part_validation4' => $this->data['part_validation4'],
|
||||||
'part_validation5' => $this->data['part_validation5'],
|
'part_validation5' => $this->data['part_validation5'],
|
||||||
|
'laser_part_validation1' => $this->data['laser_part_validation1'],
|
||||||
|
'laser_part_validation2' => $this->data['laser_part_validation2'],
|
||||||
'panel_box_code' => $this->data['panel_box_code'],
|
'panel_box_code' => $this->data['panel_box_code'],
|
||||||
'load_rate' => $this->data['load_rate'],
|
'load_rate' => $this->data['load_rate'],
|
||||||
'bundle_quantity' => $this->data['bundle_quantity'],
|
'bundle_quantity' => $this->data['bundle_quantity'],
|
||||||
'material_type' => $this->data['material_type']
|
'material_type' => $this->data['material_type']
|
||||||
]);
|
]);
|
||||||
|
return null;
|
||||||
// return StickerMaster::firstOrNew([
|
// return StickerMaster::firstOrNew([
|
||||||
// // Update existing records, matching them by `$this->data['column_name']`
|
// // Update existing records, matching them by `$this->data['column_name']`
|
||||||
// 'email' => $this->data['email'],
|
// 'email' => $this->data['email'],
|
||||||
|
|||||||
Reference in New Issue
Block a user