diff --git a/app/Generator/Report/Audit/MonthReportGenerator.php b/app/Generator/Report/Audit/MonthReportGenerator.php index a54ec88e0d..53b9b13670 100644 --- a/app/Generator/Report/Audit/MonthReportGenerator.php +++ b/app/Generator/Report/Audit/MonthReportGenerator.php @@ -31,7 +31,7 @@ use FireflyIII\Generator\Report\ReportGeneratorInterface; use FireflyIII\Helpers\Collector\GroupCollectorInterface; use FireflyIII\Models\Account; use FireflyIII\Repositories\Account\AccountRepositoryInterface; -use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface; +use FireflyIII\Repositories\Journal\JournalRepositoryInterface; use Illuminate\Support\Collection; use Log; use Throwable; @@ -76,6 +76,10 @@ class MonthReportGenerator implements ReportGeneratorInterface // more new optional fields 'create_date', 'update_date', + + // date fields. + 'interest_date', 'book_date', 'process_date', + 'due_date', 'payment_date', 'invoice_date', ]; try { $result = view('reports.audit.report', compact('reportType', 'accountIds', 'auditData', 'hideable', 'defaultShow')) @@ -200,13 +204,14 @@ class MonthReportGenerator implements ReportGeneratorInterface */ public function getAuditReport(Account $account, Carbon $date): array { - /** @var CurrencyRepositoryInterface $currencyRepos */ - $currencyRepos = app(CurrencyRepositoryInterface::class); - /** @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) @@ -214,7 +219,7 @@ class MonthReportGenerator implements ReportGeneratorInterface $journals = $collector->getExtractedJournals(); $dayBeforeBalance = app('steam')->balance($account, $date); $startBalance = $dayBeforeBalance; - $currency = $currencyRepos->findNull((int)$accountRepository->getMetaValue($account, 'currency_id')); + $currency = $accountRepository->getAccountCurrency($account); if (null === $currency) { throw new FireflyException('Unexpected NULL value in account currency preference.'); // @codeCoverageIgnore @@ -232,6 +237,14 @@ class MonthReportGenerator implements ReportGeneratorInterface $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 = [ diff --git a/app/Repositories/Journal/JournalRepository.php b/app/Repositories/Journal/JournalRepository.php index dd1752dc9b..df607ffa80 100644 --- a/app/Repositories/Journal/JournalRepository.php +++ b/app/Repositories/Journal/JournalRepository.php @@ -867,4 +867,33 @@ class JournalRepository implements JournalRepositoryInterface ->with(['user', 'transactionType', 'transactionCurrency', 'transactions', 'transactions.account']) ->get(['transaction_journals.*']); } + + /** + * Return Carbon value of a meta field (or NULL). + * + * @param int $journalId + * @param string $field + * + * @return null|Carbon + */ + public function getMetaDateById(int $journalId, string $field): ?Carbon + { + $cache = new CacheProperties; + $cache->addProperty('journal-meta-updated'); + $cache->addProperty($journalId); + $cache->addProperty($field); + + if ($cache->has()) { + return new Carbon($cache->get()); // @codeCoverageIgnore + } + $entry = TransactionJournalMeta::where('transaction_journal_id', $journalId) + ->where('name', $field)->first(); + if (null === $entry) { + return null; + } + $value = new Carbon($entry->data); + $cache->store($entry->data); + + return $value; + } } diff --git a/app/Repositories/Journal/JournalRepositoryInterface.php b/app/Repositories/Journal/JournalRepositoryInterface.php index 0fe12b0ce1..8586eec220 100644 --- a/app/Repositories/Journal/JournalRepositoryInterface.php +++ b/app/Repositories/Journal/JournalRepositoryInterface.php @@ -238,6 +238,16 @@ interface JournalRepositoryInterface */ public function getMetaDate(TransactionJournal $journal, string $field): ?Carbon; + /** + * Return Carbon value of a meta field (or NULL). + * + * @param int $journalId + * @param string $field + * + * @return null|Carbon + */ + public function getMetaDateById(int $journalId, string $field): ?Carbon; + /** * Return string value of a meta date (or NULL). * diff --git a/resources/views/v1/reports/partials/journals-audit.twig b/resources/views/v1/reports/partials/journals-audit.twig index 1eb246fcd8..fda96e3377 100644 --- a/resources/views/v1/reports/partials/journals-audit.twig +++ b/resources/views/v1/reports/partials/journals-audit.twig @@ -22,6 +22,14 @@ {{ trans('list.create_date') }} {{ trans('list.update_date') }} + {# even more optional fields #} + {{ trans('list.interest_date') }} + {{ trans('list.book_date') }} + {{ trans('list.process_date') }} + {{ trans('list.due_date') }} + {{ trans('list.payment_date') }} + {{ trans('list.invoice_date') }} + @@ -106,6 +114,38 @@ {{ journal.updated_at.formatLocalized(dateTimeFormat) }} + + + + {% if null != journal.interest_date %} + {{ journal.interest_date.formatLocalized(monthAndDayFormat) }} + {% endif %} + + + {% if null != journal.book_date %} + {{ journal.book_date.formatLocalized(monthAndDayFormat) }} + {% endif %} + + + {% if null != journal.process_date %} + {{ journal.process_date.formatLocalized(monthAndDayFormat) }} + {% endif %} + + + {% if null != journal.due_date %} + {{ journal.due_date.formatLocalized(monthAndDayFormat) }} + {% endif %} + + + {% if null != journal.payment_date %} + {{ journal.payment_date.formatLocalized(monthAndDayFormat) }} + {% endif %} + + + {% if null != journal.invoice_date %} + {{ journal.invoice_date.formatLocalized(monthAndDayFormat) }} + {% endif %} + {% endfor %}