mirror of
https://github.com/itflow-org/itflow
synced 2026-11-21 03:47:25 +00:00
Recurring tickets and events can repeat on a weekday, such as the third Wednesday or the last Friday, instead of the same date: monthly, quarterly, twice-yearly and yearly recurring tickets and monthly and yearly events get Repeats on once a date is picked, moving the next run or an event's start keeps the same kind of weekday, the recurring tickets list, events and invitations say which, and subscribed calendars get it as an RRULE BYDAY; the API takes repeat_on and event_repeat_by_day; database 3.8.3 adds recurring_tickets.recurring_ticket_by_day and calendar_events.event_repeat_by_day; 26.11.9 changelog entries
This commit is contained in:
@@ -1806,13 +1806,15 @@ function recurringTicketFrequency($frequency) {
|
||||
* was due fell on - except when that was a shorter month's last day standing
|
||||
* in for a later one: one that started ($anchor) on the 31st runs on the last
|
||||
* day of shorter months and back on the 31st after, rather than drifting.
|
||||
* Missed runs are stepped over, not raised one by one.
|
||||
* Missed runs are stepped over, not raised one by one. With a weekday rule
|
||||
* ($by_day, "3WE") month-based ones land on that weekday of the month instead.
|
||||
*/
|
||||
function recurringTicketNextRun($due, $frequency, $anchor = '', $after = '') {
|
||||
function recurringTicketNextRun($due, $frequency, $anchor = '', $after = '', $by_day = '') {
|
||||
$frequency = recurringTicketFrequency($frequency) ?: 'Monthly';
|
||||
$step = RECURRING_TICKET_FREQUENCIES[$frequency];
|
||||
$after = $after !== '' ? $after : date('Y-m-d');
|
||||
$date = DateTime::createFromFormat('!Y-m-d', substr((string) $due, 0, 10)) ?: new DateTime('today');
|
||||
$by_day = isset($step['months']) ? byDayRule($by_day) : '';
|
||||
$anchor_date = DateTime::createFromFormat('!Y-m-d', substr((string) $anchor, 0, 10));
|
||||
$anchor_day = intval($date->format('j'));
|
||||
if ($anchor_date && intval($anchor_date->format('j')) > $anchor_day && $anchor_day === intval($date->format('t'))) {
|
||||
@@ -1827,6 +1829,10 @@ function recurringTicketNextRun($due, $frequency, $anchor = '', $after = '') {
|
||||
$month = intval($date->format('n')) + $step['months'];
|
||||
$year += intdiv($month - 1, 12);
|
||||
$month = ($month - 1) % 12 + 1;
|
||||
if ($by_day !== '') {
|
||||
$date = DateTime::createFromFormat('!Y-m-d', byDayDate($year, $month, $by_day));
|
||||
continue;
|
||||
}
|
||||
$days_in_month = intval(date('t', mktime(0, 0, 0, $month, 1, $year)));
|
||||
$date->setDate($year, $month, min($anchor_day, $days_in_month));
|
||||
}
|
||||
@@ -1845,6 +1851,10 @@ function recurringTicketCadenceText($row) {
|
||||
if (isset($step['days'])) {
|
||||
return $step['days'] === 7 ? 'on ' . $next->format('l') . 's' : ($step['days'] === 14 ? 'every other ' . $next->format('l') : 'every three days');
|
||||
}
|
||||
$by_day = byDayText($row['recurring_ticket_by_day'] ?? '');
|
||||
if ($by_day !== '') {
|
||||
return 'on ' . $by_day . ($frequency === 'Annually' ? ' of ' . $next->format('F') : '');
|
||||
}
|
||||
$day = intval($next->format('j'));
|
||||
$start = DateTime::createFromFormat('!Y-m-d', substr((string) ($row['recurring_ticket_start_date'] ?? ''), 0, 10));
|
||||
if ($start && intval($start->format('j')) > $day && $day === intval($next->format('t'))) {
|
||||
@@ -1997,7 +2007,7 @@ function recurringTicketRunNow($row, $by) {
|
||||
$due = (string) $row['recurring_ticket_next_run'];
|
||||
// Booked for the day of the run it is for, at its time - when it has one
|
||||
recurringTicketBook($ticket_id, $recurring_ticket_id, $due);
|
||||
$next_run = recurringTicketNextRun($due, $row['recurring_ticket_frequency'], $row['recurring_ticket_start_date'], max(date('Y-m-d'), substr($due, 0, 10)));
|
||||
$next_run = recurringTicketNextRun($due, $row['recurring_ticket_frequency'], $row['recurring_ticket_start_date'], max(date('Y-m-d'), substr($due, 0, 10)), $row['recurring_ticket_by_day'] ?? '');
|
||||
mysqli_query($mysqli, "UPDATE recurring_tickets SET recurring_ticket_next_run = '$next_run' WHERE recurring_ticket_id = $recurring_ticket_id");
|
||||
}
|
||||
return $ticket_id;
|
||||
@@ -2034,6 +2044,20 @@ function recurringTicketMonthBased($frequency) {
|
||||
return isset(RECURRING_TICKET_FREQUENCIES[recurringTicketFrequency($frequency)]['months']);
|
||||
}
|
||||
|
||||
/*
|
||||
* The weekday it repeats on (functions/by_day.php), as SQL for recurring_ticket_by_day - NULL is the
|
||||
* same date each time. $posted is the Repeats on choice when one was sent (null when not), kept only
|
||||
* when $date - the first or next run - falls on it; without one the rule it had ($current) follows the
|
||||
* run to $date. Only month-based repeats have one.
|
||||
*/
|
||||
function recurringTicketByDaySql($frequency, $date, $posted, $current = '') {
|
||||
if (!recurringTicketMonthBased($frequency)) {
|
||||
return 'NULL';
|
||||
}
|
||||
$rule = $posted !== null ? byDayForDate($posted, $date) : byDayFollow($current, $date);
|
||||
return $rule !== '' ? "'$rule'" : 'NULL';
|
||||
}
|
||||
|
||||
/*
|
||||
* Days ahead as kept: up to 90, and short of one step of the repeat (a month
|
||||
* counts as 28 days), so the next run is never due before this one is made -
|
||||
@@ -2159,7 +2183,7 @@ function recurringTicketUpcoming($row, $count = 3) {
|
||||
}
|
||||
$runs[] = $date;
|
||||
while (count($runs) < $count) {
|
||||
$date = recurringTicketNextRun($date, $row['recurring_ticket_frequency'], $row['recurring_ticket_start_date'], $date);
|
||||
$date = recurringTicketNextRun($date, $row['recurring_ticket_frequency'], $row['recurring_ticket_start_date'], $date, $row['recurring_ticket_by_day'] ?? '');
|
||||
$runs[] = $date;
|
||||
}
|
||||
return $runs;
|
||||
|
||||
Reference in New Issue
Block a user