public function get_county_facility_mapping_ajax_request($option = null) { //pick the county id from the session $county_id = $this->session->userdata('county_id'); //get the names and ids of the districts in the county $district_data = districts::getDistrict($county_id); //Start building the table with the data $table_data = "<tbody>"; //for the summary table $table_data_summary = "<tbody>"; //Holds the district names and months rolled out in a particular county $district_names = "<thead><tr><th>Sub County Roll Outs</th>"; $sub_county_names = "<thead><tr><th>Sub County</th>"; $monthly_district_names = $district_names; $monthly_sub_county_names = $sub_county_names; //Total number of facilities 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(); //total number of facilities using HCMP $district_total_facilities_using_hcmp = array(); //initialize the variables $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; foreach ($district_data as $district_detail) { $monthly_sub_county_names .= '<th>' . $district_detail->district . '</th>'; $monthly_district_names .= '<th>' . $district_detail->district . '</th>'; } //get the months and dates the facilities rolled out on HCMP $get_dates_facility_went_online = facilities::get_dates_facility_went_online_cleaned($county_id); $accordion = '<div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">'; $counter = 0; foreach ($get_dates_facility_went_online as $key => $value) { $counter++; $accordion .= '<div class="panel panel-default">'; $accordion .= '<div class="panel-heading" role="tab" id="heading_' . $counter . '">'; $accordion .= '<h4 class="panel-title"><a data-toggle="collapse" data-parent="#accordion" href="#collapse_' . $counter . '" aria-expanded="true" aria-controls="collapse_' . $counter . '">' . $key . '</a></h4>'; $accordion .= '</div>'; $accordion .= '<div id="collapse_' . $counter . '" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="heading_' . $counter . '">'; $accordion .= '<div class = "panel-body">'; $accordion .= '<table class = "table table-bordered table-hover">'; $accordion .= $monthly_district_names; $accordion .= '<th>Total</th></thead>'; foreach ($value as $k => $v) { //explode $v so that only the month is displayed $month = explode(" ", $v); $accordion .= '<tr><td>' . $month[0] . '</td>'; $monthly_total = 0; 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, $v); $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; $accordion .= '<td>'; $accordion .= $total > 0 ? '<a href="#"" id="' . $district_id . '" class="ajax_call2 link" date=' . $v . '>' . $total . '</a>' : $total; $accordion .= '</td>'; //total facilities online in that particular month 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))); //total facilities in the district 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))); //total facilities targetted in the district 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))); //total facilities using hcmp using HCMP in the district 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))); } $accordion .= '<td>' . $monthly_total . '</td></tr>'; } $accordion .= '</table>'; $accordion .= '</div>'; $accordion .= '</div>'; $accordion .= '</div>'; } $district_percetage_coverage = array(); foreach ($district_data as $district_detail) { $dt = $district_total[$district_detail->district]; $dtf = $district_total_facilities[$district_detail->district]; $pc = round($dt / $dtf * 100, 0); $district_percetage_coverage[$district_detail->district] = $pc; } $district_totals = array_sum($district_total); $district_total_facility = array_sum($district_total_facilities); $total_covered = round($district_totals / $district_total_facility * 100, 1); $accordion .= '<div class="panel panel-default">'; $accordion .= '<div class="panel-heading" role="tab" id="summary_heading">'; $accordion .= '<h4 class="panel-title"><a data-toggle="collapse" data-parent="#accordion" href="#collapse_summary" aria-expanded="true" aria-controls="collapse_summary">Rollout Summary</a></h4>'; $accordion .= '</div>'; $accordion .= '<div id="collapse_summary" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="summary_heading">'; $accordion .= '<div class = "panel-body">'; $accordion .= '<table class = "table table-bordered table-hover">'; $accordion .= '<thead>'; $accordion .= $monthly_sub_county_names; $accordion .= '<th>Total</th></thead>'; $accordion .= '<tbody>'; $accordion .= '<tr><th>Total: Facilities Using HCMP</th>'; foreach ($district_data as $district_detail) { $accordion .= '<td>'; $accordion .= $district_total[$district_detail->district]; $accordion .= '</td>'; } $accordion .= '<td>' . $district_totals . '</td>'; $accordion .= '</tr>'; $accordion .= '<tr>'; $accordion .= '<th>TOTAL: Facilities in Sub County</th>'; foreach ($district_data as $district_detail) { $accordion .= '<td>'; $accordion .= $district_total_facilities[$district_detail->district]; $accordion .= '</td>'; } $accordion .= '<td>' . $district_total_facility . '</td>'; $accordion .= '</tr>'; $accordion .= '<tr><th>% Coverage</th>'; foreach ($district_data as $district_detail) { $accordion .= '<td>'; $accordion .= $district_percetage_coverage[$district_detail->district] . ' %'; $accordion .= '</td>'; } $accordion .= '<td>' . $total_covered . ' %</td>'; $accordion .= '</tr>'; $accordion .= '</tbody></table>'; $accordion .= '</div>'; $accordion .= '</div>'; $accordion .= '</div>'; $accordion .= '</div>'; // echo $accordion;die; foreach ($get_dates_facility_went_online as $facility_dates) { $monthly_total = 0; $date = $facility_dates['date_when_facility_went_online']; //table data is for the monthly roll out progress $table_data .= "<tr><td>" . $date . "</td>"; //loop through the districts in the county foreach ($district_data as $district_detail) { //picks the id and name $district_id = $district_detail->id; $district_name = $district_detail->district; //picks the respective details from the db using the date and district id $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; //total facilities online in that particular month 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))); //total facilities in the district 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))); //total facilities targetted in the district 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))); //total facilities using hcmp using HCMP in the district 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; // echo "<pre>";print_r($district_total);exit; foreach ($district_total as $key => $value) { $coverage = 0; $using = 0; //calculates total coverage % @($coverage = round($value / $district_total_facilities[$key] * 100, 0)); @($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; //the names of the sub counties in a county $district_names .= "<th>{$key}</th>"; $sub_county_names .= "<th>{$key}</th>"; $total_facility_list .= $checker == 1 ? "<tr><td><b>TOTAL: Facilities in Sub County</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>{$district_total_facilities_using_hcmp[$key]}</td>" : "<td>{$district_total_facilities_using_hcmp[$key]}</td>"; $table_summary .= $checker == 1 ? "<td><b>TOTAL: Facilities using HCMP</b></td><td>{$district_total_facilities_using_hcmp[$key]}</td>" : "<td>{$district_total_facilities_using_hcmp[$key]}</td>"; //$total_targetted_facility_list .= ($checker == 1) ? "<tr><td><b>TOTAL: Targetted Facilities in Sub County</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 .= $checker == 1 ? "<tr><td><b>% Coverage</b></td>\n\t\t<td>{$coverage} %</td>" : "<td>{$coverage} %</td>"; $checker++; } $list_url = base_url() . 'reports/list_facilities'; $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='{$list_url}' id='total' class='ajax_call1 link' date='total'>{$all_facilities}</a></td>"; $district_names .= "<th>TOTAL</th></tr></thead>"; $sub_county_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)); //$system_usage = $this->monitoring(); $data_ = "\n\t\t<div class='tabbable tabs-left'>\n\t\t\t<div class='tab-content'>\n\t\t\t\t<ul class='nav nav-tabs'>\n\t\t\t\t\t<li class='active'><a href='#A' data-toggle='tab'>Roll out Summary</a></li>\n\t\t\t\t\t<li ><a href='#B' data-toggle='tab'>Monthly Break Down</a></li>\n\t\t\t\t\t<li><button type='button' class='btn btn-default download'>System Usage Breakdown</button></li>\n\t\t\t\t</ul>\n\t\t\t\t<div id='B' class='tab-pane fade'>" . $accordion . "\t\t\t</table>\n\t\t\t\t</div>\n\t\t\t\t\n\t\t\t\t<div id='A' class='tab-pane fade active in' >\n\t\t\t\t\t<table class='row-fluid table table-hover table-bordered table-update' width='80%' id='test2'>" . $sub_county_names . $table_summary . $table_datas_summary . $total_facility_list . "<td>{$total_facilities_in_county}</td></tr>" . $total_targetted_facility_list . $percentage_coverage . "<td>{$final_coverage_total} %</td></tr>" . $percentage_coverage_using . "</tr></table>\n\t\t\t\t</div>\n\t\t\t</div>"; if (isset($option)) { return $data_; } else { echo $data_; } }