Improve export CSV import

This commit is contained in:
Hillel Coren 2017-01-08 16:02:52 +02:00
parent 4596ce4095
commit 7b92eb62fe
2 changed files with 11 additions and 10 deletions

View File

@ -79,7 +79,7 @@ class BaseTransformer extends TransformerAbstract
*/ */
protected function getClientId($name) protected function getClientId($name)
{ {
$name = strtolower($name); $name = strtolower(trim($name));
return isset($this->maps[ENTITY_CLIENT][$name]) ? $this->maps[ENTITY_CLIENT][$name] : null; 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) protected function getProductId($name)
{ {
$name = strtolower($name); $name = strtolower(trim($name));
return isset($this->maps[ENTITY_PRODUCT][$name]) ? $this->maps[ENTITY_PRODUCT][$name] : null; 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) protected function getCountryId($name)
{ {
$name = strtolower($name); $name = strtolower(trim($name));
return isset($this->maps['countries'][$name]) ? $this->maps['countries'][$name] : null; return isset($this->maps['countries'][$name]) ? $this->maps['countries'][$name] : null;
} }
@ -109,7 +109,7 @@ class BaseTransformer extends TransformerAbstract
*/ */
protected function getCountryIdBy2($name) protected function getCountryIdBy2($name)
{ {
$name = strtolower($name); $name = strtolower(trim($name));
return isset($this->maps['countries2'][$name]) ? $this->maps['countries2'][$name] : null; return isset($this->maps['countries2'][$name]) ? $this->maps['countries2'][$name] : null;
} }
@ -196,7 +196,7 @@ class BaseTransformer extends TransformerAbstract
*/ */
public function getVendorId($name) public function getVendorId($name)
{ {
$name = strtolower($name); $name = strtolower(trim($name));
return isset($this->maps[ENTITY_VENDOR][$name]) ? $this->maps[ENTITY_VENDOR][$name] : null; 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) 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; return isset($this->maps[ENTITY_EXPENSE_CATEGORY][$name]) ? $this->maps[ENTITY_EXPENSE_CATEGORY][$name] : null;
} }

View File

@ -286,6 +286,8 @@ class ImportService
*/ */
private function transformRow($source, $entityType, $row) private function transformRow($source, $entityType, $row)
{ {
// TODO skip import if row is blank
$transformer = $this->getTransformer($source, $entityType, $this->maps); $transformer = $this->getTransformer($source, $entityType, $this->maps);
// Create expesnse category // Create expesnse category
@ -297,10 +299,9 @@ class ImportService
$this->addExpenseCategoryToMaps($category); $this->addExpenseCategoryToMaps($category);
} }
} }
if ( ! empty($row->vendor)) { if ( ! empty($row->vendor) && ($vendorName = trim($row->vendor))) {
$vendorId = $transformer->getVendorId($row->vendor); if ( ! $transformer->getVendorId($vendorName)) {
if ( ! $vendorId) { $vendor = $this->vendorRepo->save(['name' => $vendorName, 'vendor_contact' => []]);
$vendor = $this->vendorRepo->save(['name' => $row->vendor, 'vendor_contact' => []]);
$this->addVendorToMaps($vendor); $this->addVendorToMaps($vendor);
} }
} }