Exemple #1
0
 public function get_county_facility_mapping_ajax_request($option = null)
 {
     //$district_id = $this -> session -> userdata('district_id');
     $county_id = $this->session->userdata('county_id');
     //echo $county_id;
     $district_data = districts::getDistrict($county_id);
     $table_data = "<tbody>";
     $table_data_summary = "<tbody>";
     $district_names = "<thead><tr><th>Monthly Activities</th>";
     //Total number of facilities using HCMP in the district
     $district_total = array();
     //Total number of facilities in the district
     $district_total_facilities = array();
     //Total number of facilities targetted in the district
     $district_total_facilities_targetted = array();
     $district_total_facilities_using_hcmp = array();
     $table_district_totals = "";
     $all_facilities = 0;
     $total_using_hcmp = 0;
     $total_facility_list = '';
     $total_facilities_in_county = 0;
     $total_facilities_targetted = 0;
     $percentage_coverage = "";
     $percentage_coverage_total = 0;
     $percentage_coverage_using = "";
     $percentage_coverage_total_using = 0;
     $get_dates_facility_went_online = facilities::get_dates_facility_went_online($county_id);
     foreach ($get_dates_facility_went_online as $facility_dates) {
         $monthly_total = 0;
         $date = $facility_dates['date_when_facility_went_online'];
         $table_data .= "<tr>\n\t    <td>" . $date . "</td>";
         foreach ($district_data as $district_detail) {
             $district_id = $district_detail->id;
             $district_name = $district_detail->district;
             $get_facilities_which_went_online_ = facilities::get_facilities_which_went_online_($district_id, $facility_dates['date_when_facility_went_online']);
             $total = $get_facilities_which_went_online_[0]['total'];
             $total_facilities = $get_facilities_which_went_online_[0]['total_facilities'];
             $total_facilities_targetted = $get_facilities_which_went_online_[0]['total_facilities_targetted'];
             $total_facilitites_using_hcmp = $get_facilities_which_went_online_[0]['total_using_hcmp'];
             $monthly_total = $monthly_total + $total;
             $all_facilities = $all_facilities + $total;
             array_key_exists($district_name, $district_total) ? $district_total[$district_name] = $district_total[$district_name] + $total : ($district_total = array_merge($district_total, array($district_name => $total)));
             array_key_exists($district_name, $district_total_facilities) ? $district_total_facilities[$district_name] = $total_facilities : ($district_total_facilities = array_merge($district_total_facilities, array($district_name => $total_facilities)));
             array_key_exists($district_name, $district_total_facilities_targetted) ? $district_total_facilities_targetted[$district_name] = $total_facilities_targetted : ($district_total_facilities_targetted = array_merge($district_total_facilities_targetted, array($district_name => $total_facilities_targetted)));
             array_key_exists($district_name, $district_total_facilities_using_hcmp) ? $district_total_facilities_using_hcmp[$district_name] = $total_facilitites_using_hcmp : ($district_total_facilities_using_hcmp = array_merge($district_total_facilities_using_hcmp, array($district_name => $total_facilitites_using_hcmp)));
             $table_data .= $total > 0 ? "<td><a href='#' id='{$district_id}' class='ajax_call2 link' date='{$date}'> {$total}</a></td>" : "<td>{$total}</td>";
         }
         $table_data .= "<td>{$monthly_total}</td></tr>";
     }
     $table_data .= "<tr>";
     $table_data_summary .= "<tr>";
     $checker = 1;
     foreach ($district_total as $key => $value) {
         $coverage = 0;
         $using = 0;
         @($coverage = round($value / $district_total_facilities[$key] * 100, 1));
         @($using_percentage = round($district_total_facilities_targetted[$key] / $value * 100, 1));
         $percentage_coverage_total = $percentage_coverage_total + $coverage;
         $percentage_coverage_total_using = $percentage_coverage_total_using + $using_percentage;
         $district_names .= "<th>{$key}</th>";
         $total_facility_list .= $checker == 1 ? "<tr><td><b>TOTAL: Facilities in District</b></td><td>{$district_total_facilities[$key]}</td>" : "<td>{$district_total_facilities[$key]}</td>";
         $table_data .= $checker == 1 ? "<td><b>TOTAL: Facilities using HCMP</b></td><td>{$value}</td>" : "<td>{$value}</td>";
         $table_summary .= $checker == 1 ? "<td><b>TOTAL: Facilities using HCMP</b></td><td>{$value}</td>" : "<td>{$value}</td>";
         $total_targetted_facility_list .= $checker == 1 ? "<tr><td><b>TOTAL: Targetted Facilities in District</b></td><td>{$district_total_facilities_targetted[$key]}</td>" : "<td>{$district_total_facilities_targetted[$key]}</td>";
         $total_facilities_in_county = $total_facilities_in_county + $district_total_facilities[$key];
         $targetted_total = $targetted_total + $district_total_facilities_targetted[$key];
         $total_using_hcmp = $total_using_hcmp + $district_total_facilities_using_hcmp[$key];
         @($targetted_vs_using_hcmp = round($total_facilitites_using_hcmp / $total_facilities_targetted * 100, 1));
         @($final_coverage_total = round($all_facilities / $total_facilities_in_county * 100, 1));
         $percentage_coverage_using .= $checker == 1 ? "<tr><td><b>TOTAL: Targetted vs Using HCMP%</b></td>\n\t\t\t<td>{$targetted_vs_using_hcmp} %</td>" : "<td>{$using_percentage} %</td>";
         $percentage_coverage .= $checker == 1 ? "<tr><td><b>% Coverage</b></td>\n\t\t\t<td>{$coverage} %</td>" : "<td>{$coverage} %</td>";
         $checker++;
     }
     $table_data .= "<td><a href='#' id='total' class='ajax_call1 link' option='total' date='total'>{$all_facilities}</a></td></tr></tbody>";
     $table_data_summary .= "<td><a href='#' id='total' class='ajax_call2 link' date='total'>{$all_facilities}</a></td></tr></tbody>";
     $table_datas_summary .= "<td><a href='#' id='total' class='ajax_call1 link' date='total'>{$all_facilities}</a></td>";
     $district_names .= "<th>TOTAL</th></tr></thead>";
     $final_coverage_total = 0;
     $targetted_vs_using_hcmp = 0;
     @($final_coverage_total = round($all_facilities / $total_facilities_in_county * 100, 1));
     @($targetted_vs_using_hcmp = round($targetted_total / $all_facilities * 100, 1));
     $data_ = "\n\t\t<div class='tabbable tabs-left'>\n\t\t<div class='tab-content'>\n        <ul class='nav nav-tabs'>\n        <li class='active'><a href='#A' data-toggle='tab'>Monthly Break Down</a></li>\n        <li class=><a href='#B' data-toggle='tab'>Roll out Summary</a></li>\n        </ul>\n         <div  id='A' class='tab-pane fade active in'>\n\t\t\t<table class='row-fluid table table-hover table-bordered table-update' width='80%' id='test1'>" . $district_names . $table_data . $total_facility_list . "<td>{$total_facilities_in_county}</td></tr>" . $total_targetted_facility_list . "<td>{$targetted_total}</td>" . $percentage_coverage . "<td>{$final_coverage_total} %</td></tr>" . $percentage_coverage_using . "<td>{$targetted_vs_using_hcmp} %</td></tr>\n\t\t\t</table>\n\t\t</div>\n\t\t\n\t\t<div id='B' class='tab-pane fade' >\n\t\t<table class='row-fluid table table-hover table-bordered table-update' width='80%' id='test2'>" . $district_names . $table_summary . $table_datas_summary . $total_facility_list . "<td>{$total_facilities_in_county}</td></tr>" . $total_targetted_facility_list . "<td>{$targetted_total}</td>" . $percentage_coverage . "<td>{$final_coverage_total} %</td></tr>" . $percentage_coverage_using . "<td>{$targetted_vs_using_hcmp} %</td></tr></table>\n\t\t </div>\n\t\t </div>";
     if (isset($option)) {
         return $data_;
     } else {
         echo $data_;
     }
 }
Exemple #2
0
 public function get_sub_county_facility_mapping_data($year = null, $month = NULL)
 {
     /*$year = (isset($year) && ($year > 0)) ? $year : date("Y");
     	 $month = (isset($month) && ($month > 0)) ? $month : date("m");
     	 $identifier = $this -> session -> userdata('user_indicator');
     	 $county_id = $this -> session -> userdata('county_id');
     	 //Get facility code
     	 $facility_code = $this -> session -> userdata('facility_id');
     	 $facility_code_ = (isset($facility_code) && ($facility_code > 0)) ? facilities::get_facility_name_($facility_code) -> toArray() : null;
     	 $facility_name = $facility_code_[0]['facility_name'];
     	 $district_id = $this -> session -> userdata('district_id');
     	 $district = $this -> session -> userdata('district_id');
     	 //Get the name of the county
     	 $county_name = Counties::get_county_name($county_id);
     	 $county_name = $county_name;
     	 //get the name of the district
     	 $district_name_ = (isset($district_id) && ($district_id > 0)) ? Districts::get_district_name_($district_id) : null;
     	 $district_name = $district_name_['district'];
     	 $first_day_of_the_month = date("Y-m-1", strtotime(date($year . "-" . $month)));
     	 $last_day_of_the_month = date("Y-m-t", strtotime(date($year . "-" . $month)));
     	 $date_1 = new DateTime($first_day_of_the_month);
     	 $date_2 = new DateTime($last_day_of_the_month);
     	 $facility_data = Facilities::get_Facilities_using_HCMP($county_id, $district);
     	 $series_data = array();
     	 $category_data = array();
     	 $series_data_monthly = array();
     	 $category_data_monthly = array();
     	 $seconds_diff = strtotime($last_day_of_the_month) - strtotime($first_day_of_the_month);
     	 $date_diff = floor($seconds_diff / 3600 / 24);
     	 switch ($identifier) :
     	 case 'county' :
     	 $graph_category_data = $facility_data;
     	 $graph_title = $county_name['county'] . " County ";
     	 break;
     	 case 'facility_admin' :
     	 case 'facility' :
     	 $graph_category_data = $facility_data;
     	 $graph_title = $facility_name;
     	 break;
     	 case 'district' :
     	 $graph_category_data = $facility_data;
     	 $graph_title = $district_name . " SubCounty ";
     	 break;
     	 endswitch;
     	 for ($i = 0; $i <= $date_diff; $i++) :
     	 $day = 1 + $i;
     	 $new_date = "$year-$month-" . $day;
     	 $new_date = date('Y-m-d', strtotime($new_date));
     	 if (date('N', strtotime($new_date)) < 6) {
     	 $date_ = date('D d', strtotime($new_date));
     	 $category_data = array_merge($category_data, array($date_));
     	 $temp_1 = array();
     	 foreach ($graph_category_data as $facility_) :
     	 $facility_id = $facility_ -> facility_code;
     	 $facility_name = $facility_ -> facility_name;
     	 $subcounty_data = Log::get_subcounty_login_count($county_id, $district_id, $facility_id, $new_date);
     	 (array_key_exists($facility_name, $series_data)) ? $series_data[$facility_name] = array_merge($series_data[$facility_name], array((int)$subcounty_data[0]['total'])) : $series_data = array_merge($series_data, array($facility_name => array((int)$subcounty_data[0]['total'])));
     	 endforeach;
     	 } else {
     	 // do nothing
     	 }
     	 endfor;
     	 //for setting the month name in the graph when filtering
     	 $m = date('F', strtotime('2000-' . $month . '-01'));
     	 $graph_data_daily = array();
     	 $graph_data_daily = array_merge($graph_data_daily, array("graph_id" => 'container'));
     	 $graph_data_daily = array_merge($graph_data_daily, array("graph_title" => 'Daily Facility Access log for ' . $m . " for " . $graph_title));
     	 $graph_data_daily = array_merge($graph_data_daily, array("graph_type" => 'line'));
     	 $graph_data_daily = array_merge($graph_data_daily, array("graph_yaxis_title" => 'log In'));
     	 $graph_data_daily = array_merge($graph_data_daily, array("graph_categories" => array()));
     	 $graph_data_daily = array_merge($graph_data_daily, array("series_data" => $series_data));
     	 $graph_data_daily['graph_categories'] = $category_data;
     	 $graph_daily = $this -> hcmp_functions -> create_high_chart_graph($graph_data_daily);
     	 for ($i = 0; $i < 12; $i++) :
     	 $day = 1 + $i;
     	 //changed it to be a month
     	 $new_date = "$year-$day";
     	 $new_date = date('Y-m', strtotime($new_date));
     	 $date_ = date('M', strtotime($new_date));
     	 $category_data_monthly = array_merge($category_data_monthly, array($date_));
     	 foreach ($graph_category_data as $facility_) :
     	 $facility_id = $facility_ -> facility_code;
     	 $facility_name = $facility_ -> facility_name;
     	 $subcounty_data = Log::get_subcounty_login_monthly_count($county_id, $district_id, $facility_id, $new_date);
     	 (array_key_exists($facility_name, $series_data_monthly)) ? $series_data_monthly[$facility_name] = array_merge($series_data_monthly[$facility_name], array((int)$subcounty_data[0]['total'])) : $series_data_monthly = array_merge($series_data_monthly, array($facility_name => array((int)$subcounty_data[0]['total'])));
     	 endforeach;
     	 endfor;
     	 $graph_data = array();
     	 $graph_data = array_merge($graph_data, array("graph_id" => 'container_monthly'));
     	 $graph_data = array_merge($graph_data, array("graph_title" => 'Monthly Facility Access for ' . $year));
     	 $graph_data = array_merge($graph_data, array("graph_type" => 'line'));
     	 $graph_data = array_merge($graph_data, array("graph_yaxis_title" => 'log In'));
     	 $graph_data = array_merge($graph_data, array("graph_categories" => array()));
     	 $graph_data = array_merge($graph_data, array("series_data" => $series_data_monthly));
     	 $graph_data['graph_categories'] = $category_data_monthly;
     	 $graph_monthly = $this -> hcmp_functions -> create_high_chart_graph($graph_data);
     	 $graph_log_data = array();
     	 $graph_log_data = array_merge($graph_log_data, array("graph_id" => 'log_data_graph'));
     	 $graph_log_data = array_merge($graph_log_data, array("graph_title" => 'User Activity for  ' . $m . ' for ' . $graph_title));
     	 $graph_log_data = array_merge($graph_log_data, array("graph_type" => 'column'));
     	 $graph_log_data = array_merge($graph_log_data, array("graph_yaxis_title" => 'Frequency'));
     	 $graph_log_data = array_merge($graph_log_data, array("graph_categories" => array('Decommissions', 'Redistributions', 'Stock Updates', 'Orders', 'Issues', 'Log Ins')));
     	 $graph_log_data = array_merge($graph_log_data, array("series_data" => array('Total %' => array())));
     	 $log_data = Log::get_log_data($facility_code, $district_id, $county_id, $year, $month);
     	 $log_data_login_only = Log::get_login_only($facility_code, $district_id, $county_id, $year, $month);
     	 //echo "<pre>";print_r($facility_data);echo "</pre>";exit;
     	 foreach ($log_data as $log_data_) {
     	 $sum = $log_data_['user_log'] + $log_data_login_only[0]['total'];
     	 $issues = ($log_data_['total_issues'] / $sum) * 100;
     	 $orders = ($log_data_['total_orders'] / $sum) * 100;
     	 $decommissions = ($log_data_['total_decommisions'] / $sum) * 100;
     	 $redistributions = ($log_data_['total_redistributions'] / $sum) * 100;
     	 $stock = ($log_data_['total_stock_added'] / $sum) * 100;
     	 ;
     	 $user = ($log_data_login_only[0]['total'] / $sum) * 100;
     	 ;
     	 $temp = array((int)$decommissions, (int)$redistributions, (int)$stock, (int)$orders, (int)$issues, (int)$user);
     	 $graph_log_data['series_data']['Total %'] = array_merge($graph_log_data['series_data']['Total %'], $temp);
     	 }
     	 $graph_log = $this -> hcmp_functions -> create_high_chart_graph($graph_log_data);
     	 $data['graph_data_monthly'] = $graph_monthly;
     	 $data['graph_data_daily'] = $graph_daily;
     	 $data['graph_log'] = $graph_log;
     	 */
     $county_id = $this->session->userdata('county_id');
     $data['get_facility_data'] = facilities::get_facilities_online_per_district($county_id);
     $get_dates_facility_went_online = facilities::get_dates_facility_went_online($county_id);
     $data['data'] = $this->get_county_facility_mapping_ajax_request("on_load");
     if ($this->input->is_ajax_request()) {
         return $this->load->view('subcounty/ajax/facility_roll_out_at_a_glance_v', $data);
     } else {
         $data['title'] = "User Logs";
         $data['banner_text'] = "System Use Statistics";
         $data['report_view'] = "subcounty/ajax/facility_roll_out_at_a_glance_v";
         $data['sidebar'] = !$this->session->userdata('facility_id') ? "shared_files/report_templates/side_bar_sub_county_v" : "shared_files/report_templates/side_bar_v";
         $data['content_view'] = "facility/facility_reports/reports_v";
         $data['active_panel'] = !$this->session->userdata('facility_id') ? "system_usage" : "system_usage";
         $view = 'shared_files/template/template';
         $this->load->view($view, $data);
     }
 }
 public function get_county_facility_mapping_ajax_request($option = null)
 {
     $county_id = $this->session->userdata('county_id');
     $district_data = districts::getDistrict($county_id);
     $table_data = "<tbody>";
     $table_data_summary = "<tbody>";
     $district_names = "<thead><tr><th>Monthly Activities</th>";
     $district_total = array();
     $district_total_facilities = array();
     $table_district_totals = "";
     $all_facilities = 0;
     $total_facility_list = '';
     $total_facilities_in_county = 0;
     $percentage_coverage = "";
     $percentage_coverage_total = 0;
     $get_dates_facility_went_online = facilities::get_dates_facility_went_online($county_id);
     foreach ($get_dates_facility_went_online as $facility_dates) {
         $monthly_total = 0;
         $date = $facility_dates['date_when_facility_went_online'];
         $table_data .= "<tr>\n\t    <td>" . $date . "</td>";
         foreach ($district_data as $district_detail) {
             $district_id = $district_detail->id;
             $district_name = $district_detail->district;
             $get_facilities_which_went_online_ = facilities::get_facilities_which_went_online_($district_id, $facility_dates['date_when_facility_went_online']);
             $total = $get_facilities_which_went_online_[0]['total'];
             $total_facilities = $get_facilities_which_went_online_[0]['total_facilities'];
             $monthly_total = $monthly_total + $total;
             $all_facilities = $all_facilities + $total;
             array_key_exists($district_name, $district_total) ? $district_total[$district_name] = $district_total[$district_name] + $total : ($district_total = array_merge($district_total, array($district_name => $total)));
             array_key_exists($district_name, $district_total_facilities) ? $district_total_facilities[$district_name] = $total_facilities : ($district_total_facilities = array_merge($district_total_facilities, array($district_name => $total_facilities)));
             $table_data .= $total > 0 ? "<td><a href='#' id='{$district_id}' class='ajax_call_1 link' option='monthly' date='{$date}'> {$total}</a></td>" : "<td>{$total}</td>";
         }
         $table_data .= "<td>{$monthly_total}</td></tr>";
     }
     $table_data .= "<tr>";
     $table_data_summary .= "<tr>";
     $checker = 1;
     foreach ($district_total as $key => $value) {
         $coverage = 0;
         @($coverage = round($value / $district_total_facilities[$key] * 100, 1));
         $percentage_coverage_total = $percentage_coverage_total + $coverage;
         $district_names .= "<th>{$key}</th>";
         $table_data .= $checker == 1 ? "<td><b>TOTAL: Facilities using HCMP</b></td><td>{$value}</td>" : "<td>{$value}</td>";
         $table_data_summary .= $checker == 1 ? "<td><b>TOTAL: Facilities using HCMP</b></td><td>{$value}</td>" : "<td>{$value}</td>";
         $total_facility_list .= $checker == 1 ? "<tr><td><b>TOTAL: Facilities in District</b></td><td>{$district_total_facilities[$key]}</td>" : "<td>{$district_total_facilities[$key]}</td>";
         $total_facilities_in_county = $total_facilities_in_county + $district_total_facilities[$key];
         $percentage_coverage .= $checker == 1 ? "<tr><td><b>% Coverage</b></td><td>{$coverage} %</td>" : "<td>{$coverage} %</td>";
         $checker++;
     }
     $table_data .= "<td><a href='#' id='total' class='ajax_call_1 link' option='total' date='total'>{$all_facilities}</a></td></tr></tbody>";
     $table_data_summary .= "<td><a href='#' id='total' class='ajax_call_1 link' option='total' date='total'>{$all_facilities}</a></td></tr></tbody>";
     $district_names .= "<th>TOTAL</th></tr></thead>";
     $final_coverage_total = 0;
     @($final_coverage_total = round($all_facilities / $total_facilities_in_county * 100, 1));
     $data_ = "\n\t\t<div class='tabbable tabs-left'>\n\t\t<div class='tab-content'>\n        <ul class='nav nav-tabs'>\n        <li class=''><a href='#A' data-toggle='tab'><h3>Monthly Break Down</h3></a></li>\n        <li class='active'><a href='#B' data-toggle='tab'><h3>Roll out Summary</h3></a></li>\n        </ul>\n         <div class='tab-pane' id='A'>\n\t\t<table class='data-table' width='100%'>" . $district_names . $table_data . $total_facility_list . "<td>{$total_facilities_in_county}</td></tr>" . $percentage_coverage . "<td>{$final_coverage_total} %</td></tr></table>\n\t\t </div>\n\t\t <div class='tab-pane active' id='B'>\n\t\t <table class='data-table' width='100%'>" . $district_names . $table_data_summary . $total_facility_list . "<td>{$total_facilities_in_county}</td></tr>" . $percentage_coverage . "<td>{$final_coverage_total} %</td></tr></table>\n\t\t </div></div>";
     if (isset($option)) {
         return $data_;
     } else {
         echo $data_;
     }
 }