mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-18 10:16:49 +00:00
@@ -25,6 +25,10 @@ namespace FireflyIII\Support;
|
||||
use Amount as Amt;
|
||||
use Carbon\Carbon;
|
||||
use Eloquent;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\AccountType;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\MessageBag;
|
||||
use RuntimeException;
|
||||
@@ -61,6 +65,58 @@ class ExpandedForm
|
||||
return $this->currencyField($name, 'amount-small', $value, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param null $value
|
||||
* @param array $options
|
||||
*
|
||||
* @return string
|
||||
* @throws \Throwable
|
||||
*/
|
||||
public function assetAccountList(string $name, $value = null, array $options = []): string
|
||||
{
|
||||
// properties for cache
|
||||
$cache = new CacheProperties;
|
||||
$cache->addProperty('exp-form-asset-list');
|
||||
$cache->addProperty($name);
|
||||
$cache->addProperty($value);
|
||||
$cache->addProperty($options);
|
||||
|
||||
if ($cache->has()) {
|
||||
return $cache->get();
|
||||
}
|
||||
// make repositories
|
||||
/** @var AccountRepositoryInterface $repository */
|
||||
$repository = app(AccountRepositoryInterface::class);
|
||||
/** @var CurrencyRepositoryInterface $currencyRepos */
|
||||
$currencyRepos = app(CurrencyRepositoryInterface::class);
|
||||
|
||||
$assetAccounts = $repository->getAccountsByType([AccountType::ASSET, AccountType::DEFAULT]);
|
||||
$defaultCurrency = app('amount')->getDefaultCurrency();
|
||||
$grouped = [];
|
||||
// group accounts:
|
||||
/** @var Account $account */
|
||||
foreach ($assetAccounts as $account) {
|
||||
$balance = app('steam')->balance($account, new Carbon);
|
||||
$currencyId = intval($account->getMeta('currency_id'));
|
||||
$currency = $currencyRepos->findNull($currencyId);
|
||||
$role = $account->getMeta('accountRole');
|
||||
if (0 === strlen($role)) {
|
||||
$role = 'no_account_type'; // @codeCoverageIgnore
|
||||
}
|
||||
if (is_null($currency)) {
|
||||
$currency = $defaultCurrency;
|
||||
}
|
||||
|
||||
$key = strval(trans('firefly.opt_group_' . $role));
|
||||
$grouped[$key][$account->id] = $account->name . ' (' . app('amount')->formatAnything($currency, $balance, false) . ')';
|
||||
}
|
||||
$res = $this->select($name, $grouped, $value, $options);
|
||||
$cache->store($res);
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
* @param null $value
|
||||
|
Reference in New Issue
Block a user