mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-21 03:39:00 +00:00
Move getActiveAccountsByType
This commit is contained in:
@@ -84,33 +84,6 @@ class AccountCrud implements AccountCrudInterface
|
|||||||
return new Account;
|
return new Account;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param array $types
|
|
||||||
*
|
|
||||||
* @return Collection
|
|
||||||
*/
|
|
||||||
public function getActiveAccountsByType(array $types): Collection
|
|
||||||
{
|
|
||||||
/** @var Collection $result */
|
|
||||||
$query = $this->user->accounts()->with(
|
|
||||||
['accountmeta' => function (HasMany $query) {
|
|
||||||
$query->where('name', 'accountRole');
|
|
||||||
}]
|
|
||||||
);
|
|
||||||
if (count($types) > 0) {
|
|
||||||
$query->accountTypeIn($types);
|
|
||||||
}
|
|
||||||
$query->where('active', 1);
|
|
||||||
$result = $query->get(['accounts.*']);
|
|
||||||
$result = $result->sortBy(
|
|
||||||
function (Account $account) {
|
|
||||||
return strtolower($account->name);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $data
|
* @param array $data
|
||||||
*
|
*
|
||||||
@@ -132,18 +105,6 @@ class AccountCrud implements AccountCrudInterface
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param $account
|
|
||||||
* @param $name
|
|
||||||
* @param $value
|
|
||||||
*
|
|
||||||
* @return AccountMeta
|
|
||||||
*/
|
|
||||||
public function storeMeta(Account $account, string $name, $value): AccountMeta
|
|
||||||
{
|
|
||||||
return AccountMeta::create(['name' => $name, 'data' => $value, 'account_id' => $account->id,]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Account $account
|
* @param Account $account
|
||||||
* @param array $data
|
* @param array $data
|
||||||
|
@@ -35,13 +35,6 @@ interface AccountCrudInterface
|
|||||||
*/
|
*/
|
||||||
public function findByName(string $name, array $types): Account;
|
public function findByName(string $name, array $types): Account;
|
||||||
|
|
||||||
/**
|
|
||||||
* @param array $types
|
|
||||||
*
|
|
||||||
* @return Collection
|
|
||||||
*/
|
|
||||||
public function getActiveAccountsByType(array $types): Collection;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $data
|
* @param array $data
|
||||||
*
|
*
|
||||||
@@ -49,15 +42,6 @@ interface AccountCrudInterface
|
|||||||
*/
|
*/
|
||||||
public function store(array $data) : Account;
|
public function store(array $data) : Account;
|
||||||
|
|
||||||
/**
|
|
||||||
* @param $account
|
|
||||||
* @param $name
|
|
||||||
* @param $value
|
|
||||||
*
|
|
||||||
* @return AccountMeta
|
|
||||||
*/
|
|
||||||
public function storeMeta(Account $account, string $name, $value): AccountMeta;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Account $account
|
* @param Account $account
|
||||||
* @param array $data
|
* @param array $data
|
||||||
|
@@ -15,7 +15,6 @@ namespace FireflyIII\Http\Controllers;
|
|||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use ExpandedForm;
|
use ExpandedForm;
|
||||||
use FireflyIII\Crud\Account\AccountCrudInterface;
|
|
||||||
use FireflyIII\Events\TransactionJournalStored;
|
use FireflyIII\Events\TransactionJournalStored;
|
||||||
use FireflyIII\Events\TransactionJournalUpdated;
|
use FireflyIII\Events\TransactionJournalUpdated;
|
||||||
use FireflyIII\Helpers\Attachments\AttachmentHelperInterface;
|
use FireflyIII\Helpers\Attachments\AttachmentHelperInterface;
|
||||||
@@ -63,13 +62,13 @@ class TransactionController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function create(string $what = TransactionType::DEPOSIT)
|
public function create(string $what = TransactionType::DEPOSIT)
|
||||||
{
|
{
|
||||||
/** @var AccountCrudInterface $crud */
|
/** @var AccountRepositoryInterface $accountRepository */
|
||||||
$crud = app(AccountCrudInterface::class);
|
$accountRepository = app(AccountRepositoryInterface::class);
|
||||||
$budgetRepository = app('FireflyIII\Repositories\Budget\BudgetRepositoryInterface');
|
$budgetRepository = app('FireflyIII\Repositories\Budget\BudgetRepositoryInterface');
|
||||||
$piggyRepository = app('FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface');
|
$piggyRepository = app('FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface');
|
||||||
$what = strtolower($what);
|
$what = strtolower($what);
|
||||||
$uploadSize = min(Steam::phpBytes(ini_get('upload_max_filesize')), Steam::phpBytes(ini_get('post_max_size')));
|
$uploadSize = min(Steam::phpBytes(ini_get('upload_max_filesize')), Steam::phpBytes(ini_get('post_max_size')));
|
||||||
$assetAccounts = ExpandedForm::makeSelectList($crud->getActiveAccountsByType(['Default account', 'Asset account']));
|
$assetAccounts = ExpandedForm::makeSelectList($accountRepository->getActiveAccountsByType(['Default account', 'Asset account']));
|
||||||
$budgets = ExpandedForm::makeSelectListWithEmpty($budgetRepository->getActiveBudgets());
|
$budgets = ExpandedForm::makeSelectListWithEmpty($budgetRepository->getActiveBudgets());
|
||||||
$piggyBanks = $piggyRepository->getPiggyBanksWithAmount();
|
$piggyBanks = $piggyRepository->getPiggyBanksWithAmount();
|
||||||
$piggies = ExpandedForm::makeSelectListWithEmpty($piggyBanks);
|
$piggies = ExpandedForm::makeSelectListWithEmpty($piggyBanks);
|
||||||
|
@@ -225,6 +225,33 @@ class AccountRepository implements AccountRepositoryInterface
|
|||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $types
|
||||||
|
*
|
||||||
|
* @return Collection
|
||||||
|
*/
|
||||||
|
public function getActiveAccountsByType(array $types): Collection
|
||||||
|
{
|
||||||
|
/** @var Collection $result */
|
||||||
|
$query = $this->user->accounts()->with(
|
||||||
|
['accountmeta' => function (HasMany $query) {
|
||||||
|
$query->where('name', 'accountRole');
|
||||||
|
}]
|
||||||
|
);
|
||||||
|
if (count($types) > 0) {
|
||||||
|
$query->accountTypeIn($types);
|
||||||
|
}
|
||||||
|
$query->where('active', 1);
|
||||||
|
$result = $query->get(['accounts.*']);
|
||||||
|
$result = $result->sortBy(
|
||||||
|
function (Account $account) {
|
||||||
|
return strtolower($account->name);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the date of the very first transaction in this account.
|
* Returns the date of the very first transaction in this account.
|
||||||
*
|
*
|
||||||
|
@@ -89,6 +89,13 @@ interface AccountRepositoryInterface
|
|||||||
*/
|
*/
|
||||||
public function getAccountsByType(array $types): Collection;
|
public function getAccountsByType(array $types): Collection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $types
|
||||||
|
*
|
||||||
|
* @return Collection
|
||||||
|
*/
|
||||||
|
public function getActiveAccountsByType(array $types): Collection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the date of the very first transaction in this account.
|
* Returns the date of the very first transaction in this account.
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user