mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-24 22:48:18 +00:00
Add the ability to make transactions to and from liability accounts.
This commit is contained in:
@@ -66,6 +66,46 @@ class ExpandedForm
|
|||||||
/** @var CurrencyRepositoryInterface $currencyRepos */
|
/** @var CurrencyRepositoryInterface $currencyRepos */
|
||||||
$currencyRepos = app(CurrencyRepositoryInterface::class);
|
$currencyRepos = app(CurrencyRepositoryInterface::class);
|
||||||
|
|
||||||
|
$accountList = $repository->getActiveAccountsByType([AccountType::ASSET, AccountType::DEFAULT]);
|
||||||
|
$defaultCurrency = app('amount')->getDefaultCurrency();
|
||||||
|
$grouped = [];
|
||||||
|
// group accounts:
|
||||||
|
/** @var Account $account */
|
||||||
|
foreach ($accountList as $account) {
|
||||||
|
$balance = app('steam')->balance($account, new Carbon);
|
||||||
|
$currencyId = (int)$repository->getMetaValue($account, 'currency_id');
|
||||||
|
$currency = $currencyRepos->findNull($currencyId);
|
||||||
|
$role = $repository->getMetaValue($account, 'accountRole');
|
||||||
|
if ('' === $role) {
|
||||||
|
$role = 'no_account_type'; // @codeCoverageIgnore
|
||||||
|
}
|
||||||
|
|
||||||
|
if (null === $currency) {
|
||||||
|
$currency = $defaultCurrency;
|
||||||
|
}
|
||||||
|
|
||||||
|
$key = (string)trans('firefly.opt_group_' . $role);
|
||||||
|
$grouped[$key][$account->id] = $account->name . ' (' . app('amount')->formatAnything($currency, $balance, false) . ')';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->select($name, $grouped, $value, $options);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $name
|
||||||
|
* @param mixed $value
|
||||||
|
* @param array $options
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function activeLongAccountList(string $name, $value = null, array $options = null): string
|
||||||
|
{
|
||||||
|
// make repositories
|
||||||
|
/** @var AccountRepositoryInterface $repository */
|
||||||
|
$repository = app(AccountRepositoryInterface::class);
|
||||||
|
/** @var CurrencyRepositoryInterface $currencyRepos */
|
||||||
|
$currencyRepos = app(CurrencyRepositoryInterface::class);
|
||||||
|
|
||||||
$accountList = $repository->getActiveAccountsByType(
|
$accountList = $repository->getActiveAccountsByType(
|
||||||
[AccountType::ASSET, AccountType::DEFAULT, AccountType::MORTGAGE, AccountType::DEBT, AccountType::CREDITCARD, AccountType::LOAN,]
|
[AccountType::ASSET, AccountType::DEFAULT, AccountType::MORTGAGE, AccountType::DEBT, AccountType::CREDITCARD, AccountType::LOAN,]
|
||||||
);
|
);
|
||||||
@@ -200,8 +240,7 @@ class ExpandedForm
|
|||||||
/** @var CurrencyRepositoryInterface $currencyRepos */
|
/** @var CurrencyRepositoryInterface $currencyRepos */
|
||||||
$currencyRepos = app(CurrencyRepositoryInterface::class);
|
$currencyRepos = app(CurrencyRepositoryInterface::class);
|
||||||
|
|
||||||
$accountList = $repository->getAccountsByType([AccountType::ASSET, AccountType::DEFAULT, AccountType::MORTGAGE, AccountType::DEBT, AccountType::CREDITCARD, AccountType::LOAN,]);
|
$accountList = $repository->getAccountsByType([AccountType::ASSET, AccountType::DEFAULT]);
|
||||||
$liabilityTypes = [AccountType::MORTGAGE, AccountType::DEBT, AccountType::CREDITCARD, AccountType::LOAN];
|
|
||||||
$defaultCurrency = app('amount')->getDefaultCurrency();
|
$defaultCurrency = app('amount')->getDefaultCurrency();
|
||||||
$grouped = [];
|
$grouped = [];
|
||||||
// group accounts:
|
// group accounts:
|
||||||
@@ -215,10 +254,6 @@ class ExpandedForm
|
|||||||
$role = 'no_account_type'; // @codeCoverageIgnore
|
$role = 'no_account_type'; // @codeCoverageIgnore
|
||||||
}
|
}
|
||||||
|
|
||||||
if (\in_array($account->accountType->type, $liabilityTypes, true)) {
|
|
||||||
$role = 'l_' . $account->accountType->type; // @codeCoverageIgnore
|
|
||||||
}
|
|
||||||
|
|
||||||
if (null === $currency) {
|
if (null === $currency) {
|
||||||
$currency = $defaultCurrency;
|
$currency = $defaultCurrency;
|
||||||
}
|
}
|
||||||
@@ -243,7 +278,6 @@ class ExpandedForm
|
|||||||
return $this->currencyField($name, 'balance', $value, $options);
|
return $this->currencyField($name, 'balance', $value, $options);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @noinspection MoreThanThreeArgumentsInspection */
|
|
||||||
/**
|
/**
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param int $value
|
* @param int $value
|
||||||
@@ -280,6 +314,8 @@ class ExpandedForm
|
|||||||
return $html;
|
return $html;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @noinspection MoreThanThreeArgumentsInspection */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
@@ -427,6 +463,53 @@ class ExpandedForm
|
|||||||
return $html;
|
return $html;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $name
|
||||||
|
* @param mixed $value
|
||||||
|
* @param array $options
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function longAccountList(string $name, $value = null, array $options = null): string
|
||||||
|
{
|
||||||
|
// make repositories
|
||||||
|
/** @var AccountRepositoryInterface $repository */
|
||||||
|
$repository = app(AccountRepositoryInterface::class);
|
||||||
|
/** @var CurrencyRepositoryInterface $currencyRepos */
|
||||||
|
$currencyRepos = app(CurrencyRepositoryInterface::class);
|
||||||
|
|
||||||
|
$accountList = $repository->getAccountsByType(
|
||||||
|
[AccountType::ASSET, AccountType::DEFAULT, AccountType::MORTGAGE, AccountType::DEBT, AccountType::CREDITCARD, AccountType::LOAN,]
|
||||||
|
);
|
||||||
|
$liabilityTypes = [AccountType::MORTGAGE, AccountType::DEBT, AccountType::CREDITCARD, AccountType::LOAN];
|
||||||
|
$defaultCurrency = app('amount')->getDefaultCurrency();
|
||||||
|
$grouped = [];
|
||||||
|
// group accounts:
|
||||||
|
/** @var Account $account */
|
||||||
|
foreach ($accountList as $account) {
|
||||||
|
$balance = app('steam')->balance($account, new Carbon);
|
||||||
|
$currencyId = (int)$repository->getMetaValue($account, 'currency_id');
|
||||||
|
$currency = $currencyRepos->findNull($currencyId);
|
||||||
|
$role = (string)$repository->getMetaValue($account, 'accountRole');
|
||||||
|
if ('' === $role) {
|
||||||
|
$role = 'no_account_type'; // @codeCoverageIgnore
|
||||||
|
}
|
||||||
|
|
||||||
|
if (\in_array($account->accountType->type, $liabilityTypes, true)) {
|
||||||
|
$role = 'l_' . $account->accountType->type; // @codeCoverageIgnore
|
||||||
|
}
|
||||||
|
|
||||||
|
if (null === $currency) {
|
||||||
|
$currency = $defaultCurrency;
|
||||||
|
}
|
||||||
|
|
||||||
|
$key = (string)trans('firefly.opt_group_' . $role);
|
||||||
|
$grouped[$key][$account->id] = $account->name . ' (' . app('amount')->formatAnything($currency, $balance, false) . ')';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->select($name, $grouped, $value, $options);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Takes any collection and tries to make a sensible select list compatible array of it.
|
* Takes any collection and tries to make a sensible select list compatible array of it.
|
||||||
*
|
*
|
||||||
|
@@ -187,9 +187,9 @@ return [
|
|||||||
'ExpandedForm' => [
|
'ExpandedForm' => [
|
||||||
'is_safe' => [
|
'is_safe' => [
|
||||||
'date', 'text', 'select', 'balance', 'optionsList', 'checkbox', 'amount', 'tags', 'integer', 'textarea', 'location',
|
'date', 'text', 'select', 'balance', 'optionsList', 'checkbox', 'amount', 'tags', 'integer', 'textarea', 'location',
|
||||||
'file', 'staticText', 'password', 'nonSelectableAmount',
|
'file', 'staticText', 'password', 'nonSelectableAmount',
|
||||||
'number', 'assetAccountList','amountNoCurrency','currencyList','ruleGroupList','assetAccountCheckList','ruleGroupListWithEmpty',
|
'number', 'assetAccountList', 'amountNoCurrency', 'currencyList', 'ruleGroupList', 'assetAccountCheckList', 'ruleGroupListWithEmpty',
|
||||||
'piggyBankList','currencyListEmpty','activeAssetAccountList','percentage'
|
'piggyBankList', 'currencyListEmpty', 'activeAssetAccountList', 'percentage', 'activeLongAccountList', 'longAccountList',
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
'Form' => [
|
'Form' => [
|
||||||
|
@@ -89,13 +89,13 @@
|
|||||||
{{ ExpandedForm.amountNoCurrency('amount', []) }}
|
{{ ExpandedForm.amountNoCurrency('amount', []) }}
|
||||||
|
|
||||||
{# source account if withdrawal, or if transfer: #}
|
{# source account if withdrawal, or if transfer: #}
|
||||||
{{ ExpandedForm.activeAssetAccountList('source_id', null, {label: trans('form.asset_source_account')}) }}
|
{{ ExpandedForm.activeLongAccountList('source_id', null, {label: trans('form.asset_source_account')}) }}
|
||||||
|
|
||||||
{# source account name for deposits: #}
|
{# source account name for deposits: #}
|
||||||
{{ ExpandedForm.text('source_name', null, {label: trans('form.revenue_account')}) }}
|
{{ ExpandedForm.text('source_name', null, {label: trans('form.revenue_account')}) }}
|
||||||
|
|
||||||
{# destination if deposit or transfer: #}
|
{# destination if deposit or transfer: #}
|
||||||
{{ ExpandedForm.activeAssetAccountList('destination_id', null, {label: trans('form.asset_destination_account')} ) }}
|
{{ ExpandedForm.activeLongAccountList('destination_id', null, {label: trans('form.asset_destination_account')} ) }}
|
||||||
|
|
||||||
{# destination account name for withdrawals #}
|
{# destination account name for withdrawals #}
|
||||||
{{ ExpandedForm.text('destination_name', null, {label: trans('form.expense_account')}) }}
|
{{ ExpandedForm.text('destination_name', null, {label: trans('form.expense_account')}) }}
|
||||||
|
@@ -88,13 +88,13 @@
|
|||||||
{{ ExpandedForm.amountNoCurrency('amount', array.transactions[0].amount) }}
|
{{ ExpandedForm.amountNoCurrency('amount', array.transactions[0].amount) }}
|
||||||
|
|
||||||
{# source account if withdrawal, or if transfer: #}
|
{# source account if withdrawal, or if transfer: #}
|
||||||
{{ ExpandedForm.assetAccountList('source_id', array.transactions[0].source_id, {label: trans('form.asset_source_account')}) }}
|
{{ ExpandedForm.longAccountList('source_id', array.transactions[0].source_id, {label: trans('form.asset_source_account')}) }}
|
||||||
|
|
||||||
{# source account name for deposits: #}
|
{# source account name for deposits: #}
|
||||||
{{ ExpandedForm.text('source_name', array.transactions[0].source_name, {label: trans('form.revenue_account')}) }}
|
{{ ExpandedForm.text('source_name', array.transactions[0].source_name, {label: trans('form.revenue_account')}) }}
|
||||||
|
|
||||||
{# destination if deposit or transfer: #}
|
{# destination if deposit or transfer: #}
|
||||||
{{ ExpandedForm.assetAccountList('destination_id', array.transactions[0].destination_id, {label: trans('form.asset_destination_account')} ) }}
|
{{ ExpandedForm.longAccountList('destination_id', array.transactions[0].destination_id, {label: trans('form.asset_destination_account')} ) }}
|
||||||
|
|
||||||
{# destination account name for withdrawals #}
|
{# destination account name for withdrawals #}
|
||||||
{{ ExpandedForm.text('destination_name', array.transactions[0].destination_name, {label: trans('form.expense_account')}) }}
|
{{ ExpandedForm.text('destination_name', array.transactions[0].destination_name, {label: trans('form.expense_account')}) }}
|
||||||
|
@@ -33,7 +33,7 @@
|
|||||||
{{ ExpandedForm.text('description') }}
|
{{ ExpandedForm.text('description') }}
|
||||||
|
|
||||||
{# SELECTABLE SOURCE ACCOUNT ONLY FOR WITHDRAWALS AND TRANSFERS #}
|
{# SELECTABLE SOURCE ACCOUNT ONLY FOR WITHDRAWALS AND TRANSFERS #}
|
||||||
{{ ExpandedForm.activeAssetAccountList('source_id', null, {label: trans('form.asset_source_account') }) }}
|
{{ ExpandedForm.activeLongAccountList('source_id', null, {label: trans('form.asset_source_account') }) }}
|
||||||
|
|
||||||
{# FREE FORMAT SOURCE ACCOUNT ONLY FOR DEPOSITS #}
|
{# FREE FORMAT SOURCE ACCOUNT ONLY FOR DEPOSITS #}
|
||||||
{{ ExpandedForm.text('source_name', null, {label: trans('form.revenue_account')}) }}
|
{{ ExpandedForm.text('source_name', null, {label: trans('form.revenue_account')}) }}
|
||||||
@@ -42,7 +42,7 @@
|
|||||||
{{ ExpandedForm.text('destination_name', null, {label: trans('form.expense_account')}) }}
|
{{ ExpandedForm.text('destination_name', null, {label: trans('form.expense_account')}) }}
|
||||||
|
|
||||||
{# SELECTABLE DESTINATION ACCOUNT ONLY FOR TRANSFERS AND DEPOSITS #}
|
{# SELECTABLE DESTINATION ACCOUNT ONLY FOR TRANSFERS AND DEPOSITS #}
|
||||||
{{ ExpandedForm.activeAssetAccountList('destination_id', null, {label: trans('form.asset_destination_account')} ) }}
|
{{ ExpandedForm.activeLongAccountList('destination_id', null, {label: trans('form.asset_destination_account')} ) }}
|
||||||
|
|
||||||
{# ALWAYS SHOW AMOUNT #}
|
{# ALWAYS SHOW AMOUNT #}
|
||||||
<!-- A -->
|
<!-- A -->
|
||||||
|
@@ -39,7 +39,7 @@
|
|||||||
|
|
||||||
{# SELECTABLE SOURCE ACCOUNT ONLY FOR WITHDRAWALS AND TRANSFERS #}
|
{# SELECTABLE SOURCE ACCOUNT ONLY FOR WITHDRAWALS AND TRANSFERS #}
|
||||||
{% if what == 'transfer' or what == 'withdrawal' %}
|
{% if what == 'transfer' or what == 'withdrawal' %}
|
||||||
{{ ExpandedForm.assetAccountList('source_id', data.source_id, {label: trans('form.asset_source_account')}) }}
|
{{ ExpandedForm.longAccountList('source_id', data.source_id, {label: trans('form.asset_source_account')}) }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{# FREE FORMAT SOURCE ACCOUNT ONLY FOR DEPOSITS #}
|
{# FREE FORMAT SOURCE ACCOUNT ONLY FOR DEPOSITS #}
|
||||||
@@ -54,7 +54,7 @@
|
|||||||
|
|
||||||
{# SELECTABLE DESTINATION ACCOUNT ONLY FOR TRANSFERS AND DEPOSITS #}
|
{# SELECTABLE DESTINATION ACCOUNT ONLY FOR TRANSFERS AND DEPOSITS #}
|
||||||
{% if what == 'transfer' or what == 'deposit' %}
|
{% if what == 'transfer' or what == 'deposit' %}
|
||||||
{{ ExpandedForm.assetAccountList('destination_id', data.destination_id, {label: trans('form.asset_destination_account')} ) }}
|
{{ ExpandedForm.longAccountList('destination_id', data.destination_id, {label: trans('form.asset_destination_account')} ) }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{# ALWAYS SHOW AMOUNT #}
|
{# ALWAYS SHOW AMOUNT #}
|
||||||
|
@@ -42,12 +42,12 @@
|
|||||||
|
|
||||||
{# show source if withdrawal or transfer #}
|
{# show source if withdrawal or transfer #}
|
||||||
{% if preFilled.what == 'withdrawal' or preFilled.what == 'transfer' %}
|
{% if preFilled.what == 'withdrawal' or preFilled.what == 'transfer' %}
|
||||||
{{ ExpandedForm.activeAssetAccountList('journal_source_id', preFilled.journal_source_id) }}
|
{{ ExpandedForm.activeLongAccountList('journal_source_id', preFilled.journal_source_id) }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{# show destination account id, if deposit (is asset): #}
|
{# show destination account id, if deposit (is asset): #}
|
||||||
{% if preFilled.what == 'deposit' or preFilled.what == 'transfer' %}
|
{% if preFilled.what == 'deposit' or preFilled.what == 'transfer' %}
|
||||||
{{ ExpandedForm.activeAssetAccountList('journal_destination_id', preFilled.journal_destination_id) }}
|
{{ ExpandedForm.activeLongAccountList('journal_destination_id', preFilled.journal_destination_id) }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{# show amount and some helper text when making splits: #}
|
{# show amount and some helper text when making splits: #}
|
||||||
|
@@ -62,7 +62,7 @@ class JavascriptControllerTest extends TestCase
|
|||||||
$account = factory(Account::class)->make();
|
$account = factory(Account::class)->make();
|
||||||
|
|
||||||
$accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection([$account]))
|
$accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection([$account]))
|
||||||
->withArgs([[AccountType::DEFAULT, AccountType::ASSET]])->once();
|
->withArgs([[AccountType::DEFAULT, AccountType::ASSET, AccountType::DEBT,AccountType::LOAN,AccountType::MORTGAGE, AccountType::CREDITCARD]])->once();
|
||||||
$currencyRepos->shouldReceive('findByCodeNull')->withArgs(['EUR'])->andReturn(new TransactionCurrency);
|
$currencyRepos->shouldReceive('findByCodeNull')->withArgs(['EUR'])->andReturn(new TransactionCurrency);
|
||||||
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1');
|
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1');
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user