mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-19 10:53:31 +00:00
Update some things for recurring transactions.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user