From ecc37b2ed314d50ab836327d888577fb1dd43678 Mon Sep 17 00:00:00 2001 From: James Cole Date: Wed, 21 Aug 2019 04:59:35 +0200 Subject: [PATCH] Some undocumented changes for #2445 and #2447 --- app/Repositories/Bill/BillRepository.php | 8 +++---- app/Transformers/BillTransformer.php | 29 +++++++++++++----------- resources/views/v1/list/bills.twig | 8 +++---- 3 files changed, 24 insertions(+), 21 deletions(-) diff --git a/app/Repositories/Bill/BillRepository.php b/app/Repositories/Bill/BillRepository.php index b089ceca6d..17bafb5796 100644 --- a/app/Repositories/Bill/BillRepository.php +++ b/app/Repositories/Bill/BillRepository.php @@ -413,13 +413,13 @@ class BillRepository implements BillRepositoryInterface */ 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.transaction_group_id', ] - )->pluck('date', 'id'); - - return $dates; + ); } /** diff --git a/app/Transformers/BillTransformer.php b/app/Transformers/BillTransformer.php index 6f469b8824..c551d10fa0 100644 --- a/app/Transformers/BillTransformer.php +++ b/app/Transformers/BillTransformer.php @@ -25,6 +25,7 @@ namespace FireflyIII\Transformers; use Carbon\Carbon; use FireflyIII\Models\Bill; +use FireflyIII\Models\TransactionJournal; use FireflyIII\Repositories\Bill\BillRepositoryInterface; use Illuminate\Support\Collection; use Log; @@ -109,11 +110,11 @@ class BillTransformer extends AbstractTransformer if (0 === $dates->count()) { return $default; // @codeCoverageIgnore } - $latest = $dates->first(); - /** @var Carbon $date */ - foreach ($dates as $date) { - if ($date->gte($latest)) { - $latest = $date; + $latest = $dates->first()->date; + /** @var TransactionJournal $date */ + foreach ($dates as $journal) { + if ($journal->date->gte($latest)) { + $latest = $journal->date; } } @@ -160,11 +161,6 @@ class BillTransformer extends AbstractTransformer $set = $this->repository->getPaidDatesInRange($bill, $this->parameters->get('start'), $this->parameters->get('end')); 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: $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); } $end = app('navigation')->addPeriod($nextMatch, $bill->repeat_freq, $bill->skip); - $journalCount = $this->repository->getPaidDatesInRange($bill, $nextMatch, $end)->count(); - if ($journalCount > 0) { + if ($set->count() > 0) { $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 [ - 'paid_dates' => $simple->toArray(), + 'paid_dates' => $result, 'next_expected_match' => $nextMatch->format('Y-m-d'), ]; } diff --git a/resources/views/v1/list/bills.twig b/resources/views/v1/list/bills.twig index 8937b937fa..2fb46b2748 100644 --- a/resources/views/v1/list/bills.twig +++ b/resources/views/v1/list/bills.twig @@ -96,10 +96,10 @@ Don't care about pay_dates. #} {% if entry.paid_dates|length > 0 and entry.active %} - - {% for transaction_id, date in entry.paid_dates %} - - {{ formatDate(date, monthAndDayFormat) }} + + {% for currentPaid in entry.paid_dates %} + + {{ formatDate(currentPaid.date, monthAndDayFormat) }}
{% endfor %}