From 80169de16dbcee6680fd55fff2b8ae01c1c12c85 Mon Sep 17 00:00:00 2001 From: Jared Vititoe Date: Fri, 11 Sep 2026 22:17:25 -0400 Subject: [PATCH] Fix User Activity report's Tickets Assigned column to use assignment date (#49) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The "Tickets Assigned" column filtered by tickets.created_at, so a ticket created outside the selected date range but assigned to a user within it never counted, while one created in-range but assigned/reassigned later counted as if the assignment happened in-range — filtered by the wrong date field for what the column claims to measure. tickets has no assigned_at column, so derive the count from audit_log's 'assign' events (already logged by both the single-ticket and bulk-assign paths) instead, filtered by the event's own created_at. COUNT(DISTINCT entity_id) so a ticket reassigned more than once to the same user within the range still counts once. Verified against real MariaDB: seeded one ticket created outside the test range but assigned inside it, and one created inside the range but assigned outside it. The old query counted the wrong one; the new query correctly flips to count the one actually assigned within the range. Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_0117oBw2jN4kALYeS8HPq4zV --- index.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/index.php b/index.php index f18bc99..3245c66 100644 --- a/index.php +++ b/index.php @@ -388,9 +388,19 @@ switch (true) { GROUP BY user_id ) cm ON u.user_id = cm.user_id LEFT JOIN ( - SELECT assigned_to, COUNT(*) as tickets_assigned - FROM tickets - WHERE DATE(created_at) BETWEEN ? AND ? + -- Assignment date, not ticket creation date: a ticket created + -- outside the range but assigned within it should count, and + -- one created in-range but assigned later shouldn't (until it + -- is). Derived from audit_log's 'assign' events since tickets + -- has no assigned_at column; COUNT(DISTINCT ...) so a ticket + -- reassigned more than once to the same user in-range still + -- counts once. + SELECT + CAST(JSON_UNQUOTE(JSON_EXTRACT(details, '$.assigned_to')) AS UNSIGNED) as assigned_to, + COUNT(DISTINCT entity_id) as tickets_assigned + FROM audit_log + WHERE action_type = 'assign' AND entity_type = 'ticket' + AND DATE(created_at) BETWEEN ? AND ? GROUP BY assigned_to ) ta ON u.user_id = ta.assigned_to LEFT JOIN (