diff --git a/app/Ninja/Import/BaseTransformer.php b/app/Ninja/Import/BaseTransformer.php index 3400d5dade23..528c5fc2bc2c 100644 --- a/app/Ninja/Import/BaseTransformer.php +++ b/app/Ninja/Import/BaseTransformer.php @@ -79,7 +79,7 @@ class BaseTransformer extends TransformerAbstract */ protected function getClientId($name) { - $name = strtolower($name); + $name = strtolower(trim($name)); return isset($this->maps[ENTITY_CLIENT][$name]) ? $this->maps[ENTITY_CLIENT][$name] : null; } @@ -89,7 +89,7 @@ class BaseTransformer extends TransformerAbstract */ protected function getProductId($name) { - $name = strtolower($name); + $name = strtolower(trim($name)); return isset($this->maps[ENTITY_PRODUCT][$name]) ? $this->maps[ENTITY_PRODUCT][$name] : null; } @@ -99,7 +99,7 @@ class BaseTransformer extends TransformerAbstract */ protected function getCountryId($name) { - $name = strtolower($name); + $name = strtolower(trim($name)); return isset($this->maps['countries'][$name]) ? $this->maps['countries'][$name] : null; } @@ -109,7 +109,7 @@ class BaseTransformer extends TransformerAbstract */ protected function getCountryIdBy2($name) { - $name = strtolower($name); + $name = strtolower(trim($name)); return isset($this->maps['countries2'][$name]) ? $this->maps['countries2'][$name] : null; } @@ -196,7 +196,7 @@ class BaseTransformer extends TransformerAbstract */ public function getVendorId($name) { - $name = strtolower($name); + $name = strtolower(trim($name)); return isset($this->maps[ENTITY_VENDOR][$name]) ? $this->maps[ENTITY_VENDOR][$name] : null; } @@ -207,7 +207,7 @@ class BaseTransformer extends TransformerAbstract */ public function getExpenseCategoryId($name) { - $name = strtolower($name); + $name = strtolower(trim($name)); return isset($this->maps[ENTITY_EXPENSE_CATEGORY][$name]) ? $this->maps[ENTITY_EXPENSE_CATEGORY][$name] : null; } diff --git a/app/Services/ImportService.php b/app/Services/ImportService.php index 8d9214acf59d..09305a91b45e 100644 --- a/app/Services/ImportService.php +++ b/app/Services/ImportService.php @@ -286,6 +286,8 @@ class ImportService */ private function transformRow($source, $entityType, $row) { + // TODO skip import if row is blank + $transformer = $this->getTransformer($source, $entityType, $this->maps); // Create expesnse category @@ -297,10 +299,9 @@ class ImportService $this->addExpenseCategoryToMaps($category); } } - if ( ! empty($row->vendor)) { - $vendorId = $transformer->getVendorId($row->vendor); - if ( ! $vendorId) { - $vendor = $this->vendorRepo->save(['name' => $row->vendor, 'vendor_contact' => []]); + if ( ! empty($row->vendor) && ($vendorName = trim($row->vendor))) { + if ( ! $transformer->getVendorId($vendorName)) { + $vendor = $this->vendorRepo->save(['name' => $vendorName, 'vendor_contact' => []]); $this->addVendorToMaps($vendor); } }