Hi all,
I have knocked up a little bit of code (probably not the best way but it works) to calculate the percentage of SLA time of a current ticket.
This is displayed in a new column in the ticket list. (see pic) This uses a pending mod in order to calculate the current ticket time minus any time in pending, aligned to ticket priority.

I would love to expand this to subtract hours outside of office hours, but thats beyond my skills.
This is added to tickets.inc.php at the appropriate column/cell.
<?php
$startt = new DateTime($row);
$endt = new DateTime($row);
$reopendt = new DateTime($row);
$pendstartt = new DateTime($row);
$pendendt = new DateTime($row);
$pendtime = $pendstartt -> diff($pendendt);
$ticktime = $startt ->diff($endt);
$pendint = ($pendtime->d * 24 * 60) + ($pendtime->h * 60) + $pendtime->i;
$tickint = ($ticktime->d * 24 * 60) + ($ticktime->h * 60) + $ticktime->i;
$reopint = ($reopendt->d * 24 * 60) + ($reopendt->h * 60) + $reopendt->i;
$priority = $row;
$slaint = $tickint - $pendint;
if ($priority == 4){$slaper = ($slaint / 60) * 100;}
if ($priority == 3){$slaper = ($slaint / 240) * 100;}
if ($priority == 2){$slaper = ($slaint / 480) * 100;}
if ($priority == 1){$slaper = ($slaint / 2880) * 100;}
if ($slaper <=50) {
$slacolor = '#b5eaaa';
$percent = round($slaper,1);
}
if ($slaper >50 && $slaper <=99) {
$slacolor = '#ffe87c';
$percent = round($slaper,1);
}
if ($slaper >=100) {
$slaper = 100;
$slacolor = '#f88158';
$percent = round($slaper,1);
}
echo "<td align=center style='background-color:".$slacolor.";'>";
echo $percent;
?>%</td>
At the moment I have been unable to code for a couple of evantualities:
1. Ticket reopened - gives a huge negative percentage
2. Ticket unpended then repended - gives a huge negative.