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; // echo $county_id."<pre>";echo $county_name;echo "</pre>";exit; //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); // echo "<pre>";print_r($facility_data);echo "</pre>";exit; $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; } 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'])))); } } else { // do nothing } } //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'])))); } } $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" => 'User Activities')); $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); 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; $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"); // echo "<pre>";print_r($data);echo "</pre>";exit; 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); } }