mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Some more importers.
This commit is contained in:
29
app/Helpers/Csv/Converter/BudgetId.php
Normal file
29
app/Helpers/Csv/Converter/BudgetId.php
Normal file
@@ -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;
|
||||
}
|
||||
}
|
35
app/Helpers/Csv/Converter/BudgetName.php
Normal file
35
app/Helpers/Csv/Converter/BudgetName.php
Normal file
@@ -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;
|
||||
}
|
||||
}
|
29
app/Helpers/Csv/Converter/CategoryId.php
Normal file
29
app/Helpers/Csv/Converter/CategoryId.php
Normal file
@@ -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;
|
||||
}
|
||||
}
|
34
app/Helpers/Csv/Converter/CategoryName.php
Normal file
34
app/Helpers/Csv/Converter/CategoryName.php
Normal file
@@ -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;
|
||||
}
|
||||
}
|
28
app/Helpers/Csv/Converter/CurrencyId.php
Normal file
28
app/Helpers/Csv/Converter/CurrencyId.php
Normal file
@@ -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;
|
||||
}
|
||||
}
|
27
app/Helpers/Csv/Converter/CurrencyName.php
Normal file
27
app/Helpers/Csv/Converter/CurrencyName.php
Normal file
@@ -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;
|
||||
}
|
||||
}
|
28
app/Helpers/Csv/Converter/CurrencySymbol.php
Normal file
28
app/Helpers/Csv/Converter/CurrencySymbol.php
Normal file
@@ -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;
|
||||
}
|
||||
}
|
@@ -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.
|
||||
*
|
||||
|
@@ -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 Importer
|
||||
bcscale(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 Importer
|
||||
return $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;
|
||||
|
||||
|
||||
|
@@ -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',
|
||||
|
Reference in New Issue
Block a user