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 (