Skip to content

Firefly III: a personal finances manager

Some new converters.

James Cole1069db3c134b
diff --git a/app/Helpers/Csv/Converter/BasicConverter.php b/app/Helpers/Csv/Converter/BasicConverter.php
index ff19555071..ba2bffc864 100644
--- a/app/Helpers/Csv/Converter/BasicConverter.php
+++ b/app/Helpers/Csv/Converter/BasicConverter.php
@@ -11,10 +11,15 @@ class BasicConverter
{
/** @var array */
protected $data;
+ /** @var string */
+ protected $field;
+ /** @var int */
protected $index;
/** @var array */
protected $mapped;
+ /** @var string */
protected $role;
+ /** @var string */
protected $value;
/**
@@ -28,13 +33,29 @@ class BasicConverter
/**
* @param array $data
*/
- public function setData($data)
+ public function setData(array $data)
{
$this->data = $data;
}
/**
- * @return mixed
+ * @return string
+ */
+ public function getField()
+ {
+ return $this->field;
+ }
+
+ /**
+ * @param string $field
+ */
+ public function setField($field)
+ {
+ $this->field = $field;
+ }
+
+ /**
+ * @return int
*/
public function getIndex()
{
@@ -42,7 +63,7 @@ class BasicConverter
}
/**
- * @param mixed $index
+ * @param int $index
*/
public function setIndex($index)
{
@@ -66,7 +87,7 @@ class BasicConverter
}
/**
- * @return mixed
+ * @return string
*/
public function getRole()
{
@@ -74,7 +95,7 @@ class BasicConverter
}
/**
- * @param mixed $role
+ * @param string $role
*/
public function setRole($role)
{
@@ -82,7 +103,7 @@ class BasicConverter
}
/**
- * @return mixed
+ * @return string
*/
public function getValue()
{
@@ -90,7 +111,7 @@ class BasicConverter
}
/**
- * @param mixed $value
+ * @param string $value
*/
public function setValue($value)
{
diff --git a/app/Helpers/Csv/Converter/ConverterInterface.php b/app/Helpers/Csv/Converter/ConverterInterface.php
index 3efd70555c..1e9eb275e3 100644
--- a/app/Helpers/Csv/Converter/ConverterInterface.php
+++ b/app/Helpers/Csv/Converter/ConverterInterface.php
@@ -22,30 +22,34 @@ interface ConverterInterface
public function convert();
/**
- * @param $index
+ * @param int $index
*/
public function setIndex($index);
/**
- * @param $mapped
+ * @param array $mapped
*/
public function setMapped($mapped);
/**
- * @param $role
+ * @param string $role
*/
public function setRole($role);
/**
- * @param $value
+ * @param string $value
*/
public function setValue($value);
/**
* @param array $data
- *
- * @return mixed
*/
public function setData(array $data);
+ /**
+ * @param string $field
+ *
+ */
+ public function setField($field);
+
}
\ No newline at end of file
diff --git a/app/Helpers/Csv/Converter/OpposingName.php b/app/Helpers/Csv/Converter/OpposingName.php
new file mode 100644
index 0000000000..25ab7b00be
--- /dev/null
+++ b/app/Helpers/Csv/Converter/OpposingName.php
@@ -0,0 +1,24 @@
+<?php
+
+namespace FireflyIII\Helpers\Csv\Converter;
+
+/**
+ * Class OpposingName
+ *
+ * @package FireflyIII\Helpers\Csv\Converter
+ */
+class OpposingName extends BasicConverter implements ConverterInterface
+{
+
+ /**
+ * This method cannot search yet for the correct account (Expense account or Revenue account) because simply put,
+ * Firefly doesn't know yet if this account needs to be an Expense account or a Revenue account. This depends
+ * on the amount which is in the current row and that's a big unknown.
+ *
+ * @return mixed
+ */
+ public function convert()
+ {
+ return $this->value;
+ }
+}
\ No newline at end of file
diff --git a/app/Helpers/Csv/Importer.php b/app/Helpers/Csv/Importer.php
index eeda8892c5..644daaebea 100644
--- a/app/Helpers/Csv/Importer.php
+++ b/app/Helpers/Csv/Importer.php
@@ -78,6 +78,7 @@ class Importer
/** @var ConverterInterface $converter */
$converter = App::make('FireflyIII\Helpers\Csv\Converter\\' . $class);
$converter->setData($data); // the complete array so far.
+ $converter->setField($field);
$converter->setIndex($index);
$converter->setValue($value);
$converter->setRole($role);
diff --git a/config/csv.php b/config/csv.php
index 7c65084ffd..dea1edb42f 100644
--- a/config/csv.php
+++ b/config/csv.php
@@ -2,8 +2,8 @@
return [
'roles' => [
'_ignore' => [
- 'name' => '(ignore this column)',
- 'mappable' => false,
+ 'name' => '(ignore this column)',
+ 'mappable' => false,
'converter' => 'Ignore',
'field' => 'ignored',
],
@@ -46,6 +46,8 @@ return [
'date-rent' => [
'name' => 'Rent calculation date',
'mappable' => false,
+ 'converter' => 'Date',
+ 'field' => 'date-rent',
],
'budget-id' => [
'name' => 'Budget ID (matching Firefly)',
@@ -96,8 +98,10 @@ return [
'mappable' => true,
],
'opposing-name' => [
- 'name' => 'Expense or revenue account name',
- 'mappable' => true,
+ 'name' => 'Expense or revenue account name',
+ 'mappable' => true,
+ 'converter' => 'OpposingName',
+ 'field' => 'opposing-account'
],
'opposing-iban' => [
'name' => 'Expense or revenue account IBAN',