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;
|
namespace FireflyIII\Import\Converter;
|
||||||
|
|
||||||
|
use Log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class RabobankDebetCredit
|
* Class RabobankDebetCredit
|
||||||
*
|
*
|
||||||
@ -34,31 +36,40 @@ class Amount implements ConverterInterface
|
|||||||
*/
|
*/
|
||||||
public function convert($value): string
|
public function convert($value): string
|
||||||
{
|
{
|
||||||
|
Log::debug(sprintf('Start with amount "%s"', $value));
|
||||||
$len = strlen($value);
|
$len = strlen($value);
|
||||||
$decimalPosition = $len - 3;
|
$decimalPosition = $len - 3;
|
||||||
$decimal = null;
|
$decimal = null;
|
||||||
|
|
||||||
if (($len > 2 && $value{$decimalPosition} === '.') || ($len > 2 && strpos($value, '.') > $decimalPosition)) {
|
if (($len > 2 && $value{$decimalPosition} === '.') || ($len > 2 && strpos($value, '.') > $decimalPosition)) {
|
||||||
$decimal = '.';
|
$decimal = '.';
|
||||||
|
Log::debug(sprintf('Decimal character in "%s" seems to be a dot.', $value));
|
||||||
}
|
}
|
||||||
if ($len > 2 && $value{$decimalPosition} === ',') {
|
if ($len > 2 && $value{$decimalPosition} === ',') {
|
||||||
$decimal = ',';
|
$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 is dot, replace all comma's and spaces with nothing. then parse as float (round to 4 pos)
|
||||||
if ($decimal === '.') {
|
if ($decimal === '.') {
|
||||||
$search = [',', ' '];
|
$search = [',', ' '];
|
||||||
|
$oldValue = $value;
|
||||||
$value = str_replace($search, '', $value);
|
$value = str_replace($search, '', $value);
|
||||||
|
Log::debug(sprintf('Converted amount from "%s" to "%s".', $oldValue, $value));
|
||||||
}
|
}
|
||||||
if ($decimal === ',') {
|
if ($decimal === ',') {
|
||||||
$search = ['.', ' '];
|
$search = ['.', ' '];
|
||||||
|
$oldValue = $value;
|
||||||
$value = str_replace($search, '', $value);
|
$value = str_replace($search, '', $value);
|
||||||
$value = str_replace(',', '.', $value);
|
$value = str_replace(',', '.', $value);
|
||||||
|
Log::debug(sprintf('Converted amount from "%s" to "%s".', $oldValue, $value));
|
||||||
}
|
}
|
||||||
if (is_null($decimal)) {
|
if (is_null($decimal)) {
|
||||||
// replace all:
|
// replace all:
|
||||||
$search = ['.', ' ', ','];
|
$search = ['.', ' ', ','];
|
||||||
|
$oldValue = $value;
|
||||||
$value = str_replace($search, '', $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));
|
return strval(round(floatval($value), 12));
|
||||||
|
@ -154,7 +154,11 @@ class CsvProcessor implements FileProcessorInterface
|
|||||||
$content = $this->job->uploadFileContents();
|
$content = $this->job->uploadFileContents();
|
||||||
$config = $this->job->configuration;
|
$config = $this->job->configuration;
|
||||||
$reader = Reader::createFromString($content);
|
$reader = Reader::createFromString($content);
|
||||||
$reader->setDelimiter($config['delimiter']);
|
$delimiter = $config['delimiter'];
|
||||||
|
if ($delimiter === 'tab') {
|
||||||
|
$delimiter = "\t";
|
||||||
|
}
|
||||||
|
$reader->setDelimiter($delimiter);
|
||||||
$start = $config['has-headers'] ? 1 : 0;
|
$start = $config['has-headers'] ? 1 : 0;
|
||||||
$results = $reader->setOffset($start)->fetch();
|
$results = $reader->setOffset($start)->fetch();
|
||||||
Log::debug(sprintf('Created a CSV reader starting at offset %d', $start));
|
Log::debug(sprintf('Created a CSV reader starting at offset %d', $start));
|
||||||
|
Loading…
Reference in New Issue
Block a user