Tickets: booked work has an end - the Schedule window has How long from 15 minutes to a day and an Agent picker that gives the ticket to someone else and takes it off the old agent's calendar; New Ticket's Schedule and a recurring ticket's Book the work for take a length; the calendar draws each booking at its length and dragging its bottom edge changes it after asking; the booking email, calendar file, ticket and guest page show the end; the double-booking warning lists the agent's tickets and timed events that overlap the booking instead of anything within two hours; database 3.8.2 adds tickets.ticket_schedule_end and recurring_tickets.recurring_ticket_schedule_minutes; 26.11.9 changelog entries

This commit is contained in:
johnnyq
2026-11-17 20:50:59 -05:00
parent 1c4c8be8de
commit 512ac75c73
18 changed files with 350 additions and 76 deletions

View File

@@ -2618,8 +2618,13 @@ if (isset($_POST['calendar_move'])) {
if (!empty($_POST['all_day'])) {
$start = substr($start, 0, 10) . ' ' . ($row['ticket_schedule'] ? date('H:i:s', strtotime($row['ticket_schedule'])) : '09:00:00');
}
// Its end dragged - or moved as it is, keeping its length (the usual length for one not booked yet)
$end = !empty($_POST['all_day']) ? '' : ticketScheduleValue($_POST['end'] ?? '');
if ($end === '' || $end <= $start || strtotime($end) - strtotime($start) > 86400) {
$end = date('Y-m-d H:i:s', strtotime($start) + ticketScheduleMinutes($row['ticket_schedule'], $row['ticket_schedule_end'] ?? null) * 60);
}
$onsite = isset($_POST['onsite']) ? intval($_POST['onsite']) : intval($row['ticket_onsite']);
$result = ticketSetSchedule($row, $start, $onsite);
$result = ticketSetSchedule($row, $start, $onsite, $end);
echo json_encode(['ok' => true, 'message' => ticketReference($row) . ' scheduled for ' . $result['when_text'], 'conflicts' => $result['conflicts']]);
exit;

View File

@@ -2,8 +2,8 @@
/*
* The Schedule tab's booking and making ahead, in New and Edit Recurring
* Ticket (agent/modals/recurring_ticket/) - the time and visit each ticket is
* booked for, and how many days ahead it is made (functions/ticket.php). Set
* Ticket (agent/modals/recurring_ticket/) - the time, length and visit each
* ticket is booked for, and how many days ahead it is made (functions/ticket.php). Set
* $ahead_row to the recurring ticket when editing, null for a new one. Only
* after the 3.7.7 update. Saved by recurringTicketFromPost()
* (agent/post/recurring_ticket.php).
@@ -14,6 +14,7 @@ isset($mysqli) || die("Direct file access is not allowed");
if (recurringAheadReady()) {
$ahead_time = substr((string) ($ahead_row['recurring_ticket_schedule_time'] ?? ''), 0, 5);
$ahead_onsite = intval($ahead_row['recurring_ticket_schedule_onsite'] ?? 0);
$ahead_minutes = intval($ahead_row['recurring_ticket_schedule_minutes'] ?? CALENDAR_TICKET_MINUTES) ?: CALENDAR_TICKET_MINUTES;
$ahead_days = intval($ahead_row['recurring_ticket_lead_days'] ?? 0);
$ahead_mode = ($ahead_row['recurring_ticket_lead_mode'] ?? '') === 'month' ? 'month' : 'days';
$ahead_next = $ahead_row ? substr((string) $ahead_row['recurring_ticket_next_run'], 0, 10) : '';
@@ -25,12 +26,19 @@ if (recurringAheadReady()) {
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-clock"></i></span>
<input type="time" class="form-control" name="schedule_time" step="900" value="<?= escapeHtml($ahead_time) ?>">
<select class="form-select select2" name="schedule_onsite">
<?php if (ticketScheduleEndReady()) { ?>
<select class="form-select select2" name="schedule_minutes" aria-label="How long">
<?php foreach (ticketScheduleLengths($ahead_minutes) as $minutes => $label) { ?>
<option value="<?= intval($minutes) ?>" <?= intval($minutes) === $ahead_minutes ? 'selected' : '' ?>><?= escapeHtml($label) ?></option>
<?php } ?>
</select>
<?php } ?>
<select class="form-select select2" name="schedule_onsite" aria-label="Visit">
<option value="0" <?= $ahead_onsite ? '' : 'selected' ?>>Remote</option>
<option value="1" <?= $ahead_onsite ? 'selected' : '' ?>>Onsite</option>
</select>
</div>
<div class="form-text">Each ticket is booked for its run day at this time, with the emails and calendar invite booking it on the ticket sends. Leave it empty to book nothing.</div>
<div class="form-text">Each ticket is booked for its run day at this time, for this long, with the emails and calendar invite booking it on the ticket sends. Leave the time empty to book nothing.</div>
</div>
</div>
<div class="col-md-6">

View File

@@ -164,7 +164,7 @@
function saved(json) {
itflowToast(json.message, 'success');
if (json.conflicts && json.conflicts.length) {
itflowToast('Same agent, within two hours: ' + json.conflicts.join('; '), 'warning');
itflowToast('The same agent already has work then: ' + json.conflicts.join('; '), 'warning');
}
}
@@ -288,7 +288,7 @@
moved(info);
},
eventResize: function (info) {
moved(info);
moved(info, true);
},
// A ticket from To schedule
@@ -301,23 +301,26 @@
// ---------- moving things ----------
function moved(info) {
function moved(info, resized) {
const event = info.event;
const props = event.extendedProps || {};
const start = event.start;
const end = event.end;
if (props.kind === 'ticket') {
// Its end dragged (resized), or the whole booking moved
confirmDialog({
title: 'Move ' + event.title.split(' ')[0] + ' to ' + words(start, false) + '?',
title: resized && end
? 'Book ' + event.title.split(' ')[0] + ' until ' + end.toLocaleTimeString([], {hour: 'numeric', minute: '2-digit'}) + '?'
: 'Move ' + event.title.split(' ')[0] + ' to ' + words(start, false) + '?',
text: 'The agent and the contact are emailed the new time, as when it is rescheduled on the ticket.',
confirmButtonText: 'Move it'
confirmButtonText: resized ? 'Change it' : 'Move it'
}).then(function (result) {
if (!result.isConfirmed) {
info.revert();
return;
}
post({kind: 'ticket', id: props.ticket_id, start: ymdhm(start), all_day: event.allDay ? 1 : 0}, function (json) {
post({kind: 'ticket', id: props.ticket_id, start: ymdhm(start), end: end && !event.allDay ? ymdhm(end) : '', all_day: event.allDay ? 1 : 0}, function (json) {
saved(json);
calendar.refetchEvents();
}, function (error) {

View File

@@ -1,12 +1,13 @@
// The ticket's Schedule dialog (agent/modals/ticket/ticket_edit_schedule.php):
// as a day is picked, what the assigned agent already has on it - their other
// scheduled tickets and the events they are on - so a visit is not booked on
// top of another. Wrapped in an IIFE because the modal can open more than once.
// as a day and an agent are picked, what that agent already has on it - their
// other scheduled tickets and the events they are on - so a visit is not booked
// on top of another. Wrapped in an IIFE because the modal can open more than once.
(function () {
const panel = document.getElementById('scheduleAgentDay');
const field = document.getElementById('scheduleDateTime');
const tech = document.getElementById('scheduleTech');
if (!panel || !field) {
return;
}
@@ -17,14 +18,21 @@
function load() {
const date = (field.value || '').slice(0, 10);
if (!/^\d{4}-\d{2}-\d{2}$/.test(date)) {
// The agent picked in the dialog - nobody, nothing to show
if (tech) {
const option = tech.options[tech.selectedIndex];
panel.dataset.user = tech.value;
panel.dataset.name = option ? (option.dataset.name || option.textContent.trim()) : '';
}
if (!/^\d{4}-\d{2}-\d{2}$/.test(date) || !parseInt(panel.dataset.user, 10)) {
panel.hidden = true;
shown = '';
return;
}
if (date === shown) {
if (date + '/' + panel.dataset.user === shown) {
return;
}
shown = date;
shown = date + '/' + panel.dataset.user;
const day = new Date(date + 'T12:00:00');
title.textContent = panel.dataset.name + "'s day - " + day.toLocaleDateString(undefined, {weekday: 'short', month: 'short', day: 'numeric'});
open.href = 'calendar.php?date=' + date;
@@ -62,6 +70,9 @@
field.addEventListener('change', load);
field.addEventListener('input', load);
if (tech) {
tech.addEventListener('change', load);
}
load();
})();

View File

@@ -177,7 +177,7 @@ ob_start();
<?php if (!empty($ticket['ticket_schedule'])) { ?>
<dt>Scheduled</dt>
<dd><i class="fas fa-<?= intval($ticket['ticket_onsite']) ? 'truck' : 'calendar-check' ?> text-body-secondary me-1"></i><?= escapeHtml(date('D M j, g:i A', strtotime($ticket['ticket_schedule']))) ?><?= intval($ticket['ticket_onsite']) ? ' <span class="text-body-secondary">on site</span>' : '' ?></dd>
<dd><i class="fas fa-<?= intval($ticket['ticket_onsite']) ? 'truck' : 'calendar-check' ?> text-body-secondary me-1"></i><?= escapeHtml(ticketScheduleShortText($ticket['ticket_schedule'], $ticket['ticket_schedule_end'] ?? null)) ?><?= intval($ticket['ticket_onsite']) ? ' <span class="text-body-secondary">on site</span>' : '' ?></dd>
<?php } ?>
<?php if (intval($ticket['ticket_project_id']) && $ticket['project_name'] !== null) { ?>

View File

@@ -250,12 +250,17 @@ ob_start();
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-calendar-day"></i></span>
<input type="datetime-local" class="form-control" name="schedule" min="<?= date('Y-m-d\TH:i') ?>" aria-label="Date and time of the work">
<select class="form-select flex-grow-0 w-auto" name="schedule_minutes" aria-label="How long">
<?php foreach (ticketScheduleLengths() as $minutes => $label) { ?>
<option value="<?= intval($minutes) ?>" <?= intval($minutes) === CALENDAR_TICKET_MINUTES ? 'selected' : '' ?>><?= escapeHtml($label) ?></option>
<?php } ?>
</select>
<select class="form-select flex-grow-0 w-auto" name="onsite" aria-label="Visit">
<option value="0">Remote</option>
<option value="1">Onsite</option>
</select>
</div>
<div class="form-text">Leave it empty to book the work later.</div>
<div class="form-text">When, how long and where. Leave it empty to book the work later.</div>
</div>
</div>
</div>

View File

@@ -15,6 +15,11 @@ $ticket_onsite = intval($row['ticket_onsite']);
$client_name = escapeHtml($row['client_name']);
$client_id = intval($row['ticket_client_id']);
// Who does the work - the agents who can open this client's tickets, and whoever has it now - and for how long
$schedule_tech = intval($row['ticket_assigned_to']);
$schedule_agents = ticketMentionAgents($client_id);
$schedule_minutes = ticketScheduleMinutes($row['ticket_schedule'], $row['ticket_schedule_end'] ?? null);
ob_start();
?>
@@ -38,6 +43,34 @@ ob_start();
</div>
</div>
<div class="row g-2 mb-3">
<div class="col-sm-7">
<label>Agent</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-user-check"></i></span>
<select class="form-select select2" name="schedule_tech" id="scheduleTech">
<?php if (!$schedule_tech || !isset($schedule_agents[$schedule_tech])) { ?>
<option value="<?= $schedule_tech ?>"><?= $schedule_tech ? escapeHtml($row['user_name']) : '- Unassigned -' ?></option>
<?php } ?>
<?php foreach ($schedule_agents as $agent) { ?>
<option value="<?= intval($agent['id']) ?>" data-name="<?= escapeHtml($agent['name']) ?>" <?= intval($agent['id']) === $schedule_tech ? 'selected' : '' ?><?= selectOptionData($agent['avatar'] !== '' ? ['image' => $agent['avatar']] : ['initials' => $agent['initials'], 'shape' => 'circle', 'tone' => 'secondary']) ?>><?= escapeHtml($agent['name']) ?></option>
<?php } ?>
</select>
</div>
</div>
<div class="col-sm-5">
<label>How long</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-hourglass-half"></i></span>
<select class="form-select select2" name="schedule_minutes" id="scheduleMinutes">
<?php foreach (ticketScheduleLengths($schedule_minutes) as $minutes => $label) { ?>
<option value="<?= intval($minutes) ?>" <?= intval($minutes) === $schedule_minutes ? 'selected' : '' ?>><?= escapeHtml($label) ?></option>
<?php } ?>
</select>
</div>
</div>
</div>
<div class="mb-3">
<label>Visit</label>
<div class="input-group">
@@ -49,9 +82,9 @@ ob_start();
</div>
</div>
<?php if (intval($row['ticket_assigned_to'])) { ?>
<!-- What else the agent has that day, so it is not booked on top of something (agent/js/ticket_schedule_modal.js) -->
<div class="border rounded p-2 small" id="scheduleAgentDay" data-user="<?= intval($row['ticket_assigned_to']) ?>" data-ticket="<?= $ticket_id ?>" data-name="<?= escapeHtml($row['user_name']) ?>" hidden>
<?php if ($schedule_agents) { ?>
<!-- What else the chosen agent has that day, so it is not booked on top of something (agent/js/ticket_schedule_modal.js) -->
<div class="border rounded p-2 small" id="scheduleAgentDay" data-user="<?= $schedule_tech ?>" data-ticket="<?= $ticket_id ?>" data-name="<?= escapeHtml((string) $row['user_name']) ?>" hidden>
<div class="d-flex align-items-center mb-1">
<span class="fw-semibold"><i class="far fa-calendar-alt fa-fw text-secondary me-1"></i><span class="js-day-title"></span></span>
<a class="ms-auto js-day-open" href="calendar.php">Calendar</a>

View File

@@ -59,6 +59,7 @@ function recurringTicketFromPost($client_id, $current = null) {
$mode = ($_POST['lead_mode'] ?? '') === 'month' && recurringTicketMonthBased($frequency) ? 'month' : 'days';
$ahead = ", recurring_ticket_schedule_time = " . (preg_match('/^([01]\d|2[0-3]):[0-5]\d$/', $time) ? "'$time:00'" : 'NULL')
. ", recurring_ticket_schedule_onsite = " . (intval($_POST['schedule_onsite'] ?? 0) ? 1 : 0)
. (ticketScheduleEndReady() && isset($_POST['schedule_minutes']) ? ", recurring_ticket_schedule_minutes = " . ticketScheduleMinutesValue($_POST['schedule_minutes']) : '')
. ", recurring_ticket_lead_days = " . recurringTicketLeadDays($_POST['lead_days'], $frequency, $mode)
. ", recurring_ticket_lead_mode = '$mode'";
}

View File

@@ -233,10 +233,11 @@ if (isset($_POST['add_ticket'])) {
// The work booked - the same emails, note and history as the ticket's Schedule window
$created_alert = "Ticket <strong>" . escapeHtml($config_ticket_prefix . $ticket_number) . "</strong> created";
if ($schedule !== '') {
$booked = ticketSetSchedule(ticketRow($ticket_id), $schedule, intval($_POST['onsite'] ?? 0) ? 1 : 0);
$booked = ticketSetSchedule(ticketRow($ticket_id), $schedule, intval($_POST['onsite'] ?? 0) ? 1 : 0,
date('Y-m-d H:i:s', strtotime($schedule) + ticketScheduleMinutesValue($_POST['schedule_minutes'] ?? 0) * 60));
$created_alert .= " and scheduled for " . escapeHtml($booked['when_text']);
if ($booked['conflicts']) {
$created_alert .= ".<br>The same agent has other work within two hours of it: <br>" . implode(", <br>", array_map('escapeHtml', $booked['conflicts']));
$created_alert .= ".<br>The same agent already has work at that time: <br>" . implode(", <br>", array_map('escapeHtml', $booked['conflicts']));
}
}
@@ -2000,11 +2001,31 @@ if (isset($_POST['edit_ticket_schedule'])) {
redirect();
}
$result = ticketSetSchedule($row, $schedule, intval($_POST['onsite'] ?? 0) ? 1 : 0);
// Who does it - given to them first when it's someone new, one who can open the client's tickets - and for how long
$schedule_tech = intval($_POST['schedule_tech'] ?? $row['ticket_assigned_to']);
if ($schedule_tech && $schedule_tech !== intval($row['ticket_assigned_to'])) {
if (!isset(ticketMentionAgents($row['ticket_client_id'])[$schedule_tech])) {
flashAlert('That agent can\'t open this client\'s tickets.', 'error');
redirect();
}
[$assigned_ok, $assigned_message] = ticketChangeAssignee($row['ticket_id'], $schedule_tech);
if (!$assigned_ok) {
flashAlert($assigned_message, 'error');
redirect();
}
// The agent who had the booking has it taken off their calendar
ticketMailScheduleAgentCancelled($row);
$row = ticketForRequest($row['ticket_id'], 2);
}
$schedule_end = date('Y-m-d H:i:s', strtotime($schedule) + ticketScheduleMinutesValue($_POST['schedule_minutes'] ?? 0) * 60);
flashAlert("Ticket scheduled for " . escapeHtml($result['when_text']));
$result = ticketSetSchedule($row, $schedule, intval($_POST['onsite'] ?? 0) ? 1 : 0, $schedule_end);
$scheduled = "Ticket scheduled for " . escapeHtml($result['when_text']) . (!empty($row['user_name']) ? " with <strong>" . escapeHtml($row['user_name']) . "</strong>" : '');
if ($result['conflicts']) {
flashAlert("The same agent has other work within two hours of it: <br>" . implode(", <br>", array_map('escapeHtml', $result['conflicts'])), 'warning');
flashAlert("$scheduled.<br>The same agent already has work at that time: <br>" . implode(", <br>", array_map('escapeHtml', $result['conflicts'])), 'warning');
} else {
flashAlert($scheduled);
}
redirect();

View File

@@ -73,7 +73,8 @@ if (isset($_GET['ticket_id'])) {
$ticket_scheduled_for = escapeHtml($ticket['ticket_schedule']);
$ticket_onsite = intval($ticket['ticket_onsite']);
if ($ticket_scheduled_for) {
$ticket_scheduled_wording = date('M d, Y • g:i A', strtotime($ticket_scheduled_for));
// From when to when (functions/ticket.php)
$ticket_scheduled_wording = escapeHtml(ticketScheduleShortText($ticket['ticket_schedule'], $ticket['ticket_schedule_end'] ?? null));
} else {
$ticket_scheduled_wording = "Not scheduled";
}