<?php

class Announcement {

    private $db;
    private $info;

    public function __construct() {
        $this->db = DBConnectorFactory::loadDriver();
    }

    public function setData(array $info) {
        $this->info = $info;
        return $this;
    }

    public function create() {
        $this->db->query('START TRANSACTION;');
        $today = date('Y-m-d');
        $date_time = date('Y-m-d h:i:s');
        $content = htmlentities($this->info['Announcement_Content']);
        $logged_id = Session::getUserID();
        $annoucement_value = $this->info['Announcement_Type'] == 'public' ? null : $this->info['Announcement_Value'];
        $item_data = [&$this->info['Announcement_Title'], &$content, &$this->info['Announcement_Subtitle'], &$today, &$this->info['Post_Time'], &$logged_id, &$this->info['Announcement_Type'], &$annoucement_value];
        $query = $this->db->prepare_Stmt('
			INSERT INTO tbl_hrm_announcements (
				Announcement_Title,
				Announcement_Content,
                                Announcement_Subtitle,
				Announcement_DateCreated,
				Post_Time,
                                Logged_ID,
                                `Announcement_Type`,
                                `Announcement_Value` 
                                
			)
			VALUES (?,?,?,?,?,?,?,?)
		', $item_data);
//        $sentemail = self::sendmail_SystemAdmin($this->info['Announcement_Title']);
        $annc_id = $this->db->id();
        $title = CommonLanguage::getMessage('waiting_approved') . ' ' . CommonLanguage::getMessage('new_annoucement') . ' - ' . $this->info['Announcement_Title'];
        $emp_arr = User::getDepartmentAdmins(smc_session()['user_department_id']);
//        echo "<pre>";die(print_r(em))
        foreach ($emp_arr as $emp_id) {
            $task_arr = array();
            $task_arr['emp_id'] = &$emp_id['User_ID'];
            $task_arr['task_desc'] = &$title;
            $task_arr['due_date'] = &$date_time;
            $task_arr['main_type'] = "annoucement";
            $task_arr['main_id'] = &$annc_id;
            $task_arr['task_type'] = "ntf";
//             echo"<pre>";
//        print_r($task_arr);
            CommonFunctions::insertEmpTask($task_arr);
        }
        $error = $this->db->error();
//        echo"<pre>";
//        die(print_r($emp_arr));
        if (empty($error) /* && $sentemail */) {
            $this->db->query('COMMIT');
            return array('sent');
        } else {
            $this->db->query('ROLLBACK');
            return $error;
        }
    }

    public function update($PubID) {
        $content = htmlentities($this->info['Announcement_Content']);
        $logged_id = Session::getUserID();
        $date_time = date('Y-m-d h:i:s');
        $annoucement_value = $this->info['Announcement_Type'] == 'public' ? null : $this->info['Announcement_Value'];
        $this->db->prepare_Stmt('UPDATE
                                    tbl_hrm_announcements
                                  SET
                                    Announcement_Title=?,
                                    Announcement_Subtitle=?,
                                    Post_Time=?,
                                    Announcement_Content=?,
                                    Logged_ID           =?,
                                    Announcement_Status = 0,
                                     Announcement_Type = ?,
                                `Announcement_Value`  = ?
                                  WHERE
                                    Announcement_ID=?
                ', [&$this->info['Announcement_Title'], &$this->info['Announcement_Subtitle'], &$this->info['Post_Time'], &$content, &$logged_id, &$this->info['Announcement_Type'], &$annoucement_value, &$PubID]);
        $error = $this->db->error();
        $this->db->prepare_Stmt('delete from tbl_emp_tasks where main_type="annoucement" and main_id = ? ', [&$PubID]);
        $title = CommonLanguage::getMessage('waiting_approved') . ' ' . CommonLanguage::getMessage('new_annoucement') . ' - ' . $this->info['Announcement_Title'];
        $emp_arr = User::getDepartmentAdmins(smc_session()['user_department_id']);
//        echo "<pre>";die(print_r($emp_arr));
        foreach ($emp_arr as $emp_id) {
            $task_arr = array();
            $task_arr['emp_id'] = &$emp_id['User_ID'];
            $task_arr['task_desc'] = &$title;
            $task_arr['due_date'] = &$date_time;
            $task_arr['main_type'] = "annoucement";
            $task_arr['main_id'] = &$PubID;
            $task_arr['task_type'] = "ntf";
            CommonFunctions::insertEmpTask($task_arr);
        }
        //  $sentemail = self::sendmail_SystemAdmin($this->info['Announcement_Title']);
        if (empty($error) /* && $sentemail */) {
            return array('sent');
        } else {
            return $error;
        }
    }

//    public function create() {
//        $today = date('Y-m-d');
//        $content = htmlentities($this->info['Announcement_Content']);
//        $logged_id = Session::getUserID();
//
//        $item_data = [&$this->info['Announcement_Title'], &$content, &$this->info['Announcement_Subtitle'], &$today, &$this->info['Post_Time'], &$this->info['Announcement_Type'], &$this->info['Branch_ID'], &$logged_id, &$this->info['Employee_ID']];
//        $er = $this->db->prepare_Stmt('
//			INSERT INTO tbl_hrm_announcements (
//				Announcement_Title,
//				Announcement_Content,
//                                Announcement_Subtitle,
//				Announcement_DateCreated,
//				Post_Time,
//                                Announcement_Type,
//                                Branch_ID,
//                                Logged_ID,
//                                Employee_ID
//			)
//			VALUES (?,?,?,?,?,?,?,?,?)
//		', $item_data);
////echo"<pre>";
//        $error = $this->db->error();
////        die(print_r($item_data));
//        $sentemail = self::sendmail_SystemAdmin($this->info['Announcement_Title']);
//        if (empty($error) && $sentemail) {
//            return array('sent');
//        } else {
//            return $error;
//        }
//    }
//
//    public function update($PubID) {
//        $content = htmlentities($this->info['Announcement_Content']);
//        $logged_id = Session::getUserID();
//        $this->db->prepare_Stmt('UPDATE
//                                    tbl_hrm_announcements
//                                  SET
//                                    Announcement_Title=?,
//                                    Announcement_Subtitle=?,
//                                    Post_Time=?,
//                                    Announcement_Content=?,
//                                    Logged_ID           =?,
//                                    Announcement_Status = 0,
//                                    Employee_ID = ?,
//                                    Branch_ID = ?,
//                                     Announcement_Type = ?
//                                  WHERE
//                                    Announcement_ID=?
//                ', [&$this->info['Announcement_Title'], &$this->info['Announcement_Subtitle'], &$this->info['Post_Time'], &$content, &$logged_id, &$this->info['Employee_ID'], &$this->info['Branch_ID'], &$this->info['Announcement_Type'], &$PubID]);
//        $error = $this->db->error();
//        $sentemail = self::sendmail_SystemAdmin($this->info['Announcement_Title']);
//        if (empty($error) && $sentemail) {
//            return array('sent');
//        } else {
//            return $error;
//        }
//    }

    public function view() {
        $data = array();
        $query = '
			SELECT * FROM tbl_hrm_announcements WHERE Status_ID =1
		';
        $results = $this->db->query($query);
        $i = 0;
        while ($row = $this->db->assoc($results)) {
            foreach ($row as $col => $field) {
                if ($col == 'Announcement_Content')
                    $data[$i][$col] = html_entity_decode($field);
                else
                    $data[$i][$col] = $field;
            }
            $i++;
        }
        return $data;
    }

    public function viewWithApproved($id = null) {
        $condition = '';
        $data = array();
        if (!is_null($id)) {
            $condition .= ' AND Announcement_ID = "' . $id . '"  ';
        }
        $query = '
			SELECT * FROM tbl_hrm_announcements WHERE Status_ID = 1 AND Announcement_Status = 1
		' . $condition;
        $results = $this->db->query($query);
        if ($results !== false) {
            $i = 0;
            while ($row = $this->db->assoc($results)) {
                foreach ($row as $col => $field) {
                    if ($col == 'Announcement_Content')
                        $data[$i][$col] = html_entity_decode($field);
                    else
                        $data[$i][$col] = $field;
                }
                $i++;
            }
            return $data;
        }
    }

    public function viewWithAnnoucementID($ID) {
        $data = array();
        $query = '
            SELECT  a.*, group_concat(concat("{id:\'", b.department_id,"\', text:\'", REPLACE(b.department_name, "\'", "\\\\\'"),"\'}") SEPARATOR ", ") as Branch_Name,
            
 group_concat(concat("{id:\'", e.Employee_ID,"\', text:\'", REPLACE(concat(e.Employee_FirstName," ",e.Employee_MiddleName," ",e.Employee_LastName), "\'", "\\\\\'"),"\'}") SEPARATOR ", ") as Employee_Name
FROM tbl_hrm_announcements a 
            left join tbl_department b on FIND_IN_SET (b.department_id, a.Branch_ID)
             left join tbl_hrm_employee e on FIND_IN_SET (e.Employee_ID, a.Employee_ID)
            WHERE a.Announcement_ID     =   "' . $ID . '" AND a.Status_ID   = 1
            group by a.Announcement_ID
        ';
        $results = $this->db->query($query);

        $row = $this->db->fetch($results);
        $data = array($row['Announcement_ID'],
            $row['Announcement_Title'],
            $row['Announcement_Subtitle'],
            $row['Post_Time'],
            html_entity_decode($row['Announcement_Content']),
            $row['Announcement_DateCreated'],
            $row['Announcement_Type'],
            $row['Branch_ID'],
            $row['Branch_Name'],
            $row['Employee_ID'],
            $row['Employee_Name'],
            $row['Announcement_Value']
        );
        return $data;
    }

    public function updateAnnouncementStatus($id, $status) {

        $today = Date::getToday();
        $data = [&$today, &$this->info['Post_Time'], &$status, &$this->info[0], &$id];
        $this->db->prepare_Stmt('UPDATE 
                                    tbl_hrm_announcements 
                                SET 
                                    Announcement_DateCreated = ?,
                                    Post_Time= ?,
                                    Announcement_Status= ?, 
                                    Logged_ID = ?
                                WHERE 
                                    Announcement_ID= ?', $data);
        $error = $this->db->error();

        return array_unique($error);
    }

    public function deleteAnnouncement($id) {
        $data = [&$id];
        $this->db->prepare_Stmt('DELETE FROM tbl_hrm_announcements WHERE Announcement_ID=?', $data);
        $error = $this->db->error();
        return array_unique($error);
    }

    public function sendmail_SystemAdmin($Title) {
        require dirname(__FILE__) . '/../../libs/Mail/class.phpmailer.php';
        require dirname(__FILE__) . '/../../libs/Mail/class.smtp.php';




        $receivers = User::getDepartmentAdmins(smc_session()['user_details']['Branch_ID']);
//        $receivers = $this->db->query('SELECT 
//                                            e.Employee_FirstName,
//                                            e.Employee_LastName,
//                                            e.Employee_Email
//                                        FROM 
//                                            tbl_hrm_employee e
//                                        LEFT JOIN 
//                                            tbl_common_users  u
//                                        ON
//                                            e.Employee_ID = u.Employee_ID
//                                        WHERE 
//                                          u.Role_ID = 1
//                                        AND 
//                                            u.Status_ID = 1
//                                        AND 
//                                            e.Status_ID = 1
//        ');
        $receipientsEmails = array();
        $receipientsNames = array();
        foreach ($receivers as $k => $receiver) {

            $ReceiverEmail = $receiver['Employee_Email'];
            $ReceiverName = $receiver['Employee_Name'];
            array_push($receipientsEmails, $ReceiverEmail);
            array_push($receipientsNames, $ReceiverName);
        }
        $BodyHTML = "Dear Mr./Ms.<br/><br/>
                                A new Announcement has been created ,Please Check it.<br/><br/>
                                Thank You.<br/><br/>";
        $BodyText = str_replace("<br/><br/>", "\n\n", $BodyHTML);
//echo '<pre>';
        $sentEmail = SendEmail(['System@trustotech.com', 'Admin'], $receipientsEmails, [], [], $Title, $BodyHTML, $BodyText);

        if ($sentEmail)
            return true;
        else
            return false;
    }

    public function sendmail_ToAllEmployee($Announce_ID, $loggingID) {
        require dirname(__FILE__) . '/../../libs/Mail/class.phpmailer.php';
        require dirname(__FILE__) . '/../../libs/Mail/class.smtp.php';



        $Annouce = $this->db->query('SELECT
                                        *
                                     FROM
                                        tbl_hrm_announcements
                                    WHERE
                                         Announcement_ID     =   "' . $Announce_ID . '"
                                   ');
        foreach ($Annouce as $announce) {
            $Title = $announce['Announcement_Title'];
            $Status = $announce['Announcement_Status'];
            $Type = $announce['Announcement_Type'];
            $Branch_ID = empty($announce['Branch_ID']) ? null : $announce['Branch_ID'];
            $Employee_ID = empty($announce['Employee_ID']) ? null : $announce['Employee_ID'];
            $Content = html_entity_decode($announce['Announcement_Content']);
        }


        $users = $this->db->query('SELECT 
                                    e.Employee_FirstName,
                                    e.Employee_LastName,
                                    e.Employee_Email
                                    FROM 
                                    tbl_hrm_employee e
                                    LEFT JOIN 
                                    tbl_common_users  u
                                    ON
                                    e.Employee_ID = u.Employee_ID
                                    WHERE 
                                    User_ID = "' . $loggingID . '"
                                    AND 
                                    u.Status_ID = 1
                                    AND 
                                    e.Status_ID = 1
                                    ');

        foreach ($users as $user) {
            $UserEmail = $user['Employee_Email'];
            $UserName = $user['Employee_FirstName'] . ' ' . $user['Employee_LastName'];
        }
        if ($Type == 1) {

            $receivers = $this->db->query('SELECT 
                                    e.Employee_FirstName,
                                    e.Employee_LastName,
                                    e.Employee_Email
                                    FROM 
                                    tbl_hrm_employee e

                                    WHERE 

                                    e.Status_ID = 1
        ');
        }
        if ($Type == 3) {
            $receivers = $this->db->query('SELECT 
                                    e.Employee_FirstName,
                                    e.Employee_LastName,
                                    e.Employee_Email
                                    FROM 
                                    tbl_hrm_employee e

                                    WHERE 
                                  e.Employee_ID IN (' . $Employee_ID . ')
                                  and
                                    e.Status_ID = 1
        ');
        } if ($Type == 2) {
            $receivers = $this->db->query('SELECT 
                                    e.Employee_FirstName,
                                    e.Employee_LastName,
                                    e.Employee_Email
                                    FROM 
                                    tbl_hrm_employee e

                                    WHERE 
                                    e.Branch_ID IN (' . $Branch_ID . ')
                                    and e.Status_ID = 1 
            ');
        }

        $receipientsEmails = array();
        $receipientsNames = array();

        foreach ($receivers as $receiver) {
            $ReceiverEmail = $receiver['Employee_Email'];
            $ReceiverName = $receiver['Employee_FirstName'] . ' ' . $receiver['Employee_LastName'];
            array_push($receipientsEmails, $ReceiverEmail);
            array_push($receipientsNames, $ReceiverName);
        }
        $receipients = $receipientsEmails;



        $ccMails = [];
        $bccMails = [];
        if ($Status == 1) {
            $Subject = $Title;
            $BodyHTML = "Dear All ,<br/><br/>" . $Content . "
                                <br/><br/>
                                Thank You.<br/><br/>";
            $BodyText = str_replace("<br/><br/>", "\n\n", $BodyHTML);
        } else {
            $Subject = "Urgent " . $Title . " was canceled";
            $BodyHTML = "Dear All ,<br/><br/>
                                This Announncement " . $Content . " is canceled
                                <br/><br/>
                                Thank You.<br/><br/>";
            $BodyText = str_replace("<br/><br/>", "\n\n", $BodyHTML);
        }

        $sentEmail = SendEmail([$UserEmail, $UserName], $receipients, $ccMails, $bccMails, $Subject, $BodyHTML, $BodyText);
        if (!$sentEmail)
            return false;
        return true;
    }

    public function createAssignLeave() {
        $data = [&$this->info['AssignLeave_Reason'],
            &$this->info['AssignLeave_From_Date'],
            &$this->info['AssignLeave_To_Date'],
            &$this->info['AssignLeave_Start_Time'],
            &$this->info['AssignLeave_End_Time'],
            &$this->info['Employee_ID'],
            &$this->info[0]
        ];

        $this->db->prepare_Stmt('INSERT INTO 
                                    tbl_hrm_leave (
                                                    AssignLeave_Reason,
                                                    AssignLeave_From_Date,
                                                    AssignLeave_To_Date,
                                                    AssignLeave_Start_Time,
                                                    AssignLeave_End_Time,
                                                    Employee_ID,
                                                    Logged_ID)VALUES (?,?,?,?,?,?,?)', $data);
        $error = $this->db->error();
        if (empty($error))
            return true;
        return false;
    }

    public function viewAllAssignLeave() {
        $data = array();

        $query = $this->db->query('SELECT 
                                    l.*,
                                    CONCAT (l.AssignLeave_Start_Time,"##",l.AssignLeave_End_Time) AS LeaveTime,
                                    CONCAT(e.Employee_FirstName, " ", e.Employee_MiddleName, " ", e.Employee_LastName) AS Employee_Name

                                FROM
                                    tbl_hrm_leave l
                                LEFT JOIN
                                    tbl_hrm_employee e
                                ON
                                    l.Employee_ID = e.Employee_ID
                              ');


        while ($row = $this->db->assoc($query)) {
            $data[] = $row;
        }
        return $data;
    }

    public function updateAssignLeave($id, $what) {
        $data = [&$what["AssignLeave_Reason"],
            &$what["AssignLeave_From_Date"],
            &$what["AssignLeave_To_Date"],
            &$what["AssignLeave_Start_Time"],
            &$what["AssignLeave_End_Time"],
            &$what["LeaveRequest_Status"],
            &$id
        ];
        $query = $this->db->query("Update 
                                        tbl_hrm_leave 
                                   SET
                                        AssignLeave_Reason= ?,
                                        AssignLeave_From_Date= ?,
                                        AssignLeave_To_Date= ?,
                                        AssignLeave_Start_Time= ?,
                                        AssignLeave_End_Time= ?,
                                        LeaveRequest_Status= ?
                                   WHERE 
                                        Leave_ID = ?", $data);
        $error = $this->db->error();
        if (empty($error))
            return true;
        return false;
    }

    public function updateAssignLeaveStatus($Leave_ID, $Status) {
        $this->db->prepare_Stmt("Update tbl_hrm_leave SET LeaveRequest_Status=? WHERE Leave_ID=?", [&$Status, &$Leave_ID]);
        $error = $this->db->error();
        if (empty($error))
            return true;
        return false;
    }

    public function GetStatuses() {
        return array("Planned", "Declined", "Approved", "Done", "Deleted");
    }

    public function getEmployee() {

        $date = array();
        $query = $this->db->query('SELECT 
                                    Employee_ID,
                                    CONCAT(Employee_FirstName," ",Employee_MiddleName,"",Employee_LastName) AS Employee_Name       
                                  FROM      
                                    tbl_hrm_employee
                                  WHERE 
                                    Status_ID = 1 

                                ');

        while ($row = $this->db->assoc($query)) {
            $data[] = $row;
        }
        return $data;
    }

    public function viewLeaveByID($id) {
        $data = array();

        $query = $this->db->query('SELECT 
                                    l.*,
                                    CONCAT(e.Employee_FirstName, " ", e.Employee_MiddleName, " ", e.Employee_LastName) AS Employee_Name

                                FROM
                                    tbl_hrm_leave l
                                LEFT JOIN
                                    tbl_hrm_employee e
                                ON
                                    l.Employee_ID = e.Employee_ID
                                WHERE
                                    l.Leave_ID = "' . $id . '"
                              ');


        while ($row = $this->db->assoc($query)) {
            $data[] = $row;
        }
        return $data;
    }

    public function EditAssignLeave() {
        $data = [&$this->info['AssignLeave_Reason'],
            &$this->info['AssignLeave_From_Date'],
            &$this->info['AssignLeave_To_Date'],
            &$this->info['AssignLeave_Start_Time'],
            &$this->info['AssignLeave_End_Time'],
            &$this->info['Employee_ID'],
            &$this->info[0],
            &$this->info['LeaveRequest_Status'],
            &$this->info['Leave_ID']
        ];
        $this->db->prepare_Stmt(' UPDATE 
                                        tbl_hrm_leave
                                    SET 
                                        AssignLeave_Reason       = ?,
                                        AssignLeave_From_Date    = ?,
                                        AssignLeave_To_Date      = ?,
                                        AssignLeave_Start_Time   = ?,
                                        AssignLeave_End_Time     = ?,
                                        Employee_ID              = ?,
                                        Logged_ID                = ?,
                                        LeaveRequest_Status      = ?
                                    WHERE
                                        Leave_ID                 = ?', $data);
        $error = $this->db->error();
        if (empty($error))
            return true;
        return false;
    }

    public function updateLeaveStatus() {
        $today = Date::getToday();
        $data = [&$today];
        $query = $this->db->query('UPDATE 
                                       tbl_hrm_leave
                                    SET 
                                        LeaveRequest_Status = 3
                                    WHERE 
                                        AssignLeave_To_Date < ?
                                    AND 
                                        LeaveRequest_Status = 2', $data);
        $error = $this->db->error();
        if (empty($error))
            return true;
        return false;
    }

    public function checkExistLeave($is_hidden = false) {
        $branch = $this->db->query('SELECT Branch_ID FROM tbl_hrm_employee WHERE Employee_ID ="' . $this->info['Employee_ID'] . '"');
        $row = $this->db->assoc($branch);
        $branch_id = $row['Branch_ID'];
        $data = array();
        $condition = '';
        if (!$is_hidden)
            $condition .= ' AND e.Is_Hidden = 0 ';
        $check = $this->db->query('SELECT 
                                            l.*,
                                            CONCAT(e.Employee_FirstName," ",e.Employee_FirstName," ",e.Employee_FirstName) AS Employee_Name

                                        FROM 
                                            tbl_hrm_leave l
                                        LEFT JOIN  
                                            tbl_hrm_employee e
                                        ON
                                            e.Employee_ID = l.Employee_ID
                                        WHERE
                                            e.Branch_ID = "' . $branch_id . '"
                                        AND 
                                            l.AssignLeave_From_Date <= "' . $this->info['AssignLeave_From_Date'] . '"
                                        AND 
                                            l.AssignLeave_Start_Time <= "' . $this->info['AssignLeave_Start_Time'] . '"
                                        AND 
                                            l.AssignLeave_To_Date <= "' . $this->info['AssignLeave_To_Date'] . '"
                                        AND 
                                            l.AssignLeave_End_Time <= "' . $this->info['AssignLeave_End_Time'] . '"
                                        AND 
                                            l.AssignLeave_To_Date >= "' . $this->info['AssignLeave_From_Date'] . '"
                                        AND 
                                            l.AssignLeave_End_Time >= "' . $this->info['AssignLeave_Start_Time'] . '"

                                    ' . $condition);
        while ($row_Check = $this->db->assoc($check))
            $data[] = $row_Check;
        if (count($data) > 0)
            return $data;
        else
            return self::createAssignLeave();
    }

    public static function viewNotification() {
        if (empty(smc_session()['user_logged_id']))
            return 0;
        $emp_id = smc_session()['user_logged_id'];
        $db = DBConnectorFactory::loadDriver();
        $query = $db->prepare_Stmt('select count(*) as total from tbl_emp_tasks where task_status = 0 and employee_id = ? ', [$emp_id]);
        $row = $db->assoc($query);
        return $row['total'];
    }

    public function updateStatusTask($task_status, $task_id) {
//          die('hereee');
        $this->db->prepare_Stmt('update tbl_emp_tasks set task_status = ? where task_id = ? ', [&$task_status, &$task_id]);
        $error = $this->db->error();
//        die(print_r($error));
        return array_unique($error);
    }

    public function doneStatusTask($task_id) {
        $date_done = date('Y-m-d');
        $this->db->prepare_Stmt('update tbl_emp_tasks set task_status = 2,date_done = ? where task_id = ? ', [&$date_done, &$task_id]);
        $error = $this->db->error();
        return array_unique($error);
    }

    public function getNtfDetails($main_id, $main_type) {
        $data = array();
        if ($main_type == 'tr')
            $query = $this->db->prepare_Stmt('SELECT  `schd_date` as date_set , `schd_from_time` as  from_time , `schd_to_time` as to_time FROM `tbl_schdl_training_dtl` where `schdl_id` = ?', [&$main_id]);
        if ($main_type == 'exam')
            $query = $this->db->prepare_Stmt('SELECT  `exam_date` as date_set , `exam_from_time` as  from_time, `exam_to_time`as to_time FROM `tbl_exam_schedule` where `exam_schld_id` = ?', [&$main_id]);
        if ($main_type == 'doc')
            $query = $this->db->prepare_Stmt('SELECT  `document_upload_date` as date_set , concat(`document_title`,"-",document_description) as  from_time, `document_upload_name`as to_time FROM `tbl_documentation_document` where `document_id` = ?', [&$main_id]);

        while ($row = $this->db->assoc($query)) {
            $data[] = $row;
        }
        return $data;
    }

}
