Exemplo n.º 1
0
 public function reporting_notification()
 {
     $deadline = date('Y-m-10');
     $today = date('Y-m-d');
     $notification_days = 10;
     $notification = "";
     $message = "";
     $notification_link = site_url('order/satellites_reported');
     //get reporting satellites
     $start_date = date('Y-m-01', strtotime("-1 month"));
     $facility_code = $this->session->userdata("facility");
     $central_site = Sync_Facility::getId($facility_code, 0);
     $central_site = $central_site['id'];
     $sql = "SELECT \n\t\t            sf.name as facility_name,\n\t\t            sf.code as facility_code,\n\t\t            IF(c.id,'reported','not reported') as status\n\t\t        FROM sync_facility sf\n\t\t        LEFT JOIN cdrr c ON c.facility_id=sf.id AND c.period_begin='{$start_date}' \n\t\t        WHERE sf.parent_id='{$central_site}'\n\t\t        AND sf.category LIKE '%satellite%'\n\t\t        AND sf.name NOT LIKE '%dispensing%'\n\t\t        GROUP BY sf.id";
     $query = $this->db->query($sql);
     $satellites = $query->result_array();
     if ($satellites) {
         if ($deadline > $today) {
             $diff = abs(strtotime($deadline) - strtotime($today));
             $years = floor($diff / (365 * 60 * 60 * 24));
             $months = floor(($diff - $years * 365 * 60 * 60 * 24) / (30 * 60 * 60 * 24));
             $period = floor(($diff - $years * 365 * 60 * 60 * 24 - $months * 30 * 60 * 60 * 24) / (60 * 60 * 24));
             if ($notification_days >= $period) {
                 $notification = "<li><a href='" . $notification_link . "'><i class='icon-th'></i>Reporting Deadline<div class='badge badge-important'>" . $period . " days</div></a><li>";
             }
         }
     }
     echo $notification;
 }
Exemplo n.º 2
0
 public function satellites_reported()
 {
     $start_date = date('Y-m-01', strtotime("-1 month"));
     $facility_code = $this->session->userdata("facility");
     $central_site = Sync_Facility::getId($facility_code, $this->facility_type);
     $central_site = $central_site['id'];
     $notification = "";
     $sql = "SELECT sf.name as facility_name,sf.code as facility_code,IF(c.id,'reported','not reported') as status\n\t\t        FROM sync_facility sf\n\t\t        LEFT JOIN cdrr c ON c.facility_id=sf.id AND c.period_begin='{$start_date}' \n\t\t        WHERE sf.parent_id='{$central_site}'\n\t\t        AND sf.category LIKE '%satellite%'\n\t\t        AND sf.name NOT LIKE '%dispensing%'\n\t\t        GROUP BY sf.id";
     $query = $this->db->query($sql);
     $satellites = $query->result_array();
     $notification .= "<table class='dataTables table table-bordered table-hover'>";
     $notification .= "<thead><tr><th>Name</th><th>Code</th><th>Status</th></tr></thead><tbody>";
     if ($satellites) {
         foreach ($satellites as $satellite) {
             //echo "<pre>";print_r($satellite);die;
             if ($satellite['status'] == "reported") {
                 $satellite['status'] = "<div class='alert-success'>" . $satellite['status'] . "</div>";
             } else {
                 $satellite['status'] = "<div class='alert-danger'>" . $satellite['status'] . "</div>";
             }
             $notification .= "<tr><td>" . $satellite['facility_name'] . "</td><td>" . $satellite['facility_code'] . "</td><td>" . $satellite['status'] . "</td></tr>";
         }
     }
     $notification .= "</tbody></table>";
     $data['notification_table'] = $notification;
     $data['content_view'] = "satellite_reported_v";
     $data['page_title'] = "my Orders";
     $data['banner_text'] = "Satellites Reported";
     $this->base_params($data);
 }
Exemplo n.º 3
0
 public function update_reporting()
 {
     $deadline = date('Y-m-10');
     $today = date('Y-m-d');
     $notification_days = 10;
     $notification = "";
     $message = "";
     $notification_link = site_url('order');
     if ($deadline > $today) {
         $diff = abs(strtotime($deadline) - strtotime($today));
         $years = floor($diff / (365 * 60 * 60 * 24));
         $months = floor(($diff - $years * 365 * 60 * 60 * 24) / (30 * 60 * 60 * 24));
         $period = floor(($diff - $years * 365 * 60 * 60 * 24 - $months * 30 * 60 * 60 * 24) / (60 * 60 * 24));
         if ($notification_days >= $period) {
             $notification = "Dear webADT User,<br/>";
             $notification .= "The order reporting deadline is in " . $period . " days.<br/>";
             $notification .= "The Satellites List is below: <br/>";
         }
         //get reporting satellites
         $start_date = date('Y-m-01', strtotime("-1 month"));
         $facility_code = $this->session->userdata("facility");
         $central_site = Sync_Facility::getId($facility_code, 0);
         $central_site = $central_site['id'];
         $sql = "SELECT sf.name as facility_name,sf.code as facility_code,IF(c.id,'reported','not reported') as status\n\t\t\t        FROM sync_facility sf\n\t\t\t        LEFT JOIN cdrr c ON c.facility_id=sf.id AND c.period_begin='{$start_date}' \n\t\t\t        WHERE sf.parent_id='{$central_site}'\n\t\t\t        AND sf.category LIKE '%satellite%'\n\t\t\t        AND sf.name NOT LIKE '%dispensing%'\n\t\t\t        GROUP BY sf.id";
         $query = $this->db->query($sql);
         $satellites = $query->result_array();
         $notification .= "<table border='1'>";
         $notification .= "<thead><tr><th>Name</th><th>Code</th><th>Status</th></tr></thead><tbody>";
         if ($satellites) {
             foreach ($satellites as $satellite) {
                 $notification .= "<tr><td>" . $satellite['facility_name'] . "</td><td>" . $satellite['facility_code'] . "</td><td>" . $satellite['status'] . "</td></tr>";
             }
         }
         $notification .= "</tbody></table>";
         //send notification via email
         ini_set("SMTP", "ssl://smtp.gmail.com");
         ini_set("smtp_port", "465");
         $sql = "SELECT DISTINCT(Email_Address) as email \n\t\t\t        FROM users u\n\t\t\t        LEFT JOIN access_level al ON al.id=u.Access_Level\n\t\t\t        WHERE al.Level_Name LIKE '%facility%' \n                    AND u.Facility_Code = '{$facility_code}'\n\t\t\t        AND Email_Address !=''\n\t\t\t        AND Email_Address !='*****@*****.**'";
         $query = $this->db->query($sql);
         $emails = $query->result_array();
         if ($emails) {
             foreach ($emails as $email) {
                 $mail_list[] = $email['email'];
             }
         }
         if (!empty($mail_list)) {
             $mail_list = implode(",", $mail_list);
             $config['mailtype'] = "html";
             $config['protocol'] = 'smtp';
             $config['smtp_host'] = 'ssl://smtp.googlemail.com';
             $config['smtp_port'] = 465;
             $config['smtp_user'] = stripslashes('*****@*****.**');
             $config['smtp_pass'] = stripslashes('WebAdt_052013');
             $this->load->library('email', $config);
             $this->email->set_newline("\r\n");
             $this->email->from('*****@*****.**', "WEB_ADT CHAI");
             $this->email->to("{$mail_list}");
             $this->email->subject("ORDER REPORTING NOTIFICATION");
             $this->email->message("{$notification}");
             if ($this->email->send()) {
                 $message = 'Reporting Notification was sent!<br/>';
                 $this->email->clear(TRUE);
             } else {
                 $message = 'Reporting Notification Failed!<br/>';
             }
         }
     }
     return $message;
 }