public function stock_out_sms() { $stock_outs = Facility_stocks::get_stock_outs_sms(); $total_stock_outs = count($stock_outs); if ($total_stock_outs > 0) { $total_facilitites = count($stock_outs); $total_commodities = ""; foreach ($stock_outs as $stock_outs_) { $facility_code = $stock_outs_['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)) { $total_subcounties = count($data['']); foreach ($data as $users) { $user_type = $users['usertype_id']; switch ($user_type) { //Facility Admin case 2: $message = $stock_outs_['total'] . " commodities are out of stock."; break; //Sub County Head //Sub County Head case 3: $message = $total_facilitites . " facilities have a total number of " . $total_stock_outs . " stock outs."; break; //County Head //County Head case 10: $message = "There are " . $total_stock_outs . " stock outs in the county"; break; //For test purposes only //For test purposes only case 5: $message = "To Me"; 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 Stock Outs } }