mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-22 04:00:58 -04:00
Improve handling invalid date with CSV import
This commit is contained in:
parent
41bfea1edb
commit
9a21f754d5
@ -5,6 +5,7 @@ namespace App\Ninja\Import;
|
|||||||
use Carbon;
|
use Carbon;
|
||||||
use League\Fractal\TransformerAbstract;
|
use League\Fractal\TransformerAbstract;
|
||||||
use Utils;
|
use Utils;
|
||||||
|
use Exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class BaseTransformer.
|
* Class BaseTransformer.
|
||||||
@ -158,6 +159,7 @@ class BaseTransformer extends TransformerAbstract
|
|||||||
$date = new Carbon($date);
|
$date = new Carbon($date);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
// if we fail to parse return blank
|
// if we fail to parse return blank
|
||||||
|
$date = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,6 +30,7 @@ use parsecsv;
|
|||||||
use Session;
|
use Session;
|
||||||
use stdClass;
|
use stdClass;
|
||||||
use Utils;
|
use Utils;
|
||||||
|
use Carbon;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class ImportService.
|
* Class ImportService.
|
||||||
@ -594,8 +595,24 @@ class ImportService
|
|||||||
'hasHeaders' => $hasHeaders,
|
'hasHeaders' => $hasHeaders,
|
||||||
'columns' => $columns,
|
'columns' => $columns,
|
||||||
'mapped' => $mapped,
|
'mapped' => $mapped,
|
||||||
|
'warning' => false,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
// check that dates are valid
|
||||||
|
if (count($data['data']) > 1) {
|
||||||
|
$row = $data['data'][1];
|
||||||
|
foreach ($mapped as $index => $field) {
|
||||||
|
if (! strstr($field, 'date')) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
$date = new Carbon($row[$index]);
|
||||||
|
} catch(Exception $e) {
|
||||||
|
$data['warning'] = 'invalid_date';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2296,6 +2296,7 @@ $LANG = array(
|
|||||||
'credit_number_help' => 'Specify a prefix or use a custom pattern to dynamically set the credit number for negative invoices.',
|
'credit_number_help' => 'Specify a prefix or use a custom pattern to dynamically set the credit number for negative invoices.',
|
||||||
'next_credit_number' => 'The next credit number is :number.',
|
'next_credit_number' => 'The next credit number is :number.',
|
||||||
'padding_help' => 'The number of zero\'s to pad the number.',
|
'padding_help' => 'The number of zero\'s to pad the number.',
|
||||||
|
'import_warning_invalid_date' => 'Warning: The date format appears to be invalid.',
|
||||||
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -10,6 +10,10 @@
|
|||||||
|
|
||||||
<p> </p>
|
<p> </p>
|
||||||
|
|
||||||
|
@if (! empty($warning))
|
||||||
|
<div class="alert alert-warning">{{ trans('texts.import_warning_' . $warning) }}</div>
|
||||||
|
@endif
|
||||||
|
|
||||||
<table class="table invoice-table">
|
<table class="table invoice-table">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user