Some undocumented changes for #2445 and #2447

This commit is contained in:
James Cole
2019-08-21 04:59:35 +02:00
parent c0935e192d
commit ecc37b2ed3
3 changed files with 24 additions and 21 deletions

View File

@@ -413,13 +413,13 @@ class BillRepository implements BillRepositoryInterface
*/ */
public function getPaidDatesInRange(Bill $bill, Carbon $start, Carbon $end): Collection public function getPaidDatesInRange(Bill $bill, Carbon $start, Carbon $end): Collection
{ {
$dates = $bill->transactionJournals()->before($end)->after($start)->get( return $bill->transactionJournals()
->before($end)->after($start)->get(
[ [
'transaction_journals.id', 'transaction_journals.date', 'transaction_journals.id', 'transaction_journals.date',
'transaction_journals.transaction_group_id',
] ]
)->pluck('date', 'id'); );
return $dates;
} }
/** /**

View File

@@ -25,6 +25,7 @@ namespace FireflyIII\Transformers;
use Carbon\Carbon; use Carbon\Carbon;
use FireflyIII\Models\Bill; use FireflyIII\Models\Bill;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Bill\BillRepositoryInterface; use FireflyIII\Repositories\Bill\BillRepositoryInterface;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Log; use Log;
@@ -109,11 +110,11 @@ class BillTransformer extends AbstractTransformer
if (0 === $dates->count()) { if (0 === $dates->count()) {
return $default; // @codeCoverageIgnore return $default; // @codeCoverageIgnore
} }
$latest = $dates->first(); $latest = $dates->first()->date;
/** @var Carbon $date */ /** @var TransactionJournal $date */
foreach ($dates as $date) { foreach ($dates as $journal) {
if ($date->gte($latest)) { if ($journal->date->gte($latest)) {
$latest = $date; $latest = $journal->date;
} }
} }
@@ -160,11 +161,6 @@ class BillTransformer extends AbstractTransformer
$set = $this->repository->getPaidDatesInRange($bill, $this->parameters->get('start'), $this->parameters->get('end')); $set = $this->repository->getPaidDatesInRange($bill, $this->parameters->get('start'), $this->parameters->get('end'));
Log::debug(sprintf('Count %d entries in getPaidDatesInRange()', $set->count())); Log::debug(sprintf('Count %d entries in getPaidDatesInRange()', $set->count()));
$simple = $set->map(
function (Carbon $date) {
return $date->format('Y-m-d');
}
);
// calculate next expected match: // calculate next expected match:
$lastPaidDate = $this->lastPaidDate($set, $this->parameters->get('start')); $lastPaidDate = $this->lastPaidDate($set, $this->parameters->get('start'));
@@ -173,13 +169,20 @@ class BillTransformer extends AbstractTransformer
$nextMatch = app('navigation')->addPeriod($nextMatch, $bill->repeat_freq, $bill->skip); $nextMatch = app('navigation')->addPeriod($nextMatch, $bill->repeat_freq, $bill->skip);
} }
$end = app('navigation')->addPeriod($nextMatch, $bill->repeat_freq, $bill->skip); $end = app('navigation')->addPeriod($nextMatch, $bill->repeat_freq, $bill->skip);
$journalCount = $this->repository->getPaidDatesInRange($bill, $nextMatch, $end)->count(); if ($set->count() > 0) {
if ($journalCount > 0) {
$nextMatch = clone $end; $nextMatch = clone $end;
} }
$result = [];
foreach ($set as $entry) {
$result[] = [
'transaction_group_id' => (int)$entry->transaction_group_id,
'transaction_journal_id' => (int)$entry->id,
'date' => $entry->date->format('Y-m-d'),
];
}
return [ return [
'paid_dates' => $simple->toArray(), 'paid_dates' => $result,
'next_expected_match' => $nextMatch->format('Y-m-d'), 'next_expected_match' => $nextMatch->format('Y-m-d'),
]; ];
} }

View File

@@ -96,10 +96,10 @@
Don't care about pay_dates. Don't care about pay_dates.
#} #}
{% if entry.paid_dates|length > 0 and entry.active %} {% if entry.paid_dates|length > 0 and entry.active %}
<td class="paid_in_period text-success" data-value="{{ entry.paid_dates[0] }}"> <td class="paid_in_period text-success" data-value="{{ entry.paid_dates[0].date }}">
{% for transaction_id, date in entry.paid_dates %} {% for currentPaid in entry.paid_dates %}
<a href="{{ route('transactions.show',transaction_id) }}"> <a href="{{ route('transactions.show',currentPaid.transaction_group_id) }}">
{{ formatDate(date, monthAndDayFormat) }} {{ formatDate(currentPaid.date, monthAndDayFormat) }}
</a> </a>
<br/> <br/>
{% endfor %} {% endfor %}