I would like to display a timer in a dashboard. I'm developing a section in a ticket management system, which is Real Time Monitoring.
My current section is this one:
<div class="card-body p-0">
<div class="table-responsive">
<table class="table m-0">
<thead>
<tr>
<th># Ticket</th>
<th>Technician</th>
<th>Status</th>
<th>Time elapsed from assigned time</th>
<th>Assigned Time</th>
</tr>
</thead>
<tbody>
<?php
$tickets = array();{
$tickets = TicketData::getAllToDo();
}
if (count($tickets) > 0) {
// if there are tickets opened
?>
<?php
foreach ($tickets as $ticket) {
$project = $ticket->getProject();
$events = TicketData::getEvents();
?>
<?php $ticketStatus = $ticket->getStatus()->name; ?>
<tr>
<td><a href="index.php?view=viewticket&id=<?php echo$ticket->id; ?>"><?php $ticketId=$ticket->id; echo $ticketId; ?></a></td>
<td><?php echo $ticket->getUser()->name." ".$ticket->getUser()->lastname; ?></td>
<td>
<?php if($ticketStatus=="In Process"){
echo "<span class='badge badge-warning'>".$ticketStatus."</span>";
}elseif ($ticketStatus=="Pending") {
echo "<span class='badge badge-danger'>".$ticketStatus."</span>";
}
?>
</td>
<td>
<?php
$newCon = new Database();
$con = $newCon->connect();
$assignedToTecnico = "SELECT id, SUM(TIMESTAMPDIFF(MINUTE,convert(time_at,time),convert(visit_hour_in, time))) as tiempo, (TIMESTAMPDIFF(MINUTE,convert(time_at,time),convert(visit_hour_in, time))/COUNT(tecnico_id)) as average FROM ticket where id=".$ticketId;
$query = $con->query($assignedToTecnico);
$row = $query->fetch_row();
$time= $row[2];
$timesec= ($time)*60;
$days = floor($timesec / (60 * 60 * 24));
$timesec -= $days * (60 * 60 * 24);
$hours = floor($timesec / (60 * 60));
$timesec -= $hours * (60 * 60);
$minutes = floor($timesec / 60);
$timesec -= $minutes * 60;
$seconds = floor($timesec);
$timesec -= $seconds;
if ($days==0 && $hours==0 && $minutes==0) {
echo "The technician hasn't visited the client yet.";
}else{
echo "{$days} days, {$hours} hours, {$minutes} minutes.";
}
?>
</td>
<td>
<?php echo$ticket->time_at; ?>
</td>
</tr>
<?php } ?>
<?php
} else {
echo "<p class='alert alert-danger'>No hay tickets abiertos</p>";
}
?>
</tbody>
</table>
</div>
</div>
I'm printing a static table right now, and my PHP code will say the amount of time that has elapsed from the moment the ticket was assigned.
However, we'd like to have a running timer which will stop whenever the technician clocks in, instead of the text The technician hasn't visited the client yet.
I saw this answer to a similar issue, and this question trying to solve the issue I'm stating.
I tried with the latter, and all I'm getting in the fields is this:
NaN
How can I achieve this?