Changeset 906 for pro-violet-viettel/sourcecode/application/modules/collaborator/controllers/collaborator.php
- Timestamp:
- Apr 23, 2015 12:00:06 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pro-violet-viettel/sourcecode/application/modules/collaborator/controllers/collaborator.php
r883 r906 14 14 $this->lang->load('messages', 'message'); 15 15 } 16 17 public function index() { 18 $data = array(); 19 $collaborator_info = $this->session->userdata('collaboratorInfo'); 20 if ($collaborator_info) { 21 $data['statistics'] = $this->getStatistics(); 22 $data['content'] = $this->getCollaborators(); 23 $this->load->view('collaborator/reportAsistant/index', $data); 24 } else { 25 $this->load->view('login'); 26 } 27 } 28 29 public function viewAsistant() { 30 $data = array(); 31 32 $collaborator_info = $this->session->userdata('collaboratorInfo'); 33 if ($collaborator_info) { 34 $id = $this->uri->segment(2); 35 $data['id'] = $id; 36 $data['statistics'] = $this->getStatistics($id); 37 $data['content'] = $this->getCollaboratorsUsers(array(), $id); 38 $this->load->view('collaborator/reportAsistant/indexCollaborator', $data); 39 } else { 40 $this->load->view('login'); 41 } 42 } 43 44 public function getStatistics($id = false) { 45 $data = array(); 46 47 $this_year['start'] = strtotime(date("Y") . "-01-01 00:00:00"); 48 49 $this->load->model('admin/collabolator_model'); 50 $collaborators = $this->collabolator_model->getAllCollaboratorUser($this_year['start'], $id); 51 for ($i = 1; $i <= 12; $i++) { 52 $statistics[$i] = 0; 53 } 54 $y = date("Y"); 55 foreach ($collaborators as $collaborator) { 56 for ($i = 1; $i <= 12; $i++) { 57 if ($i < 12) { 58 if (($collaborator['time'] > strtotime($y . "-" . $i . "-1 00:00:00")) && (($collaborator['time'] < strtotime($y . "-" . ($i + 1) . "-1 00:00:00")))) { 59 $statistics[$i] ++; 60 } 61 } else { 62 if (($collaborator['time'] > strtotime($y . "-" . $i . "-1 00:00:00")) && (($collaborator['time'] < strtotime(($y + 1) . "-1-1 00:00:00")))) { 63 $statistics[$i] ++; 64 } 65 } 66 } 67 } 68 69 $max = 0; 70 foreach ($statistics as $index => $total) { 71 if ($total > $max) { 72 $max = $total; 73 } 74 $chart[] = array($index, $total); 75 } 76 77 $data['max'] = $max; 78 $chard[] = array("color" => "#e67e22", "label" => "Lượng ngưá»i dùng giá»i thiá»u bá»i cá»ng tác viên theo từng tháng", "data" => $chart); 79 $data['chard'] = $chard; 80 81 return $this->load->view('collaborator/reportAsistant/statistics', $data, true); 82 } 83 84 public function getLastquarter() { 85 $current_month = date('m'); 86 $current_year = date('Y'); 87 88 if ($current_month >= 1 && $current_month <= 3) { 89 $start_date = strtotime('1-October-' . ($current_year - 1)); // timestamp or 1-October Last Year 12:00:00 AM 90 $end_date = strtotime('1-Janauary-' . $current_year); // // timestamp or 1-January 12:00:00 AM means end of 31 December Last year 91 } else if ($current_month >= 4 && $current_month <= 6) { 92 $start_date = strtotime('1-January-' . $current_year); // timestamp or 1-Janauray 12:00:00 AM 93 $end_date = strtotime('1-April-' . $current_year); // timestamp or 1-April 12:00:00 AM means end of 31 March 94 } else if ($current_month >= 7 && $current_month <= 9) { 95 $start_date = strtotime('1-April-' . $current_year); // timestamp or 1-April 12:00:00 AM 96 $end_date = strtotime('1-July-' . $current_year); // timestamp or 1-July 12:00:00 AM means end of 30 June 97 } else if ($current_month >= 10 && $current_month <= 12) { 98 $start_date = strtotime('1-July-' . $current_year); // timestamp or 1-July 12:00:00 AM 99 $end_date = strtotime('1-October-' . $current_year); // timestamp or 1-October 12:00:00 AM means end of 30 September 100 } 101 return array("start" => $start_date, "end" => $end_date); 102 } 103 104 105 public function getCollaboratorsUsers($filters = array(), $id = false) { 106 107 $this->load->helper('pagging'); 108 $this->load->model('admin/collabolator_model'); 109 $data['current_page'] = $this->uri->segment(5, 1); 110 111 $data['itemsoptions'] = array(10, 25, 50, 100); 112 $data['perpage'] = 10; 113 if (!$id) { 114 $data['id'] = $this->uri->segment(4, 1); 115 } else { 116 $data['id'] = $id; 117 } 118 119 $data['keyword'] = ""; 120 $data['sorting_order'] = "sorting_desc"; 121 $data['sorting_field'] = "id"; 122 123 if ($this->input->post('sorting_order')) { 124 if ($this->input->post('sorting_order') != "sorting") { 125 $data['sorting_order'] = $this->input->post('sorting_order'); 126 $data['sorting_field'] = $this->input->post('sorting_field'); 127 } 128 } 129 if ($this->input->post('items')) { 130 $data['perpage'] = $this->input->post('items'); 131 } 132 if ($this->input->post('keyword')) { 133 $data['search_field'] = ""; 134 $data['keyword'] = $this->input->post('keyword'); 135 136 if (preg_match("/[0-9]/", $data['keyword'])) { 137 $data['search_field'] = "cellphone"; 138 } 139 } 140 141 $data['daterange_start'] = ""; 142 $data['daterange_end'] = ""; 143 if ($this->input->post('daterange')){ 144 $daterange = explode(" - ", $this->input->post('daterange')); 145 $daterange[0] = str_replace('/', '-', $daterange[0]); 146 $daterange[1] = str_replace('/', '-', $daterange[1]); 147 $data['daterange_start'] = date('Y-m-d H:i:s', strtotime($daterange[0])); 148 $data['daterange_end'] = date('Y-m-d H:is:s', strtotime($daterange[1].' + 1 day')); 149 } 150 151 $data['start'] = ($data['current_page'] - 1) * $data['perpage']; 152 $data['total'] = $this->collabolator_model->countCountCollaboratorUsers($data); 153 $data['paidlogs'] = $this->collabolator_model->getCountCollaboratorUsers($data); 154 foreach ($data['paidlogs'] as $index=>$paidlog) 155 { 156 $data['paidlogs'][$index]['username']=$this->get_fullname($paidlog['us_id']); 157 } 158 $data['paging_url'] = base_url() . "/cong_tac_vien/thong_ke_cong_tac_vien/trang_ctv/" . $data['id']; 159 $data['num_links'] = 2; 160 $data['paging'] = pagging($data); 161 162 if ($this->input->is_ajax_request()) { 163 return $this->load->view('collaborator/reportAsistant/listview_user', $data); 164 } 165 return $this->load->view('collaborator/reportAsistant/listview_user', $data, true); 166 } 167 168 private function get_fullname($us_id) { 169 $fullname=""; 170 $src = 'violet'; 171 $token = md5($us_id . self::TOKENPW); 172 $this->load->model('admin/user_model'); 173 $data = $this->user_model->get_user_info($src, $us_id, $token); 174 parse_str($data,$data); 175 if (isset($data['fullname'])) 176 { 177 $fullname=$data['fullname']; 178 } 179 return $fullname; 180 } 181 16 182 17 public function profile(){ 183 18 $collaborator_info = $this->session->userdata('collaboratorInfo'); 184 19 if ($collaborator_info) { 185 20 $data['collaborator_id'] = $collaborator_info['id']; 21 $data['username'] = $collaborator_info['login_name']; 22 $data['fullname'] = $collaborator_info['fullname']; 186 23 $this->load->view('collaborator/collaborator_profile', $data); 24 }else{ 25 $this->load->view('login'); 26 } 27 } 28 29 public function updateCollaborator(){ 30 $this->load->model('collaborator_model'); 31 $collaborator_info = $this->session->userdata('collaboratorInfo'); 32 $result['success'] = 0; 33 if ($collaborator_info) { 34 35 $collaborator_id = $collaborator_info['id']; 36 $login_name = $collaborator_info['login_name']; 37 $input = $this->input->post(); 38 if (strlen($input['fullname']) == 0) { 39 $result['errors'][] = array("content"=>lang('_SBG_FULLNAME_REQUIRED_MSG'),"field"=>"fullname_err"); 40 } 41 if (!isset($result['errors'])) { 42 $collaborator = array('full_name' => $input['fullname']); 43 $result['success'] = 1; 44 $result['data'] = $this->collaborator_model->updateCollaborator($collaborator_id, $collaborator); 45 $collaboratorData = array('login_name' => $login_name, 'id' => $collaborator_id, 'fullname' => $input['fullname'], 'logined_in' => TRUE); 46 $this->session->set_userdata('collaboratorInfo', $collaboratorData); 47 } 48 echo json_encode($result); 187 49 }else{ 188 50 $this->load->view('login'); … … 192 54 public function change_password(){ 193 55 $this->load->model('collaborator_model'); 194 //$collaborator_id = $this->uri->segment(4, 1);195 56 $collaborator_info = $this->session->userdata('collaboratorInfo'); 196 57 if ($collaborator_info) {
Note: See TracChangeset
for help on using the changeset viewer.