Update some things for recurring transactions.

This commit is contained in:
James Cole
2018-06-28 06:31:31 +02:00
parent d378e7e897
commit 57cf7f6f0d
5 changed files with 36 additions and 13 deletions

View File

@@ -547,6 +547,8 @@ class RecurringRepository implements RecurringRepositoryInterface
protected function filterWeekends(RecurrenceRepetition $repetition, array $dates): array
{
if ($repetition->weekend === RecurrenceRepetition::WEEKEND_DO_NOTHING) {
Log::debug('Repetition will not be filtered on weekend days.');
return $dates;
}
$return = [];
@@ -555,29 +557,42 @@ class RecurringRepository implements RecurringRepositoryInterface
$isWeekend = $date->isWeekend();
if (!$isWeekend) {
$return[] = clone $date;
Log::debug(sprintf('Date is %s, not a weekend date.', $date->format('D d M Y')));
continue;
}
// is weekend and must set back to Friday?
if ($isWeekend && $repetition->weekend === RecurrenceRepetition::WEEKEND_TO_FRIDAY) {
if ($repetition->weekend === RecurrenceRepetition::WEEKEND_TO_FRIDAY) {
$clone = clone $date;
$clone->addDays(5 - $date->dayOfWeekIso);
Log::debug(
sprintf('Date is %s, and this is in the weekend, so corrected to %s (Friday).', $date->format('D d M Y'), $clone->format('D d M Y'))
);
$return[] = clone $clone;
continue;
}
// postpone to Monday?
if ($isWeekend && $repetition->weekend === RecurrenceRepetition::WEEKEND_TO_MONDAY) {
if ($repetition->weekend === RecurrenceRepetition::WEEKEND_TO_MONDAY) {
$clone = clone $date;
$clone->addDays(8 - $date->dayOfWeekIso);
Log::debug(
sprintf('Date is %s, and this is in the weekend, so corrected to %s (Monday).', $date->format('D d M Y'), $clone->format('D d M Y'))
);
$return[] = $clone;
continue;
}
Log::debug(sprintf('Date is %s, removed from final result', $date->format('D d M Y')));
}
// filter unique dates
Log::debug(sprintf('Count before filtering: %d', \count($dates)));
$collection = new Collection($return);
$filtered = $collection->unique();
$return = $filtered->toArray();
Log::debug(sprintf('Count after filtering: %d', \count($return)));
return $return;
}
}