From 512ac75c7342a1bb4399c9524e9f2cdfd2ca6bbb Mon Sep 17 00:00:00 2001 From: johnnyq Date: Tue, 17 Nov 2026 20:50:59 -0500 Subject: [PATCH] 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 --- CHANGELOG.md | 5 +- admin/database_updates/3.8.2.php | 30 +++ agent/ajax.php | 7 +- agent/includes/inc_recurring_ticket_ahead.php | 16 +- agent/js/calendar.js | 15 +- agent/js/ticket_schedule_modal.js | 23 +- agent/modals/ticket/ticket.php | 2 +- agent/modals/ticket/ticket_add.php | 7 +- agent/modals/ticket/ticket_edit_schedule.php | 39 +++- agent/post/recurring_ticket.php | 1 + agent/post/ticket.php | 31 ++- agent/ticket.php | 3 +- db.sql | 2 + functions/app.php | 9 +- functions/calendar.php | 16 +- functions/ticket.php | 214 +++++++++++++++--- guest/guest_post.php | 2 +- guest/guest_view_ticket.php | 4 +- 18 files changed, 350 insertions(+), 76 deletions(-) create mode 100644 admin/database_updates/3.8.2.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 26f2bd4f5..0b8928e93 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ This file documents all notable changes made to ITFlow. ### Upgrading -Update from Maintenance > Update — Queue Update hands the job to cron, which updates the files and applies this release's fifteen database changes (3.6.6 to 3.8.1) in the same pass. They add four tables for RMM providers and their alerts, a setting for device actions and one for API keys in the address, a column marking the emails the mail queue clears once sent, a column and a table for agent banners, two columns for ticket statuses with a setting for the "ticket assigned" message, a column on tickets with a setting for the "no response" message, a table for who a ticket's email replies go to, the settings for Quick tickets, columns on recurring tickets and recurring invoices for booking and making them ahead, two columns on ticket replies for when their time was worked, the settings for cron alerts, a table and a setting for labor costs, and a column on users for API / service accounts, and change nothing that is there. Nothing else is required. This release has eleven security fixes - see Security. On Apache, ITFlow's own .htaccess now sends security headers: if you show ITFlow inside a frame on another website, it will now refuse to load there. On nginx, add the same headers to your server block if you want them - see Developer Updates. +Update from Maintenance > Update — Queue Update hands the job to cron, which updates the files and applies this release's sixteen database changes (3.6.6 to 3.8.2) in the same pass. They add four tables for RMM providers and their alerts, a setting for device actions and one for API keys in the address, a column marking the emails the mail queue clears once sent, a column and a table for agent banners, two columns for ticket statuses with a setting for the "ticket assigned" message, a column on tickets with a setting for the "no response" message, a table for who a ticket's email replies go to, the settings for Quick tickets, columns on recurring tickets and recurring invoices for booking and making them ahead, two columns on ticket replies for when their time was worked, the settings for cron alerts, a table and a setting for labor costs, a column on users for API / service accounts, and columns on tickets and recurring tickets for how long booked work takes, and change nothing that is there. Nothing else is required. This release has eleven security fixes - see Security. On Apache, ITFlow's own .htaccess now sends security headers: if you show ITFlow inside a frame on another website, it will now refuse to load there. On nginx, add the same headers to your server block if you want them - see Developer Updates. ### Security @@ -96,6 +96,8 @@ Update from Maintenance > Update — Queue Update hands the job to cron, which u - Admin > Labor Costs, under Lists: what an hour of each agent costs your company - wage, payroll taxes and benefits - with the date each rate counts from, so a raise doesn't change what last year cost, and a company default for agents with none. Only admins see it, and the audit log never records the amounts. From Mountaineer IT's build of ITFlow. - Reports: Client Profitability, with labor costs set, shows each client's labor cost (their hours at the cost of the agent who worked them), parts cost (the products on their invoices, at cost), profit and margin, and for flat monthly fees the hours a month their fee pays for against the hours they take, marked Over when they take more. The totals along the top add labor, parts, profit, and how many clients lose money or go over. Paid and Invoiced switch income between money received, as before, and sales before tax on invoices dated in the period. Hours by agents with no cost and no default are flagged. From Mountaineer IT's build of ITFlow. - Users: an API / service account is a login that API keys act as - for your RMM or a sync. Turn on API / service account on a user's Sign in tab (a new one needs Set a password now, as it isn't invited). It keeps its role, so its keys work as before, but it's left out of the calendar, the assign pickers, the reports and the other agent lists, gets no notifications or admin alerts, and can't sign in to ITFlow - a session it has is ended. Admin > Users lists them under API accounts, with an API badge, and leaves them out of the other tabs but Archived. It still takes a seat where there's a limit on agents. From Mountaineer IT's build of ITFlow. +- Tickets: booked work has an end. The Schedule window has How long - 15 minutes to a day, an hour unless picked - and an Agent picker, so booking someone else's ticket gives it to them 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 too. The calendar draws each booking at its length, and dragging its bottom edge changes how long it takes, after asking. The booking email, the calendar file, the ticket and the guest page say when it ends. From Mountaineer IT's build of ITFlow. +- Tickets: the warning when an agent is booked twice now means it - it lists their tickets and timed events that overlap the booking, at their lengths, instead of anything within two hours. From Mountaineer IT's build of ITFlow. ### Bug Fixes @@ -218,6 +220,7 @@ Update from Maintenance > Update — Queue Update hands the job to cron, which u - Restoring from Maintenance > Backup (`functions/backup_restore.php`): `restore_backup` (`admin/post/backup.php`) checks the password and RESTORE, then `backupRestoreQueue()` checks the archive with `backupRestoreCheck()` (`backupInspectArchive()`, refused when its database version is newer) and the disk (three times its size), writes `restore_queued.json` beside the backups - another install's key sealed with this one's (`backupRestoreSealKey()`, AES-256-GCM) - and `restore_status.json`, and sets the Backup job's `cron_job_run_now`. `cron/backup.php` calls `backupRestoreRunQueued()` after the queued backups: it deletes the request first, refuses one older than `BACKUP_RESTORE_WAIT_MINUTES`, makes a Full Backup with source `Before restore`, runs `backupRestoreArchive()`, puts that row and the restored one back in the restored `backups` (others found again by retention), marks `Running` and `Pending` rows `Failed`, runs `scripts/update_cli.php --update_db`, records the outcome and sets `$cron_dispatch_stop_cycle`. `cron/cron.php` exits before its heartbeat while `backupRestoreInProgress()`. `cancel_restore` removes a request. Uploads: `backup_upload` in one request, or `backup_upload_start`, `backup_upload_chunk` and `backup_upload_finish` from `js/backup_restore.js` (JSON, the upload in the session, pieces of `backupRestoreChunkBytes()` appended to `upload_.part`, retried smaller when a proxy refuses), then `backupRestoreAdopt()` lists it with source `Uploaded`. The Restore window is `admin/modals/backup/backup_restore.php`, opened from a row's menu or by `?restore=`; `backupMadeBy()` words a row's source. All locked in the demo. From Mountaineer IT's build of ITFlow. - Database 3.8.0: `user_cost_rates` (`user_cost_rate_user_id`, `_from`, `_hourly`, `_created_by`, `_created_at`, one a day per agent) and `config_labor_cost_default` (NULL leaves time uncosted) - `laborCostReady()`. `functions/labor_cost.php`: `laborCostRates()`, `laborCostRateOn()` (the newest rate on or before the day, the first also before it, else the default), `laborCostRateSave()`, `laborCostRateDelete()`, `laborCostParse()`. `admin/labor_costs.php`, `admin/modals/labor_cost/labor_cost_rates.php` and `labor_cost_default.php`, handlers `add_labor_cost_rate`, `delete_labor_cost_rate` and `edit_labor_cost_default` (`admin/post/labor_cost.php`). `agent/reports/client_profitability.php` calls `laborProfitAdd()` before net - `?basis=invoiced` replaces income with `item_subtotal` less `invoice_discount_amount` on Sent, Viewed, Partial and Paid invoices by `invoice_date`, plus revenue; labor by `ticket_reply_by` and day; parts as `product_cost * item_quantity` - and `laborProfitFinish()` after it for profit, margin, `hours_month` and `break_even`; the columns, totals, basis switch (`laborProfitBasis()`, paid by default) and second stats row are there only with 3.8.0. From Mountaineer IT's build of ITFlow. - Database 3.8.1: `users.user_service_account` - `serviceAccountsReady()`, `serviceAccountIs()`, `serviceAccountSave()` (`functions/service_account.php`). `serviceAccountsOutSql($column)` adds ` AND user_service_account = 0` to the agent lists and pickers (tickets, recurring tickets, projects, contracts, calendar and events, ticket templates, bulk assign, exports, reports, client onboarding, Quick ticket, mentions, trips, expenses, labor costs, Getting Started's team, user archive's hand-over, incident response) and to `appNotify()`, `signInAdmins()`, `cronHealthRecipients()` and the last-admin checks (`userActiveAdminCount()` in `functions/user.php`, `roles.php`). Not to `apiKeyAgents()`, the API's own checks (`api/v1/enforce_api_rbac.php`) or `getActiveAgentUserCount()`. `login.php` matches agents with `user_service_account = 0`, and `includes/load_user_session.php` ends a service account's session. The switch is `service_account` with `service_account_present` on `admin/modals/user/user_form.php`'s Sign in tab, saved by `add_user` (an invite with it is refused) and `edit_user`. `admin/users.php` adds the `service` view and excludes them from the others but `archived`. From Mountaineer IT's build of ITFlow. +- Database 3.8.2: `tickets.ticket_schedule_end` (NULL is `CALENDAR_TICKET_MINUTES` after the start) and `recurring_tickets.recurring_ticket_schedule_minutes` (default 60) - `ticketScheduleEndReady()`. `ticketSetSchedule($row, $schedule, $onsite, $end = null)` keeps the end (cancelling clears it) and `ticketScheduleIcs()` and `createiCalStr(..., $uid, $end)` write it as DTEND. `ticketScheduleEnd()`, `ticketScheduleMinutes()`, `ticketScheduleMinutesValue()` (15 to 1440), `ticketScheduleLengths()`, `ticketScheduleLengthText()`, `ticketScheduleWhenText()` and `ticketScheduleShortText()` word it; `ticketScheduleOverlapSql($from, $to)` finds bookings running into a range, used by the calendar's tickets source, the agent feed and `ticketScheduleConflicts()` (overlapping tickets and timed calendar events of the agent). `edit_ticket_schedule` takes `schedule_tech` (one of `ticketMentionAgents()`, given the ticket with `ticketChangeAssignee()`, the old agent sent `ticketMailScheduleAgentCancelled()`) and `schedule_minutes`; `add_ticket` and the recurring ticket handlers take `schedule_minutes`, and `recurringTicketBook()` books that long. `calendar_move` (`agent/ajax.php`) takes an `end` from a resize, or keeps the length on a move; ticket items are `durationEditable`. From Mountaineer IT's build of ITFlow. ## [26.11.8] diff --git a/admin/database_updates/3.8.2.php b/admin/database_updates/3.8.2.php new file mode 100644 index 000000000..14ca4ed1a --- /dev/null +++ b/admin/database_updates/3.8.2.php @@ -0,0 +1,30 @@ + 0; + }; + + if (!$itflow_column('tickets', 'ticket_schedule_end')) { + mysqli_query($mysqli, "ALTER TABLE `tickets` ADD `ticket_schedule_end` datetime DEFAULT NULL AFTER `ticket_schedule`"); + } + + if (!$itflow_column('recurring_tickets', 'recurring_ticket_schedule_minutes')) { + mysqli_query($mysqli, "ALTER TABLE `recurring_tickets` ADD `recurring_ticket_schedule_minutes` int(11) NOT NULL DEFAULT 60 AFTER `recurring_ticket_schedule_onsite`"); + } diff --git a/agent/ajax.php b/agent/ajax.php index 109be67c3..318c722ba 100644 --- a/agent/ajax.php +++ b/agent/ajax.php @@ -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; diff --git a/agent/includes/inc_recurring_ticket_ahead.php b/agent/includes/inc_recurring_ticket_ahead.php index e29415f83..95d8a8e21 100644 --- a/agent/includes/inc_recurring_ticket_ahead.php +++ b/agent/includes/inc_recurring_ticket_ahead.php @@ -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()) {
- + $label) { ?> + + + + +
-
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.
+
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.
diff --git a/agent/js/calendar.js b/agent/js/calendar.js index 9eceefd6d..3b3208a7e 100644 --- a/agent/js/calendar.js +++ b/agent/js/calendar.js @@ -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) { diff --git a/agent/js/ticket_schedule_modal.js b/agent/js/ticket_schedule_modal.js index 8c1d49c7a..d41dd4e63 100644 --- a/agent/js/ticket_schedule_modal.js +++ b/agent/js/ticket_schedule_modal.js @@ -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(); })(); diff --git a/agent/modals/ticket/ticket.php b/agent/modals/ticket/ticket.php index 8e88f3295..b440a82d9 100644 --- a/agent/modals/ticket/ticket.php +++ b/agent/modals/ticket/ticket.php @@ -177,7 +177,7 @@ ob_start();
Scheduled
-
on site' : '' ?>
+
on site' : '' ?>
diff --git a/agent/modals/ticket/ticket_add.php b/agent/modals/ticket/ticket_add.php index af263831e..35a4707a1 100644 --- a/agent/modals/ticket/ticket_add.php +++ b/agent/modals/ticket/ticket_add.php @@ -250,12 +250,17 @@ ob_start();
+
-
Leave it empty to book the work later.
+
When, how long and where. Leave it empty to book the work later.
diff --git a/agent/modals/ticket/ticket_edit_schedule.php b/agent/modals/ticket/ticket_edit_schedule.php index ab26147a9..75f717308 100644 --- a/agent/modals/ticket/ticket_edit_schedule.php +++ b/agent/modals/ticket/ticket_edit_schedule.php @@ -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(); +
+
+ +
+ + +
+
+
+ +
+ + +
+
+
+
@@ -49,9 +82,9 @@ ob_start();
- - -