Skip to content

Commit

Permalink
Merge pull request #952 from wrongecho/report-tickets-time
Browse files Browse the repository at this point in the history
Add total time worked to 'Tickets by client' report
  • Loading branch information
johnnyq authored May 5, 2024
2 parents 4069dc9 + 8d5c71f commit c471228
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion report_ticket_by_client.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function secondsToTime($inputSeconds) {

$sql_ticket_years = mysqli_query($mysqli, "SELECT DISTINCT YEAR(ticket_created_at) AS ticket_year FROM tickets ORDER BY ticket_year DESC");

$sql_clients = mysqli_query($mysqli, "SELECT client_id, client_name FROM clients ORDER BY client_name ASC");
$sql_clients = mysqli_query($mysqli, "SELECT client_id, client_name FROM clients WHERE client_archived_at IS NULL ORDER BY client_name ASC");

?>

Expand Down Expand Up @@ -79,6 +79,7 @@ function secondsToTime($inputSeconds) {
<th>Client</th>
<th class="text-right">Tickets raised</th>
<th class="text-right">Tickets closed</th>
<th class="text-right">Time worked <i>(H:M:S)</i></th>
<th class="text-right">Avg time to close</th>
</tr>
</thead>
Expand All @@ -101,6 +102,11 @@ function secondsToTime($inputSeconds) {
// Used to calculate average time to close tickets that were raised in period specified
$sql_tickets = mysqli_query($mysqli, "SELECT ticket_created_at, ticket_closed_at FROM tickets WHERE YEAR(ticket_created_at) = $year AND ticket_client_id = $client_id AND ticket_closed_at IS NOT NULL");

// Calculate total time tracked towards tickets in the period
$sql_time = mysqli_query($mysqli, "SELECT SEC_TO_TIME(SUM(TIME_TO_SEC(ticket_reply_time_worked))) as total_time FROM ticket_replies LEFT JOIN tickets ON tickets.ticket_id = ticket_replies.ticket_reply_ticket_id WHERE YEAR(ticket_created_at) = $year AND ticket_client_id = $client_id AND ticket_reply_time_worked IS NOT NULL");
$row = mysqli_fetch_array($sql_time);
$ticket_total_time_worked = nullable_htmlentities($row['total_time']);

if ($ticket_raised_count > 0) {

// Calculate average time to solve
Expand All @@ -120,6 +126,7 @@ function secondsToTime($inputSeconds) {
<td><?php echo $client_name; ?></td>
<td class="text-right"><?php echo $ticket_raised_count; ?></td>
<td class="text-right"><?php echo $ticket_closed_count; ?></td>
<td class="text-right"><?php echo $ticket_total_time_worked; ?></td>
<td class="text-right"><?php echo secondsToTime($total); ?></td>
</tr>
<?php
Expand Down

0 comments on commit c471228

Please sign in to comment.