Skip to content

Firefly III: a personal finances manager

Code for #819

James Cole2dff8aec69be
diff --git a/app/Import/Converter/Amount.php b/app/Import/Converter/Amount.php
index 160c8c05e6..1177b86a2e 100644
--- a/app/Import/Converter/Amount.php
+++ b/app/Import/Converter/Amount.php
@@ -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));
diff --git a/app/Import/FileProcessor/CsvProcessor.php b/app/Import/FileProcessor/CsvProcessor.php
index e81ec8a87a..d671a65d63 100644
--- a/app/Import/FileProcessor/CsvProcessor.php
+++ b/app/Import/FileProcessor/CsvProcessor.php
@@ -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));