Fix some things in recurring transactions.

This commit is contained in:
James Cole 2020-05-04 10:26:01 +02:00
parent 6f6087995d
commit be8286b15c
5 changed files with 56 additions and 15 deletions

View File

@ -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);

View File

@ -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'));
}
}

View File

@ -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;
}
}

View File

@ -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>&nbsp;</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>

View File

@ -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>