mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-07 10:17:30 -04:00
Skip blank rows in CSV import
This commit is contained in:
parent
7b92eb62fe
commit
7711d0a456
@ -252,6 +252,10 @@ class ImportService
|
|||||||
$this->checkData($entityType, count($reader->all()));
|
$this->checkData($entityType, count($reader->all()));
|
||||||
|
|
||||||
$reader->each(function ($row) use ($source, $entityType, &$row_list, &$results) {
|
$reader->each(function ($row) use ($source, $entityType, &$row_list, &$results) {
|
||||||
|
if ($this->isRowEmpty($row)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$data_index = $this->transformRow($source, $entityType, $row);
|
$data_index = $this->transformRow($source, $entityType, $row);
|
||||||
|
|
||||||
if ($data_index !== false) {
|
if ($data_index !== false) {
|
||||||
@ -286,8 +290,6 @@ 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
|
||||||
@ -620,6 +622,9 @@ class ImportService
|
|||||||
}
|
}
|
||||||
|
|
||||||
$row = $this->convertToObject($entityType, $row, $map);
|
$row = $this->convertToObject($entityType, $row, $map);
|
||||||
|
if ($this->isRowEmpty($row)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
$data_index = $this->transformRow($source, $entityType, $row);
|
$data_index = $this->transformRow($source, $entityType, $row);
|
||||||
|
|
||||||
if ($data_index !== false) {
|
if ($data_index !== false) {
|
||||||
@ -812,4 +817,17 @@ class ImportService
|
|||||||
$this->maps['expense_category'][$name] = $category->id;
|
$this->maps['expense_category'][$name] = $category->id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function isRowEmpty($row)
|
||||||
|
{
|
||||||
|
$isEmpty = true;
|
||||||
|
|
||||||
|
foreach ($row as $key => $val) {
|
||||||
|
if (trim($val)) {
|
||||||
|
$isEmpty = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $isEmpty;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user