Skip to content

Firefly III: a personal finances manager

Refactor the expandedform methods. First commit to see how Scrutinizer likes this. This commit will break most views.

James Cole6e2978231bf0
diff --git a/app/Providers/FireflyServiceProvider.php b/app/Providers/FireflyServiceProvider.php
index d297c39294..4d6957ff89 100644
--- a/app/Providers/FireflyServiceProvider.php
+++ b/app/Providers/FireflyServiceProvider.php
@@ -55,6 +55,7 @@ use FireflyIII\Services\Password\Verifier;
use FireflyIII\Support\Amount;
use FireflyIII\Support\ExpandedForm;
use FireflyIII\Support\FireflyConfig;
+use FireflyIII\Support\Form\AccountForm;
use FireflyIII\Support\Navigation;
use FireflyIII\Support\Preferences;
use FireflyIII\Support\Steam;
@@ -147,6 +148,13 @@ class FireflyServiceProvider extends ServiceProvider
}
);
+ $this->app->bind(
+ 'accountform',
+ static function () {
+ return new AccountForm;
+ }
+ );
+
// chart generator:
$this->app->bind(GeneratorInterface::class, ChartJsGenerator::class);
diff --git a/app/Support/ExpandedForm.php b/app/Support/ExpandedForm.php
index 603127fe04..a938b73572 100644
--- a/app/Support/ExpandedForm.php
+++ b/app/Support/ExpandedForm.php
@@ -35,6 +35,7 @@ use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
+use FireflyIII\Support\Form\FormSupport;
use Form;
use Illuminate\Support\Collection;
use Illuminate\Support\HtmlString;
@@ -52,221 +53,7 @@ use Throwable;
*/
class ExpandedForm
{
- /**
- * @param string $name
- * @param mixed $value
- * @param array $options
- *
- * @return string
- */
- public function activeAssetAccountList(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([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, 'account_role');
- 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);
- $accountList = $repository->getActiveAccountsByType(
- [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);
-
- $currency = $repository->getAccountCurrency($account) ?? $defaultCurrency;
-
- $role = $repository->getMetaValue($account, 'account_role');
-
- if ('' === $role && !in_array($account->accountType->type, $liabilityTypes, true)) {
- $role = 'no_account_type'; // @codeCoverageIgnore
- }
-
- if (in_array($account->accountType->type, $liabilityTypes, true)) {
- $role = 'l_' . $account->accountType->type; // @codeCoverageIgnore
- }
- $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);
- }
-
- /**
- * Grouped dropdown list of all accounts that are valid as the destination of a withdrawal.
- *
- * @param string $name
- * @param mixed $value
- * @param array $options
- *
- * @return string
- */
- public function activeWithdrawalDestinations(string $name, $value = null, array $options = null): string
- {
- // make repositories
- /** @var AccountRepositoryInterface $repository */
- $repository = app(AccountRepositoryInterface::class);
-
- $accountList = $repository->getActiveAccountsByType(
- [
- AccountType::MORTGAGE,
- AccountType::DEBT,
- AccountType::CREDITCARD,
- AccountType::LOAN,
- AccountType::EXPENSE,
- ]
- );
- $liabilityTypes = [AccountType::MORTGAGE, AccountType::DEBT, AccountType::CREDITCARD, AccountType::LOAN];
- $defaultCurrency = app('amount')->getDefaultCurrency();
- $grouped = [];
-
- // add cash account first:
- $cash = $repository->getCashAccount();
- $key = (string)trans('firefly.cash_account_type');
- $grouped[$key][$cash->id] = sprintf('(%s)', (string)trans('firefly.cash'));
-
- // group accounts:
- /** @var Account $account */
- foreach ($accountList as $account) {
- $balance = app('steam')->balance($account, new Carbon);
- $currency = $repository->getAccountCurrency($account) ?? $defaultCurrency;
- $role = (string)$repository->getMetaValue($account, 'account_role');
- if ('' === $role && !in_array($account->accountType->type, $liabilityTypes, true)) {
- $role = 'no_account_type'; // @codeCoverageIgnore
- }
- if ('no_account_type' === $role && AccountType::EXPENSE === $account->accountType->type) {
- $role = 'expense_account'; // @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);
- }
-
- /**
- * Grouped dropdown list of all accounts that are valid as the destination of a withdrawal.
- *
- * @param string $name
- * @param mixed $value
- * @param array $options
- *
- * @return string
- */
- public function activeDepositDestinations(string $name, $value = null, array $options = null): string
- {
- // make repositories
- /** @var AccountRepositoryInterface $repository */
- $repository = app(AccountRepositoryInterface::class);
-
- $accountList = $repository->getActiveAccountsByType(
- [
- AccountType::MORTGAGE,
- AccountType::DEBT,
- AccountType::CREDITCARD,
- AccountType::LOAN,
- AccountType::REVENUE,
- ]
- );
- $liabilityTypes = [AccountType::MORTGAGE, AccountType::DEBT, AccountType::CREDITCARD, AccountType::LOAN];
- $defaultCurrency = app('amount')->getDefaultCurrency();
- $grouped = [];
-
- // add cash account first:
- $cash = $repository->getCashAccount();
- $key = (string)trans('firefly.cash_account_type');
- $grouped[$key][$cash->id] = sprintf('(%s)', (string)trans('firefly.cash'));
-
- // group accounts:
- /** @var Account $account */
- foreach ($accountList as $account) {
- $balance = app('steam')->balance($account, new Carbon);
- $currency = $repository->getAccountCurrency($account) ?? $defaultCurrency;
- $role = (string)$repository->getMetaValue($account, 'account_role');
- if ('' === $role && !in_array($account->accountType->type, $liabilityTypes, true)) {
- $role = 'no_account_type'; // @codeCoverageIgnore
- }
- if ('no_account_type' === $role && AccountType::REVENUE === $account->accountType->type) {
- $role = 'revenue_account'; // @codeCoverageIgnore
-
- }
-
- if (in_array($account->accountType->type, $liabilityTypes, true)) {
- $role = 'l_' . $account->accountType->type; // @codeCoverageIgnore
- }
-
- $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 amount(string $name, $value = null, array $options = null): string
- {
- return $this->currencyField($name, 'amount', $value, $options);
- }
-
+ use FormSupport;
/**
* @param string $name
* @param mixed $value
@@ -299,114 +86,6 @@ class ExpandedForm
return $html;
}
- /**
- * @param string $name
- * @param array $options
- *
- * @return string
- *
- */
- public function assetAccountCheckList(string $name, array $options = null): string
- {
- $options = $options ?? [];
- $label = $this->label($name, $options);
- $options = $this->expandOptionArray($name, $label, $options);
- $classes = $this->getHolderClasses($name);
- $selected = request()->old($name) ?? [];
-
- // get all asset accounts:
- /** @var AccountRepositoryInterface $repository */
- $repository = app(AccountRepositoryInterface::class);
- $assetAccounts = $repository->getAccountsByType([AccountType::ASSET, AccountType::DEFAULT]);
- $grouped = [];
- // group accounts:
- /** @var Account $account */
- foreach ($assetAccounts as $account) {
- $role = $repository->getMetaValue($account, 'account_role');
- if (null === $role) {
- $role = 'no_account_type'; // @codeCoverageIgnore
- }
- $key = (string)trans('firefly.opt_group_' . $role);
- $grouped[$key][$account->id] = $account->name;
- }
-
- unset($options['class']);
- try {
- $html = view('form.assetAccountCheckList', compact('classes', 'selected', 'name', 'label', 'options', 'grouped'))->render();
- } catch (Throwable $e) {
- Log::debug(sprintf('Could not render assetAccountCheckList(): %s', $e->getMessage()));
- $html = 'Could not render assetAccountCheckList.';
- }
-
- return $html;
- }
-
- /**
- * @param string $name
- * @param mixed $value
- * @param array $options
- *
- * @return string
- */
- public function assetAccountList(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]);
- $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, 'account_role');
- 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
- * @throws FireflyException
- */
- public function balance(string $name, $value = null, array $options = null): string
- {
- return $this->currencyField($name, 'balance', $value, $options);
- }
-
- /**
- * @param string $name
- * @param mixed $value
- * @param array $options
- *
- * @return string
- * @throws FireflyException
- */
- public function balanceAll(string $name, $value = null, array $options = null): string
- {
- return $this->allCurrencyField($name, 'balance', $value, $options);
- }
-
/**
* @param string $name
* @param int $value
@@ -443,56 +122,6 @@ class ExpandedForm
return $html;
}
- /** @noinspection MoreThanThreeArgumentsInspection */
-
- /**
- * @param string $name
- * @param mixed $value
- * @param array $options
- *
- * @return string
- */
- public function currencyList(string $name, $value = null, array $options = null): string
- {
- /** @var CurrencyRepositoryInterface $currencyRepos */
- $currencyRepos = app(CurrencyRepositoryInterface::class);
-
- // get all currencies:
- $list = $currencyRepos->get();
- $array = [];
- /** @var TransactionCurrency $currency */
- foreach ($list as $currency) {
- $array[$currency->id] = $currency->name . ' (' . $currency->symbol . ')';
- }
-
- return $this->select($name, $array, $value, $options);
- }
-
- /**
- * @param string $name
- * @param mixed $value
- * @param array $options
- *
- * @return string
- */
- public function currencyListEmpty(string $name, $value = null, array $options = null): string
- {
- /** @var CurrencyRepositoryInterface $currencyRepos */
- $currencyRepos = app(CurrencyRepositoryInterface::class);
-
- // get all currencies:
- $list = $currencyRepos->get();
- $array = [
- 0 => (string)trans('firefly.no_currency'),
- ];
- /** @var TransactionCurrency $currency */
- foreach ($list as $currency) {
- $array[$currency->id] = $currency->name . ' (' . $currency->symbol . ')';
- }
-
- return $this->select($name, $array, $value, $options);
- }
-
/**
* @param string $name
* @param mixed $value
@@ -592,81 +221,6 @@ class ExpandedForm
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, 'account_role'); // TODO bad form for currency
- 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.
- *
- * @param \Illuminate\Support\Collection $set
- *
- * @return array
- * @SuppressWarnings(PHPMD.CyclomaticComplexity)
- */
- public function makeSelectList(Collection $set): array
- {
- $selectList = [];
- $fields = ['title', 'name', 'description'];
- /** @var Eloquent $entry */
- foreach ($set as $entry) {
- $entryId = (int)$entry->id;
- $title = null;
-
- foreach ($fields as $field) {
- if (isset($entry->$field) && null === $title) {
- $title = $entry->$field;
- }
- }
- $selectList[$entryId] = $title;
- }
-
- return $selectList;
- }
-
/**
* @param \Illuminate\Support\Collection $set
*
@@ -821,110 +375,6 @@ class ExpandedForm
return $html;
}
- /**
- * @param string $name
- * @param mixed $value
- * @param array $options
- *
- * @return string
- */
- public function piggyBankList(string $name, $value = null, array $options = null): string
- {
-
- // make repositories
- /** @var PiggyBankRepositoryInterface $repository */
- $repository = app(PiggyBankRepositoryInterface::class);
- $piggyBanks = $repository->getPiggyBanksWithAmount();
- $array = [
- 0 => (string)trans('firefly.none_in_select_list'),
- ];
- /** @var PiggyBank $piggy */
- foreach ($piggyBanks as $piggy) {
- $array[$piggy->id] = $piggy->name;
- }
-
- return $this->select($name, $array, $value, $options);
- }
-
- /**
- * @param string $name
- * @param mixed $value
- * @param array $options
- *
- * @return string
- */
- public function ruleGroupList(string $name, $value = null, array $options = null): string
- {
- /** @var RuleGroupRepositoryInterface $groupRepos */
- $groupRepos = app(RuleGroupRepositoryInterface::class);
-
- // get all currencies:
- $list = $groupRepos->get();
- $array = [];
- /** @var RuleGroup $group */
- foreach ($list as $group) {
- $array[$group->id] = $group->title;
- }
-
- return $this->select($name, $array, $value, $options);
- }
-
- /**
- * @param string $name
- * @param null $value
- * @param array|null $options
- *
- * @return HtmlString
- */
- public function ruleGroupListWithEmpty(string $name, $value = null, array $options = null): HtmlString
- {
- $options = $options ?? [];
- $options['class'] = 'form-control';
- /** @var RuleGroupRepositoryInterface $groupRepos */
- $groupRepos = app(RuleGroupRepositoryInterface::class);
-
- // get all currencies:
- $list = $groupRepos->get();
- $array = [
- 0 => (string)trans('firefly.none_in_select_list'),
- ];
- /** @var RuleGroup $group */
- foreach ($list as $group) {
- if (isset($options['hidden']) && (int)$options['hidden'] !== $group->id) {
- $array[$group->id] = $group->title;
- }
- }
-
- return Form::select($name, $array, $value, $options);
- }
-
- /** @noinspection MoreThanThreeArgumentsInspection */
- /**
- * @param string $name
- * @param array $list
- * @param mixed $selected
- * @param array $options
- *
- * @return string
- */
- public function select(string $name, array $list = null, $selected = null, array $options = null): string
- {
- $list = $list ?? [];
- $label = $this->label($name, $options);
- $options = $this->expandOptionArray($name, $label, $options);
- $classes = $this->getHolderClasses($name);
- $selected = $this->fillFieldValue($name, $selected);
- unset($options['autocomplete'], $options['placeholder']);
- try {
- $html = view('form.select', compact('classes', 'name', 'label', 'selected', 'options', 'list'))->render();
- } catch (Throwable $e) {
- Log::debug(sprintf('Could not render select(): %s', $e->getMessage()));
- $html = 'Could not render select.';
- }
-
- return $html;
- }
-
/**
* @param string $name
* @param mixed $value
@@ -948,31 +398,6 @@ class ExpandedForm
return $html;
}
- /**
- * @param string $name
- * @param mixed $value
- * @param array $options
- *
- * @return string
- *
- */
- public function tags(string $name, $value = null, array $options = null): string
- {
- $label = $this->label($name, $options);
- $options = $this->expandOptionArray($name, $label, $options);
- $classes = $this->getHolderClasses($name);
- $value = $this->fillFieldValue($name, $value);
- $options['data-role'] = 'tagsinput';
- try {
- $html = view('form.tags', compact('classes', 'name', 'label', 'value', 'options'))->render();
- } catch (Throwable $e) {
- Log::debug(sprintf('Could not render tags(): %s', $e->getMessage()));
- $html = 'Could not render tags.';
- }
-
- return $html;
- }
-
/**
* @param string $name
* @param mixed $value
@@ -1026,197 +451,4 @@ class ExpandedForm
return $html;
}
-
- /** @noinspection MoreThanThreeArgumentsInspection */
-
- /**
- * @param string $name
- * @param string $view
- * @param mixed $value
- * @param array $options
- *
- * @return string
- * @SuppressWarnings(PHPMD.CyclomaticComplexity)
- */
- protected function allCurrencyField(string $name, string $view, $value = null, array $options = null): string
- {
- $label = $this->label($name, $options);
- $options = $this->expandOptionArray($name, $label, $options);
- $classes = $this->getHolderClasses($name);
- $value = $this->fillFieldValue($name, $value);
- $options['step'] = 'any';
- $defaultCurrency = $options['currency'] ?? Amt::getDefaultCurrency();
- /** @var Collection $currencies */
- $currencies = app('amount')->getAllCurrencies();
- unset($options['currency'], $options['placeholder']);
-
- // perhaps the currency has been sent to us in the field $amount_currency_id_$name (amount_currency_id_amount)
- $preFilled = session('preFilled');
- $key = 'amount_currency_id_' . $name;
- $sentCurrencyId = isset($preFilled[$key]) ? (int)$preFilled[$key] : $defaultCurrency->id;
-
- Log::debug(sprintf('Sent currency ID is %d', $sentCurrencyId));
-
- // find this currency in set of currencies:
- foreach ($currencies as $currency) {
- if ($currency->id === $sentCurrencyId) {
- $defaultCurrency = $currency;
- Log::debug(sprintf('default currency is now %s', $defaultCurrency->code));
- break;
- }
- }
-
- // make sure value is formatted nicely:
- if (null !== $value && '' !== $value) {
- $value = round($value, $defaultCurrency->decimal_places);
- }
- try {
- $html = view('form.' . $view, compact('defaultCurrency', 'currencies', 'classes', 'name', 'label', 'value', 'options'))->render();
- } catch (Throwable $e) {
- Log::debug(sprintf('Could not render currencyField(): %s', $e->getMessage()));
- $html = 'Could not render currencyField.';
- }
-
- return $html;
- }
-
- /** @noinspection MoreThanThreeArgumentsInspection */
-
- /**
- * @param string $name
- * @param string $view
- * @param mixed $value
- * @param array $options
- *
- * @return string
- * @SuppressWarnings(PHPMD.CyclomaticComplexity)
- */
- protected function currencyField(string $name, string $view, $value = null, array $options = null): string
- {
- $label = $this->label($name, $options);
- $options = $this->expandOptionArray($name, $label, $options);
- $classes = $this->getHolderClasses($name);
- $value = $this->fillFieldValue($name, $value);
- $options['step'] = 'any';
- $defaultCurrency = $options['currency'] ?? Amt::getDefaultCurrency();
- /** @var Collection $currencies */
- $currencies = app('amount')->getCurrencies();
- unset($options['currency'], $options['placeholder']);
-
- // perhaps the currency has been sent to us in the field $amount_currency_id_$name (amount_currency_id_amount)
- $preFilled = session('preFilled');
- $key = 'amount_currency_id_' . $name;
- $sentCurrencyId = isset($preFilled[$key]) ? (int)$preFilled[$key] : $defaultCurrency->id;
-
- Log::debug(sprintf('Sent currency ID is %d', $sentCurrencyId));
-
- // find this currency in set of currencies:
- foreach ($currencies as $currency) {
- if ($currency->id === $sentCurrencyId) {
- $defaultCurrency = $currency;
- Log::debug(sprintf('default currency is now %s', $defaultCurrency->code));
- break;
- }
- }
-
- // make sure value is formatted nicely:
- if (null !== $value && '' !== $value) {
- $value = round($value, $defaultCurrency->decimal_places);
- }
- try {
- $html = view('form.' . $view, compact('defaultCurrency', 'currencies', 'classes', 'name', 'label', 'value', 'options'))->render();
- } catch (Throwable $e) {
- Log::debug(sprintf('Could not render currencyField(): %s', $e->getMessage()));
- $html = 'Could not render currencyField.';
- }
-
- return $html;
- }
-
- /**
- * @param $name
- * @param $label
- * @param array $options
- *
- * @return array
- */
- protected function expandOptionArray(string $name, $label, array $options = null): array
- {
- $options = $options ?? [];
- $name = str_replace('[]', '', $name);
- $options['class'] = 'form-control';
- $options['id'] = 'ffInput_' . $name;
- $options['autocomplete'] = 'off';
- $options['placeholder'] = ucfirst($label);
-
- return $options;
- }
-
- /**
- * @param string $name
- * @param $value
- *
- * @return mixed
- * @SuppressWarnings(PHPMD.CyclomaticComplexity)
- */
- protected function fillFieldValue(string $name, $value = null)
- {
- if (app('session')->has('preFilled')) {
- $preFilled = session('preFilled');
- $value = isset($preFilled[$name]) && null === $value ? $preFilled[$name] : $value;
- }
-
- try {
- if (null !== request()->old($name)) {
- $value = request()->old($name);
- }
- } catch (RuntimeException $e) {
- // don't care about session errors.
- Log::debug(sprintf('Run time: %s', $e->getMessage()));
- }
-
- if ($value instanceof Carbon) {
- $value = $value->format('Y-m-d');
- }
-
- return $value;
- }
-
- /**
- * @param $name
- *
- * @return string
- */
- protected function getHolderClasses(string $name): string
- {
- // Get errors from session:
- /** @var MessageBag $errors */
- $errors = session('errors');
- $classes = 'form-group';
-
- if (null !== $errors && $errors->has($name)) {
- $classes = 'form-group has-error has-feedback';
- }
-
- return $classes;
- }
-
- /** @noinspection MoreThanThreeArgumentsInspection */
-
- /**
- * @param $name
- * @param $options
- *
- * @return mixed
- */
- protected function label(string $name, array $options = null): string
- {
- $options = $options ?? [];
- if (isset($options['label'])) {
- return $options['label'];
- }
- $name = str_replace('[]', '', $name);
-
- return (string)trans('form.' . $name);
- }
}
diff --git a/app/Support/Facades/AccountForm.php b/app/Support/Facades/AccountForm.php
new file mode 100644
index 0000000000..5e2328a42d
--- /dev/null
+++ b/app/Support/Facades/AccountForm.php
@@ -0,0 +1,44 @@
+<?php
+/**
+ * AccountForm.php
+ * Copyright (c) 2019 [email protected]
+ *
+ * This file is part of Firefly III.
+ *
+ * Firefly III is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Firefly III is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
+ */
+declare(strict_types=1);
+
+namespace FireflyIII\Support\Facades;
+
+use Illuminate\Support\Collection;
+use Illuminate\Support\Facades\Facade;
+
+/**
+ * @codeCoverageIgnore
+ * Class ExpandedForm.
+ *
+ */
+class AccountForm extends Facade
+{
+ /**
+ * Get the registered name of the component.
+ *
+ * @return string
+ */
+ protected static function getFacadeAccessor(): string
+ {
+ return 'accountform';
+ }
+}
diff --git a/app/Support/Form/AccountForm.php b/app/Support/Form/AccountForm.php
new file mode 100644
index 0000000000..e5e07422d3
--- /dev/null
+++ b/app/Support/Form/AccountForm.php
@@ -0,0 +1,380 @@
+<?php
+/**
+ * AccountForm.php
+ * Copyright (c) 2019 [email protected]
+ *
+ * This file is part of Firefly III.
+ *
+ * Firefly III is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Firefly III is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+namespace FireflyIII\Support\Form;
+
+
+use Carbon\Carbon;
+use FireflyIII\Models\Account;
+use FireflyIII\Models\AccountType;
+use FireflyIII\Repositories\Account\AccountRepositoryInterface;
+use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
+use Log;
+use Throwable;
+
+/**
+ * Class AccountForm
+ *
+ * All form methods that are account related.
+ *
+ * TODO describe all methods.
+ * TODO optimize repositories and methods.
+ */
+class AccountForm
+{
+ use FormSupport;
+
+ /**
+ * @param string $name
+ * @param mixed $value
+ * @param array $options
+ *
+ * @return string
+ */
+ public function activeAssetAccountList(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([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, 'account_role');
+ 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);
+ $accountList = $repository->getActiveAccountsByType(
+ [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);
+
+ $currency = $repository->getAccountCurrency($account) ?? $defaultCurrency;
+
+ $role = $repository->getMetaValue($account, 'account_role');
+
+ if ('' === $role && !in_array($account->accountType->type, $liabilityTypes, true)) {
+ $role = 'no_account_type'; // @codeCoverageIgnore
+ }
+
+ if (in_array($account->accountType->type, $liabilityTypes, true)) {
+ $role = 'l_' . $account->accountType->type; // @codeCoverageIgnore
+ }
+ $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);
+ }
+
+ /**
+ * Grouped dropdown list of all accounts that are valid as the destination of a withdrawal.
+ *
+ * @param string $name
+ * @param mixed $value
+ * @param array $options
+ *
+ * @return string
+ */
+ public function activeWithdrawalDestinations(string $name, $value = null, array $options = null): string
+ {
+ // make repositories
+ /** @var AccountRepositoryInterface $repository */
+ $repository = app(AccountRepositoryInterface::class);
+
+ $accountList = $repository->getActiveAccountsByType(
+ [
+ AccountType::MORTGAGE,
+ AccountType::DEBT,
+ AccountType::CREDITCARD,
+ AccountType::LOAN,
+ AccountType::EXPENSE,
+ ]
+ );
+ $liabilityTypes = [AccountType::MORTGAGE, AccountType::DEBT, AccountType::CREDITCARD, AccountType::LOAN];
+ $defaultCurrency = app('amount')->getDefaultCurrency();
+ $grouped = [];
+
+ // add cash account first:
+ $cash = $repository->getCashAccount();
+ $key = (string)trans('firefly.cash_account_type');
+ $grouped[$key][$cash->id] = sprintf('(%s)', (string)trans('firefly.cash'));
+
+ // group accounts:
+ /** @var Account $account */
+ foreach ($accountList as $account) {
+ $balance = app('steam')->balance($account, new Carbon);
+ $currency = $repository->getAccountCurrency($account) ?? $defaultCurrency;
+ $role = (string)$repository->getMetaValue($account, 'account_role');
+ if ('' === $role && !in_array($account->accountType->type, $liabilityTypes, true)) {
+ $role = 'no_account_type'; // @codeCoverageIgnore
+ }
+ if ('no_account_type' === $role && AccountType::EXPENSE === $account->accountType->type) {
+ $role = 'expense_account'; // @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);
+ }
+
+ /**
+ * Grouped dropdown list of all accounts that are valid as the destination of a withdrawal.
+ *
+ * @param string $name
+ * @param mixed $value
+ * @param array $options
+ *
+ * @return string
+ */
+ public function activeDepositDestinations(string $name, $value = null, array $options = null): string
+ {
+ // make repositories
+ /** @var AccountRepositoryInterface $repository */
+ $repository = app(AccountRepositoryInterface::class);
+
+ $accountList = $repository->getActiveAccountsByType(
+ [
+ AccountType::MORTGAGE,
+ AccountType::DEBT,
+ AccountType::CREDITCARD,
+ AccountType::LOAN,
+ AccountType::REVENUE,
+ ]
+ );
+ $liabilityTypes = [AccountType::MORTGAGE, AccountType::DEBT, AccountType::CREDITCARD, AccountType::LOAN];
+ $defaultCurrency = app('amount')->getDefaultCurrency();
+ $grouped = [];
+
+ // add cash account first:
+ $cash = $repository->getCashAccount();
+ $key = (string)trans('firefly.cash_account_type');
+ $grouped[$key][$cash->id] = sprintf('(%s)', (string)trans('firefly.cash'));
+
+ // group accounts:
+ /** @var Account $account */
+ foreach ($accountList as $account) {
+ $balance = app('steam')->balance($account, new Carbon);
+ $currency = $repository->getAccountCurrency($account) ?? $defaultCurrency;
+ $role = (string)$repository->getMetaValue($account, 'account_role');
+ if ('' === $role && !in_array($account->accountType->type, $liabilityTypes, true)) {
+ $role = 'no_account_type'; // @codeCoverageIgnore
+ }
+ if ('no_account_type' === $role && AccountType::REVENUE === $account->accountType->type) {
+ $role = 'revenue_account'; // @codeCoverageIgnore
+
+ }
+
+ if (in_array($account->accountType->type, $liabilityTypes, true)) {
+ $role = 'l_' . $account->accountType->type; // @codeCoverageIgnore
+ }
+
+ $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 array $options
+ *
+ * @return string
+ *
+ */
+ public function assetAccountCheckList(string $name, array $options = null): string
+ {
+ $options = $options ?? [];
+ $label = $this->label($name, $options);
+ $options = $this->expandOptionArray($name, $label, $options);
+ $classes = $this->getHolderClasses($name);
+ $selected = request()->old($name) ?? [];
+
+ // get all asset accounts:
+ /** @var AccountRepositoryInterface $repository */
+ $repository = app(AccountRepositoryInterface::class);
+ $assetAccounts = $repository->getAccountsByType([AccountType::ASSET, AccountType::DEFAULT]);
+ $grouped = [];
+ // group accounts:
+ /** @var Account $account */
+ foreach ($assetAccounts as $account) {
+ $role = $repository->getMetaValue($account, 'account_role');
+ if (null === $role) {
+ $role = 'no_account_type'; // @codeCoverageIgnore
+ }
+ $key = (string)trans('firefly.opt_group_' . $role);
+ $grouped[$key][$account->id] = $account->name;
+ }
+
+ unset($options['class']);
+ try {
+ $html = view('form.assetAccountCheckList', compact('classes', 'selected', 'name', 'label', 'options', 'grouped'))->render();
+ } catch (Throwable $e) {
+ Log::debug(sprintf('Could not render assetAccountCheckList(): %s', $e->getMessage()));
+ $html = 'Could not render assetAccountCheckList.';
+ }
+
+ return $html;
+ }
+
+ /**
+ * @param string $name
+ * @param mixed $value
+ * @param array $options
+ *
+ * @return string
+ */
+ public function assetAccountList(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]);
+ $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, 'account_role');
+ 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 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, 'account_role'); // TODO bad form for currency
+ 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);
+ }
+}
\ No newline at end of file
diff --git a/app/Support/Form/CurrencyForm.php b/app/Support/Form/CurrencyForm.php
new file mode 100644
index 0000000000..6f16f4230c
--- /dev/null
+++ b/app/Support/Form/CurrencyForm.php
@@ -0,0 +1,219 @@
+<?php
+/**
+ * CurrencyForm.php
+ * Copyright (c) 2019 [email protected]
+ *
+ * This file is part of Firefly III.
+ *
+ * Firefly III is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Firefly III is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+namespace FireflyIII\Support\Form;
+
+
+use Amount as Amt;
+use FireflyIII\Exceptions\FireflyException;
+use FireflyIII\Models\TransactionCurrency;
+use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
+use Illuminate\Support\Collection;
+use Log;
+use Throwable;
+
+/**
+ * Class CurrencyForm
+ *
+ * All currency related form methods.
+ *
+ * TODO cleanup and describe.
+ */
+class CurrencyForm
+{
+ use FormSupport;
+ /**
+ * @param string $name
+ * @param mixed $value
+ * @param array $options
+ *
+ * @return string
+ */
+ public function currencyList(string $name, $value = null, array $options = null): string
+ {
+ /** @var CurrencyRepositoryInterface $currencyRepos */
+ $currencyRepos = app(CurrencyRepositoryInterface::class);
+
+ // get all currencies:
+ $list = $currencyRepos->get();
+ $array = [];
+ /** @var TransactionCurrency $currency */
+ foreach ($list as $currency) {
+ $array[$currency->id] = $currency->name . ' (' . $currency->symbol . ')';
+ }
+
+ return $this->select($name, $array, $value, $options);
+ }
+
+ /**
+ * @param string $name
+ * @param mixed $value
+ * @param array $options
+ *
+ * @return string
+ */
+ public function currencyListEmpty(string $name, $value = null, array $options = null): string
+ {
+ /** @var CurrencyRepositoryInterface $currencyRepos */
+ $currencyRepos = app(CurrencyRepositoryInterface::class);
+
+ // get all currencies:
+ $list = $currencyRepos->get();
+ $array = [
+ 0 => (string)trans('firefly.no_currency'),
+ ];
+ /** @var TransactionCurrency $currency */
+ foreach ($list as $currency) {
+ $array[$currency->id] = $currency->name . ' (' . $currency->symbol . ')';
+ }
+
+ return $this->select($name, $array, $value, $options);
+ }
+
+
+ /**
+ * @param string $name
+ * @param mixed $value
+ * @param array $options
+ *
+ * @return string
+ * @throws FireflyException
+ */
+ public function balanceAll(string $name, $value = null, array $options = null): string
+ {
+ return $this->allCurrencyField($name, 'balance', $value, $options);
+ }
+
+ /**
+ * @param string $name
+ * @param string $view
+ * @param mixed $value
+ * @param array $options
+ *
+ * @return string
+ * @SuppressWarnings(PHPMD.CyclomaticComplexity)
+ */
+ protected function allCurrencyField(string $name, string $view, $value = null, array $options = null): string
+ {
+ $label = $this->label($name, $options);
+ $options = $this->expandOptionArray($name, $label, $options);
+ $classes = $this->getHolderClasses($name);
+ $value = $this->fillFieldValue($name, $value);
+ $options['step'] = 'any';
+ $defaultCurrency = $options['currency'] ?? Amt::getDefaultCurrency();
+ /** @var Collection $currencies */
+ $currencies = app('amount')->getAllCurrencies();
+ unset($options['currency'], $options['placeholder']);
+
+ // perhaps the currency has been sent to us in the field $amount_currency_id_$name (amount_currency_id_amount)
+ $preFilled = session('preFilled');
+ $key = 'amount_currency_id_' . $name;
+ $sentCurrencyId = isset($preFilled[$key]) ? (int)$preFilled[$key] : $defaultCurrency->id;
+
+ Log::debug(sprintf('Sent currency ID is %d', $sentCurrencyId));
+
+ // find this currency in set of currencies:
+ foreach ($currencies as $currency) {
+ if ($currency->id === $sentCurrencyId) {
+ $defaultCurrency = $currency;
+ Log::debug(sprintf('default currency is now %s', $defaultCurrency->code));
+ break;
+ }
+ }
+
+ // make sure value is formatted nicely:
+ if (null !== $value && '' !== $value) {
+ $value = round($value, $defaultCurrency->decimal_places);
+ }
+ try {
+ $html = view('form.' . $view, compact('defaultCurrency', 'currencies', 'classes', 'name', 'label', 'value', 'options'))->render();
+ } catch (Throwable $e) {
+ Log::debug(sprintf('Could not render currencyField(): %s', $e->getMessage()));
+ $html = 'Could not render currencyField.';
+ }
+
+ return $html;
+ }
+
+ /**
+ * @param string $name
+ * @param string $view
+ * @param mixed $value
+ * @param array $options
+ *
+ * @return string
+ * @SuppressWarnings(PHPMD.CyclomaticComplexity)
+ */
+ protected function currencyField(string $name, string $view, $value = null, array $options = null): string
+ {
+ $label = $this->label($name, $options);
+ $options = $this->expandOptionArray($name, $label, $options);
+ $classes = $this->getHolderClasses($name);
+ $value = $this->fillFieldValue($name, $value);
+ $options['step'] = 'any';
+ $defaultCurrency = $options['currency'] ?? Amt::getDefaultCurrency();
+ /** @var Collection $currencies */
+ $currencies = app('amount')->getCurrencies();
+ unset($options['currency'], $options['placeholder']);
+
+ // perhaps the currency has been sent to us in the field $amount_currency_id_$name (amount_currency_id_amount)
+ $preFilled = session('preFilled');
+ $key = 'amount_currency_id_' . $name;
+ $sentCurrencyId = isset($preFilled[$key]) ? (int)$preFilled[$key] : $defaultCurrency->id;
+
+ Log::debug(sprintf('Sent currency ID is %d', $sentCurrencyId));
+
+ // find this currency in set of currencies:
+ foreach ($currencies as $currency) {
+ if ($currency->id === $sentCurrencyId) {
+ $defaultCurrency = $currency;
+ Log::debug(sprintf('default currency is now %s', $defaultCurrency->code));
+ break;
+ }
+ }
+
+ // make sure value is formatted nicely:
+ if (null !== $value && '' !== $value) {
+ $value = round($value, $defaultCurrency->decimal_places);
+ }
+ try {
+ $html = view('form.' . $view, compact('defaultCurrency', 'currencies', 'classes', 'name', 'label', 'value', 'options'))->render();
+ } catch (Throwable $e) {
+ Log::debug(sprintf('Could not render currencyField(): %s', $e->getMessage()));
+ $html = 'Could not render currencyField.';
+ }
+
+ return $html;
+ }
+
+ /**
+ * @param string $name
+ * @param mixed $value
+ * @param array $options
+ *
+ * @return string
+ */
+ public function amount(string $name, $value = null, array $options = null): string
+ {
+ return $this->currencyField($name, 'amount', $value, $options);
+ }
+
+}
\ No newline at end of file
diff --git a/app/Support/Form/FormSupport.php b/app/Support/Form/FormSupport.php
new file mode 100644
index 0000000000..4f3ef06336
--- /dev/null
+++ b/app/Support/Form/FormSupport.php
@@ -0,0 +1,144 @@
+<?php
+/**
+ * FormSupport.php
+ * Copyright (c) 2019 [email protected]
+ *
+ * This file is part of Firefly III.
+ *
+ * Firefly III is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Firefly III is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+namespace FireflyIII\Support\Form;
+
+use Carbon\Carbon;
+use Illuminate\Support\MessageBag;
+use Log;
+use RuntimeException;
+use Throwable;
+
+/**
+ * Trait FormSupport
+ */
+trait FormSupport
+{
+ /**
+ * @param string $name
+ * @param array $list
+ * @param mixed $selected
+ * @param array $options
+ *
+ * @return string
+ */
+ public function select(string $name, array $list = null, $selected = null, array $options = null): string
+ {
+ $list = $list ?? [];
+ $label = $this->label($name, $options);
+ $options = $this->expandOptionArray($name, $label, $options);
+ $classes = $this->getHolderClasses($name);
+ $selected = $this->fillFieldValue($name, $selected);
+ unset($options['autocomplete'], $options['placeholder']);
+ try {
+ $html = view('form.select', compact('classes', 'name', 'label', 'selected', 'options', 'list'))->render();
+ } catch (Throwable $e) {
+ Log::debug(sprintf('Could not render select(): %s', $e->getMessage()));
+ $html = 'Could not render select.';
+ }
+
+ return $html;
+ }
+
+ /**
+ * @param $name
+ * @param $label
+ * @param array $options
+ *
+ * @return array
+ */
+ protected function expandOptionArray(string $name, $label, array $options = null): array
+ {
+ $options = $options ?? [];
+ $name = str_replace('[]', '', $name);
+ $options['class'] = 'form-control';
+ $options['id'] = 'ffInput_' . $name;
+ $options['autocomplete'] = 'off';
+ $options['placeholder'] = ucfirst($label);
+
+ return $options;
+ }
+
+ /**
+ * @param string $name
+ * @param $value
+ *
+ * @return mixed
+ */
+ protected function fillFieldValue(string $name, $value = null)
+ {
+ if (app('session')->has('preFilled')) {
+ $preFilled = session('preFilled');
+ $value = isset($preFilled[$name]) && null === $value ? $preFilled[$name] : $value;
+ }
+
+ try {
+ if (null !== request()->old($name)) {
+ $value = request()->old($name);
+ }
+ } catch (RuntimeException $e) {
+ // don't care about session errors.
+ Log::debug(sprintf('Run time: %s', $e->getMessage()));
+ }
+
+ if ($value instanceof Carbon) {
+ $value = $value->format('Y-m-d');
+ }
+
+ return $value;
+ }
+
+ /**
+ * @param $name
+ *
+ * @return string
+ */
+ protected function getHolderClasses(string $name): string
+ {
+ // Get errors from session:
+ /** @var MessageBag $errors */
+ $errors = session('errors');
+ $classes = 'form-group';
+
+ if (null !== $errors && $errors->has($name)) {
+ $classes = 'form-group has-error has-feedback';
+ }
+
+ return $classes;
+ }
+
+ /**
+ * @param $name
+ * @param $options
+ *
+ * @return mixed
+ */
+ protected function label(string $name, array $options = null): string
+ {
+ $options = $options ?? [];
+ if (isset($options['label'])) {
+ return $options['label'];
+ }
+ $name = str_replace('[]', '', $name);
+
+ return (string)trans('form.' . $name);
+ }
+}
\ No newline at end of file
diff --git a/app/Support/Form/PiggyBankForm.php b/app/Support/Form/PiggyBankForm.php
new file mode 100644
index 0000000000..38fae973a8
--- /dev/null
+++ b/app/Support/Form/PiggyBankForm.php
@@ -0,0 +1,60 @@
+<?php
+/**
+ * PiggyBankForm.php
+ * Copyright (c) 2019 [email protected]
+ *
+ * This file is part of Firefly III.
+ *
+ * Firefly III is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Firefly III is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+namespace FireflyIII\Support\Form;
+
+
+use FireflyIII\Models\PiggyBank;
+use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
+
+/**
+ * Class PiggyBankForm
+ *
+ * TODO cleanup and describe.
+ */
+class PiggyBankForm
+{
+ use FormSupport;
+ /**
+ * @param string $name
+ * @param mixed $value
+ * @param array $options
+ *
+ * @return string
+ */
+ public function piggyBankList(string $name, $value = null, array $options = null): string
+ {
+
+ // make repositories
+ /** @var PiggyBankRepositoryInterface $repository */
+ $repository = app(PiggyBankRepositoryInterface::class);
+ $piggyBanks = $repository->getPiggyBanksWithAmount();
+ $array = [
+ 0 => (string)trans('firefly.none_in_select_list'),
+ ];
+ /** @var PiggyBank $piggy */
+ foreach ($piggyBanks as $piggy) {
+ $array[$piggy->id] = $piggy->name;
+ }
+
+ return $this->select($name, $array, $value, $options);
+ }
+}
\ No newline at end of file
diff --git a/app/Support/Form/RuleForm.php b/app/Support/Form/RuleForm.php
new file mode 100644
index 0000000000..1cf57d9c16
--- /dev/null
+++ b/app/Support/Form/RuleForm.php
@@ -0,0 +1,88 @@
+<?php
+/**
+ * RuleForm.php
+ * Copyright (c) 2019 [email protected]
+ *
+ * This file is part of Firefly III.
+ *
+ * Firefly III is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Firefly III is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+namespace FireflyIII\Support\Form;
+
+
+use FireflyIII\Models\RuleGroup;
+use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
+use Form;
+use Illuminate\Support\HtmlString;
+
+/**
+ * Class RuleForm
+ * TODO cleanup and describe.
+ */
+class RuleForm
+{
+ use FormSupport;
+ /**
+ * @param string $name
+ * @param mixed $value
+ * @param array $options
+ *
+ * @return string
+ */
+ public function ruleGroupList(string $name, $value = null, array $options = null): string
+ {
+ /** @var RuleGroupRepositoryInterface $groupRepos */
+ $groupRepos = app(RuleGroupRepositoryInterface::class);
+
+ // get all currencies:
+ $list = $groupRepos->get();
+ $array = [];
+ /** @var RuleGroup $group */
+ foreach ($list as $group) {
+ $array[$group->id] = $group->title;
+ }
+
+ return $this->select($name, $array, $value, $options);
+ }
+
+ /**
+ * @param string $name
+ * @param null $value
+ * @param array|null $options
+ *
+ * @return HtmlString
+ */
+ public function ruleGroupListWithEmpty(string $name, $value = null, array $options = null): HtmlString
+ {
+ $options = $options ?? [];
+ $options['class'] = 'form-control';
+ /** @var RuleGroupRepositoryInterface $groupRepos */
+ $groupRepos = app(RuleGroupRepositoryInterface::class);
+
+ // get all currencies:
+ $list = $groupRepos->get();
+ $array = [
+ 0 => (string)trans('firefly.none_in_select_list'),
+ ];
+ /** @var RuleGroup $group */
+ foreach ($list as $group) {
+ if (isset($options['hidden']) && (int)$options['hidden'] !== $group->id) {
+ $array[$group->id] = $group->title;
+ }
+ }
+
+ return Form::select($name, $array, $value, $options);
+ }
+}
\ No newline at end of file
diff --git a/config/app.php b/config/app.php
index f95262a3b1..7941e75248 100644
--- a/config/app.php
+++ b/config/app.php
@@ -21,6 +21,7 @@
declare(strict_types=1);
+
use FireflyIII\Providers\ImportServiceProvider;
@@ -145,6 +146,7 @@ return [
'Amount' => \FireflyIII\Support\Facades\Amount::class,
'Steam' => \FireflyIII\Support\Facades\Steam::class,
'ExpandedForm' => \FireflyIII\Support\Facades\ExpandedForm::class,
+ 'AccountForm' => \FireflyIII\Support\Facades\AccountForm::class,
'Google2FA' => PragmaRX\Google2FALaravel\Facade::class,
],
diff --git a/config/twigbridge.php b/config/twigbridge.php
index 02f8f8c206..30e7604efc 100644
--- a/config/twigbridge.php
+++ b/config/twigbridge.php
@@ -21,17 +21,17 @@
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
-use TwigBridge\Extension\Laravel\Url;
-use TwigBridge\Extension\Laravel\Str;
-use TwigBridge\Extension\Laravel\Translator;
-use TwigBridge\Extension\Laravel\Session;
+use TwigBridge\Extension\Laravel\Auth;
+use TwigBridge\Extension\Laravel\Config;
use TwigBridge\Extension\Laravel\Dump;
use TwigBridge\Extension\Laravel\Input;
-use TwigBridge\Extension\Laravel\Config;
-use TwigBridge\Extension\Laravel\Auth;
+use TwigBridge\Extension\Laravel\Session;
+use TwigBridge\Extension\Laravel\Str;
+use TwigBridge\Extension\Laravel\Translator;
+use TwigBridge\Extension\Laravel\Url;
+use TwigBridge\Extension\Loader\Facades;
use TwigBridge\Extension\Loader\Filters;
use TwigBridge\Extension\Loader\Functions;
-use TwigBridge\Extension\Loader\Facades;
use TwigBridge\Twig\Template;
/**
@@ -193,16 +193,21 @@ return [
'Steam',
'Config',
'Request',
+ 'Form' => ['is_safe' => ['input', 'select', 'checkbox', 'model', 'open', 'radio', 'textarea', 'file',],],
'ExpandedForm' => [
- 'is_safe' => ['date', 'text', 'select', 'balance', 'optionsList', 'checkbox', 'amount', 'tags', 'integer', 'textarea', 'location', 'file',
- 'staticText', 'password', 'nonSelectableAmount', 'number', 'assetAccountList', 'amountNoCurrency', 'currencyList',
- 'ruleGroupList', 'assetAccountCheckList', 'ruleGroupListWithEmpty', 'piggyBankList', 'currencyListEmpty',
- 'activeAssetAccountList', 'percentage', 'activeLongAccountList', 'longAccountList','balanceAll',
- 'activeWithdrawalDestinations','activeDepositDestinations'
+ 'is_safe' => [
+ 'date', 'text', 'select', 'balance', 'optionsList', 'checkbox', 'amount', 'tags', 'integer', 'textarea', 'location', 'file', 'staticText',
+ 'password', 'nonSelectableAmount', 'number', 'assetAccountList', 'amountNoCurrency', 'currencyList', 'ruleGroupList',
+ 'assetAccountCheckList', 'ruleGroupListWithEmpty', 'piggyBankList', 'currencyListEmpty', 'percentage',
+ 'activeLongAccountList', 'longAccountList', 'balanceAll', 'activeWithdrawalDestinations', 'activeDepositDestinations',
- ],],
- 'Form' => ['is_safe' => ['input', 'select', 'checkbox', 'model', 'open', 'radio', 'textarea', 'file',],
+ ],
+ ],
+ 'AccountForm' => [
+ 'is_safe' => [
+ 'activeAssetAccountList', 'activeLongAccountList',
+ ],
],
],
diff --git a/resources/views/v1/import/file/configure-upload.twig b/resources/views/v1/import/file/configure-upload.twig
index 73d00f3ab4..2a3c5eef92 100644
--- a/resources/views/v1/import/file/configure-upload.twig
+++ b/resources/views/v1/import/file/configure-upload.twig
@@ -38,7 +38,7 @@
{{ ExpandedForm.checkbox('has_headers',1,importJob.configuration['has-headers'],{helpText: trans('import.job_config_uc_header_help')}) }}
{{ ExpandedForm.text('date_format',importJob.configuration['date-format'],{helpText: trans('import.job_config_uc_date_help', {dateExample: phpdate('Ymd')}) }) }}
{{ ExpandedForm.select('csv_delimiter', data.delimiters, importJob.configuration['delimiter'], {helpText: trans('import.job_config_uc_delimiter_help') } ) }}
- {{ ExpandedForm.activeAssetAccountList('csv_import_account', importJob.configuration['import-account'], {helpText: trans('import.job_config_uc_account_help')}) }}
+ {{ AccountForm.activeAssetAccountList('csv_import_account', importJob.configuration['import-account'], {helpText: trans('import.job_config_uc_account_help')}) }}
<h4>{{ 'optionalFields'|_ }}</h4>
<div class="form-group">
diff --git a/resources/views/v1/piggy-banks/create.twig b/resources/views/v1/piggy-banks/create.twig
index e9208bb055..db388cbeb0 100644
--- a/resources/views/v1/piggy-banks/create.twig
+++ b/resources/views/v1/piggy-banks/create.twig
@@ -18,7 +18,7 @@
<div class="box-body">
{{ ExpandedForm.text('name') }}
- {{ ExpandedForm.activeAssetAccountList('account_id', null, {label: 'saveOnAccount'|_ }) }}
+ {{ AccountForm.activeAssetAccountList('account_id', null, {label: 'saveOnAccount'|_ }) }}
{{ ExpandedForm.amountNoCurrency('targetamount') }}
</div>
diff --git a/resources/views/v1/recurring/create.twig b/resources/views/v1/recurring/create.twig
index 654aecc5da..51616a2595 100644
--- a/resources/views/v1/recurring/create.twig
+++ b/resources/views/v1/recurring/create.twig
@@ -90,16 +90,13 @@
{{ ExpandedForm.amountNoCurrency('amount', []) }}
{# source account if withdrawal, or if transfer: #}
- {{ ExpandedForm.activeLongAccountList('source_id', null, {label: trans('form.asset_source_account')}) }}
-
- {# source account name for deposits: #}
- {#{{ ExpandedForm.text('source_name', null, {label: trans('form.revenue_account')}) }}#}
+ {{ AccountForm.activeLongAccountList('source_id', null, {label: trans('form.asset_source_account')}) }}
{# for deposits, a drop down with revenue accounts, loan debt cash and mortgage #}
{{ ExpandedForm.activeDepositDestinations('deposit_source_id', null, {label: trans('form.deposit_source_id')}) }}
{# destination if deposit or transfer: #}
- {{ ExpandedForm.activeLongAccountList('destination_id', null, {label: trans('form.asset_destination_account')} ) }}
+ {{ AccountForm.activeLongAccountList('destination_id', null, {label: trans('form.asset_destination_account')} ) }}
{# destination account name for withdrawals #}
{#{{ ExpandedForm.text('destination_name', null, {label: trans('form.expense_account')}) }} #}
diff --git a/resources/views/v1/transactions/convert.twig b/resources/views/v1/transactions/convert.twig
index ab228f72fe..eba06b4339 100644
--- a/resources/views/v1/transactions/convert.twig
+++ b/resources/views/v1/transactions/convert.twig
@@ -314,168 +314,6 @@
{{ ExpandedForm.staticText('destination_account_asset', '<a href="'~route('accounts.show',[destinationAccount.id])~'">'~destinationAccount.name|escape~'</a>') }}
{% endif %}
#}
-
- {# ONE #}
- {#
- {% if journalType.type == 'Withdrawal' and destinationType.type == 'Deposit' %}
- ONE
- {% endif %}
- {% if journalType.type == 'Withdrawal' and destinationType.type == 'Deposit' %}
- <p><em>
- {{ trans('firefly.convert_explanation_withdrawal_deposit',
- {
- amount: positiveAmount|formatAmount,
- sourceRoute: route('accounts.show', [sourceAccount.id]),
- sourceName: sourceAccount.name|escape,
- destinationRoute: route('accounts.show', [destinationAccount.id]),
- destinationName: destinationAccount.name|escape,
- })|raw }}
- </em>
- </p>
- <p><em>
- {{ 'convert_please_set_revenue_source'|_ }}
- </em>
- </p>
- {% if destinationAccount.accountType.type == "Cash account" %}
- {{ ExpandedForm.text('source_account_revenue', '') }}
- {% else %}
- {{ ExpandedForm.text('source_account_revenue', destinationAccount.name|escape) }}
- {% endif %}
- {% endif %}
- #}
- {# TWO #}
- {#
- {% if journalType.type == 'Withdrawal' and destinationType.type == 'Transfer' %}
- <p><em>
- {{ trans('firefly.convert_explanation_withdrawal_transfer',
- {
- amount: positiveAmount|formatAmount,
- sourceRoute: route('accounts.show', [sourceAccount.id]),
- sourceName: sourceAccount.name|escape,
- destinationRoute: route('accounts.show', [destinationAccount.id]),
- destinationName: destinationAccount.name|escape,
- })|raw }}
- </em></p>
-
- <p>
- <em>
- {{ 'convert_please_set_asset_destination'|_ }}
-
- </em>
- </p>
- {{ ExpandedForm.activeLongAccountList('destination_account_asset', null) }}
-
- {% endif %}
- #}
- {# THREE #}
- {#
- {% if journalType.type == 'Deposit' and destinationType.type == 'Withdrawal' %}
- <p>
- <em>
- {{ trans('firefly.convert_explanation_deposit_withdrawal',
- {
- amount: positiveAmount|formatAmount,
- sourceRoute: route('accounts.show', [sourceAccount.id]),
- sourceName: sourceAccount.name|escape,
- destinationRoute: route('accounts.show', [destinationAccount.id]),
- destinationName: destinationAccount.name|escape,
- })|raw }}
- </em>
- </p>
- <p>
- <em>
- {{ 'convert_please_set_expense_destination'|_ }}
-
- </em>
- </p>
- {% if sourceAccount.accountType.type == "Cash account" %}
- {{ ExpandedForm.text('destination_account_expense', '') }}
- {% else %}
- {{ ExpandedForm.text('destination_account_expense', destinationAccount.name|escape) }}
- {% endif %}
-
- {% endif %}
- #}
- {# FOUR #}
- {#
- {% if journalType.type == 'Deposit' and destinationType.type == 'Transfer' %}
-
- <p>
- <em>
- {{ trans('firefly.convert_explanation_deposit_transfer',
- {
- amount: positiveAmount|formatAmount,
- sourceRoute: route('accounts.show', [sourceAccount.id]),
- sourceName: sourceAccount.name|escape,
- destinationRoute: route('accounts.show', [destinationAccount.id]),
- destinationName: destinationAccount.name|escape,
- })|raw }}
- </em>
- </p>
- <p>
- <em>
- {{ 'convert_please_set_asset_source'|_ }}
-
- </em>
- </p>
- {{ ExpandedForm.activeLongAccountList('source_account_asset', null) }}
- {% endif %}
- #}
- {# FIVE #}
- {#
- {% if journalType.type == 'Transfer' and destinationType.type == 'Withdrawal' %}
-
- <p>
- <em>
- {{ trans('firefly.convert_explanation_transfer_withdrawal',
- {
- amount: positiveAmount|formatAmount,
- sourceRoute: route('accounts.show', [sourceAccount.id]),
- sourceName: sourceAccount.name|escape,
- destinationRoute: route('accounts.show', [destinationAccount.id]),
- destinationName: destinationAccount.name|escape,
- })|raw }}
- </em>
- </p>
-
- <p>
- <em>
- {{ 'convert_please_set_expense_destination'|_ }}
- </em>
- </p>
-
- {{ ExpandedForm.text('destination_account_expense', destinationAccount.name|escape) }}
-
- {% endif %}
- #}
- {# SIX #}
- {#
- {% if journalType.type == 'Transfer' and destinationType.type == 'Deposit' %}
-
-
- <p>
- <em>
- {{ trans('firefly.convert_explanation_transfer_deposit',
- {
- amount: positiveAmount|formatAmount,
- sourceRoute: route('accounts.show', [sourceAccount.id]),
- sourceName: sourceAccount.name|escape,
- destinationRoute: route('accounts.show', [destinationAccount.id]),
- destinationName: destinationAccount.name|escape,
- })|raw }}
- </em>
- </p>
-
- <p>
- <em>
- {{ 'convert_please_set_revenue_source'|_ }}
- </em>
- </p>
-
- {{ ExpandedForm.text('source_account_revenue', sourceAccount.name|escape) }}
-
- {% endif %}
- #}
</div>
<div class="box-footer">
<a href="{{ route('transactions.show', group.id) }}" class="btn btn-danger">{{ 'cancel'|_ }}</a>
diff --git a/resources/views/v1/transactions/split/edit.twig b/resources/views/v1/transactions/split/edit.twig
deleted file mode 100644
index 0b6eb9dfb6..0000000000
--- a/resources/views/v1/transactions/split/edit.twig
+++ /dev/null
@@ -1,337 +0,0 @@
-{% extends "./layout/default" %}
-
-{% block breadcrumbs %}
- {{ Breadcrumbs.render(Route.getCurrentRoute.getName, journal) }}
-{% endblock %}
-{% block content %}
- <form method="POST" action="{{ route('transactions.split.update',journal.id) }}" accept-charset="UTF-8" class="form-horizontal" id="update"
- enctype="multipart/form-data">
- <input name="_token" type="hidden" value="{{ csrf_token() }}">
- <input type="hidden" name="id" value="{{ journal.id }}"/>
- <input type="hidden" name="what" value="{{ preFilled.what }}"/>
- <input type="hidden" name="journal_currency_id" value="{{ journal.transaction_currency_id }}"/>
-
- {% if errors.all()|length > 0 %}
- <div class="row">
- <div class="col-lg-12 col-md-12 col-sm-12">
- <div class="box box-danger">
- <div class="box-header with-border">
- <h3 class="box-title">{{ 'errors'|_ }}</h3>
- </div>
- <div class="box-body">
- <ul>
- {% for key, err in errors.all() %}
- <li class="text-danger">{{ err }}</li>
- {% endfor %}
- </ul>
- </div>
- </div>
- </div>
- </div>
- {% endif %}
- <div class="row">
- <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
- <div class="box">
- <div class="box-header with-border">
- <h3 class="box-title">{{ 'transaction_data'|_ }}</h3>
- </div>
- <div class="box-body">
-
- {# DESCRIPTION IS ALWAYS AVAILABLE #}
- {{ ExpandedForm.text('journal_description', journal.description) }}
-
- {# show source if withdrawal or transfer #}
- {% if preFilled.what == 'withdrawal' or preFilled.what == 'transfer' %}
- {{ ExpandedForm.activeLongAccountList('journal_source_id', preFilled.journal_source_id) }}
- {% endif %}
-
- {# show destination account id, if deposit (is asset): #}
- {% if preFilled.what == 'deposit' or preFilled.what == 'transfer' %}
- {{ ExpandedForm.activeLongAccountList('journal_destination_id', preFilled.journal_destination_id) }}
- {% endif %}
-
- {# show amount and some helper text when making splits: #}
- {# amount #}
- <div id="journal_amount_holder" class="form-group">
- <label for="ffInput_journal_amount" class="col-sm-4 control-label">{{ trans('form.amount') }}</label>
- <div class="col-sm-8">
- <p id="ffInput_journal_amount" class="form-control-static">
- {{ formatAmountBySymbol(preFilled.journal_amount|default("0"), preFilled.transactions[0].currency_symbol|default("x"), preFilled.transactions[0].currency_decimal_places) }}
- </p>
- </div>
- </div>
-
- {# foreign amount, if not zero. #}
- {% if preFilled.journal_foreign_amount != 0 %}
- <div id="journal_foreign_amount_holder" class="form-group">
- <label for="ffInput_foreign_journal_amount" class="col-sm-4 control-label">{{ trans('form.foreign_amount') }}</label>
- <div class="col-sm-8">
- <p id="ffInput_foreign_journal_amount" class="form-control-static">
- {{ formatAmountBySymbol(preFilled.journal_foreign_amount, preFilled.transactions[0].foreign_currency_symbol, preFilled.transactions[0].foreign_currency_decimal_places) }}
- </p>
- </div>
- </div>
- {% endif %}
- <input type="hidden" name="journal_amount" value="{{ preFilled.journal_amount }}"/>
- {# DATE #}
- {{ ExpandedForm.date('date', journal.date) }}
- </div>
- </div>
- </div>
- <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
- <div class="box">
- <div class="box-header with-border">
- <h3 class="box-title">{{ 'optional_field_meta_data'|_ }}</h3>
- </div>
- <div class="box-body">
- {# ALWAYS TAGS #}
- {{ ExpandedForm.text('tags', preFilled.tags) }}
- </div>
- </div>
-
- {# EXPLANATION IF NECESSARY: #}
- {% if
- not optionalFields.interest_date or
- not optionalFields.book_date or
- not optionalFields.process_date or
- not optionalFields.due_date or
- not optionalFields.payment_date or
- not optionalFields.invoice_date or
- not optionalFields.internal_reference or
- not optionalFields.notes or
- not optionalFields.attachments %}
- <p class="text-center text-success"><i class="fa fa-info-circle"></i>
- <em>{{ trans('firefly.hidden_fields_preferences', {link: route('preferences.index')})|raw }}</em></p>
- {% endif %}
-
- {# BOX FOR DATES #}
- {% if
- optionalFields.interest_date or optionalFields.book_date or optionalFields.process_date
- or optionalFields.due_date or optionalFields.payment_date
- or optionalFields.invoice_date %}
- <div class="box">
- <div class="box-header with-border">
- <h3 class="box-title">{{ 'optional_field_meta_dates'|_ }}</h3>
- </div>
- <div class="box-body">
-
- {# INTEREST DATE #}
- {% if optionalFields.interest_date or journal.interest_date %}
- {{ ExpandedForm.date('interest_date', journal.interest_date) }}
- {% endif %}
-
- {# BOOK DATE #}
- {% if optionalFields.book_date or journal.book_date %}
- {{ ExpandedForm.date('book_date', journal.book_date) }}
- {% endif %}
-
- {# PROCESSING DATE #}
- {% if optionalFields.process_date or journal.process_date %}
- {{ ExpandedForm.date('process_date', journal.process_date) }}
- {% endif %}
-
- {# DUE DATE #}
- {% if optionalFields.due_date or journal.due_date %}
- {{ ExpandedForm.date('due_date', journal.due_date) }}
- {% endif %}
-
- {# PAYMENT DATE #}
- {% if optionalFields.payment_date or journal.payment_date %}
- {{ ExpandedForm.date('payment_date', journal.payment_date) }}
- {% endif %}
-
- {# INVOICE DATE #}
- {% if optionalFields.invoice_date or journal.invoice_date %}
- {{ ExpandedForm.date('invoice_date', journal.invoice_date) }}
- {% endif %}
- </div>
- </div>
- {% endif %}
-
- {# BOX FOR BUSINESS FIELDS #}
- {% if optionalFields.internal_reference or optionalFields.notes %}
- <div class="box">
- <div class="box-header with-border">
- <h3 class="box-title">{{ 'optional_field_meta_business'|_ }}</h3>
- </div>
- <div class="box-body">
-
- {# INTERNAL REFERENCE #}
- {% if optionalFields.internal_reference or journal.internal_reference %}
- {{ ExpandedForm.text('internal_reference', journal.internal_reference) }}
- {% endif %}
-
- {# NOTES #}
- {% if optionalFields.notes or journal.notes %}
- {{ ExpandedForm.textarea('notes',preFilled.notes) }}
- {% endif %}
- </div>
- </div>
- {% endif %}
-
- {# BOX FOR ATTACHMENTS #}
- {% if optionalFields.attachments %}
- <div class="box">
- <div class="box-header with-border">
- <h3 class="box-title">{{ 'optional_field_attachments'|_ }}</h3>
- </div>
- <div class="box-body">
- {# ATTACHMENTS #}
- {% if optionalFields.attachments %}
- {{ ExpandedForm.file('attachments[]', {'multiple': 'multiple','helpText': trans('firefly.upload_max_file_size', {'size': uploadSize|filesize}) }) }}
- {% endif %}
- </div>
- </div>
- {% endif %}
-
- </div>
- </div>
- <div class="row">
- <div class="col-lg-12 col-md-12 col-sm-12">
- <div class="box">
- <div class="box-header with-border">
- <h3 class="box-title">{{ 'splits'|_ }}</h3>
- </div>
- <div class="box-body">
- <div class="container-fluid split_row_holder">
- <div class="row bg-gray-light" style="padding-bottom:3px;">
- {# HEADER #}
- <div class="col-lg-1 col-md-1 col-sm-6 col-xs-6"><strong>{{ trans('list.split_number') }}</strong></div>
- <div class="col-lg-3 col-md-5 col-sm-12 col-xs-12"><strong>{{ trans('list.description') }}</strong></div>
- {# withdrawal and deposit have a destination. #}
- {% if preFilled.what == 'withdrawal' %}
- <div class="col-lg-2 col-md-5 col-sm-12 col-xs-12"><strong>{{ trans('list.destination') }}</strong></div>
- {% endif %}
- {# Deposit has a source #}
- {% if preFilled.what == 'deposit' %}
- <div class="col-lg-2 col-md-5 col-sm-12 col-xs-12"><strong>{{ trans('list.source') }}</strong></div>
- {% endif %}
- <div class="col-lg-2 col-md-5 col-sm-12 col-xs-12"><strong>{{ trans('list.amount') }}</strong></div>
- {# only withdrawal has budget #}
- {% if preFilled.what == 'withdrawal' %}
- <div class="col-lg-2 col-md-6 col-sm-12 col-xs-12"><strong>{{ trans('list.budget') }}</strong></div>
- {% endif %}
- <div class="col-lg-2 col-md-6 col-sm-12 col-xs-12"><strong>{{ trans('list.category') }}</strong></div>
- </div>
-
- {# ROWS #}
-
-
- {% for index, transaction in preFilled.transactions %}
- <div class="row {% if loop.index0 % 2 == 1 %}bg-gray-light{% endif %} split_row" data-split="{{ loop.index0 }}">
- {# button #}
- <div class="col-lg-1 col-md-1 col-sm-6 col-xs-6">
- <a href="#" class="btn btn-xs btn-danger remove-current-split" data-split="{{ loop.index0 }}">
- <i class="fa fa-trash" data-split="{{ loop.index0 }}"></i><span> #{{ loop.index }}</span></a>
- </div>
-
- {# description #}
- <div class="col-lg-3 col-md-5 col-sm-12 col-xs-12">
- <input autocomplete="off" type="text" name="transactions[{{ loop.index0 }}][transaction_description]"
- value="{{ transaction.transaction_description }}"
- class="form-control"/>
- </div>
-
- {# destination for withdrawals: #}
- {% if preFilled.what == 'withdrawal' %}
- <div class="col-lg-2 col-md-5 col-sm-12 col-xs-12">
- <input autocomplete="off" type="text" name="transactions[{{ loop.index0 }}][destination_name]"
- value="{% if transaction.destination_type != 'Cash account' %}{{ transaction.destination_name }}{% endif %}"
- class="form-control"/>
- </div>
- {% endif %}
-
- {# source for deposits #}
- {% if preFilled.what == 'deposit' %}
- <div class="col-lg-2 col-md-5 col-sm-12 col-xs-12">
- <input autocomplete="off" type="text" name="transactions[{{ loop.index0 }}][source_name]"
- value="{{ transaction.source_name }}" class="form-control"/>
- </div>
- {% endif %}
-
- {# amount#}
- <div class="col-lg-2 col-md-5 col-sm-12 col-xs-12">
- {{ transaction.currency_symbol }}&nbsp;<input class="split_amount_input" type="number"
- name="transactions[{{ loop.index0 }}][amount]"
- value="{{ transaction.amount }}"
- autocomplete="off" step="any">
- {% if transaction.foreign_amount != null %}
- {{ transaction.foreign_currency_symbol }}&nbsp;<input class="split_amount_input" type="number"
- name="transactions[{{ loop.index0 }}][foreign_amount]"
- value="{{ transaction.foreign_amount }}" autocomplete="off"
- step="any">
- <input type="hidden" name="transactions[{{ loop.index0 }}][foreign_currency_id]"
- value="{{ transaction.foreign_currency_id }}">
- {% endif %}
- <input type="hidden" name="transactions[{{ loop.index0 }}][currency_id]"
- value="{{ transaction.currency_id }}">
- </div>
- {# budget #}
- {% if preFilled.what == 'withdrawal' %}
- <div class="col-lg-2 col-md-6 col-sm-12 col-xs-12">
- <select class="form-control" name="transactions[{{ loop.index0 }}][budget_id]">
- {% for key, budget in budgets %}
- <option label="{{ budget }}" value="{{ key }}"
- {% if transaction.budget_id == key %} selected="selected"{% endif %}>{{ budget }}</option>
- {% endfor %}
- </select>
- </div>
- {% endif %}
-
- {# category #}
- <div class="col-lg-2 col-md-6 col-sm-12 col-xs-12">
- <input autocomplete="off" type="text" name="transactions[{{ loop.index0 }}][category_name]"
- value="{{ transaction.category_name }}"
- class="form-control"/>
- </div>
- </div>
- {% endfor %}
- </div>
- <p>
- <br/>
- <a href="#" class="btn btn-default btn-do-split"><i class="fa fa-plus-circle"></i> {{ 'add_another_split'|_ }}</a>
- </p>
- </div>
- </div>
- </div>
- </div>
- <div class="row">
- <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
- {# panel for options #}
- <div class="box">
- <div class="box-header with-border">
- <h3 class="box-title">{{ 'options'|_ }}</h3>
- </div>
- <div class="box-body">
- {{ ExpandedForm.optionsList('update','split-transaction') }}
- </div>
- <div class="box-footer">
- <button type="submit" class="pull-right btn btn-success">{{ ('update_' ~ preFilled.what)|_ }}</button>
- </div>
- </div>
- </div>
- </div>
- </form>
-
-{% endblock %}
-{% block styles %}
- <link href="v1/css/bootstrap-tagsinput.css?v={{ FF_VERSION }}" type="text/css" rel="stylesheet" media="all">
- <link href="v1/css/jquery-ui/jquery-ui.structure.min.css?v={{ FF_VERSION }}" type="text/css" rel="stylesheet" media="all">
- <link href="v1/css/jquery-ui/jquery-ui.theme.min.css?v={{ FF_VERSION }}" type="text/css" rel="stylesheet" media="all">
-{% endblock %}
-{% block scripts %}
- <script type="text/javascript" src="{{ route('javascript.currencies') }}?ext=.js&amp;v={{ FF_VERSION }}"></script>
- <script type="text/javascript">
- var currencySymbol = "{{ preFilled.transactions[0].currency_symbol }}";
- var foreignCurrencySymbol = "{{ preFilled.transactions[0].foreign_currency_symbol }}";
- var originalSum = {{ preFilled.journal_amount }};
- var originalForeignSum = {{ preFilled.journal_foreign_amount }};
- var what = "{{ preFilled.what }}";
- </script>
- <script type="text/javascript" src="v1/js/lib/typeahead/typeahead.bundle.min.js?v={{ FF_VERSION }}"></script>
- <script type="text/javascript" src="v1/js/ff/common/autocomplete.js?v={{ FF_VERSION }}"></script>
- <script type="text/javascript" src="v1/js/lib/bootstrap-tagsinput.min.js?v={{ FF_VERSION }}"></script>
- <script type="text/javascript" src="v1/js/lib/jquery-ui.min.js?v={{ FF_VERSION }}"></script>
- <script type="text/javascript" src="v1/js/lib/modernizr-custom.js?v={{ FF_VERSION }}"></script>
- <script type="text/javascript" src="v1/js/ff/transactions/split/edit.js?v={{ FF_VERSION }}"></script>
-{% endblock %}