Support importing exported files

This commit is contained in:
Hillel Coren 2017-01-08 14:19:40 +02:00
parent 86af13f924
commit 4596ce4095
2 changed files with 15 additions and 2 deletions

View File

@ -360,6 +360,7 @@ Route::get('/comments/feed', function() {
}); });
if (!defined('CONTACT_EMAIL')) { if (!defined('CONTACT_EMAIL')) {
define('APP_NAME', env('APP_NAME', 'Invoice Ninja'));
define('CONTACT_EMAIL', config('mail.from.address')); define('CONTACT_EMAIL', config('mail.from.address'));
define('CONTACT_NAME', config('mail.from.name')); define('CONTACT_NAME', config('mail.from.name'));
define('SITE_URL', config('app.url')); define('SITE_URL', config('app.url'));

View File

@ -485,14 +485,24 @@ class ImportService
$csv->heading = false; $csv->heading = false;
$csv->auto($filename); $csv->auto($filename);
Session::put("{$entityType}-data", $csv->data);
$headers = false; $headers = false;
$hasHeaders = false; $hasHeaders = false;
$mapped = []; $mapped = [];
if (count($csv->data) > 0) { if (count($csv->data) > 0) {
$headers = $csv->data[0]; $headers = $csv->data[0];
// Remove Invoice Ninja headers
if (count($headers) && count($csv->data) > 4) {
$firstCell = $headers[0];
if (strstr($firstCell, APP_NAME)) {
array_shift($csv->data); // Invoice Ninja...
array_shift($csv->data); // <blank line>
array_shift($csv->data); // Enitty Type Header
}
$headers = $csv->data[0];
}
foreach ($headers as $title) { foreach ($headers as $title) {
if (strpos(strtolower($title), 'name') > 0) { if (strpos(strtolower($title), 'name') > 0) {
$hasHeaders = true; $hasHeaders = true;
@ -514,6 +524,8 @@ class ImportService
} }
} }
Session::put("{$entityType}-data", $csv->data);
$data = [ $data = [
'entityType' => $entityType, 'entityType' => $entityType,
'data' => $csv->data, 'data' => $csv->data,