Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Fix #2513
James Cole8246d901e778
diff --git a/app/Generator/Report/Audit/MonthReportGenerator.php b/app/Generator/Report/Audit/MonthReportGenerator.phpindex 53b9b13670..23abef23a3 100644--- a/app/Generator/Report/Audit/MonthReportGenerator.php+++ b/app/Generator/Report/Audit/MonthReportGenerator.php@@ -94,6 +94,79 @@ class MonthReportGenerator implements ReportGeneratorInterfacereturn $result;}+ /**+ * Get the audit report.+ *+ * @param Account $account+ * @param Carbon $date+ *+ * @return array+ *+ * @throws FireflyException+ */+ public function getAuditReport(Account $account, Carbon $date): array+ {+ /** @var AccountRepositoryInterface $accountRepository */+ $accountRepository = app(AccountRepositoryInterface::class);+ $accountRepository->setUser($account->user);++ /** @var JournalRepositoryInterface $journalRepository */+ $journalRepository = app(JournalRepositoryInterface::class);+ $journalRepository->setUser($account->user);++ /** @var GroupCollectorInterface $collector */+ $collector = app(GroupCollectorInterface::class);+ $collector->setAccounts(new Collection([$account]))->setRange($this->start, $this->end)->withAccountInformation();+ $journals = $collector->getExtractedJournals();+ $journals = array_reverse($journals, true);++ $dayBeforeBalance = app('steam')->balance($account, $date);+ $startBalance = $dayBeforeBalance;+ $currency = $accountRepository->getAccountCurrency($account);++ if (null === $currency) {+ throw new FireflyException('Unexpected NULL value in account currency preference.'); // @codeCoverageIgnore+ }++ foreach ($journals as $index => $journal) {+ $journals[$index]['balance_before'] = $startBalance;+ $transactionAmount = $journal['amount'];++ // make sure amount is in the right "direction".+ if ($account->id === $journal['destination_account_id']) {+ $transactionAmount = app('steam')->positive($journal['amount']);+ }++ if ($currency->id === $journal['foreign_currency_id']) {+ $transactionAmount = $journal['foreign_amount'];+ }++ $newBalance = bcadd($startBalance, $transactionAmount);+ $journals[$index]['balance_after'] = $newBalance;+ $startBalance = $newBalance;++ // add meta dates for each journal.+ $journals[$index]['interest_date'] = $journalRepository->getMetaDateById($journal['transaction_journal_id'], 'interest_date');+ $journals[$index]['book_date'] = $journalRepository->getMetaDateById($journal['transaction_journal_id'], 'book_date');+ $journals[$index]['process_date'] = $journalRepository->getMetaDateById($journal['transaction_journal_id'], 'process_date');+ $journals[$index]['due_date'] = $journalRepository->getMetaDateById($journal['transaction_journal_id'], 'due_date');+ $journals[$index]['payment_date'] = $journalRepository->getMetaDateById($journal['transaction_journal_id'], 'payment_date');+ $journals[$index]['invoice_date'] = $journalRepository->getMetaDateById($journal['transaction_journal_id'], 'invoice_date');++ }++ $return = [+ 'journals' => $journals,+ 'exists' => count($journals) > 0,+ 'end' => $this->end->formatLocalized((string)trans('config.month_and_day')),+ 'endBalance' => app('steam')->balance($account, $this->end),+ 'dayBefore' => $date->formatLocalized((string)trans('config.month_and_day')),+ 'dayBeforeBalance' => $dayBeforeBalance,+ ];++ return $return;+ }+/*** Account collection setter.*@@ -191,71 +264,4 @@ class MonthReportGenerator implements ReportGeneratorInterface{return $this;}-- /**- * Get the audit report.- *- * @param Account $account- * @param Carbon $date- *- * @return array- *- * @throws FireflyException- */- public function getAuditReport(Account $account, Carbon $date): array- {- /** @var AccountRepositoryInterface $accountRepository */- $accountRepository = app(AccountRepositoryInterface::class);- $accountRepository->setUser($account->user);-- /** @var JournalRepositoryInterface $journalRepository */- $journalRepository = app(JournalRepositoryInterface::class);- $journalRepository->setUser($account->user);-- /** @var GroupCollectorInterface $collector */- $collector = app(GroupCollectorInterface::class);- $collector->setAccounts(new Collection([$account]))->setRange($this->start, $this->end)- ->withAccountInformation();- $journals = $collector->getExtractedJournals();- $dayBeforeBalance = app('steam')->balance($account, $date);- $startBalance = $dayBeforeBalance;- $currency = $accountRepository->getAccountCurrency($account);-- if (null === $currency) {- throw new FireflyException('Unexpected NULL value in account currency preference.'); // @codeCoverageIgnore- }-- foreach ($journals as $index => $journal) {- $journals[$index]['balance_before'] = $startBalance;- $transactionAmount = $journal['amount'];-- if ($currency->id === $journal['foreign_currency_id']) {- $transactionAmount = $journal['foreign_amount'];- }-- $newBalance = bcadd($startBalance, $transactionAmount);- $journals[$index]['balance_after'] = $newBalance;- $startBalance = $newBalance;-- // add meta dates for each journal.- $journals[$index]['interest_date'] = $journalRepository->getMetaDateById($journal['transaction_journal_id'], 'interest_date');- $journals[$index]['book_date'] = $journalRepository->getMetaDateById($journal['transaction_journal_id'], 'book_date');- $journals[$index]['process_date'] = $journalRepository->getMetaDateById($journal['transaction_journal_id'], 'process_date');- $journals[$index]['due_date'] = $journalRepository->getMetaDateById($journal['transaction_journal_id'], 'due_date');- $journals[$index]['payment_date'] = $journalRepository->getMetaDateById($journal['transaction_journal_id'], 'payment_date');- $journals[$index]['invoice_date'] = $journalRepository->getMetaDateById($journal['transaction_journal_id'], 'invoice_date');-- }-- $return = [- 'journals' => $journals,- 'exists' => count($journals) > 0,- 'end' => $this->end->formatLocalized((string)trans('config.month_and_day')),- 'endBalance' => app('steam')->balance($account, $this->end),- 'dayBefore' => $date->formatLocalized((string)trans('config.month_and_day')),- 'dayBeforeBalance' => $dayBeforeBalance,- ];-- return $return;- }}diff --git a/resources/views/v1/reports/audit/report.twig b/resources/views/v1/reports/audit/report.twigindex 6dd1bcbfbc..bbd5a372c2 100644--- a/resources/views/v1/reports/audit/report.twig+++ b/resources/views/v1/reports/audit/report.twig@@ -53,24 +53,24 @@{% else %}<div class="box-body table-responsive no-padding"><p style="padding:10px;">-{{ trans('firefly.audit_end_balance',{account_name: account.name|escape,url: url,- end: auditData[account.id].end,- balance: formatAmountByAccount(account,auditData[account.id].endBalance)+ end: auditData[account.id].dayBefore,+ balance: formatAmountByAccount(account, auditData[account.id].dayBeforeBalance)})|raw }}- <!-- TODO VERIFY THAT STEAM BALANCE ACTUALLY WORKS --></p>{% include 'reports.partials.journals-audit' with {'journals': auditData[account.id].journals,'account':account} %}+<p style="padding:10px;">+{{ trans('firefly.audit_end_balance',{account_name: account.name|escape,url: url,- end: auditData[account.id].dayBefore,- balance: formatAmountByAccount(account, auditData[account.id].dayBeforeBalance)+ end: auditData[account.id].end,+ balance: formatAmountByAccount(account,auditData[account.id].endBalance)})|raw }}</p></div>diff --git a/resources/views/v1/reports/partials/journals-audit.twig b/resources/views/v1/reports/partials/journals-audit.twigindex 0310f3ca64..b864699fe5 100644--- a/resources/views/v1/reports/partials/journals-audit.twig+++ b/resources/views/v1/reports/partials/journals-audit.twig@@ -57,11 +57,11 @@{% endif %}{% if journal.transaction_type_type == 'Reconciliation' %}- XX+ <i class="fa-fw fa fa-calculator" title="{{ trans('firefly.reconciliation_transaction') }}"></i>{% endif %}{% if journal.transaction_type_type == 'Opening balance' %}- XX+ <i class="fa-fw fa fa-star-o" title="{{ trans('firefly.Opening balance') }}"></i>{% endif %}</td>@@ -80,7 +80,12 @@{{ formatAmountBySymbol(journal.balance_before, journal.currency_symbol, journal.currency_decimal_places) }}</td><td class="hide-amount" style="text-align: right;">- {{ formatAmountBySymbol(journal.amount, journal.currency_symbol, journal.currency_decimal_places) }}+ {% if account.id == journal.destination_account_id and journal.transaction_type_type == 'Opening balance' %}+ {{ formatAmountBySymbol(journal.amount*-1, journal.currency_symbol, journal.currency_decimal_places) }}+ {% else %}+ {{ formatAmountBySymbol(journal.amount, journal.currency_symbol, journal.currency_decimal_places) }}+ {% endif %}+</td><td class="hide-balance_after" style="text-align: right;">