Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Some fixes in the account list
James Colea41d7378ef34
diff --git a/app/Http/Controllers/Account/IndexController.php b/app/Http/Controllers/Account/IndexController.phpindex ac0c95de4a..c80673db05 100644--- a/app/Http/Controllers/Account/IndexController.php+++ b/app/Http/Controllers/Account/IndexController.php@@ -160,14 +160,19 @@ class IndexController extends Controller$accounts->each(function (Account $account) use ($activities, $startBalances, $endBalances) {// TODO lots of queries executed in this block.- $account->lastActivityDate = $this->isInArray($activities, $account->id);- $account->startBalance = $this->isInArray($startBalances, $account->id);- $account->endBalance = $this->isInArray($endBalances, $account->id);- $account->difference = bcsub($account->endBalance, $account->startBalance);- $account->interest = number_format((float)$this->repository->getMetaValue($account, 'interest'), 4, '.', '');- $account->interestPeriod = (string)trans(sprintf('firefly.interest_calc_%s', $this->repository->getMetaValue($account, 'interest_period')));- $account->accountTypeString = (string)trans(sprintf('firefly.account_type_%s', $account->accountType->type));- $account->location = $this->repository->getLocation($account);+ $account->lastActivityDate = $this->isInArray($activities, $account->id);+ $account->startBalance = $this->isInArray($startBalances, $account->id);+ $account->endBalance = $this->isInArray($endBalances, $account->id);+ $account->difference = bcsub($account->endBalance, $account->startBalance);+ $account->interest = number_format((float)$this->repository->getMetaValue($account, 'interest'), 4, '.', '');+ $account->interestPeriod = (string)trans(+ sprintf('firefly.interest_calc_%s', $this->repository->getMetaValue($account, 'interest_period'))+ );+ $account->accountTypeString = (string)trans(sprintf('firefly.account_type_%s', $account->accountType->type));+ $account->location = $this->repository->getLocation($account);++ $account->liability_direction = $this->repository->getMetaValue($account, 'liability_direction');+ $account->current_debt = $this->repository->getMetaValue($account, 'current_debt');});// make paginator:diff --git a/app/Services/Internal/Support/CreditRecalculateService.php b/app/Services/Internal/Support/CreditRecalculateService.phpindex 2f925730d0..c4d2a8a457 100644--- a/app/Services/Internal/Support/CreditRecalculateService.php+++ b/app/Services/Internal/Support/CreditRecalculateService.php@@ -28,6 +28,7 @@ use FireflyIII\Models\Account;use FireflyIII\Models\Transaction;use FireflyIII\Models\TransactionGroup;use FireflyIII\Models\TransactionJournal;+use FireflyIII\Models\TransactionType;use FireflyIII\Repositories\Account\AccountRepositoryInterface;use Log;@@ -101,13 +102,18 @@ class CreditRecalculateService// get opening balance (if present)$this->repository->setUser($account->user);$startOfDebt = $this->repository->getOpeningBalanceAmount($account) ?? '0';-+ $leftOfDebt = app('steam')->positive($startOfDebt);/** @var AccountMetaFactory $factory */$factory = app(AccountMetaFactory::class);$factory->crud($account, 'start_of_debt', $startOfDebt);- $factory->crud($account, 'current_debt', $startOfDebt);- // update meta data:+ // now loop all transactions (except opening balance and credit thing)+ $transactions = $account->transactions()->get();+ /** @var Transaction $transaction */+ foreach ($transactions as $transaction) {+ $leftOfDebt = $this->processTransaction($transaction, $leftOfDebt);+ }+ $factory->crud($account, 'current_debt', $leftOfDebt);Log::debug(sprintf('Done with %s(#%d)', __METHOD__, $account->id));@@ -230,5 +236,22 @@ class CreditRecalculateService$this->group = $group;}+ /**+ * @param Transaction $transaction+ * @param string $amount+ *+ * @return string+ */+ private function processTransaction(Transaction $transaction, string $amount): string+ {+ $journal = $transaction->transactionJournal;+ $type = $journal->transactionType->type;+ if (in_array($type, [TransactionType::WITHDRAWAL, TransactionType::DEPOSIT, TransactionType::TRANSFER], true)) {+ $amount = bcadd($amount, bcmul($transaction->amount, '-1'));+ }++ return $amount;+ }+}\ No newline at end of filediff --git a/resources/lang/en_US/firefly.php b/resources/lang/en_US/firefly.phpindex c305df31b8..c3c5f46972 100644--- a/resources/lang/en_US/firefly.php+++ b/resources/lang/en_US/firefly.php@@ -1322,6 +1322,8 @@ return ['account_type_Credit card' => 'Credit card','liability_direction_credit' => 'I am owed this debt','liability_direction_debit' => 'I owe this debt to somebody else',+ 'liability_direction_credit_short' => 'Owed this debt',+ 'liability_direction_debit_short' => 'Owe this debt','Liability credit' => 'Liability credit','budgets' => 'Budgets','tags' => 'Tags',@@ -1393,6 +1395,7 @@ return ['splitByAccount' => 'Split by account','coveredWithTags' => 'Covered with tags','leftInBudget' => 'Left in budget',+ 'left_in_debt' => 'Left','sumOfSums' => 'Sum of sums','noCategory' => '(no category)','notCharged' => 'Not charged (yet)',diff --git a/resources/views/v1/list/accounts.twig b/resources/views/v1/list/accounts.twigindex 8c487ff83d..03c2694001 100644--- a/resources/views/v1/list/accounts.twig+++ b/resources/views/v1/list/accounts.twig@@ -11,12 +11,15 @@{% endif %}{% if objectType == 'liabilities' %}<th>{{ trans('list.liability_type') }}</th>+ <th>{{ trans('form.liability_direction') }}</th><th>{{ trans('list.interest') }} ({{ trans('list.interest_period') }})</th>{% endif %}<th class="hidden-sm hidden-xs">{{ trans('form.account_number') }}</th><th style="text-align: right;">{{ trans('list.currentBalance') }}</th>{% if objectType == 'liabilities' %}- <th>Left to pay off</th>+ <th style="text-align: right;">+ {{ trans('firefly.left_in_debt') }}+ </th>{% endif %}<th class="hidden-sm hidden-xs">{{ trans('list.active') }}</th>{# hide last activity to make room for other stuff #}@@ -54,6 +57,7 @@{% endif %}{% if objectType == 'liabilities' %}<td>{{ account.accountTypeString }}</td>+ <td>{{ trans('firefly.liability_direction_'~account.liability_direction~'_short') }}</td><td>{{ account.interest }}% ({{ account.interestPeriod|lower }})</td>{% endif %}<td class="hidden-sm hidden-xs">{{ account.iban }}{% if account.iban == '' %}{{ accountGetMetaField(account, 'account_number') }}{% endif %}</td>@@ -63,8 +67,8 @@</span></td>{% if objectType == 'liabilities' %}- <td>- Test+ <td style="text-align: right;">+ <span class="text-info">{{ formatAmountByAccount(account, account.current_debt, false) }}</span></td>{% endif %}<td class="hidden-sm hidden-xs">