1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-08 20:22:42 +01:00

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)
{
$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;
}

View File

@ -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);
}
}