mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Code for #819
This commit is contained in:
parent
aae26c5da9
commit
2dff8aec69
@ -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));
|
||||
|
@ -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));
|
||||
|
Loading…
Reference in New Issue
Block a user