Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Some more importers.
James Cole601f9f86bb99
diff --git a/app/Helpers/Csv/Converter/BudgetId.php b/app/Helpers/Csv/Converter/BudgetId.phpnew file mode 100644index 0000000000..daaec82688--- /dev/null+++ b/app/Helpers/Csv/Converter/BudgetId.php@@ -0,0 +1,29 @@+<?php+namespace FireflyIII\Helpers\Csv\Converter;++use Auth;+use FireflyIII\Models\Budget;++/**+ * Class AccountId+ *+ * @package FireflyIII\Helpers\Csv\Converter+ */+class BudgetId extends BasicConverter implements ConverterInterface+{++ /**+ * @return Budget+ */+ public function convert()+ {+ // is mapped? Then it's easy!+ if (isset($this->mapped[$this->index][$this->value])) {+ $budget = Auth::user()->budgets()->find($this->mapped[$this->index][$this->value]);+ } else {+ $budget = Auth::user()->budgets()->find($this->value);+ }++ return $budget;+ }+}\ No newline at end of filediff --git a/app/Helpers/Csv/Converter/BudgetName.php b/app/Helpers/Csv/Converter/BudgetName.phpnew file mode 100644index 0000000000..26ff92a1ec--- /dev/null+++ b/app/Helpers/Csv/Converter/BudgetName.php@@ -0,0 +1,35 @@+<?php+namespace FireflyIII\Helpers\Csv\Converter;++use Auth;+use FireflyIII\Models\Budget;++/**+ * Class BudgetName+ *+ * @package FireflyIII\Helpers\Csv\Converter+ */+class BudgetName extends BasicConverter implements ConverterInterface+{++ /**+ * @return Budget+ */+ public function convert()+ {+ // is mapped? Then it's easy!+ if (isset($this->mapped[$this->index][$this->value])) {+ $budget = Auth::user()->budgets()->find($this->mapped[$this->index][$this->value]);+ } else {+ $budget = Budget::firstOrCreateEncrypted(+ [+ 'name' => $this->value,+ 'user_id' => Auth::user()->id,+ 'active' => true,+ ]+ );+ }++ return $budget;+ }+}\ No newline at end of filediff --git a/app/Helpers/Csv/Converter/CategoryId.php b/app/Helpers/Csv/Converter/CategoryId.phpnew file mode 100644index 0000000000..9b6b089d37--- /dev/null+++ b/app/Helpers/Csv/Converter/CategoryId.php@@ -0,0 +1,29 @@+<?php+namespace FireflyIII\Helpers\Csv\Converter;++use Auth;+use FireflyIII\Models\Category;++/**+ * Class CategoryId+ *+ * @package FireflyIII\Helpers\Csv\Converter+ */+class CategoryId extends BasicConverter implements ConverterInterface+{++ /**+ * @return Category+ */+ public function convert()+ {+ // is mapped? Then it's easy!+ if (isset($this->mapped[$this->index][$this->value])) {+ $category = Auth::user()->categories()->find($this->mapped[$this->index][$this->value]);+ } else {+ $category = Auth::user()->categories()->find($this->value);+ }++ return $category;+ }+}\ No newline at end of filediff --git a/app/Helpers/Csv/Converter/CategoryName.php b/app/Helpers/Csv/Converter/CategoryName.phpnew file mode 100644index 0000000000..5a35ecbcb9--- /dev/null+++ b/app/Helpers/Csv/Converter/CategoryName.php@@ -0,0 +1,34 @@+<?php+namespace FireflyIII\Helpers\Csv\Converter;++use Auth;+use FireflyIII\Models\Category;++/**+ * Class CategoryName+ *+ * @package FireflyIII\Helpers\Csv\Converter+ */+class CategoryName extends BasicConverter implements ConverterInterface+{++ /**+ * @return Category+ */+ public function convert()+ {+ // is mapped? Then it's easy!+ if (isset($this->mapped[$this->index][$this->value])) {+ $category = Auth::user()->categories()->find($this->mapped[$this->index][$this->value]);+ } else {+ $category = Category::firstOrCreateEncrypted(+ [+ 'name' => $this->value,+ 'user_id' => Auth::user()->id+ ]+ );+ }++ return $category;+ }+}\ No newline at end of filediff --git a/app/Helpers/Csv/Converter/CurrencyId.php b/app/Helpers/Csv/Converter/CurrencyId.phpnew file mode 100644index 0000000000..1544acae83--- /dev/null+++ b/app/Helpers/Csv/Converter/CurrencyId.php@@ -0,0 +1,28 @@+<?php++namespace FireflyIII\Helpers\Csv\Converter;++use FireflyIII\Models\TransactionCurrency;++/**+ * Class CurrencyId+ *+ * @package FireflyIII\Helpers\Csv\Converter+ */+class CurrencyId extends BasicConverter implements ConverterInterface+{++ /**+ * @return mixed|static+ */+ public function convert()+ {+ if (isset($this->mapped[$this->index][$this->value])) {+ $currency = TransactionCurrency::find($this->mapped[$this->index][$this->value]);+ } else {+ $currency = TransactionCurrency::find($this->value);+ }++ return $currency;+ }+}\ No newline at end of filediff --git a/app/Helpers/Csv/Converter/CurrencyName.php b/app/Helpers/Csv/Converter/CurrencyName.phpnew file mode 100644index 0000000000..8788de2397--- /dev/null+++ b/app/Helpers/Csv/Converter/CurrencyName.php@@ -0,0 +1,27 @@+<?php++namespace FireflyIII\Helpers\Csv\Converter;+use FireflyIII\Models\TransactionCurrency;++/**+ * Class CurrencyName+ *+ * @package FireflyIII\Helpers\Csv\Converter+ */+class CurrencyName extends BasicConverter implements ConverterInterface+{++ /**+ * @return mixed|static+ */+ public function convert()+ {+ if (isset($this->mapped[$this->index][$this->value])) {+ $currency = TransactionCurrency::find($this->mapped[$this->index][$this->value]);+ } else {+ $currency = TransactionCurrency::whereName($this->value)->first();+ }++ return $currency;+ }+}\ No newline at end of filediff --git a/app/Helpers/Csv/Converter/CurrencySymbol.php b/app/Helpers/Csv/Converter/CurrencySymbol.phpnew file mode 100644index 0000000000..957674751f--- /dev/null+++ b/app/Helpers/Csv/Converter/CurrencySymbol.php@@ -0,0 +1,28 @@+<?php++namespace FireflyIII\Helpers\Csv\Converter;++use FireflyIII\Models\TransactionCurrency;++/**+ * Class CurrencySymbol+ *+ * @package FireflyIII\Helpers\Csv\Converter+ */+class CurrencySymbol extends BasicConverter implements ConverterInterface+{++ /**+ * @return mixed|static+ */+ public function convert()+ {+ if (isset($this->mapped[$this->index][$this->value])) {+ $currency = TransactionCurrency::find($this->mapped[$this->index][$this->value]);+ } else {+ $currency = TransactionCurrency::whereSymbol($this->value)->first();+ }++ return $currency;+ }+}\ No newline at end of filediff --git a/app/Helpers/Csv/Converter/OpposingName.php b/app/Helpers/Csv/Converter/OpposingName.phpindex 25ab7b00be..6a0662db29 100644--- a/app/Helpers/Csv/Converter/OpposingName.php+++ b/app/Helpers/Csv/Converter/OpposingName.php@@ -11,7 +11,7 @@ class OpposingName extends BasicConverter implements ConverterInterface{/**- * This method cannot search yet for the correct account (Expense account or Revenue account) because simply put,+ * This method cannot search yet for the correct account (Expense account, Revenue account or Asset 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.*diff --git a/app/Helpers/Csv/Importer.php b/app/Helpers/Csv/Importer.phpindex 65cdceb4e9..b179a9acd0 100644--- a/app/Helpers/Csv/Importer.php+++ b/app/Helpers/Csv/Importer.php@@ -148,20 +148,16 @@ class Importer*/protected function getFiller(){- return [- 'description' => '',- 'asset-account' => null,- 'opposing-account' => '',- 'opposing-account-object' => null,- 'date' => null,- 'currency' => null,- 'amount' => null,- 'amount-modifier' => 1,- 'ignored' => null,- 'date-rent' => null,- 'bill' => null,- 'bill-id' => null,- ];+ $filler = [];+ foreach (Config::get('csv.roles') as $role) {+ $fieldName = $role['field'];+ $filler[$fieldName] = null;+ }+ // some extra's:+ $filler['bill-id'] = null;+ $filler['opposing-account-object'] = null;++ return $filler;}@@ -178,6 +174,11 @@ class Importerbcscale(2);$data['description'] = trim($data['description']);$data['amount'] = bcmul($data['amount'], $data['amount-modifier']);++ // get opposing account, which is quite complex:+ $data['opposing-account-object'] = $this->processOpposingAccount($data);++ // opposing account type:if ($data['amount'] < 0) {// create expense account:$accountType = AccountType::where('type', 'Expense account')->first();@@ -220,6 +221,22 @@ class Importerreturn $data;}+ /**+ * @param array $data+ */+ public function processOpposingAccount(array $data)+ {+ // first priority. try to find the account based on ID,+ // if any.++ // second: try to find the account based on IBAN, if any.++ // third: try to find account based on name, if any.++ // if nothing, create expense/revenue, never asset.++ }+/*** @param $data*@@ -295,6 +312,16 @@ class Importer$journal->save();}+ // add budget:+ if (!is_null($data['budget'])) {+ $journal->budgets()->save($data['budget']);+ }++ // add category:+ if (!is_null($data['category'])) {+ $journal->categories()->save($data['category']);+ }+return $journal;diff --git a/config/csv.php b/config/csv.phpindex f5ebdad7fa..6164cf280c 100644--- a/config/csv.php+++ b/config/csv.php@@ -20,12 +20,16 @@ return ['field' => 'bill',],'currency-id' => [- 'name' => 'Currency ID (matching Firefly)',- 'mappable' => true,+ 'name' => 'Currency ID (matching Firefly)',+ 'mappable' => true,+ 'converter' => 'CurrencyId',+ 'field' => 'currency',],'currency-name' => [- 'name' => 'Currency name (matching Firefly)',- 'mappable' => true,+ 'name' => 'Currency name (matching Firefly)',+ 'mappable' => true,+ 'converter' => 'CurrencyName',+ 'field' => 'currency',],'currency-code' => ['name' => 'Currency code (ISO 4217)',@@ -35,8 +39,10 @@ return ['mapper' => 'TransactionCurrency'],'currency-symbol' => [- 'name' => 'Currency symbol (matching Firefly)',- 'mappable' => true,+ 'name' => 'Currency symbol (matching Firefly)',+ 'mappable' => true,+ 'converter' => 'CurrencySymbol',+ 'field' => 'currency',],'description' => ['name' => 'Description',@@ -57,12 +63,16 @@ return ['field' => 'date-rent',],'budget-id' => [- 'name' => 'Budget ID (matching Firefly)',- 'mappable' => true,+ 'name' => 'Budget ID (matching Firefly)',+ 'mappable' => true,+ 'converter' => 'BudgetId',+ 'field' => 'budget'],'budget-name' => [- 'name' => 'Budget name',- 'mappable' => true,+ 'name' => 'Budget name',+ 'mappable' => true,+ 'converter' => 'BudgetName',+ 'field' => 'budget'],'rabo-debet-credit' => ['name' => 'Rabobank specific debet/credit indicator',@@ -71,12 +81,16 @@ return ['field' => 'amount-modifier',],'category-id' => [- 'name' => 'Category ID (matching Firefly)',- 'mappable' => true,+ 'name' => 'Category ID (matching Firefly)',+ 'mappable' => true,+ 'converter' => 'CategoryId',+ 'field' => 'category'],'category-name' => [- 'name' => 'Category name',- 'mappable' => true,+ 'name' => 'Category name',+ 'mappable' => true,+ 'converter' => 'CategoryName',+ 'field' => 'category'],'tags-comma' => ['name' => 'Tags (comma separated)',@@ -110,16 +124,17 @@ return ['opposing-id' => ['name' => 'Opposing account account ID (matching Firefly)','mappable' => true,+ 'field' => 'opposing-account-id',],'opposing-name' => [- 'name' => 'Opposing account name',- 'mappable' => true,- 'converter' => 'OpposingName',- 'field' => 'opposing-account'+ 'name' => 'Opposing account name',+ 'mappable' => true,+ 'field' => 'opposing-account-name',],'opposing-iban' => ['name' => 'Opposing account IBAN','mappable' => true,+ 'field' => 'opposing-account-iban',],'amount' => ['name' => 'Amount',