예제 #1
0
파일: sms.php 프로젝트: HCMPKenya/RTK_TEST
 public function check_potential_expiries()
 {
     $year = date("Y");
     $potential_expiries = Facility_stocks::get_potential_expiries_sms();
     $total_potential = count($potential_expiries);
     if ($total_potential > 0) {
         $total_facilitites = count($potential_expiries);
         $total_commodities = "";
         foreach ($potential_expiries as $potential) {
             $facility_code = $potential['facility_code'];
             $data = Users::getUsers($facility_code)->toArray();
             //Filter the array to remove empty sections of the array
             $data = array_filter($data);
             if (!empty($data)) {
                 foreach ($data as $users) {
                     $user_type = $users['usertype_id'];
                     switch ($user_type) {
                         //Facility Admin
                         case 2:
                             $message = $potential['total'] . " commodities will expire within 3 months. HCMP";
                             break;
                             //Sub County Head
                         //Sub County Head
                         case 3:
                             $message = $total_facilitites . " facilities have commodities that will expire within 3 months. HCMP";
                             break;
                             //County Head
                         //County Head
                         case 10:
                             $message = "There are " . $total_potential . " potential expiries in the county. HCMP";
                             break;
                             //For test purposes only
                         //For test purposes only
                         case 5:
                             $message = "Test SMS. HCMP";
                             break;
                     }
                     $phone = $this->get_facility_phone_numbers($facility_code);
                     $phone .= $this->get_ddp_phone_numbers($data[0]['district']);
                     $this->hcmp_functions->send_sms(substr($phone, 0, -1), $message);
                 }
             } else {
                 //DO Nothing
                 //Array is empty
             }
         }
     } else {
         //No Potential Expiries
     }
 }