This commit is contained in:
James Cole 2017-09-08 20:24:11 +02:00
parent aae26c5da9
commit 2dff8aec69
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
2 changed files with 26 additions and 11 deletions

View File

@ -13,6 +13,8 @@ declare(strict_types=1);
namespace FireflyIII\Import\Converter;
use Log;
/**
* Class RabobankDebetCredit
*
@ -34,31 +36,40 @@ class Amount implements ConverterInterface
*/
public function convert($value): string
{
Log::debug(sprintf('Start with amount "%s"', $value));
$len = strlen($value);
$decimalPosition = $len - 3;
$decimal = null;
if (($len > 2 && $value{$decimalPosition} === '.') || ($len > 2 && strpos($value, '.') > $decimalPosition)) {
$decimal = '.';
Log::debug(sprintf('Decimal character in "%s" seems to be a dot.', $value));
}
if ($len > 2 && $value{$decimalPosition} === ',') {
$decimal = ',';
Log::debug(sprintf('Decimal character in "%s" seems to be a comma.', $value));
}
// if decimal is dot, replace all comma's and spaces with nothing. then parse as float (round to 4 pos)
if ($decimal === '.') {
$search = [',', ' '];
$value = str_replace($search, '', $value);
$search = [',', ' '];
$oldValue = $value;
$value = str_replace($search, '', $value);
Log::debug(sprintf('Converted amount from "%s" to "%s".', $oldValue, $value));
}
if ($decimal === ',') {
$search = ['.', ' '];
$value = str_replace($search, '', $value);
$value = str_replace(',', '.', $value);
$search = ['.', ' '];
$oldValue = $value;
$value = str_replace($search, '', $value);
$value = str_replace(',', '.', $value);
Log::debug(sprintf('Converted amount from "%s" to "%s".', $oldValue, $value));
}
if (is_null($decimal)) {
// replace all:
$search = ['.', ' ', ','];
$value = str_replace($search, '', $value);
$search = ['.', ' ', ','];
$oldValue = $value;
$value = str_replace($search, '', $value);
Log::debug(sprintf('No decimal character found. Converted amount from "%s" to "%s".', $oldValue, $value));
}
return strval(round(floatval($value), 12));

View File

@ -151,10 +151,14 @@ class CsvProcessor implements FileProcessorInterface
*/
private function getImportArray(): Iterator
{
$content = $this->job->uploadFileContents();
$config = $this->job->configuration;
$reader = Reader::createFromString($content);
$reader->setDelimiter($config['delimiter']);
$content = $this->job->uploadFileContents();
$config = $this->job->configuration;
$reader = Reader::createFromString($content);
$delimiter = $config['delimiter'];
if ($delimiter === 'tab') {
$delimiter = "\t";
}
$reader->setDelimiter($delimiter);
$start = $config['has-headers'] ? 1 : 0;
$results = $reader->setOffset($start)->fetch();
Log::debug(sprintf('Created a CSV reader starting at offset %d', $start));