mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-12-01 02:21:45 +00:00
Cleaned up some code.
This commit is contained in:
@@ -20,9 +20,8 @@ class AccountId extends BasicConverter implements ConverterInterface
|
|||||||
{
|
{
|
||||||
/** @var AccountRepositoryInterface $repository */
|
/** @var AccountRepositoryInterface $repository */
|
||||||
$repository = app('FireflyIII\Repositories\Account\AccountRepositoryInterface');
|
$repository = app('FireflyIII\Repositories\Account\AccountRepositoryInterface');
|
||||||
$account = isset($this->mapped[$this->index][$this->value])
|
$var = isset($this->mapped[$this->index][$this->value]) ? $this->mapped[$this->index][$this->value] : $this->value;
|
||||||
? $repository->find($this->mapped[$this->index][$this->value])
|
$account = $repository->find($var);
|
||||||
: $repository->find($this->value);
|
|
||||||
|
|
||||||
return $account;
|
return $account;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,24 @@ class AssetAccountIban extends BasicConverter implements ConverterInterface
|
|||||||
return $account;
|
return $account;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (strlen($this->value) > 0) {
|
if (strlen($this->value) > 0) {
|
||||||
|
$account = $this->searchOrCreate($repository);
|
||||||
|
|
||||||
|
return $account;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Account;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param AccountRepositoryInterface $repository
|
||||||
|
* @param $value
|
||||||
|
*
|
||||||
|
* @return Account
|
||||||
|
*/
|
||||||
|
private function searchOrCreate(AccountRepositoryInterface $repository)
|
||||||
|
{
|
||||||
// find or create new account:
|
// find or create new account:
|
||||||
$set = $repository->getAccounts(['Default account', 'Asset account']);
|
$set = $repository->getAccounts(['Default account', 'Asset account']);
|
||||||
/** @var Account $entry */
|
/** @var Account $entry */
|
||||||
@@ -66,7 +83,4 @@ class AssetAccountIban extends BasicConverter implements ConverterInterface
|
|||||||
|
|
||||||
return $account;
|
return $account;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Account;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,16 +22,12 @@ class AssetAccountName extends BasicConverter implements ConverterInterface
|
|||||||
{
|
{
|
||||||
/** @var AccountRepositoryInterface $repository */
|
/** @var AccountRepositoryInterface $repository */
|
||||||
$repository = app('FireflyIII\Repositories\Account\AccountRepositoryInterface');
|
$repository = app('FireflyIII\Repositories\Account\AccountRepositoryInterface');
|
||||||
|
|
||||||
// is mapped? Then it's easy!
|
|
||||||
if (isset($this->mapped[$this->index][$this->value])) {
|
if (isset($this->mapped[$this->index][$this->value])) {
|
||||||
$account = $repository->find(intval($this->mapped[$this->index][$this->value]));
|
$account = $repository->find(intval($this->mapped[$this->index][$this->value]));
|
||||||
|
|
||||||
return $account;
|
return $account;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// find or create new account:
|
|
||||||
$set = $repository->getAccounts(['Default account', 'Asset account']);
|
$set = $repository->getAccounts(['Default account', 'Asset account']);
|
||||||
/** @var Account $entry */
|
/** @var Account $entry */
|
||||||
foreach ($set as $entry) {
|
foreach ($set as $entry) {
|
||||||
@@ -39,8 +35,6 @@ class AssetAccountName extends BasicConverter implements ConverterInterface
|
|||||||
return $entry;
|
return $entry;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// create it if doesnt exist.
|
|
||||||
$accountData = [
|
$accountData = [
|
||||||
'name' => $this->value,
|
'name' => $this->value,
|
||||||
'accountType' => 'asset',
|
'accountType' => 'asset',
|
||||||
@@ -54,7 +48,6 @@ class AssetAccountName extends BasicConverter implements ConverterInterface
|
|||||||
'openingBalance' => 0,
|
'openingBalance' => 0,
|
||||||
'openingBalanceDate' => new Carbon,
|
'openingBalanceDate' => new Carbon,
|
||||||
'openingBalanceCurrency' => 1, // hard coded.
|
'openingBalanceCurrency' => 1, // hard coded.
|
||||||
|
|
||||||
];
|
];
|
||||||
|
|
||||||
$account = $repository->store($accountData);
|
$account = $repository->store($accountData);
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ namespace FireflyIII\Helpers\Csv\Converter;
|
|||||||
/**
|
/**
|
||||||
* Class BasicConverter
|
* Class BasicConverter
|
||||||
*
|
*
|
||||||
|
*
|
||||||
|
* @SuppressWarnings(PHPMD.NumberOfChildren)
|
||||||
* @package FireflyIII\Helpers\Csv\Converter
|
* @package FireflyIII\Helpers\Csv\Converter
|
||||||
*/
|
*/
|
||||||
class BasicConverter
|
class BasicConverter
|
||||||
|
|||||||
@@ -20,13 +20,8 @@ class BillId extends BasicConverter implements ConverterInterface
|
|||||||
{
|
{
|
||||||
/** @var BillRepositoryInterface $repository */
|
/** @var BillRepositoryInterface $repository */
|
||||||
$repository = app('FireflyIII\Repositories\Bill\BillRepositoryInterface');
|
$repository = app('FireflyIII\Repositories\Bill\BillRepositoryInterface');
|
||||||
|
$value = isset($this->mapped[$this->index][$this->value]) ? $this->mapped[$this->index][$this->value] : $this->value;
|
||||||
// is mapped? Then it's easy!
|
$bill = $repository->find($value);
|
||||||
if (isset($this->mapped[$this->index][$this->value])) {
|
|
||||||
$bill = $repository->find($this->mapped[$this->index][$this->value]);
|
|
||||||
} else {
|
|
||||||
$bill = $repository->find($this->value);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $bill;
|
return $bill;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,20 +21,18 @@ class BillName extends BasicConverter implements ConverterInterface
|
|||||||
/** @var BillRepositoryInterface $repository */
|
/** @var BillRepositoryInterface $repository */
|
||||||
$repository = app('FireflyIII\Repositories\Bill\BillRepositoryInterface');
|
$repository = app('FireflyIII\Repositories\Bill\BillRepositoryInterface');
|
||||||
|
|
||||||
$bill = null;
|
|
||||||
// is mapped? Then it's easy!
|
|
||||||
if (isset($this->mapped[$this->index][$this->value])) {
|
if (isset($this->mapped[$this->index][$this->value])) {
|
||||||
$bill = $repository->find($this->mapped[$this->index][$this->value]);
|
return $repository->find($this->mapped[$this->index][$this->value]);
|
||||||
} else {
|
}
|
||||||
$bills = $repository->getBills();
|
$bills = $repository->getBills();
|
||||||
|
|
||||||
/** @var Bill $bill */
|
/** @var Bill $bill */
|
||||||
foreach ($bills as $bill) {
|
foreach ($bills as $bill) {
|
||||||
if ($bill->name == $this->value) {
|
if ($bill->name == $this->value) {
|
||||||
return $bill;
|
return $bill;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return $bill;
|
return new Bill;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,14 +20,8 @@ class BudgetId extends BasicConverter implements ConverterInterface
|
|||||||
{
|
{
|
||||||
/** @var BudgetRepositoryInterface $repository */
|
/** @var BudgetRepositoryInterface $repository */
|
||||||
$repository = app('FireflyIII\Repositories\Budget\BudgetRepositoryInterface');
|
$repository = app('FireflyIII\Repositories\Budget\BudgetRepositoryInterface');
|
||||||
|
$value = isset($this->mapped[$this->index][$this->value]) ? $this->mapped[$this->index][$this->value] : $this->value;
|
||||||
|
$budget = $repository->find($value);
|
||||||
// is mapped? Then it's easy!
|
|
||||||
if (isset($this->mapped[$this->index][$this->value])) {
|
|
||||||
$budget = $repository->find($this->mapped[$this->index][$this->value]);
|
|
||||||
} else {
|
|
||||||
$budget = $repository->find($this->value);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $budget;
|
return $budget;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,9 +25,11 @@ class BudgetName extends BasicConverter implements ConverterInterface
|
|||||||
// is mapped? Then it's easy!
|
// is mapped? Then it's easy!
|
||||||
if (isset($this->mapped[$this->index][$this->value])) {
|
if (isset($this->mapped[$this->index][$this->value])) {
|
||||||
$budget = $repository->find($this->mapped[$this->index][$this->value]);
|
$budget = $repository->find($this->mapped[$this->index][$this->value]);
|
||||||
} else {
|
|
||||||
$budget = $repository->store(['name' => $this->value, 'user' => Auth::user()->id]);
|
return $budget;
|
||||||
}
|
}
|
||||||
|
$budget = $repository->store(['name' => $this->value, 'user' => Auth::user()->id]);
|
||||||
|
|
||||||
|
|
||||||
return $budget;
|
return $budget;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,13 +20,8 @@ class CategoryId extends BasicConverter implements ConverterInterface
|
|||||||
{
|
{
|
||||||
/** @var SingleCategoryRepositoryInterface $repository */
|
/** @var SingleCategoryRepositoryInterface $repository */
|
||||||
$repository = app('FireflyIII\Repositories\Category\SingleCategoryRepositoryInterface');
|
$repository = app('FireflyIII\Repositories\Category\SingleCategoryRepositoryInterface');
|
||||||
|
$value = isset($this->mapped[$this->index][$this->value]) ? $this->mapped[$this->index][$this->value] : $this->value;
|
||||||
// is mapped? Then it's easy!
|
$category = $repository->find($value);
|
||||||
if (isset($this->mapped[$this->index][$this->value])) {
|
|
||||||
$category = $repository->find($this->mapped[$this->index][$this->value]);
|
|
||||||
} else {
|
|
||||||
$category = $repository->find($this->value);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $category;
|
return $category;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,9 @@ class CategoryName extends BasicConverter implements ConverterInterface
|
|||||||
// is mapped? Then it's easy!
|
// is mapped? Then it's easy!
|
||||||
if (isset($this->mapped[$this->index][$this->value])) {
|
if (isset($this->mapped[$this->index][$this->value])) {
|
||||||
$category = $repository->find($this->mapped[$this->index][$this->value]);
|
$category = $repository->find($this->mapped[$this->index][$this->value]);
|
||||||
} else {
|
|
||||||
|
return $category;
|
||||||
|
}
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
'name' => $this->value,
|
'name' => $this->value,
|
||||||
@@ -33,7 +35,6 @@ class CategoryName extends BasicConverter implements ConverterInterface
|
|||||||
];
|
];
|
||||||
|
|
||||||
$category = $repository->store($data);
|
$category = $repository->store($data);
|
||||||
}
|
|
||||||
|
|
||||||
return $category;
|
return $category;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,13 +21,15 @@ class CurrencyCode extends BasicConverter implements ConverterInterface
|
|||||||
/** @var CurrencyRepositoryInterface $repository */
|
/** @var CurrencyRepositoryInterface $repository */
|
||||||
$repository = app('FireflyIII\Repositories\Currency\CurrencyRepositoryInterface');
|
$repository = app('FireflyIII\Repositories\Currency\CurrencyRepositoryInterface');
|
||||||
|
|
||||||
|
|
||||||
if (isset($this->mapped[$this->index][$this->value])) {
|
if (isset($this->mapped[$this->index][$this->value])) {
|
||||||
$currency = $repository->find($this->mapped[$this->index][$this->value]);
|
$currency = $repository->find($this->mapped[$this->index][$this->value]);
|
||||||
} else {
|
|
||||||
$currency = $repository->findByCode($this->value);
|
return $currency;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$currency = $repository->findByCode($this->value);
|
||||||
|
|
||||||
|
|
||||||
return $currency;
|
return $currency;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,12 +20,8 @@ class CurrencyId extends BasicConverter implements ConverterInterface
|
|||||||
{
|
{
|
||||||
/** @var CurrencyRepositoryInterface $repository */
|
/** @var CurrencyRepositoryInterface $repository */
|
||||||
$repository = app('FireflyIII\Repositories\Currency\CurrencyRepositoryInterface');
|
$repository = app('FireflyIII\Repositories\Currency\CurrencyRepositoryInterface');
|
||||||
|
$value = isset($this->mapped[$this->index][$this->value]) ? $this->mapped[$this->index][$this->value] : $this->value;
|
||||||
if (isset($this->mapped[$this->index][$this->value])) {
|
$currency = $repository->find($value);
|
||||||
$currency = $repository->find($this->mapped[$this->index][$this->value]);
|
|
||||||
} else {
|
|
||||||
$currency = $repository->find($this->value);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $currency;
|
return $currency;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,11 +22,12 @@ class CurrencyName extends BasicConverter implements ConverterInterface
|
|||||||
$repository = app('FireflyIII\Repositories\Currency\CurrencyRepositoryInterface');
|
$repository = app('FireflyIII\Repositories\Currency\CurrencyRepositoryInterface');
|
||||||
|
|
||||||
if (isset($this->mapped[$this->index][$this->value])) {
|
if (isset($this->mapped[$this->index][$this->value])) {
|
||||||
|
|
||||||
$currency = $repository->find($this->mapped[$this->index][$this->value]);
|
$currency = $repository->find($this->mapped[$this->index][$this->value]);
|
||||||
} else {
|
|
||||||
$currency = $repository->findByName($this->value);
|
return $currency;
|
||||||
}
|
}
|
||||||
|
$currency = $repository->findByName($this->value);
|
||||||
|
|
||||||
|
|
||||||
return $currency;
|
return $currency;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,10 +23,13 @@ class CurrencySymbol extends BasicConverter implements ConverterInterface
|
|||||||
|
|
||||||
if (isset($this->mapped[$this->index][$this->value])) {
|
if (isset($this->mapped[$this->index][$this->value])) {
|
||||||
$currency = $repository->find($this->mapped[$this->index][$this->value]);
|
$currency = $repository->find($this->mapped[$this->index][$this->value]);
|
||||||
} else {
|
|
||||||
$currency = $repository->findBySymbol($this->value);
|
return $currency;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$currency = $repository->findBySymbol($this->value);
|
||||||
|
|
||||||
|
|
||||||
return $currency;
|
return $currency;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,7 +27,8 @@ class OpposingAccountIban extends BasicConverter implements ConverterInterface
|
|||||||
$account = $repository->find($this->mapped[$this->index][$this->value]);
|
$account = $repository->find($this->mapped[$this->index][$this->value]);
|
||||||
|
|
||||||
return $account;
|
return $account;
|
||||||
} else {
|
}
|
||||||
|
|
||||||
if (strlen($this->value) > 0) {
|
if (strlen($this->value) > 0) {
|
||||||
|
|
||||||
$set = $repository->getAccounts([]);
|
$set = $repository->getAccounts([]);
|
||||||
@@ -41,7 +42,7 @@ class OpposingAccountIban extends BasicConverter implements ConverterInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
return $this->value;
|
return $this->value;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,15 +21,9 @@ class OpposingAccountId extends BasicConverter implements ConverterInterface
|
|||||||
{
|
{
|
||||||
/** @var AccountRepositoryInterface $repository */
|
/** @var AccountRepositoryInterface $repository */
|
||||||
$repository = app('FireflyIII\Repositories\Account\AccountRepositoryInterface');
|
$repository = app('FireflyIII\Repositories\Account\AccountRepositoryInterface');
|
||||||
|
$value = isset($this->mapped[$this->index][$this->value]) ? $this->mapped[$this->index][$this->value] : $this->value;
|
||||||
if (isset($this->mapped[$this->index][$this->value])) {
|
$account = $repository->find($value);
|
||||||
$account = $repository->find($this->mapped[$this->index][$this->value]);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
$account = $repository->find($this->value);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $account;
|
return $account;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,8 +27,9 @@ class OpposingAccountName extends BasicConverter implements ConverterInterface
|
|||||||
$account = $repository->find($this->mapped[$this->index][$this->value]);
|
$account = $repository->find($this->mapped[$this->index][$this->value]);
|
||||||
|
|
||||||
return $account;
|
return $account;
|
||||||
} else {
|
}
|
||||||
|
|
||||||
return $this->value;
|
return $this->value;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user