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