Skip to content

Firefly III: a personal finances manager

Moved parsing of amount with decimal separator to Converter object

Robert Horlings4909fcc8b4bb
diff --git a/app/Helpers/Csv/Converter/AmountComma.php b/app/Helpers/Csv/Converter/AmountComma.php
new file mode 100644
index 0000000000..2427361148
--- /dev/null
+++ b/app/Helpers/Csv/Converter/AmountComma.php
@@ -0,0 +1,30 @@
+<?php
+
+namespace FireflyIII\Helpers\Csv\Converter;
+
+use FireflyIII\Models\Account;
+
+/**
+ * Class AmountComma
+ *
+ * Parses the input as the amount with a comma as decimal separator
+ *
+ * @package FireflyIII\Helpers\Csv\Converter
+ */
+class AmountComma extends BasicConverter implements ConverterInterface
+{
+
+ /**
+ * @return Account|null
+ */
+ public function convert()
+ {
+ $value = str_replace(",", ".", $this->value );
+
+ if (is_numeric($value)) {
+ return floatval($value);
+ }
+
+ return 0;
+ }
+}
diff --git a/app/Helpers/Csv/Specifix/AbnAmroDescription.php b/app/Helpers/Csv/Specifix/AbnAmroDescription.php
index 5f17c62ed4..6a422a5a24 100644
--- a/app/Helpers/Csv/Specifix/AbnAmroDescription.php
+++ b/app/Helpers/Csv/Specifix/AbnAmroDescription.php
@@ -26,8 +26,6 @@ class AbnAmroDescription
*/
public function fix()
{
- $this->handleAmount();
-
// Try to parse the description in known formats.
$parsed = $this->parseSepaDescription() || $this->parseTRTPDescription() || $this->parseGEABEADescription() || $this->parseABNAMRODescription();
@@ -55,10 +53,6 @@ class AbnAmroDescription
$this->row = $row;
}
- protected function handleAmount() {
- $this->data['amount'] = floatval(str_replace(',', '.', $this->row[6]));
- }
-
/**
* Parses the current description in SEPA format
* @return boolean true if the description is SEPA format, false otherwise
diff --git a/config/csv.php b/config/csv.php
index d8cbd4daa5..dfdcc3d26f 100644
--- a/config/csv.php
+++ b/config/csv.php
@@ -177,6 +177,12 @@ return [
'converter' => 'Amount',
'field' => 'amount',
],
+ 'amount-comma-separated' => [
+ 'name' => 'Amount (comma as decimal separator)',
+ 'mappable' => false,
+ 'converter' => 'AmountComma',
+ 'field' => 'amount',
+ ],
'sepa-ct-id' => [
'name' => 'SEPA Credit Transfer end-to-end ID',
'mappable' => false,