From bfcd3c460c736df483a9504526b33fdef94fdc61 Mon Sep 17 00:00:00 2001
From: Peter Rotich <peter@osticket.com>
Date: Wed, 13 Feb 2013 11:50:47 -0500
Subject: [PATCH] Add SLA est. duedate  (only active SLAs) Add methods to get
 estimated duedate and sla duedate

---
 include/class.ticket.php | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/include/class.ticket.php b/include/class.ticket.php
index b9857d39a..e060b233f 100644
--- a/include/class.ticket.php
+++ b/include/class.ticket.php
@@ -78,12 +78,14 @@ class Ticket {
         //TODO: delete helptopic field in ticket table.
        
         $sql='SELECT  ticket.*, lock_id, dept_name, priority_desc '
+            .' ,IF(sla.id IS NULL, NULL, DATE_ADD(ticket.created, INTERVAL sla.grace_period HOUR)) as sla_duedate ' 
             .' ,count(attach.attach_id) as attachments '
             .' ,count(DISTINCT message.id) as messages '
             .' ,count(DISTINCT response.id) as responses '
             .' ,count(DISTINCT note.id) as notes '
             .' FROM '.TICKET_TABLE.' ticket '
             .' LEFT JOIN '.DEPT_TABLE.' dept ON (ticket.dept_id=dept.dept_id) '
+            .' LEFT JOIN '.SLA_TABLE.' sla ON (ticket.sla_id=sla.id AND sla.isactive=1) '
             .' LEFT JOIN '.TICKET_PRIORITY_TABLE.' pri ON ('
                 .'ticket.priority_id=pri.priority_id) '
             .' LEFT JOIN '.TICKET_LOCK_TABLE.' tlock ON ('
@@ -259,6 +261,20 @@ class Ticket {
         return $this->duedate;
     }
 
+    function getSLADuedate() {
+        return $this->ht['sla_duedate'];
+    }
+
+    function getEstDueDate() {
+
+        //Real due date 
+        if(($duedate=$this->getDueDate()))
+            return $duedate;
+
+        //return sla due date (If ANY)
+        return $this->getSLADueDate();
+    }
+
     function getCloseDate(){
         return $this->closed;
     }
-- 
GitLab