mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-05 12:12:18 +00:00
Fix #2331
This commit is contained in:
@@ -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 = [
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
||||
|
@@ -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).
|
||||
*
|
||||
|
@@ -22,6 +22,14 @@
|
||||
<th class="hide-create_date">{{ trans('list.create_date') }}</th>
|
||||
<th class="hide-update_date">{{ trans('list.update_date') }}</th>
|
||||
|
||||
{# even more optional fields #}
|
||||
<th class="hide-interest_date">{{ trans('list.interest_date') }}</th>
|
||||
<th class="hide-book_date">{{ trans('list.book_date') }}</th>
|
||||
<th class="hide-process_date">{{ trans('list.process_date') }}</th>
|
||||
<th class="hide-due_date">{{ trans('list.due_date') }}</th>
|
||||
<th class="hide-payment_date">{{ trans('list.payment_date') }}</th>
|
||||
<th class="hide-invoice_date">{{ trans('list.invoice_date') }}</th>
|
||||
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@@ -106,6 +114,38 @@
|
||||
<td class="hide-update_date">
|
||||
{{ journal.updated_at.formatLocalized(dateTimeFormat) }}
|
||||
</td>
|
||||
|
||||
<!-- more new dates -->
|
||||
<td class="hide-interest_date">
|
||||
{% if null != journal.interest_date %}
|
||||
{{ journal.interest_date.formatLocalized(monthAndDayFormat) }}
|
||||
{% endif %}
|
||||
</td>
|
||||
<td class="hide-book_date">
|
||||
{% if null != journal.book_date %}
|
||||
{{ journal.book_date.formatLocalized(monthAndDayFormat) }}
|
||||
{% endif %}
|
||||
</td>
|
||||
<td class="hide-process_date">
|
||||
{% if null != journal.process_date %}
|
||||
{{ journal.process_date.formatLocalized(monthAndDayFormat) }}
|
||||
{% endif %}
|
||||
</td>
|
||||
<td class="hide-due_date">
|
||||
{% if null != journal.due_date %}
|
||||
{{ journal.due_date.formatLocalized(monthAndDayFormat) }}
|
||||
{% endif %}
|
||||
</td>
|
||||
<td class="hide-payment_date">
|
||||
{% if null != journal.payment_date %}
|
||||
{{ journal.payment_date.formatLocalized(monthAndDayFormat) }}
|
||||
{% endif %}
|
||||
</td>
|
||||
<td class="hide-invoice_date">
|
||||
{% if null != journal.invoice_date %}
|
||||
{{ journal.invoice_date.formatLocalized(monthAndDayFormat) }}
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
{% endfor %}
|
||||
|
Reference in New Issue
Block a user