Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Fix some things in recurring transactions.
James Colebe8286b15c04
diff --git a/app/Http/Controllers/Recurring/IndexController.php b/app/Http/Controllers/Recurring/IndexController.phpindex ea84c7044e..bcb6123a43 100644--- a/app/Http/Controllers/Recurring/IndexController.php+++ b/app/Http/Controllers/Recurring/IndexController.php@@ -111,12 +111,18 @@ class IndexController extends Controller$array['first_date'] = new Carbon($array['first_date']);$array['repeat_until'] = null === $array['repeat_until'] ? null : new Carbon($array['repeat_until']);$array['latest_date'] = null === $array['latest_date'] ? null : new Carbon($array['latest_date']);- $array['occurrences'] = [];- if (0 !== $recurrence->recurrenceRepetitions->count()) {- $array['ocurrences'] = array_slice($this->recurring->getOccurrencesInRange($recurrence->recurrenceRepetitions->first(), $today, $year), 0, 1);+ // make carbon objects out of occurrences+ foreach ($array['repetitions'] as $repIndex => $repetition) {+ foreach ($repetition['occurrences'] as $occIndex => $occurrence) {+ $array['repetitions'][$repIndex]['occurrences'][$occIndex] = new Carbon($occurrence);+ }}+ //if (0 !== $recurrence->recurrenceRepetitions->count()) {+ //$array['ocurrences'] = array_slice($this->recurring->getOccurrencesInRange($recurrence->recurrenceRepetitions->first(), $today, $year), 0, 1);+ //}+$recurring[] = $array;}$paginator = new LengthAwarePaginator($recurring, $total, $pageSize, $page);diff --git a/app/Http/Controllers/Recurring/ShowController.php b/app/Http/Controllers/Recurring/ShowController.phpindex 23ddd02444..4833c983b1 100644--- a/app/Http/Controllers/Recurring/ShowController.php+++ b/app/Http/Controllers/Recurring/ShowController.php@@ -82,8 +82,10 @@ class ShowController extends Controller$transformer = app(RecurrenceTransformer::class);$transformer->setParameters(new ParameterBag);- $array = $transformer->transform($recurrence);- $groups = $this->recurring->getTransactions($recurrence);+ $array = $transformer->transform($recurrence);+ $groups = $this->recurring->getTransactions($recurrence);+ $today = new Carbon;+ $array['repeat_until'] = null !== $array['repeat_until'] ? new Carbon($array['repeat_until']) : null;// transform dates back to Carbon objects:foreach ($array['repetitions'] as $index => $repetition) {@@ -94,6 +96,6 @@ class ShowController extends Controller$subTitle = (string) trans('firefly.overview_for_recurrence', ['title' => $recurrence->title]);- return view('recurring.show', compact('recurrence', 'subTitle', 'array', 'groups'));+ return view('recurring.show', compact('recurrence', 'subTitle', 'array', 'groups','today'));}}diff --git a/app/Repositories/Recurring/RecurringRepository.php b/app/Repositories/Recurring/RecurringRepository.phpindex b91d6efdab..363c4be13c 100644--- a/app/Repositories/Recurring/RecurringRepository.php+++ b/app/Repositories/Recurring/RecurringRepository.php@@ -535,6 +535,31 @@ class RecurringRepository implements RecurringRepositoryInterface// filter out all the weekend days:$occurrences = $this->filterWeekends($repetition, $occurrences);+ // filter out everything if "repeat_until" is set.+ $repeatUntil = $repetition->recurrence->repeat_until;+ $occurrences = $this->filterMaxDate($repeatUntil, $occurrences);+return $occurrences;}++ /**+ * @param Carbon|null $max+ * @param array $occurrences+ *+ * @return array+ */+ private function filterMaxDate(?Carbon $max, array $occurrences): array+ {+ if (null === $max) {+ return $occurrences;+ }+ $filtered = [];+ foreach ($occurrences as $date) {+ if ($date->lte($max)) {+ $filtered[] = $date;+ }+ }++ return $filtered;+ }}diff --git a/resources/views/v1/recurring/index.twig b/resources/views/v1/recurring/index.twigindex dd6bd8386a..9220451138 100644--- a/resources/views/v1/recurring/index.twig+++ b/resources/views/v1/recurring/index.twig@@ -100,13 +100,13 @@({{ trans('firefly.recurring_skips_more', {count: rep.repetition_skip})|lower }}).{% endif %}{% if rep.weekend == 3 %}- {{ 'will_jump_friday'|_ }}+ <br>{{ 'will_jump_friday'|_ }}{% endif %}{% if rep.weekend == 4 %}- {{ 'will_jump_monday'|_ }}+ <br>{{ 'will_jump_monday'|_ }}{% endif %}{% if rep.weekend == 2 %}- {{ 'except_weekends'|_ }}+ <br>{{ 'except_weekends'|_ }}{% endif %}</li>{% endfor %}@@ -123,11 +123,15 @@{% endif %}</p></td>- {% if rt.occurrences|length == 0 %}- <td> </td>- {% else %}- <td>{{ rt.occurrences[0].formatLocalized(monthAndDayFormat) }}</td>- {% endif %}+ <td>+ <ul>+ {% for rep in rt.repetitions %}+ {% for occ in rep.occurrences %}+ <li>{{ occ.formatLocalized(monthAndDayFormat) }}</li>+ {% endfor %}+ {% endfor %}+ </ul>+ </td></tr>{% endfor %}</tbody>diff --git a/resources/views/v1/recurring/show.twig b/resources/views/v1/recurring/show.twigindex f0c97dd750..1669c522aa 100644--- a/resources/views/v1/recurring/show.twig+++ b/resources/views/v1/recurring/show.twig@@ -52,7 +52,11 @@</h3></div><div class="box-body">-+ {% if null != array.repeat_until and today > array.repeat_until %}+ <span class="text-danger">+ {{ trans('firefly.repeat_until_in_past', {date: array.repeat_until.formatLocalized(monthAndDayFormat) }) }}+ </span>+ {% endif %}<ul>{% for rep in array.repetitions %}<li>