From 55e7f6cc5d41c759868ff4c7e9e4eddbfe1f3377 Mon Sep 17 00:00:00 2001 From: johnnyq Date: Tue, 17 Nov 2026 21:26:50 -0500 Subject: [PATCH] Projects: Keep project tickets apart under Admin Settings Projects leaves a project's tickets off the tickets list's usual views with a Projects view of their own, out of the dashboard and menu counts and the Dispatch queue, with no SLA, while Mine, Workload and the calendar keep them in the project's color with the agent's color as a dot; a ticket taken out of its project, or every one when it is switched off, gets its SLA back counted from then; off by default; database 3.8.9 adds config_project_tickets_apart, config_project_ticket_color and tickets.ticket_sla_from; 26.11.9 changelog entries --- CHANGELOG.md | 4 +- admin/database_updates/3.8.9.php | 35 +++++ admin/post/settings_project.php | 22 ++- admin/settings_project.php | 15 +- agent/includes/get_side_nav_counts.php | 2 +- agent/js/calendar.js | 7 + agent/post/ticket.php | 5 + agent/tickets.php | 3 + api/v1/tickets/update.php | 2 + css/itflow_custom.css | 10 ++ db.sql | 3 + functions.php | 1 + functions/calendar.php | 2 + functions/dashboard.php | 4 +- functions/dispatch.php | 3 +- functions/project.php | 11 ++ functions/project_tickets.php | 190 +++++++++++++++++++++++++ functions/settings.php | 2 + functions/sla.php | 11 +- 19 files changed, 318 insertions(+), 14 deletions(-) create mode 100644 admin/database_updates/3.8.9.php create mode 100644 functions/project_tickets.php diff --git a/CHANGELOG.md b/CHANGELOG.md index aa2f3cc32..81efcf5da 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 twenty-two database changes (3.6.6 to 3.8.8) 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, columns on tickets and recurring tickets for how long booked work takes, a column each on recurring tickets and calendar events for repeating on a weekday, three columns on agents' settings for their calendar color, what their calendar shows and their own time zone, and a table for the agents helping on a ticket, three columns on quote lines with three settings for what a quote line costs and how it is priced, and a column each on quote lines and products with a setting for their pictures, 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 twenty-three database changes (3.6.6 to 3.8.9) 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, columns on tickets and recurring tickets for how long booked work takes, a column each on recurring tickets and calendar events for repeating on a weekday, three columns on agents' settings for their calendar color, what their calendar shows and their own time zone, and a table for the agents helping on a ticket, three columns on quote lines with three settings for what a quote line costs and how it is priced, a column each on quote lines and products with a setting for their pictures, and two settings and a column on tickets for keeping project tickets apart, 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 @@ -111,6 +111,7 @@ Update from Maintenance > Update — Queue Update hands the job to cron, which u - Dispatch: a new page under Support puts each agent's booked work beside the tickets still to give out. The queue on the left has three tabs - No agent, Not booked (with an agent, nothing booked) and Left behind - most urgent first, with a search, a client and a priority filter. Day shows a column for each agent through the day; Week a row for each agent with a column for each day. Drag a ticket from the queue onto an agent and a time, or drag a booking to another agent or time, and the Schedule window opens with the agent, the time, how long and onsite or remote filled in - Schedule it gives the ticket to that agent and books it, emailing them the calendar file, the agent who had it the cancellation, and the contact and watchers unless you switch that off. Drag a booking back onto the queue to take it off the schedule. One-off events move the same way, to another time or agent. Workload shows each agent's open tickets (leading and helping), SLAs breached or close to it, tickets past due, not booked or gone quiet, and the hours booked today and this week against the working hours in Admin > SLA - flagged Falling behind, Watch, Overloaded or Has room against the team. Click an agent for their tickets, or drop a ticket from the queue on one to give it to them. Under it, This week shows tickets in and closed each day, against last week and the last four, the week's SLA results and each agent's share. Which agents show, the view and weekends are kept to your account, and an agent on their own time zone sees it on their clock. Seeing Dispatch takes Support in your role; booking from it takes Support at Modify. From Mountaineer IT's build of ITFlow. - Quotes: a quote line can carry what it costs you, and its price can come from that cost. In a line's Edit window, Your cost has Cost each, Price by - Markup (a % added to the cost), Margin (a % of the price) or Set price - and the %, with buttons for the ones you use most: the Price is worked out as you type, and says what the line makes each. Typing the Price yourself makes it a set price. A line added from a product takes the product's cost and keeps its price. On the quote, while it can be changed, each line with a cost shows it under its name with its markup or margin, and the quote's Margin counts each line's own cost. Only agents see any of it - never the PDF, the guest link, the client portal or the invoice made from the quote. Admin > Settings > Quotes has what a line is priced by to start with, its % and the quick picks. From Mountaineer IT's build of ITFlow. - Quotes: a quote line can have a picture beside its name - on the quote, the guest link, the client portal and the PDF. In the line's Edit window, upload one or paste a link: a picture, or the product's web page, whose main picture is taken. A product keeps a picture too, in its Edit window, and a quote line added from it takes a copy; copying a quote copies them. ITFlow keeps its own copy of each, made smaller, and only fetches from public websites. Admin > Settings > Quotes can switch pictures off. From Mountaineer IT's build of ITFlow. +- Projects: a project's tickets can be kept apart from the service desk - switch on Keep project tickets apart under Admin > Settings > Projects. A ticket in a project is then left off the tickets list's Open, Unassigned, Needs reply and other views - it has a Projects view of its own - and out of the dashboard's unassigned count, the count beside Tickets in the menu and the Dispatch queue, and has no SLA: the project's dates are what count. It stays under Mine, Mentioned me, Closed and All, in Dispatch's Workload and on the calendar and Dispatch, drawn in the project's calendar color with the project named under it and, on the calendar, a dot in the agent's color. A ticket taken out of its project gets its SLA back counted from then, so it isn't overdue at once - and so do they all when the setting is switched off. Off to start with, so nothing changes until you switch it on. From Mountaineer IT's build of ITFlow. ### Bug Fixes @@ -242,6 +243,7 @@ Update from Maintenance > Update — Queue Update hands the job to cron, which u - Dispatch (`agent/dispatch.php`, `agent/js/dispatch.js`, `functions/dispatch.php`): `dispatchCan()` (Support at View), `dispatchCanEdit()` (`calendarCanScheduleTickets()`), `dispatchAgents()` (active agents who are admins or have Support at Modify, with `calendarAgentColor()`), `dispatchState()` / `dispatchStateSave()` (the `dispatch` key of `user_settings.user_config_calendar_state`, which `calendarUserStateSave()` now keeps: `view`, `hidden`, `weekends`), `dispatchBusinessHours()` and `dispatchWorkingDay()` from `getSlaSettings()`, `dispatchQueue($tab, $filters)` (`unassigned`, `unbooked`, `left_behind` via `calendarLeftBehindSql()`, with each tab's count), `dispatchItems($from, $to, $agent_ids)` (the tickets, helper bookings, events and holidays sources per agent, `extendedProps.agent` and `reference` added, only tickets and one-off events editable, through `timezoneItems()`), `dispatchBook()` (`ticketChangeAssignee()`, `ticketMailScheduleAgentCancelled()` for the agent who had it, then `ticketSetSchedule()`), `dispatchUnbook()` (`ticketCancelSchedule()`), `dispatchAssign()` (refused for a booked ticket), `dispatchEventMove()` (a one-off event in time and from one agent to another with `calendarEventSetAgents()`, `calendarSendInvites()` with `update` to those who have it), `dispatchWorkload()` with `dispatchWorkloadFlags()`, and `dispatchWeekStats()` (tickets given this week read from the `assigned the ticket to ` history lines). `agent/ajax.php`: GET `dispatch_queue`, `dispatch_items`, `dispatch_workload`, `dispatch_week`; POST (CSRF) `dispatch_state`, and with `dispatchCanEdit()`, after `timezoneMovePost()`, `dispatch_book`, `dispatch_unbook`, `dispatch_assign` and `dispatch_event_move` - JSON `{ok, message, conflicts}` or `{error}` with 400/403. `ticketSetSchedule()` and `ticketMailSchedule()` take `$tell_client` (default true) to leave the contact and watchers out. Day is a FullCalendar `timeGridDay` per agent in one scroller (`drop` for the queue's `FullCalendar.Interaction.Draggable`, `eventReceive` between columns, `eventDragStop` over the queue to unbook); Week and Workload use SortableJS. From Mountaineer IT's build of ITFlow. - Database 3.8.7: `quote_items.item_cost`, `item_price_method` (`markup`, `margin` or `price`) and `item_price_percent` - the names MountaineerIT's build uses - and `config_quote_price_method`, `config_quote_price_percent` and `config_quote_price_presets` - `quotePricingReady()`. `functions/quote_pricing.php`: `QUOTE_PRICE_METHODS`, `quotePricingSettings()` (read from `settings` directly, not `load_global_settings.php`), `quotePriceFromCost()`, `quotePricingFromInput()`, `quotePricingSetSql()` - `billingItemSave()` takes `pricing` with `cost`, `price_method` and `price_percent` on a quote, and gives a new line from a product its `product_cost` as a set price - `quotePricingCopySql()` (`add_quote_copy`, which now also keeps `item_product_id`, and `billingCopyLines()` to a quote), `quotePricingMethodNow()` (a markup or margin whose price was changed by hand reads as a set price), `quotePricingLineHtml()` (under the line in `includes/billing_paper.php` while `edit`) and `quotePricingFields()` with `itflowBillingPricingForm()` in `js/billing_items.js`. `billingItems()` returns the three columns for a quote; `billingMargin()` uses `item_cost` before the product's cost. The API's quote line read returns them as it returns every column. From Mountaineer IT's build of ITFlow. - Database 3.8.8: `quote_items.item_image`, `products.product_image` (paths under `uploads/`, the names MountaineerIT's build uses; their `uploads/mit_images/` files are taken as they are) and `config_quote_show_images` - `quoteImagesReady()`, `quoteImagesShown()`. `functions/quote_images.php`: `quoteImageStore()` redraws a JPG, PNG, GIF or WebP with GD at up to 800 pixels a side into `uploads/quote_images/<32 hex>.jpg|png`; `quoteImageFromUpload()`, `quoteImageFromUrl()` (the image, or a page's `og:image` / `twitter:image` / `image_src`) through `quoteImageFetch()` - http(s) on ports 80, 443, 8080 and 8443, every resolved address checked by `quoteImageIpIsPublic()` and pinned with `CURLOPT_RESOLVE`, no proxy, three redirects each checked, 8 MB and 25 seconds in all; `quoteImageSave($table, $id, $in, $files)` for `item_image` / `product_image` with `_url` and `_remove`, `quoteImageField()`, `quoteImageThumbHtml()`, `quoteImageFromProduct()` (a new quote line in `billingItemSave()`), `quoteImageCopySql()` (`add_quote_copy`, `billingCopyLines()` to a quote) and `quoteImagesDeleteFor()` (`billingItemDelete()`, `delete_quote`, deleting a client from the page or the API, the API's quote delete, demo data); `productDelete()` throws the product's away. `includes/billing_paper.php` and `billingPdfRender()` show it; the Edit Line and product windows post `multipart/form-data`, and `js/app.js` previews the file picked. From Mountaineer IT's build of ITFlow. +- Database 3.8.9: `config_project_tickets_apart` (default 0), `config_project_ticket_color` (NULL is `PROJECT_TICKET_COLOR`) and `tickets.ticket_sla_from` (when the SLA counts from; NULL is `ticket_created_at`) - `projectTicketsReady()`. `functions/project_tickets.php`: `projectTicketsSettings()`, `projectTicketsApart()`, `projectTicketsServiceSql()` (the side menu's count, the dashboard's two unassigned counts, `dispatchQueue()`), `projectTicketsShows()` (`agent/tickets.php`'s views; not with a Project filter), `projectTicketsSlaOff()` - `applyTicketSla()` reads `ticket_project_id`, `ticket_sla_id`, `ticket_closed_at` and `ticket_sla_from`, gives an open project ticket SLA 0, leaves a done one with none, and counts targets from `ticket_sla_from` - `projectTicketLeft()` / `projectTicketMoved()` (`edit_ticket`, `edit_ticket_project`, bulk project, `projectAddTicket()`, `projectRemoveTicket()`, `projectDelete()`, the API's ticket update), `projectTicketsSwitched()` (the settings save) and `projectTicketsCalendarItems()` (the tickets source: `color`, `extendedProps.agent_color`, `project`; `agent/js/calendar.js` draws the dot). No cron job: every way a ticket's project changes calls it. From Mountaineer IT's build of ITFlow. ## [26.11.8] diff --git a/admin/database_updates/3.8.9.php b/admin/database_updates/3.8.9.php new file mode 100644 index 000000000..c00917771 --- /dev/null +++ b/admin/database_updates/3.8.9.php @@ -0,0 +1,35 @@ + 0; + }; + + if (!$itflow_column('settings', 'config_project_tickets_apart')) { + mysqli_query($mysqli, "ALTER TABLE `settings` ADD `config_project_tickets_apart` tinyint(1) NOT NULL DEFAULT 0 AFTER `config_project_next_number`"); + } + if (!$itflow_column('settings', 'config_project_ticket_color')) { + mysqli_query($mysqli, "ALTER TABLE `settings` ADD `config_project_ticket_color` varchar(20) DEFAULT NULL AFTER `config_project_tickets_apart`"); + } + if (!$itflow_column('tickets', 'ticket_sla_from')) { + mysqli_query($mysqli, "ALTER TABLE `tickets` ADD `ticket_sla_from` datetime DEFAULT NULL AFTER `ticket_sla_id`"); + } diff --git a/admin/post/settings_project.php b/admin/post/settings_project.php index 0aa8a9ba3..5ba00ad0b 100644 --- a/admin/post/settings_project.php +++ b/admin/post/settings_project.php @@ -3,7 +3,9 @@ /* * Admin > Settings > Projects (admin/settings_project.php): * edit_project_settings saves the numbering - a next number already in use - * comes back to the page saying so. + * comes back to the page saying so - and whether project tickets are kept + * apart, with their calendar colour; switching that works out the open + * project tickets' SLAs again. */ defined('FROM_POST_HANDLER') || die("Direct file access is not allowed"); @@ -12,14 +14,28 @@ if (isset($_POST['edit_project_settings'])) { validateCSRFToken(); - $before = settingsCurrent(['config_project_prefix', 'config_project_next_number']); + $ticket_columns = projectTicketsReady() ? ['config_project_tickets_apart', 'config_project_ticket_color'] : []; + $before = settingsCurrent(array_merge(['config_project_prefix', 'config_project_next_number'], $ticket_columns)); [$prefix, $number, $errors] = settingsNumberingCheck('project', $_POST + array_map('strval', $before), $before); if ($errors) { settingsRefuse('project', $errors); } - settingsSave('project', $before, ['config_project_prefix' => $prefix, 'config_project_next_number' => $number]); + $after = ['config_project_prefix' => $prefix, 'config_project_next_number' => $number]; + // Project tickets kept apart, and their colour (functions/project_tickets.php) - a switch sends nothing when off + if ($ticket_columns) { + $after['config_project_tickets_apart'] = empty($_POST['config_project_tickets_apart']) ? '0' : '1'; + $color = calendarColor((string) ($_POST['config_project_ticket_color'] ?? ''), ''); + $after['config_project_ticket_color'] = $color === '' || strtolower($color) === PROJECT_TICKET_COLOR ? null : $color; + } + + settingsSave('project', $before, $after); + + // Switched on, the open project tickets lose their SLA; off, they get it back counted from now + if ($ticket_columns && $after['config_project_tickets_apart'] !== (string) intval($before['config_project_tickets_apart'])) { + projectTicketsSwitched($after['config_project_tickets_apart'] === '1'); + } redirect(); diff --git a/admin/settings_project.php b/admin/settings_project.php index dd1a41cef..0633e8d8c 100644 --- a/admin/settings_project.php +++ b/admin/settings_project.php @@ -1,8 +1,9 @@ Settings > Projects - how projects are numbered. Saved by - * edit_project_settings (admin/post/settings_project.php). + * Admin > Settings > Projects - how projects are numbered, and whether their + * tickets are kept apart from the service desk (functions/project_tickets.php). + * Saved by edit_project_settings (admin/post/settings_project.php). */ require_once "includes/inc_all_admin.php"; @@ -21,6 +22,16 @@ echo settingsPageStart('project'); + + + 'Keep project tickets apart', + 'help' => 'A ticket in a project is left off the Tickets list\'s usual views - it has a Projects view of its own - the dashboard\'s unassigned count and the Dispatch queue, and has no SLA. Agents still see their own under Mine, in Dispatch\'s Workload and on the calendar. A ticket taken out of its project gets its SLA back, counted from then - and so do they all if this is switched off.']) ?> + 'color', 'icon' => 'fa-palette', 'class' => 'form-control-color', + 'label' => 'Calendar color', 'help' => 'Their bookings on the calendar and Dispatch while they are kept apart - on the calendar, with a dot in the agent\'s own color beside their name.']) ?> + + + diff --git a/agent/includes/get_side_nav_counts.php b/agent/includes/get_side_nav_counts.php index f72a80440..d39d0d4c2 100644 --- a/agent/includes/get_side_nav_counts.php +++ b/agent/includes/get_side_nav_counts.php @@ -6,7 +6,7 @@ $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('client_id') AS nu $num_active_clients = $row['num']; // Active Ticket Count -$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('ticket_id') AS num FROM tickets WHERE ticket_archived_at IS NULL AND ticket_closed_at IS NULL AND ticket_status != 4 " . clientScopeSql('ticket_client_id') . "")); +$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('ticket_id') AS num FROM tickets WHERE ticket_archived_at IS NULL AND ticket_closed_at IS NULL AND ticket_status != 4 " . clientScopeSql('ticket_client_id') . projectTicketsServiceSql())); $num_active_tickets = $row['num']; // Recurring Ticket Count diff --git a/agent/js/calendar.js b/agent/js/calendar.js index a6d28bc62..ab4ae589a 100644 --- a/agent/js/calendar.js +++ b/agent/js/calendar.js @@ -300,6 +300,13 @@ const agent = document.createElement('span'); agent.className = 'itflow-cal-agent'; agent.textContent = props.agent_name; + // A project's booking is in the project colour - a dot in the agent's beside their name (functions/project_tickets.php) + if (props.agent_color) { + const dot = document.createElement('span'); + dot.className = 'itflow-cal-agent-dot'; + dot.style.backgroundColor = props.agent_color; + agent.prepend(dot); + } when.append(time, agent); wrap.appendChild(when); agentShown = true; diff --git a/agent/post/ticket.php b/agent/post/ticket.php index 993f612da..9391ba178 100644 --- a/agent/post/ticket.php +++ b/agent/post/ticket.php @@ -366,6 +366,8 @@ if (isset($_POST['edit_ticket'])) { } mysqli_query($mysqli, "UPDATE tickets SET $set WHERE ticket_id = $ticket_id"); + // Out of a project, its SLA counts from now (functions/project_tickets.php) + projectTicketLeft($ticket_id, $row['ticket_project_id']); applyTicketSla($ticket_id); if ($ticket_status !== intval($row['ticket_status'])) { syncTicketSlaClock($ticket_id); @@ -497,6 +499,8 @@ if (isset($_POST['edit_ticket_project'])) { $reference = escapeSql(ticketReference($row)); mysqli_query($mysqli, "UPDATE tickets SET ticket_project_id = $project_id WHERE ticket_id = $ticket_id"); + // Its SLA goes, or comes back counted from now, while project tickets are kept apart (functions/project_tickets.php) + projectTicketMoved($ticket_id, $row['ticket_project_id']); if ($project_id) { logTicketHistory($ticket_id, "$session_name added the ticket to project " . escapeSql($project_name)); @@ -1009,6 +1013,7 @@ if (isset($_POST['bulk_add_ticket_project'])) { continue; } mysqli_query($mysqli, "UPDATE tickets SET ticket_project_id = $project_id WHERE ticket_id = $ticket_id"); + projectTicketMoved($ticket_id, $row['ticket_project_id']); logTicketHistory($ticket_id, $project_id ? "$session_name added the ticket to project " . escapeSql($project_name) : "$session_name took the ticket out of its project"); logAudit("Ticket", "Edit", "$session_name " . ($project_id ? "added ticket " . escapeSql(ticketReference($row)) . " to project " . escapeSql($project_name) : "took ticket " . escapeSql(ticketReference($row)) . " out of its project"), intval($row['ticket_client_id']), $ticket_id); $count++; diff --git a/agent/tickets.php b/agent/tickets.php index c65a1a18c..0f75d33ac 100644 --- a/agent/tickets.php +++ b/agent/tickets.php @@ -238,6 +238,9 @@ if ($view === 'list') { $shows['all'] = ['label' => 'All', 'where' => '1 = 1']; } +// Project tickets kept apart - off the usual views, with a Projects view of their own (functions/project_tickets.php) +$shows = projectTicketsShows($shows, $base_sql, $project_filter); + // A status or billing filter asked for on its own looks at every ticket - unbilled work is nearly all done already $show = $_GET['show'] ?? ''; if (!isset($shows[$show])) { diff --git a/api/v1/tickets/update.php b/api/v1/tickets/update.php index 3cf59f852..fab0cda1c 100644 --- a/api/v1/tickets/update.php +++ b/api/v1/tickets/update.php @@ -37,6 +37,8 @@ if (!empty($ticket_id)) { // On or off a project if ($ticket_project_id !== intval($ticket_row['ticket_project_id'])) { + // Its SLA goes, or comes back counted from now, while project tickets are kept apart (functions/project_tickets.php) + projectTicketMoved($ticket_id, $ticket_row['ticket_project_id']); $project = $ticket_project_id ? projectRow($ticket_project_id) : null; logTicketHistory($ticket_id, $project ? "Added to project " . escapeSql(projectReference($project) . ' - ' . $project['project_name']) . " via the API ($api_key_name)" : "Taken out of its project via the API ($api_key_name)"); } diff --git a/css/itflow_custom.css b/css/itflow_custom.css index 6db8addae..58c07357a 100644 --- a/css/itflow_custom.css +++ b/css/itflow_custom.css @@ -5637,6 +5637,16 @@ img.itflow-contact-avatar { .itflow-cal-event.is-list .itflow-cal-when { display: inline-flex; } +/* A project's booking, in the project colour - its agent's colour as a dot (functions/project_tickets.php) */ +.itflow-cal-agent-dot { + display: inline-block; + width: .55rem; + height: .55rem; + margin-right: .25rem; + border-radius: 50%; + border: 1px solid rgba(255, 255, 255, .85); + vertical-align: baseline; +} /* Booked on a day gone by and still open */ #itflowCalendar .itflow-cal-left-behind { outline: 2px dashed var(--bs-danger); diff --git a/db.sql b/db.sql index 9b96a27b9..cdaa0d41e 100644 --- a/db.sql +++ b/db.sql @@ -3336,6 +3336,8 @@ CREATE TABLE `settings` ( `config_trip_item_name` varchar(200) NOT NULL DEFAULT 'Travel', `config_project_prefix` varchar(200) NOT NULL DEFAULT 'PRJ-', `config_project_next_number` int(11) NOT NULL DEFAULT 1, + `config_project_tickets_apart` tinyint(1) NOT NULL DEFAULT 0, + `config_project_ticket_color` varchar(20) DEFAULT NULL, `config_invoice_prefix` varchar(200) DEFAULT NULL, `config_invoice_next_number` int(11) DEFAULT NULL, `config_invoice_footer` text DEFAULT NULL, @@ -4349,6 +4351,7 @@ CREATE TABLE `tickets` ( `ticket_priority` varchar(200) DEFAULT NULL, `ticket_status` int(11) NOT NULL, `ticket_sla_id` int(11) NOT NULL DEFAULT 0, + `ticket_sla_from` datetime DEFAULT NULL, `ticket_billable` tinyint(1) NOT NULL DEFAULT 0, `ticket_schedule` datetime DEFAULT NULL, `ticket_schedule_end` datetime DEFAULT NULL, diff --git a/functions.php b/functions.php index abaffd84c..71a55ebad 100644 --- a/functions.php +++ b/functions.php @@ -73,6 +73,7 @@ require_once __DIR__ . '/functions/ticket.php'; require_once __DIR__ . '/functions/ticket_helpers.php'; require_once __DIR__ . '/functions/user_timezone.php'; require_once __DIR__ . '/functions/dispatch.php'; +require_once __DIR__ . '/functions/project_tickets.php'; require_once __DIR__ . '/functions/ticket_status.php'; require_once __DIR__ . '/functions/ticket_template.php'; require_once __DIR__ . '/functions/ticket_template_transfer.php'; diff --git a/functions/calendar.php b/functions/calendar.php index 31813be81..eee14d865 100644 --- a/functions/calendar.php +++ b/functions/calendar.php @@ -692,6 +692,8 @@ function calendarSourceItems($key, $from, $to, array $opts = []) { } // The agents helping, at the lead's time or their own (functions/ticket_helpers.php) $items = array_merge($items, ticketHelperCalendarItems($from, $to, $client_id, $user_id, $can_move)); + // A project's tickets in the project colour, while they are kept apart (functions/project_tickets.php) + $items = projectTicketsCalendarItems($items); } elseif ($key === 'projects') { $sql = mysqli_query($mysqli, "SELECT project_id, project_prefix, project_number, project_name, project_start, project_due, project_client_id, client_name FROM projects LEFT JOIN clients ON client_id = project_client_id diff --git a/functions/dashboard.php b/functions/dashboard.php index 5424f09dc..17f581968 100644 --- a/functions/dashboard.php +++ b/functions/dashboard.php @@ -249,7 +249,7 @@ function dashboardAttention($access) { 'url' => '/agent/tickets.php?sla=breached', ]; $items[] = [ - 'count' => dashboardCount("SELECT COUNT(ticket_id) FROM tickets WHERE ticket_resolved_at IS NULL AND ticket_assigned_to = 0 $ticket_scope"), + 'count' => dashboardCount("SELECT COUNT(ticket_id) FROM tickets WHERE ticket_resolved_at IS NULL AND ticket_assigned_to = 0 $ticket_scope" . projectTicketsServiceSql()), 'label' => 'Unassigned tickets', 'icon' => 'user-slash', 'tone' => 'warning', 'url' => '/agent/tickets.php?assigned=unassigned', ]; @@ -619,7 +619,7 @@ function dashboardTeamWorkload($limit = 8) { return [ 'techs' => $techs, - 'unassigned' => dashboardCount("SELECT COUNT(ticket_id) FROM tickets WHERE ticket_resolved_at IS NULL AND ticket_assigned_to = 0 $scope"), + 'unassigned' => dashboardCount("SELECT COUNT(ticket_id) FROM tickets WHERE ticket_resolved_at IS NULL AND ticket_assigned_to = 0 $scope" . projectTicketsServiceSql()), ]; } diff --git a/functions/dispatch.php b/functions/dispatch.php index 17e06917f..248b47bcb 100644 --- a/functions/dispatch.php +++ b/functions/dispatch.php @@ -136,7 +136,8 @@ function dispatchWorkingDay() { */ function dispatchQueue($tab, array $filters = []) { global $mysqli; - $where = TICKET_OPEN_SQL . " AND ticket_archived_at IS NULL" . clientScopeSql('ticket_client_id'); + // A project's tickets are left to the project while they are kept apart (functions/project_tickets.php) + $where = TICKET_OPEN_SQL . " AND ticket_archived_at IS NULL" . clientScopeSql('ticket_client_id') . projectTicketsServiceSql('tickets.ticket_project_id'); $client_id = intval($filters['client_id'] ?? 0); if ($client_id && hasClientAccess($client_id)) { $where .= " AND ticket_client_id = $client_id"; diff --git a/functions/project.php b/functions/project.php index 4f49d4bfd..5afe31251 100644 --- a/functions/project.php +++ b/functions/project.php @@ -569,6 +569,7 @@ function projectAddTicket($project, $ticket) { return ''; } mysqli_query($mysqli, "UPDATE tickets SET ticket_project_id = " . intval($project['project_id']) . ", ticket_updated_at = ticket_updated_at WHERE ticket_id = $ticket_id"); + projectTicketMoved($ticket_id, $ticket['ticket_project_id']); logTicketHistory($ticket_id, "$session_name added the ticket to project " . escapeSql(projectReference($project) . ' - ' . $project['project_name'])); return ''; } @@ -578,6 +579,7 @@ function projectRemoveTicket($ticket) { global $mysqli, $session_name; $ticket_id = intval($ticket['ticket_id']); mysqli_query($mysqli, "UPDATE tickets SET ticket_project_id = 0, ticket_updated_at = ticket_updated_at WHERE ticket_id = $ticket_id"); + projectTicketMoved($ticket_id, $ticket['ticket_project_id'] ?? 0); logTicketHistory($ticket_id, "$session_name took the ticket out of its project"); } @@ -628,7 +630,16 @@ function projectDelete($row) { while ($ticket = mysqli_fetch_row($sql)) { logTicketHistory(intval($ticket[0]), "$session_name deleted project $name, which the ticket was part of"); } + $left = []; + $sql = mysqli_query($mysqli, "SELECT ticket_id FROM tickets WHERE ticket_project_id = $project_id"); + while ($ticket = mysqli_fetch_row($sql)) { + $left[] = intval($ticket[0]); + } mysqli_query($mysqli, "UPDATE tickets SET ticket_project_id = 0, ticket_updated_at = ticket_updated_at WHERE ticket_project_id = $project_id"); + // Out of the project - their SLA back, counted from now, while project tickets are kept apart (functions/project_tickets.php) + foreach ($left as $ticket_id) { + projectTicketMoved($ticket_id, $project_id); + } mysqli_query($mysqli, "DELETE FROM projects WHERE project_id = $project_id"); logAudit("Project", "Delete", "$session_name deleted project $name", intval($row['project_client_id']), $project_id); } diff --git a/functions/project_tickets.php b/functions/project_tickets.php new file mode 100644 index 000000000..c34d8bd67 --- /dev/null +++ b/functions/project_tickets.php @@ -0,0 +1,190 @@ + Settings > + * Projects, Project tickets). Switched on, a ticket that is part of a project: + * - is left off the Tickets list's usual views - it has a Projects view of + * its own - and so the client's tickets, the dashboard's unassigned count + * and the side menu's count, and the Dispatch queue. It stays in Mine, + * Mentioned me, Closed and All, in Dispatch's Workload, on the calendar and + * Dispatch's board, and a Project filter shows a project's tickets as before; + * - has no SLA - the project's dates are what count. A ticket that leaves its + * project, or every one when this is switched off, gets its SLA back counted + * from that moment (tickets.ticket_sla_from), so it isn't breached at once; + * - is drawn on the calendar and Dispatch in the project colour, with a dot in + * its agent's colour beside their name. + * Only an open ticket's SLA changes: a resolved or closed one keeps what it has. + * Off - the default - is how ITFlow has always been. + * + * Settings (database 3.8.9): config_project_tickets_apart, config_project_ticket_color. + */ + +/** The colour project bookings are drawn in, when none is picked. */ +const PROJECT_TICKET_COLOR = '#8e44ad'; + +/** Whether the 3.8.9 update has run. */ +function projectTicketsReady() { + global $mysqli; + static $ready = null; + if ($ready === null) { + if (defined('CURRENT_DATABASE_VERSION')) { + $version = CURRENT_DATABASE_VERSION; + } else { + $result = mysqli_query($mysqli, "SELECT config_current_database_version FROM settings WHERE company_id = 1"); + $version = $result && ($row = mysqli_fetch_row($result)) ? (string) $row[0] : '0'; + } + $ready = version_compare($version, '3.8.9', '>='); + } + return $ready; +} + +/** The two settings, read once a request ($fresh after saving them): [apart, color]. */ +function projectTicketsSettings($fresh = false) { + global $mysqli; + static $settings = null; + if ($settings === null || $fresh) { + $row = projectTicketsReady() ? mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT config_project_tickets_apart, config_project_ticket_color FROM settings WHERE company_id = 1")) : null; + $settings = [ + 'apart' => intval($row['config_project_tickets_apart'] ?? 0) === 1, + 'color' => calendarColor((string) ($row['config_project_ticket_color'] ?? ''), PROJECT_TICKET_COLOR), + ]; + } + return $settings; +} + +/** Whether project tickets are kept apart. */ +function projectTicketsApart() { + return projectTicketsSettings()['apart']; +} + +/** " AND = 0" while they are - for a WHERE that should see the service desk's tickets only. */ +function projectTicketsServiceSql($column = 'ticket_project_id') { + return projectTicketsApart() ? " AND $column = 0" : ''; +} + +/* + * The Tickets list's views ($shows in agent/tickets.php): while kept apart, + * the usual ones leave project tickets out and a Projects view lists the open + * ones - unless a project was picked in the filters, which shows its tickets + * as before. Mine, Mentioned me, Closed and All keep them. + */ +function projectTicketsShows(array $shows, $base_sql, $project_filter) { + if (!projectTicketsApart() || intval($project_filter)) { + return $shows; + } + $view = ['label' => 'Projects', 'icon' => 'fa-project-diagram', 'where' => "$base_sql AND tickets.ticket_project_id > 0", + 'title' => 'Tickets that are part of a project - kept off the other views, with no SLA', 'divider' => true]; + $out = []; + foreach ($shows as $key => $show) { + if ($key === 'closed') { + $out['projects'] = $view; + } + if (!in_array($key, ['mine', 'mentioned', 'closed', 'all'], true)) { + $show['where'] = '(' . $show['where'] . ') AND tickets.ticket_project_id = 0'; + } + $out[$key] = $show; + } + if (!isset($out['projects'])) { + $out['projects'] = $view; + } + return $out; +} + +/* + * For applyTicketSla(), with the ticket's row (ticket_project_id, ticket_sla_id, + * ticket_resolved_at, ticket_closed_at): whether it is to have no SLA - an open + * ticket in a project, or a done one in a project that has none already. + */ +function projectTicketsSlaOff(array $row) { + if (!projectTicketsApart() || intval($row['ticket_project_id'] ?? 0) === 0) { + return false; + } + $open = empty($row['ticket_resolved_at']) && empty($row['ticket_closed_at']); + return $open || intval($row['ticket_sla_id'] ?? 0) === 0; +} + +/* + * A ticket was in project $old_project_id and its project has just been set: + * taken out of it while kept apart, an open one gets its SLA counted from now. + * Before applyTicketSla() works its SLA out again. + */ +function projectTicketLeft($ticket_id, $old_project_id) { + global $mysqli; + if (projectTicketsReady() && projectTicketsApart() && intval($old_project_id)) { + mysqli_query($mysqli, "UPDATE tickets SET ticket_sla_from = NOW(), ticket_updated_at = ticket_updated_at + WHERE ticket_id = " . intval($ticket_id) . " AND ticket_project_id = 0 AND " . TICKET_OPEN_SQL); + } +} + +/* A ticket's project changed from $old_project_id: projectTicketLeft(), then its SLA worked out again. */ +function projectTicketMoved($ticket_id, $old_project_id) { + projectTicketLeft($ticket_id, $old_project_id); + if (projectTicketsReady()) { + applyTicketSla(intval($ticket_id)); + } +} + +/* + * After Keep project tickets apart was switched: on, the open project tickets + * lose their SLA; off, they get it back counted from now. How many changed. + */ +function projectTicketsSwitched($apart) { + global $mysqli; + if (!projectTicketsReady()) { + return 0; + } + projectTicketsSettings(true); + if (!$apart) { + mysqli_query($mysqli, "UPDATE tickets SET ticket_sla_from = NOW(), ticket_updated_at = ticket_updated_at WHERE ticket_project_id > 0 AND " . TICKET_OPEN_SQL); + } + $ids = []; + $sql = mysqli_query($mysqli, "SELECT ticket_id FROM tickets WHERE ticket_project_id > 0 AND ticket_archived_at IS NULL AND " . TICKET_OPEN_SQL); + while ($row = mysqli_fetch_row($sql)) { + $ids[] = intval($row[0]); + } + foreach ($ids as $ticket_id) { + applyTicketSla($ticket_id); + } + return count($ids); +} + +/* + * Calendar items (the tickets source, so Dispatch too): while kept apart, a + * project ticket's booking - lead's and helpers' - in the project colour, its + * agent's colour kept for a dot (agent_color) and the project named in the detail. + */ +function projectTicketsCalendarItems(array $items) { + global $mysqli; + if (!projectTicketsApart() || !$items) { + return $items; + } + $ids = []; + foreach ($items as $item) { + if (in_array($item['extendedProps']['kind'] ?? '', ['ticket', 'helper'], true)) { + $ids[] = intval($item['extendedProps']['ticket_id'] ?? 0); + } + } + $ids = array_filter(array_unique($ids)); + if (!$ids) { + return $items; + } + $projects = []; + $sql = mysqli_query($mysqli, "SELECT ticket_id, project_prefix, project_number, project_name FROM tickets + JOIN projects ON project_id = ticket_project_id WHERE ticket_id IN (" . implode(',', $ids) . ")"); + while ($row = mysqli_fetch_assoc($sql)) { + $projects[intval($row['ticket_id'])] = projectReference($row) . ' ' . $row['project_name']; + } + $color = projectTicketsSettings()['color']; + foreach ($items as &$item) { + $project = $projects[intval($item['extendedProps']['ticket_id'] ?? 0)] ?? null; + if ($project === null || !in_array($item['extendedProps']['kind'] ?? '', ['ticket', 'helper'], true)) { + continue; + } + $item['extendedProps']['agent_color'] = $item['color'] ?? ''; + $item['extendedProps']['project'] = $project; + $item['extendedProps']['detail'] = trim($project . ' · ' . ($item['extendedProps']['detail'] ?? ''), ' ·'); + $item['color'] = $color; + } + unset($item); + return $items; +} diff --git a/functions/settings.php b/functions/settings.php index a096b3c83..87572eac4 100644 --- a/functions/settings.php +++ b/functions/settings.php @@ -188,6 +188,8 @@ function settingsFields() { // Projects 'config_project_prefix' => ['page' => 'project', 'section' => 'Numbering', 'label' => 'Project prefix', 'words' => 'project number prj prefix'], 'config_project_next_number' => ['page' => 'project', 'section' => 'Numbering', 'label' => 'Next project number', 'words' => 'project number counter'], + 'config_project_tickets_apart' => ['page' => 'project', 'section' => 'Project tickets', 'label' => 'Keep project tickets apart', 'kind' => 'switch', 'words' => 'project tickets sla service desk queue separate apart'], + 'config_project_ticket_color' => ['page' => 'project', 'section' => 'Project tickets', 'label' => 'Project tickets\' calendar color', 'words' => 'project ticket colour color calendar dispatch'], // Quotes 'config_quote_prefix' => ['page' => 'quote', 'section' => 'Numbering', 'label' => 'Quote prefix', 'words' => 'quote number quo prefix estimate'], diff --git a/functions/sla.php b/functions/sla.php index 9702d18bc..60f25217d 100644 --- a/functions/sla.php +++ b/functions/sla.php @@ -488,15 +488,17 @@ function applyTicketSla($ticket_id, $forced_sla_id = null) $ticket_id = intval($ticket_id); - $sql = mysqli_query($mysqli, "SELECT ticket_client_id, ticket_priority, ticket_created_at, ticket_first_response_at, ticket_resolved_at, - ticket_response_due_at, ticket_resolution_due_at, ticket_response_sla_alert_stage, ticket_resolution_sla_alert_stage FROM tickets WHERE ticket_id = $ticket_id LIMIT 1"); + $sql = mysqli_query($mysqli, "SELECT ticket_client_id, ticket_priority, ticket_created_at, ticket_first_response_at, ticket_resolved_at, ticket_closed_at, + ticket_response_due_at, ticket_resolution_due_at, ticket_response_sla_alert_stage, ticket_resolution_sla_alert_stage, ticket_project_id, ticket_sla_id" + . (projectTicketsReady() ? ', ticket_sla_from' : ', NULL AS ticket_sla_from') . " FROM tickets WHERE ticket_id = $ticket_id LIMIT 1"); if (!$sql || !mysqli_num_rows($sql)) { return; } $row = mysqli_fetch_assoc($sql); if (is_null($forced_sla_id)) { - $sla_id = getTicketSlaId($row['ticket_client_id'], $row['ticket_priority']); + // A project's ticket has no SLA while project tickets are kept apart - its project's dates count (functions/project_tickets.php) + $sla_id = projectTicketsSlaOff($row) ? 0 : getTicketSlaId($row['ticket_client_id'], $row['ticket_priority']); } else { $sla_id = intval($forced_sla_id); } @@ -514,7 +516,8 @@ function applyTicketSla($ticket_id, $forced_sla_id = null) } $sla = mysqli_fetch_assoc($sla_sql); - $created_at = $row['ticket_created_at']; + // Counted from when it was made - or from when it left a project (functions/project_tickets.php) + $created_at = !empty($row['ticket_sla_from']) && $row['ticket_sla_from'] > $row['ticket_created_at'] ? $row['ticket_sla_from'] : $row['ticket_created_at']; $response_due_at = addBusinessMinutes($created_at, $sla['sla_response_minutes']);