Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like Rates often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Rates, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 23 | // ############################################################################## |
||
| 24 | |||
| 25 | class Rates extends MX_Controller |
||
| 26 | |||
| 27 | { |
||
| 28 | function Rates() |
||
| 29 | { |
||
| 30 | parent::__construct(); |
||
| 31 | $this->load->helper('template_inheritance'); |
||
| 32 | $this->load->library('session'); |
||
| 33 | $this->load->library('rates_form'); |
||
| 34 | $this->load->library('astpp/form'); |
||
| 35 | $this->load->model('rates_model'); |
||
| 36 | $this->load->library('csvreader'); |
||
| 37 | ini_set("memory_limit", "2048M"); |
||
| 38 | ini_set("max_execution_time", "259200"); |
||
| 39 | ini_set("upload_max_filesize", "200M"); |
||
| 40 | if ($this->session->userdata('user_login') == FALSE) redirect(base_url() . '/astpp/login'); |
||
| 41 | } |
||
| 42 | |||
| 43 | function termination_rates_list() |
||
| 44 | { |
||
| 45 | $data['username'] = $this->session->userdata('user_name'); |
||
| 46 | $data['page_title'] = 'Termination Rates'; |
||
| 47 | $data['search_flag'] = true; |
||
| 48 | $data['batch_update_flag'] = true; |
||
| 49 | /********* |
||
| 50 | ASTPP 3.0 |
||
| 51 | Batch Delete |
||
| 52 | *********/ |
||
| 53 | $data['delete_batch_flag'] = true; |
||
| 54 | /***************/ |
||
| 55 | $this->session->set_userdata('advance_search', 0); |
||
| 56 | $data['grid_fields'] = $this->rates_form->build_termination_rate_for_admin(); |
||
| 57 | $data["grid_buttons"] = $this->rates_form->build_grid_buttons(); |
||
| 58 | $data['form_search'] = $this->form->build_serach_form($this->rates_form->get_termination_rate_search_form()); |
||
| 59 | $data['form_batch_update'] = $this->form->build_batchupdate_form($this->rates_form->termination_rate_batch_update_form()); |
||
| 60 | $this->load->view('view_termination_rates_list', $data); |
||
| 61 | } |
||
| 62 | |||
| 63 | /** |
||
| 64 | * -------Here we write code for controller accounts functions account_list------ |
||
| 65 | * Listing of Accounts table data through php function json_encode |
||
| 66 | */ |
||
| 67 | function termination_rates_list_json() |
||
| 68 | { |
||
| 69 | $json_data = array(); |
||
| 70 | $count_all = $this->rates_model->get_termination_rates_list(false); |
||
| 71 | $paging_data = $this->form->load_grid_config($count_all, $_GET['rp'], $_GET['page']); |
||
| 72 | $json_data = $paging_data["json_paging"]; |
||
| 73 | $query = $this->rates_model->get_termination_rates_list(true, $paging_data["paging"]["start"], $paging_data["paging"]["page_no"]); |
||
| 74 | $grid_fields = json_decode($this->rates_form->build_termination_rate_for_admin()); |
||
| 75 | $json_data['rows'] = $this->form->build_grid($query, $grid_fields); |
||
| 76 | echo json_encode($json_data); |
||
| 77 | } |
||
| 78 | |||
| 79 | function termination_rates_list_delete($flag = '') |
||
| 80 | { |
||
| 81 | $json_data = array(); |
||
| 82 | $this->session->set_userdata('advance_batch_data_delete', 1); |
||
| 83 | $count_all = $this->rates_model->get_termination_rates_list(false); |
||
| 84 | echo $count_all; |
||
| 85 | } |
||
| 86 | |||
| 87 | /****************/ |
||
| 88 | function termination_rate_import() |
||
| 89 | { |
||
| 90 | $data['page_title'] = 'Import Termination Rates'; |
||
| 91 | $this->session->set_userdata('import_termination_rate_csv', ""); |
||
| 92 | $this->session->set_userdata('import_termination_rate_csv_error', ""); |
||
| 93 | $this->load->view('view_import_termination_rate', $data); |
||
| 94 | } |
||
| 95 | |||
| 96 | function termination_rate_preview_file() |
||
| 97 | { |
||
| 98 | $invalid_flag = false; |
||
| 99 | $check_header = $this->input->post('check_header', true); |
||
| 100 | $data['page_title'] = 'Import Termination Rates'; |
||
| 101 | $new_final_arr_key = $this->config->item('Termination-rates-field'); |
||
| 102 | if (empty($_FILES) || !isset($_FILES)) |
||
| 103 | { |
||
| 104 | redirect(base_url() . "rates/termination_rates_list/"); |
||
| 105 | } |
||
| 106 | |||
| 107 | if (isset($_FILES['termination_rate_import']['name']) && $_FILES['termination_rate_import']['name'] != "" && isset($_POST['trunk_id']) && $_POST['trunk_id'] != '') |
||
| 108 | { |
||
| 109 | list($txt, $ext) = explode(".", $_FILES['termination_rate_import']['name']); |
||
| 110 | if ($ext == "csv" && $_FILES['termination_rate_import']['size'] > 0) |
||
| 111 | { |
||
| 112 | $error = $_FILES['termination_rate_import']['error']; |
||
| 113 | if ($error == 0) |
||
| 114 | { |
||
| 115 | $uploadedFile = $_FILES["termination_rate_import"]["tmp_name"]; |
||
| 116 | $csv_data = $this->csvreader->parse_file($uploadedFile, $new_final_arr_key, $check_header); |
||
| 117 | if (!empty($csv_data)) |
||
| 118 | { |
||
| 119 | $full_path = $this->config->item('rates-file-path'); |
||
| 120 | $actual_file_name = "ASTPP-TERMINATION-RATES-" . date("Y-m-d-H:i:s") . "." . $ext; |
||
| 121 | if (move_uploaded_file($uploadedFile, $full_path . $actual_file_name)) |
||
| 122 | { |
||
| 123 | $data['csv_tmp_data'] = $csv_data; |
||
| 124 | $data['trunkid'] = $_POST['trunk_id']; |
||
| 125 | $data['check_header'] = $check_header; |
||
| 126 | $data['page_title'] = 'Termination Rates Preview'; |
||
| 127 | $this->session->set_userdata('import_termination_rate_csv', $actual_file_name); |
||
| 128 | } |
||
| 129 | else |
||
| 130 | { |
||
| 131 | $data['error'] = "File Uploading Fail Please Try Again"; |
||
| 132 | } |
||
| 133 | } |
||
| 134 | } |
||
| 135 | else |
||
| 136 | { |
||
| 137 | $data['error'] == "File Uploading Fail Please Try Again"; |
||
| 138 | } |
||
| 139 | } |
||
| 140 | else |
||
| 141 | { |
||
| 142 | $data['error'] = "Invalid file format : Only CSV file allows to import records(Can't import empty file)"; |
||
| 143 | } |
||
| 144 | } |
||
| 145 | else |
||
| 146 | { |
||
| 147 | $invalid_flag = true; |
||
| 148 | } |
||
| 149 | |||
| 150 | if ($invalid_flag) |
||
| 151 | { |
||
| 152 | $str = ''; |
||
| 153 | if (!isset($_POST['trunk_id']) || empty($_POST['trunk_id'])) |
||
| 154 | { |
||
| 155 | $str.= '<br/>Please Create Trunk.'; |
||
| 156 | } |
||
| 157 | |||
| 158 | if (empty($_FILES['termination_rate_import']['name'])) |
||
| 159 | { |
||
| 160 | $str.= '<br/>Please Select File.'; |
||
| 161 | } |
||
| 162 | |||
| 163 | $data['error'] = $str; |
||
| 164 | } |
||
| 165 | |||
| 166 | $this->load->view('view_import_termination_rate', $data); |
||
| 167 | } |
||
| 168 | |||
| 169 | function termination_rate_rates_import($trunkID, $check_header = false) |
||
| 170 | { |
||
| 171 | $new_final_arr = array(); |
||
| 172 | $invalid_array = array(); |
||
| 173 | $new_final_arr_key = $this->config->item('Termination-rates-field'); |
||
| 174 | $screen_path = $this->config->item('screen_path'); |
||
| 175 | if ($this->session->userdata('logintype') == 1 || $this->session->userdata('logintype') == 5) |
||
| 176 | { |
||
| 177 | $account_data = $this->session->userdata("accountinfo"); |
||
| 178 | } |
||
| 179 | |||
| 180 | $full_path = $this->config->item('rates-file-path'); |
||
| 181 | $terminationrate_file_name = $this->session->userdata('import_termination_rate_csv'); |
||
| 182 | $csv_tmp_data = $this->csvreader->parse_file($full_path . $terminationrate_file_name, $new_final_arr_key, $check_header); |
||
| 183 | $i = 0; |
||
| 184 | foreach($csv_tmp_data as $key => $csv_data) |
||
| 185 | { |
||
| 186 | if (isset($csv_data['pattern']) && $csv_data['pattern'] != '' && $i != 0) |
||
| 187 | { |
||
| 188 | $str = null; |
||
| 189 | $csv_data['prepend'] = isset($csv_data['prepend']) ? $csv_data['prepend'] : ''; |
||
| 190 | $csv_data['comment'] = isset($csv_data['comment']) ? $csv_data['comment'] : ''; |
||
| 191 | $csv_data['connectcost'] = isset($csv_data['connectcost']) ? $csv_data['connectcost'] : 0; |
||
| 192 | $csv_data['includedseconds'] = isset($csv_data['includedseconds']) ? $csv_data['includedseconds'] : 0; |
||
| 193 | $csv_data['cost'] = !empty($csv_data['cost']) && is_numeric($csv_data['cost']) ? $csv_data['cost'] : 0; |
||
| 194 | $csv_data['inc'] = isset($csv_data['inc']) ? $csv_data['inc'] : 0; |
||
| 195 | $csv_data['precedence'] = isset($csv_data['precedence']) ? $csv_data['precedence'] : ''; |
||
| 196 | $csv_data['strip'] = isset($csv_data['strip']) ? $csv_data['strip'] : ''; |
||
| 197 | $csv_data['last_modified_date'] = date("Y-m-d H:i:s"); |
||
| 198 | $str = $this->data_validate($csv_data); |
||
| 199 | if ($str != "") |
||
| 200 | { |
||
| 201 | $invalid_array[$i] = $csv_data; |
||
| 202 | $invalid_array[$i]['error'] = $str; |
||
| 203 | } |
||
| 204 | else |
||
| 205 | { |
||
| 206 | $csv_data['trunk_id'] = $trunkID; |
||
| 207 | $csv_data['pattern'] = "^" . $csv_data['pattern'] . ".*"; |
||
| 208 | $new_final_arr[$i] = $csv_data; |
||
| 209 | } |
||
| 210 | } |
||
| 211 | |||
| 212 | $i++; |
||
| 213 | } |
||
| 214 | |||
| 215 | if (!empty($new_final_arr)) |
||
| 216 | { |
||
| 217 | $result = $this->rates_model->bulk_insert_termination_rate($new_final_arr); |
||
| 218 | } |
||
| 219 | |||
| 220 | unlink($full_path . $terminationrate_file_name); |
||
| 221 | $count = count($invalid_array); |
||
| 222 | if ($count > 0) |
||
| 223 | { |
||
| 224 | $session_id = "-1"; |
||
| 225 | $fp = fopen($full_path . $session_id . '.csv', 'w'); |
||
| 226 | foreach($new_final_arr_key as $key => $value) |
||
| 227 | { |
||
| 228 | $custom_array[0][$key] = ucfirst($key); |
||
| 229 | } |
||
| 230 | |||
| 231 | $custom_array[0]['error'] = "Error"; |
||
| 232 | $invalid_array = array_merge($custom_array, $invalid_array); |
||
| 233 | foreach($invalid_array as $err_data) |
||
| 234 | { |
||
| 235 | fputcsv($fp, $err_data); |
||
| 236 | } |
||
| 237 | |||
| 238 | fclose($fp); |
||
| 239 | $this->session->set_userdata('import_termination_rate_csv_error', $session_id . ".csv"); |
||
| 240 | $data["error"] = $invalid_array; |
||
| 241 | $data['trunkid'] = $trunkID; |
||
| 242 | $data['impoted_count'] = count($new_final_arr); |
||
| 243 | $data['failure_count'] = count($invalid_array) - 1; |
||
| 244 | $data['page_title'] = 'Termination Rates Import Error'; |
||
| 245 | $this->load->view('view_import_error', $data); |
||
| 246 | } |
||
| 247 | else |
||
| 248 | { |
||
| 249 | $this->session->set_flashdata('astpp_errormsg', 'Total ' . count($new_final_arr) . ' Termination rates imported successfully!'); |
||
| 250 | redirect(base_url() . "rates/termination_rates_list/"); |
||
| 251 | } |
||
| 252 | } |
||
| 253 | |||
| 254 | function termination_rate_error_download() |
||
| 255 | { |
||
| 256 | $this->load->helper('download'); |
||
| 257 | $error_data = $this->session->userdata('import_termination_rate_csv_error'); |
||
| 258 | $full_path = $this->config->item('rates-file-path'); |
||
| 259 | $data = file_get_contents($full_path . $error_data); |
||
| 260 | force_download("Termination_rate_error.csv", $data); |
||
| 261 | } |
||
| 262 | |||
| 263 | function origination_rate_import() |
||
| 264 | { |
||
| 265 | $data['page_title'] = 'Import Origination Rates'; |
||
| 266 | $this->session->set_userdata('import_origination_rate_csv', ""); |
||
| 267 | $error_data = $this->session->userdata('import_origination_rate_csv_error'); |
||
| 268 | $full_path = $this->config->item('rates-file-path'); |
||
| 269 | if (file_exists($full_path . $error_data) && $error_data != "") |
||
| 270 | { |
||
| 271 | unlink($full_path . $error_data); |
||
| 272 | $this->session->set_userdata('import_origination_rate_csv_error', ""); |
||
| 273 | } |
||
| 274 | |||
| 275 | $this->load->view('view_import_origination_rate', $data); |
||
| 276 | } |
||
| 277 | |||
| 278 | function origination_rate_preview_file() |
||
| 279 | { |
||
| 280 | $invalid_flag = false; |
||
| 281 | $data = array(); |
||
| 282 | $data['page_title'] = 'Import Origination Rates'; |
||
| 283 | $check_header = $this->input->post('check_header', true); |
||
| 284 | if (empty($_FILES) || !isset($_FILES)) |
||
| 285 | { |
||
| 286 | redirect(base_url() . "rates/origination_rate_list/"); |
||
| 287 | } |
||
| 288 | |||
| 289 | $get_extension = strpos($_FILES['origination_rate_import']['name'], '.'); |
||
| 290 | $new_final_arr_key = $this->config->item('Origination-rates-field'); |
||
| 291 | if (!$get_extension) |
||
| 292 | { |
||
| 293 | $data['error'] = "Please Upload File Atleast"; |
||
| 294 | } |
||
| 295 | |||
| 296 | if (isset($_FILES['origination_rate_import']['name']) && $_FILES['origination_rate_import']['name'] != "" && isset($_POST['pricelist_id']) && $_POST['pricelist_id'] != '') |
||
| 297 | { |
||
| 298 | list($txt, $ext) = explode(".", $_FILES['origination_rate_import']['name']); |
||
| 299 | if ($ext == "csv" && $_FILES['origination_rate_import']['size'] > 0) |
||
| 300 | { |
||
| 301 | $error = $_FILES['origination_rate_import']['error']; |
||
| 302 | if ($error == 0) |
||
| 303 | { |
||
| 304 | $uploadedFile = $_FILES["origination_rate_import"]["tmp_name"]; |
||
| 305 | $csv_data = $this->csvreader->parse_file($uploadedFile, $new_final_arr_key, $check_header); |
||
| 306 | if (!empty($csv_data)) |
||
| 307 | { |
||
| 308 | $full_path = $this->config->item('rates-file-path'); |
||
| 309 | $actual_file_name = "ASTPP-ORIGIN-RATES-" . date("Y-m-d H:i:s") . "." . $ext; |
||
| 310 | if (move_uploaded_file($uploadedFile, $full_path . $actual_file_name)) |
||
| 311 | { |
||
| 312 | $flag = false; |
||
| 313 | $data['trunkid'] = isset($_POST['trunk_id']) && $_POST['trunk_id'] > 0 ? $_POST['trunk_id'] : 0; |
||
| 314 | $data['csv_tmp_data'] = $csv_data; |
||
| 315 | $data['pricelistid'] = $_POST['pricelist_id']; |
||
| 316 | $data['page_title'] = "Origination Rates Preview"; |
||
| 317 | $data['check_header'] = $check_header; |
||
| 318 | $this->session->set_userdata('import_origination_rate_csv', $actual_file_name); |
||
| 319 | } |
||
| 320 | else |
||
| 321 | { |
||
| 322 | $data['error'] = "File Uploading Fail Please Try Again"; |
||
| 323 | } |
||
| 324 | } |
||
| 325 | } |
||
| 326 | else |
||
| 327 | { |
||
| 328 | $data['error'] == "File Uploading Fail Please Try Again"; |
||
| 329 | } |
||
| 330 | } |
||
| 331 | else |
||
| 332 | { |
||
| 333 | $data['error'] = "Invalid file format : Only CSV file allows to import records(Can't import empty file)"; |
||
| 334 | } |
||
| 335 | } |
||
| 336 | else |
||
| 337 | { |
||
| 338 | $invalid_flag = true; |
||
| 339 | } |
||
| 340 | |||
| 341 | if ($invalid_flag) |
||
| 342 | { |
||
| 343 | $str = ''; |
||
| 344 | if (!isset($_POST['pricelist_id']) || empty($_POST['pricelist_id'])) |
||
| 345 | { |
||
| 346 | $str.= '<br/>Please Create Rate Group.'; |
||
| 347 | } |
||
| 348 | |||
| 349 | if (empty($_FILES['origination_rate_import']['name'])) |
||
| 350 | { |
||
| 351 | $str.= '<br/>Please Select File.'; |
||
| 352 | } |
||
| 353 | |||
| 354 | $data['error'] = $str; |
||
| 355 | } |
||
| 356 | |||
| 357 | $this->load->view('view_import_origination_rate', $data); |
||
| 358 | } |
||
| 359 | |||
| 360 | function origination_rate_import_file($pricelistID, $trunkid, $check_header = false) |
||
| 361 | { |
||
| 362 | $new_final_arr = array(); |
||
| 363 | $invalid_array = array(); |
||
| 364 | $new_final_arr_key = $this->config->item('Origination-rates-field'); |
||
| 365 | $screen_path = $this->config->item('screen_path'); |
||
| 366 | $reseller_id = 0; |
||
| 367 | if ($this->session->userdata('logintype') == 1 || $this->session->userdata('logintype') == 5) |
||
| 368 | { |
||
| 369 | $reseller_id = $this->session->userdata["accountinfo"]['id']; |
||
| 370 | } |
||
| 371 | |||
| 372 | $full_path = $this->config->item('rates-file-path'); |
||
| 373 | $originationrate_file_name = $this->session->userdata('import_origination_rate_csv'); |
||
| 374 | $csv_tmp_data = $this->csvreader->parse_file($full_path . $originationrate_file_name, $new_final_arr_key, $check_header); |
||
| 375 | |||
| 376 | // echo "<pre>";print_r($csv_tmp_data);exit; |
||
|
|
|||
| 377 | |||
| 378 | $i = 0; |
||
| 379 | foreach($csv_tmp_data as $key => $csv_data) |
||
| 380 | { |
||
| 381 | if (isset($csv_data['pattern']) && $csv_data['pattern'] != '' && $i != 0) |
||
| 382 | { |
||
| 383 | $str = null; |
||
| 384 | $csv_data['comment'] = isset($csv_data['comment']) ? $csv_data['comment'] : ''; |
||
| 385 | $csv_data['connectcost'] = isset($csv_data['connectcost']) ? $csv_data['connectcost'] : 0; |
||
| 386 | $csv_data['includedseconds'] = isset($csv_data['includedseconds']) ? $csv_data['includedseconds'] : 0; |
||
| 387 | $csv_data['cost'] = !empty($csv_data['cost']) && is_numeric($csv_data['cost']) ? $csv_data['cost'] : 0; |
||
| 388 | $csv_data['inc'] = isset($csv_data['inc']) ? $csv_data['inc'] : 0; |
||
| 389 | $csv_data['precedence'] = isset($csv_data['precedence']) ? $csv_data['precedence'] : ''; |
||
| 390 | $csv_data['last_modified_date'] = date("Y-m-d H:i:s"); |
||
| 391 | $str = $this->data_validate($csv_data); |
||
| 392 | if ($str != "") |
||
| 393 | { |
||
| 394 | $invalid_array[$i] = $csv_data; |
||
| 395 | $invalid_array[$i]['error'] = $str; |
||
| 396 | } |
||
| 397 | else |
||
| 398 | { |
||
| 399 | $csv_data['pricelist_id'] = $pricelistID; |
||
| 400 | $csv_data['trunk_id'] = $trunkid; |
||
| 401 | $csv_data['pattern'] = "^" . $csv_data['pattern'] . ".*"; |
||
| 402 | $csv_data['reseller_id'] = $reseller_id; |
||
| 403 | $csv_data['creation_date'] = gmdate('Y-m-d H:i:s'); |
||
| 404 | $new_final_arr[$i] = $csv_data; |
||
| 405 | } |
||
| 406 | } |
||
| 407 | |||
| 408 | $i++; |
||
| 409 | } |
||
| 410 | |||
| 411 | if (!empty($new_final_arr)) |
||
| 412 | { |
||
| 413 | $result = $this->rates_model->bulk_insert_origination_rate($new_final_arr); |
||
| 414 | } |
||
| 415 | |||
| 416 | unlink($full_path . $originationrate_file_name); |
||
| 417 | $count = count($invalid_array); |
||
| 418 | if ($count > 0) |
||
| 419 | { |
||
| 420 | $session_id = "-1"; |
||
| 421 | $fp = fopen($full_path . $session_id . '.csv', 'w'); |
||
| 422 | foreach($new_final_arr_key as $key => $value) |
||
| 423 | { |
||
| 424 | $custom_array[0][$key] = ucfirst($key); |
||
| 425 | } |
||
| 426 | |||
| 427 | $custom_array[0]['error'] = "Error"; |
||
| 428 | $invalid_array = array_merge($custom_array, $invalid_array); |
||
| 429 | foreach($invalid_array as $err_data) |
||
| 430 | { |
||
| 431 | fputcsv($fp, $err_data); |
||
| 432 | } |
||
| 433 | |||
| 434 | fclose($fp); |
||
| 435 | $this->session->set_userdata('import_origination_rate_csv_error', $session_id . ".csv"); |
||
| 436 | $data["error"] = $invalid_array; |
||
| 437 | $data['pricelistid'] = $pricelistID; |
||
| 438 | $data['impoted_count'] = count($new_final_arr); |
||
| 439 | $data['failure_count'] = count($invalid_array) - 1; |
||
| 440 | $data['page_title'] = 'Origination Rates Import Error'; |
||
| 441 | $this->load->view('view_import_error', $data); |
||
| 442 | } |
||
| 443 | else |
||
| 444 | { |
||
| 445 | $this->session->set_flashdata('astpp_errormsg', 'Total ' . count($new_final_arr) . ' Origination rates imported successfully!'); |
||
| 446 | redirect(base_url() . "rates/origination_rates_list/"); |
||
| 447 | } |
||
| 448 | } |
||
| 449 | |||
| 450 | function data_validate($csvdata) |
||
| 451 | { |
||
| 452 | $str = null; |
||
| 453 | $alpha_regex = "/^[a-z ,.'-]+$/i"; |
||
| 454 | $alpha_numeric_regex = "/^[a-z0-9 ,.'-]+$/i"; |
||
| 455 | $email_regex = "/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/"; |
||
| 456 | $str.= $csvdata['pattern'] != '' ? null : 'Code,'; |
||
| 457 | $str = rtrim($str, ','); |
||
| 458 | if (!$str) |
||
| 459 | { |
||
| 460 | $str.= is_numeric($csvdata['pattern']) ? null : 'Code,'; |
||
| 461 | $str.= !empty($csvdata['connectcost']) && is_numeric($csvdata['connectcost']) ? null : (empty($csvdata['connectcost']) ? null : 'Connect Cost,'); |
||
| 462 | $str.= !empty($csvdata['includedseconds']) && is_numeric($csvdata['includedseconds']) ? null : (empty($csvdata['includedseconds']) ? null : 'Included Seconds,'); |
||
| 463 | $str.= !empty($csvdata['inc']) && is_numeric($csvdata['inc']) ? null : (empty($csvdata['inc']) ? null : 'Increment,'); |
||
| 464 | $str.= !empty($csvdata['precedence']) && is_numeric($csvdata['precedence']) ? null : (empty($csvdata['precedence']) ? null : 'Precedence,'); |
||
| 465 | $str.= (isset($csvdata['strip']) && !empty($csvdata['strip'])) ? (is_numeric($csvdata['strip']) ? null : 'Strip,') : null; |
||
| 466 | if ($str) |
||
| 467 | { |
||
| 468 | $str = rtrim($str, ','); |
||
| 469 | $error_field = explode(',', $str); |
||
| 470 | $count = count($error_field); |
||
| 471 | $str.= $count > 1 ? ' are not valid' : ' is not Valid'; |
||
| 472 | return $str; |
||
| 473 | } |
||
| 474 | else |
||
| 475 | { |
||
| 476 | return false; |
||
| 477 | } |
||
| 478 | } |
||
| 479 | else |
||
| 480 | { |
||
| 481 | $str = rtrim($str, ','); |
||
| 482 | $error_field = explode(',', $str); |
||
| 483 | $count = count($error_field); |
||
| 484 | $str.= $count > 1 ? ' are required' : ' is Required'; |
||
| 485 | return $str; |
||
| 486 | } |
||
| 487 | } |
||
| 488 | |||
| 489 | function origination_rate_error_download() |
||
| 490 | { |
||
| 491 | $this->load->helper('download'); |
||
| 492 | $error_data = $this->session->userdata('import_origination_rate_csv_error'); |
||
| 493 | $full_path = $this->config->item('rates-file-path'); |
||
| 494 | $data = file_get_contents($full_path . $error_data); |
||
| 495 | force_download("Origination_rate_error.csv", $data); |
||
| 496 | } |
||
| 497 | |||
| 498 | function origination_rate_add($type = "") |
||
| 499 | { |
||
| 500 | $data['username'] = $this->session->userdata('user_name'); |
||
| 501 | $data['flag'] = 'create'; |
||
| 502 | $data['page_title'] = 'Create Origination Rate'; |
||
| 503 | $data['form'] = $this->form->build_form($this->rates_form->get_origination_rate_form_fields() , ''); |
||
| 504 | $this->load->view('view_origination_rate_add_edit', $data); |
||
| 505 | } |
||
| 506 | |||
| 507 | function origination_rate_edit($edit_id = '') |
||
| 508 | { |
||
| 509 | $data['page_title'] = 'Edit Origination Rate'; |
||
| 510 | if ($this->session->userdata('logintype') == 1 || $this->session->userdata('logintype') == 5) |
||
| 511 | { |
||
| 512 | $account_data = $this->session->userdata("accountinfo"); |
||
| 513 | $reseller = $account_data['id']; |
||
| 514 | $where = array( |
||
| 515 | 'id' => $edit_id, |
||
| 516 | "reseller_id" => $reseller |
||
| 517 | ); |
||
| 518 | } |
||
| 519 | else |
||
| 520 | { |
||
| 521 | $where = array( |
||
| 522 | 'id' => $edit_id |
||
| 523 | ); |
||
| 524 | } |
||
| 525 | |||
| 526 | $account = $this->db_model->getSelect("*", "routes", $where); |
||
| 527 | if ($account->num_rows > 0) |
||
| 528 | { |
||
| 529 | foreach($account->result_array() as $key => $value) |
||
| 530 | { |
||
| 531 | $edit_data = $value; |
||
| 532 | } |
||
| 533 | |||
| 534 | $edit_data['connectcost'] = $this->common_model->to_calculate_currency($edit_data['connectcost'], '', '', true, false); |
||
| 535 | $edit_data['cost'] = $this->common_model->to_calculate_currency($edit_data['cost'], '', '', true, false); |
||
| 536 | $edit_data['pattern'] = filter_var($edit_data['pattern'], FILTER_SANITIZE_NUMBER_INT); |
||
| 537 | $data['form'] = $this->form->build_form($this->rates_form->get_origination_rate_form_fields() , $edit_data); |
||
| 538 | $this->load->view('view_origination_rate_add_edit', $data); |
||
| 539 | } |
||
| 540 | else |
||
| 541 | { |
||
| 542 | redirect(base_url() . 'rates/origination_rate_list/'); |
||
| 543 | } |
||
| 544 | } |
||
| 545 | |||
| 546 | function origination_rate_save() |
||
| 547 | { |
||
| 548 | $add_array = $this->input->post(); |
||
| 549 | $data['form'] = $this->form->build_form($this->rates_form->get_origination_rate_form_fields() , $add_array); |
||
| 550 | if ($add_array['id'] != '') |
||
| 551 | { |
||
| 552 | $data['page_title'] = 'Edit Origination Rate'; |
||
| 553 | if ($this->form_validation->run() == FALSE) |
||
| 554 | { |
||
| 555 | $data['validation_errors'] = validation_errors(); |
||
| 556 | echo $data['validation_errors']; |
||
| 557 | exit; |
||
| 558 | } |
||
| 559 | else |
||
| 560 | { |
||
| 561 | $add_array['connectcost'] = $this->common_model->add_calculate_currency($add_array['connectcost'], '', '', false, false); |
||
| 562 | $add_array['cost'] = $this->common_model->add_calculate_currency($add_array['cost'], '', '', false, false); |
||
| 563 | $this->rates_model->edit_origination_rate($add_array, $add_array['id']); |
||
| 564 | echo json_encode(array( |
||
| 565 | "SUCCESS" => "Origination rate updated successfully!" |
||
| 566 | )); |
||
| 567 | exit; |
||
| 568 | } |
||
| 569 | } |
||
| 570 | else |
||
| 571 | { |
||
| 572 | $data['page_title'] = 'Add Origination Rate'; |
||
| 573 | if ($this->form_validation->run() == FALSE) |
||
| 574 | { |
||
| 575 | $data['validation_errors'] = validation_errors(); |
||
| 576 | echo $data['validation_errors']; |
||
| 577 | exit; |
||
| 578 | } |
||
| 579 | else |
||
| 580 | { |
||
| 581 | $add_array['connectcost'] = $this->common_model->add_calculate_currency($add_array['connectcost'], '', '', false, false); |
||
| 582 | $add_array['cost'] = $this->common_model->add_calculate_currency($add_array['cost'], '', '', false, false); |
||
| 583 | $this->rates_model->add_origination_rate($add_array); |
||
| 584 | echo json_encode(array( |
||
| 585 | "SUCCESS" => "Origination rate added successfully!" |
||
| 586 | )); |
||
| 587 | exit; |
||
| 588 | } |
||
| 589 | } |
||
| 590 | } |
||
| 591 | |||
| 592 | function origination_rates_list_search() |
||
| 593 | { |
||
| 594 | $ajax_search = $this->input->post('ajax_search', 0); |
||
| 595 | if ($this->input->post('advance_search', TRUE) == 1) |
||
| 596 | { |
||
| 597 | $this->session->set_userdata('advance_search', $this->input->post('advance_search')); |
||
| 598 | $action = $this->input->post(); |
||
| 599 | unset($action['action']); |
||
| 600 | unset($action['advance_search']); |
||
| 601 | $this->session->set_userdata('origination_rate_list_search', $action); |
||
| 602 | } |
||
| 603 | |||
| 604 | if (@$ajax_search != 1) |
||
| 605 | { |
||
| 606 | redirect(base_url() . 'rates/origination_rates_list/'); |
||
| 607 | } |
||
| 608 | } |
||
| 609 | |||
| 610 | function origination_rates_list_clearsearchfilter() |
||
| 611 | { |
||
| 612 | $this->session->set_userdata('advance_search', 0); |
||
| 613 | $this->session->set_userdata('account_search', ""); |
||
| 614 | } |
||
| 615 | |||
| 616 | function termination_rate_delete($id) |
||
| 617 | { |
||
| 618 | $this->rates_model->remove_termination_rate($id); |
||
| 619 | $this->session->set_flashdata('astpp_notification', 'Termination removed successfully!'); |
||
| 620 | redirect(base_url() . '/rates/termination_rates_list/'); |
||
| 621 | } |
||
| 622 | |||
| 623 | function origination_rate_delete($id) |
||
| 624 | { |
||
| 625 | $this->rates_model->remove_origination_rate($id); |
||
| 626 | $this->session->set_flashdata('astpp_notification', 'Origination rate removed successfully!'); |
||
| 627 | redirect(base_url() . 'rates/origination_rates_list/'); |
||
| 628 | } |
||
| 629 | |||
| 630 | function origination_rates_list() |
||
| 631 | { |
||
| 632 | $data['username'] = $this->session->userdata('user_name'); |
||
| 633 | $data['page_title'] = 'Origination Rates'; |
||
| 634 | $data['search_flag'] = true; |
||
| 635 | $data['batch_update_flag'] = true; |
||
| 636 | /********* |
||
| 637 | ASTPP 3.0 |
||
| 638 | Batch Delete |
||
| 639 | *********/ |
||
| 640 | $data['delete_batch_flag'] = true; |
||
| 641 | /***************/ |
||
| 642 | $this->session->set_userdata('advance_search', 0); |
||
| 643 | $data['grid_fields'] = $this->rates_form->build_origination_rate_list_for_admin(); |
||
| 644 | $data["grid_buttons"] = $this->rates_form->build_grid_buttons_origination_rate(); |
||
| 645 | $data['form_search'] = $this->form->build_serach_form($this->rates_form->get_origination_rate_search_form()); |
||
| 646 | $data['form_batch_update'] = $this->form->build_batchupdate_form($this->rates_form->origination_rate_batch_update_form()); |
||
| 647 | $this->load->view('view_origination_rate_list', $data); |
||
| 648 | } |
||
| 649 | |||
| 650 | /********* |
||
| 651 | ASTPP 3.0 |
||
| 652 | Batch Delete |
||
| 653 | *********/ |
||
| 654 | function origination_rates_list_json() |
||
| 655 | { |
||
| 656 | $json_data = array(); |
||
| 657 | $count_all = $this->rates_model->get_origination_rate_list(false); |
||
| 658 | $paging_data = $this->form->load_grid_config($count_all, $_GET['rp'], $_GET['page']); |
||
| 659 | $json_data = $paging_data["json_paging"]; |
||
| 660 | |||
| 661 | // echo "<pre>"; print_r($json_data); |
||
| 662 | |||
| 663 | $query = $this->rates_model->get_origination_rate_list(true, $paging_data["paging"]["start"], $paging_data["paging"]["page_no"]); |
||
| 664 | $grid_fields = json_decode($this->rates_form->build_origination_rate_list_for_admin()); |
||
| 665 | $json_data['rows'] = $this->form->build_grid($query, $grid_fields); |
||
| 666 | echo json_encode($json_data); |
||
| 667 | } |
||
| 668 | |||
| 669 | function origination_rates_list_delete($flag = '') |
||
| 670 | { |
||
| 671 | $json_data = array(); |
||
| 672 | $this->session->set_userdata('advance_batch_data_delete', 1); |
||
| 673 | $count_all = $this->rates_model->get_origination_rate_list(false); |
||
| 674 | echo $count_all; |
||
| 675 | } |
||
| 676 | |||
| 677 | /*******************/ |
||
| 678 | function termination_rate_add($type = "") |
||
| 679 | { |
||
| 680 | $data['username'] = $this->session->userdata('user_name'); |
||
| 681 | $data['flag'] = 'create'; |
||
| 682 | $data['page_title'] = 'Create Termination Rate'; |
||
| 683 | $data['form'] = $this->form->build_form($this->rates_form->get_termination_rate_form_fields() , ''); |
||
| 684 | $this->load->view('view_termination_rate_add_edit', $data); |
||
| 685 | } |
||
| 686 | |||
| 687 | function termination_rate_edit($edit_id = '') |
||
| 688 | { |
||
| 689 | $data['page_title'] = 'Edit Termination Rate'; |
||
| 690 | $where = array( |
||
| 691 | 'id' => $edit_id |
||
| 692 | ); |
||
| 693 | $account = $this->db_model->getSelect("*", "outbound_routes", $where); |
||
| 694 | foreach($account->result_array() as $key => $value) |
||
| 695 | { |
||
| 696 | $edit_data = $value; |
||
| 697 | } |
||
| 698 | |||
| 699 | $edit_data['connectcost'] = $this->common_model->to_calculate_currency($edit_data['connectcost'], '', '', false, false); |
||
| 700 | $edit_data['cost'] = $this->common_model->to_calculate_currency($edit_data['cost'], '', '', false, false); |
||
| 701 | $edit_data['pattern'] = filter_var($edit_data['pattern'], FILTER_SANITIZE_NUMBER_INT); |
||
| 702 | $data['form'] = $this->form->build_form($this->rates_form->get_termination_rate_form_fields() , $edit_data); |
||
| 703 | $this->load->view('view_termination_rate_add_edit', $data); |
||
| 704 | } |
||
| 705 | |||
| 706 | function termination_rate_save() |
||
| 707 | { |
||
| 708 | $add_array = $this->input->post(); |
||
| 709 | $data['form'] = $this->form->build_form($this->rates_form->get_termination_rate_form_fields() , $add_array); |
||
| 710 | if ($add_array['id'] != '') |
||
| 711 | { |
||
| 712 | $data['page_title'] = 'Edit Termination Rate'; |
||
| 713 | if ($this->form_validation->run() == FALSE) |
||
| 714 | { |
||
| 715 | $data['validation_errors'] = validation_errors(); |
||
| 716 | echo $data['validation_errors']; |
||
| 717 | exit; |
||
| 718 | } |
||
| 719 | else |
||
| 720 | { |
||
| 721 | $add_array['connectcost'] = $this->common_model->add_calculate_currency($add_array['connectcost'], '', '', false, false); |
||
| 722 | $add_array['cost'] = $this->common_model->add_calculate_currency($add_array['cost'], '', '', false, false); |
||
| 723 | $this->rates_model->edit_termination_rate($add_array, $add_array['id']); |
||
| 724 | echo json_encode(array( |
||
| 725 | "SUCCESS" => "Termination updated successfully!" |
||
| 726 | )); |
||
| 727 | exit; |
||
| 728 | } |
||
| 729 | } |
||
| 730 | else |
||
| 731 | { |
||
| 732 | $data['page_title'] = 'Add Termination Rate'; |
||
| 733 | if ($this->form_validation->run() == FALSE) |
||
| 734 | { |
||
| 735 | $data['validation_errors'] = validation_errors(); |
||
| 736 | echo $data['validation_errors']; |
||
| 737 | exit; |
||
| 738 | } |
||
| 739 | else |
||
| 740 | { |
||
| 741 | $add_array['connectcost'] = $this->common_model->add_calculate_currency($add_array['connectcost'], '', '', false, false); |
||
| 742 | $add_array['cost'] = $this->common_model->add_calculate_currency($add_array['cost'], '', '', false, false); |
||
| 743 | $this->rates_model->add_termination_rate($add_array); |
||
| 744 | echo json_encode(array( |
||
| 745 | "SUCCESS" => "Termination added successfully!" |
||
| 746 | )); |
||
| 747 | exit; |
||
| 748 | } |
||
| 749 | } |
||
| 750 | |||
| 751 | $this->load->view('view_termination_rate_add_edit', $data); |
||
| 752 | } |
||
| 753 | |||
| 754 | function termination_rates_list_search() |
||
| 755 | { |
||
| 756 | $ajax_search = $this->input->post('ajax_search', 0); |
||
| 757 | if ($this->input->post('advance_search', TRUE) == 1) |
||
| 758 | { |
||
| 759 | $this->session->set_userdata('advance_search', $this->input->post('advance_search')); |
||
| 760 | $action = $this->input->post(); |
||
| 761 | unset($action['action']); |
||
| 762 | unset($action['advance_search']); |
||
| 763 | $this->session->set_userdata('termination_rates_list_search', $action); |
||
| 764 | } |
||
| 765 | |||
| 766 | if (@$ajax_search != 1) |
||
| 767 | { |
||
| 768 | redirect(base_url() . 'rates/termination_rates_list/'); |
||
| 769 | } |
||
| 770 | } |
||
| 771 | |||
| 772 | function termination_rates_list_clearsearchfilter() |
||
| 773 | { |
||
| 774 | $this->session->set_userdata('advance_search', 0); |
||
| 775 | $this->session->set_userdata('account_search', ""); |
||
| 776 | } |
||
| 777 | |||
| 778 | function customer_block_pattern_list($accountid, $accounttype) |
||
| 779 | { |
||
| 780 | $json_data = array(); |
||
| 781 | $where = array( |
||
| 782 | 'accountid' => $accountid |
||
| 783 | ); |
||
| 784 | $instant_search = $this->session->userdata('left_panel_search_' . $accounttype . '_pattern'); |
||
| 785 | $like_str = !empty($instant_search) ? "(blocked_patterns like '%$instant_search%' OR destination like '%$instant_search%' )" : null; |
||
| 786 | if (!empty($like_str)) $this->db->where($like_str); |
||
| 787 | $count_all = $this->db_model->countQuery("*", "block_patterns", $where); |
||
| 788 | $paging_data = $this->form->load_grid_config($count_all, $_GET['rp'], $_GET['page']); |
||
| 789 | $json_data = $paging_data["json_paging"]; |
||
| 790 | if (!empty($like_str)) $this->db->where($like_str); |
||
| 791 | $pattern_data = $this->db_model->getSelect("*", "block_patterns", $where, "id", "ASC", $paging_data["paging"]["page_no"], $paging_data["paging"]["start"]); |
||
| 792 | $grid_fields = json_decode($this->rates_form->build_pattern_list_for_customer($accountid, $accounttype)); |
||
| 793 | $json_data['rows'] = $this->form->build_grid($pattern_data, $grid_fields); |
||
| 794 | echo json_encode($json_data); |
||
| 795 | } |
||
| 796 | |||
| 797 | function termination_rate_delete_multiple() |
||
| 798 | { |
||
| 799 | $ids = $this->input->post("selected_ids", true); |
||
| 800 | $where = "id IN ($ids)"; |
||
| 801 | $this->db->where($where); |
||
| 802 | echo $this->db->delete("outbound_routes"); |
||
| 803 | } |
||
| 804 | |||
| 805 | function origination_rate_delete_multiple() |
||
| 806 | { |
||
| 807 | $ids = $this->input->post("selected_ids", true); |
||
| 808 | $where = "id IN ($ids)"; |
||
| 809 | $this->db->where($where); |
||
| 810 | echo $this->db->delete("routes"); |
||
| 811 | } |
||
| 812 | |||
| 813 | function user_origination_rate_list_json() |
||
| 814 | { |
||
| 815 | $json_data = array(); |
||
| 816 | $account_data = $this->session->userdata("accountinfo"); |
||
| 817 | $markup = $this->common->get_field_name('markup', 'pricelists', array( |
||
| 818 | 'id' => $account_data["pricelist_id"] |
||
| 819 | )); |
||
| 820 | $markup = ($markup > 0) ? $markup : 1; |
||
| 821 | $count_all = $this->rates_model->get_origination_rate_list_for_user(false); |
||
| 822 | $paging_data = $this->form->load_grid_config($count_all, $_GET['rp'], $_GET['page']); |
||
| 823 | $json_data = $paging_data["json_paging"]; |
||
| 824 | $query = $this->rates_model->get_origination_rate_list_for_user(true, $paging_data["paging"]["start"], $paging_data["paging"]["page_no"]); |
||
| 825 | $grid_fields = json_decode($this->rates_form->build_origination_rate_list_for_user()); |
||
| 826 | foreach($query->result_array() as $key => $value) |
||
| 827 | { |
||
| 828 | $json_data['rows'][] = array( |
||
| 829 | 'cell' => array( |
||
| 830 | $this->common->get_only_numeric_val("", "", $value["pattern"]) , |
||
| 831 | $value['comment'], |
||
| 832 | $value['inc'], |
||
| 833 | $this->common_model->calculate_currency(($value['cost'] + ($value['cost'] * $markup) / 100) , '', '', '', true) , |
||
| 834 | $this->common_model->calculate_currency($value['connectcost'], '', '', '', true) , |
||
| 835 | $value['includedseconds'] |
||
| 836 | ) |
||
| 837 | ); |
||
| 838 | } |
||
| 839 | |||
| 840 | // $json_data['rows'] = $this->form->build_grid($query, $grid_fields); |
||
| 841 | |||
| 842 | echo json_encode($json_data); |
||
| 843 | } |
||
| 844 | |||
| 845 | function user_origination_rate_list_search() |
||
| 846 | { |
||
| 847 | $ajax_search = $this->input->post('ajax_search', 0); |
||
| 848 | if ($this->input->post('advance_search', TRUE) == 1) |
||
| 849 | { |
||
| 850 | $this->session->set_userdata('advance_search', $this->input->post('advance_search')); |
||
| 851 | $action = $this->input->post(); |
||
| 852 | unset($action['action']); |
||
| 853 | unset($action['advance_search']); |
||
| 854 | $this->session->set_userdata('origination_rate_list_search', $action); |
||
| 855 | } |
||
| 856 | |||
| 857 | if (@$ajax_search != 1) |
||
| 858 | { |
||
| 859 | redirect(base_url() . 'user/user_rates_list/'); |
||
| 860 | } |
||
| 861 | } |
||
| 862 | |||
| 863 | function user_origination_rate_list_clearsearchfilter() |
||
| 864 | { |
||
| 865 | $this->session->set_userdata('advance_search', 0); |
||
| 866 | $this->session->set_userdata('account_search', ""); |
||
| 867 | } |
||
| 868 | |||
| 869 | function customer_rates_download_sample_file($file_name) |
||
| 870 | { |
||
| 871 | $this->load->helper('download'); |
||
| 872 | $full_path = base_url() . "assets/Rates_File/" . $file_name . ".csv"; |
||
| 873 | $arrContextOptions = array( |
||
| 874 | "ssl" => array( |
||
| 875 | "verify_peer" => false, |
||
| 876 | "verify_peer_name" => false, |
||
| 877 | ) , |
||
| 878 | ); |
||
| 879 | $file = file_get_contents($full_path, false, stream_context_create($arrContextOptions)); |
||
| 880 | force_download("samplefile.csv", $file); |
||
| 881 | } |
||
| 882 | |||
| 883 | function termination_rate_batch_update() |
||
| 884 | { |
||
| 885 | $batch_update_arr = $this->input->post(); |
||
| 886 | $batch_update_arr["cost"]["cost"] = isset($batch_update_arr["cost"]["cost"]) ? $this->common_model->add_calculate_currency($batch_update_arr["cost"]["cost"], '', '', true, false) : "0.0000"; |
||
| 887 | $batch_update_arr["connectcost"]["connectcost"] = isset($batch_update_arr["connectcost"]["connectcost"]) ? $this->common_model->add_calculate_currency($batch_update_arr["connectcost"]["connectcost"], '', '', true, false) : "0.0000"; |
||
| 888 | |||
| 889 | // $batch_update_arr = array("inc"=> array("inc"=>"1","operator"=>"3"),"cost"=> array("cost"=>"1","operator"=>"4")); |
||
| 890 | |||
| 891 | $result = $this->rates_model->termination_rate_batch_update($batch_update_arr); |
||
| 892 | echo json_encode(array( |
||
| 893 | "SUCCESS" => "Termination rates batch updated successfully!" |
||
| 894 | )); |
||
| 895 | exit; |
||
| 896 | } |
||
| 897 | |||
| 898 | function origination_rate_batch_update() |
||
| 899 | { |
||
| 900 | $batch_update_arr = $this->input->post(); |
||
| 901 | $batch_update_arr["cost"]["cost"] = isset($batch_update_arr["cost"]["cost"]) ? $this->common_model->add_calculate_currency($batch_update_arr["cost"]["cost"], '', '', true, false) : "0.0000"; |
||
| 902 | |||
| 903 | // $batch_update_arr = array("inc"=> array("inc"=>"1","operator"=>"3"),"cost"=> array("cost"=>"1","operator"=>"4")); |
||
| 904 | |||
| 905 | $result = $this->rates_model->origination_rate_batch_update($batch_update_arr); |
||
| 906 | echo json_encode(array( |
||
| 907 | "SUCCESS" => "Origination rates batch updated successfully!" |
||
| 908 | )); |
||
| 909 | exit; |
||
| 910 | } |
||
| 911 | |||
| 912 | function termination_rate_export_cdr_xls() |
||
| 913 | { |
||
| 914 | $account_info = $accountinfo = $this->session->userdata('accountinfo'); |
||
| 915 | $currency_id = $account_info['currency_id']; |
||
| 916 | $currency = $this->common->get_field_name('currency', 'currency', $currency_id); |
||
| 917 | $query = $this->rates_model->get_termination_rate(true, '', '', false); |
||
| 918 | $outbound_array = array(); |
||
| 919 | ob_clean(); |
||
| 920 | $outbound_array[] = array( |
||
| 921 | "Code", |
||
| 922 | "Destination", |
||
| 923 | "Connect Cost($currency)", |
||
| 924 | "Included Seconds", |
||
| 925 | "Per Minute Cost($currency)", |
||
| 926 | "Initial Increment", |
||
| 927 | "Increment", |
||
| 928 | "Priority", |
||
| 929 | "Strip", |
||
| 930 | "Prepend", |
||
| 931 | "Trunk", |
||
| 932 | "Status", |
||
| 933 | "Created Date" |
||
| 934 | ); |
||
| 935 | if ($query->num_rows() > 0) |
||
| 936 | { |
||
| 937 | foreach($query->result_array() as $row) |
||
| 938 | { |
||
| 939 | |||
| 940 | // echo"<pre>";print_r($row);exit; |
||
| 941 | |||
| 942 | $outbound_array[] = array( |
||
| 943 | $row['pattern'] = $this->common->get_only_numeric_val("", "", $row["pattern"]) , |
||
| 944 | $row['comment'], |
||
| 945 | $this->common_model->calculate_currency($row['connectcost'], '', '', TRUE, false) , |
||
| 946 | $row['includedseconds'], |
||
| 947 | $this->common_model->calculate_currency($row['cost'], '', '', TRUE, false) , |
||
| 948 | /** |
||
| 949 | ASTPP 3.0 |
||
| 950 | For Add Initial Increment field |
||
| 951 | * |
||
| 952 | */ |
||
| 953 | $row['init_inc'], |
||
| 954 | /****************************************/ |
||
| 955 | $row['inc'], |
||
| 956 | $row['precedence'], |
||
| 957 | $row['strip'], |
||
| 958 | $row['prepend'], |
||
| 959 | |||
| 960 | // $row['trunk_id'], |
||
| 961 | |||
| 962 | $this->common->get_field_name('name', 'trunks', $row["trunk_id"]) , |
||
| 963 | $this->common->get_status('export', '', $row['status']) , |
||
| 964 | $row['creation_date'], |
||
| 965 | ); |
||
| 966 | } |
||
| 967 | } |
||
| 968 | |||
| 969 | $this->load->helper('csv'); |
||
| 970 | array_to_csv($outbound_array, 'Termination_Rates_' . date("Y-m-d") . '.csv'); |
||
| 971 | } |
||
| 972 | |||
| 973 | function termination_rate_export_cdr_pdf() |
||
| 974 | { |
||
| 975 | $query = $this->rates_model->get_termination_rate(true, '', '', false); |
||
| 976 | $outbound_array = array(); |
||
| 977 | $this->load->library('fpdf'); |
||
| 978 | $this->load->library('pdf'); |
||
| 979 | $this->fpdf = new PDF('P', 'pt'); |
||
| 980 | $this->fpdf->initialize('P', 'mm', 'A4'); |
||
| 981 | $this->fpdf->tablewidths = array( |
||
| 982 | 20, |
||
| 983 | 30, |
||
| 984 | 20, |
||
| 985 | 20, |
||
| 986 | 20, |
||
| 987 | 20, |
||
| 988 | 20, |
||
| 989 | 20, |
||
| 990 | 20 |
||
| 991 | ); |
||
| 992 | $outbound_array[] = array( |
||
| 993 | "Code", |
||
| 994 | "Destination", |
||
| 995 | "Connect Cost", |
||
| 996 | "Included Seconds", |
||
| 997 | "Per Minute Cost", |
||
| 998 | "Initial Increment", |
||
| 999 | "Increment", |
||
| 1000 | "Precedence", |
||
| 1001 | "Prepend", |
||
| 1002 | "Strip" |
||
| 1003 | ); |
||
| 1004 | if ($query->num_rows() > 0) |
||
| 1005 | { |
||
| 1006 | foreach($query->result_array() as $row) |
||
| 1007 | { |
||
| 1008 | $outbound_array[] = array( |
||
| 1009 | $row['pattern'] = $this->common->get_only_numeric_val("", "", $row["pattern"]) , |
||
| 1010 | $row['comment'], |
||
| 1011 | $row['connectcost'], |
||
| 1012 | $row['includedseconds'], |
||
| 1013 | $this->common_model->calculate_currency($row['cost']) , |
||
| 1014 | /** |
||
| 1015 | ASTPP 3.0 |
||
| 1016 | For Add Initial Increment field |
||
| 1017 | * |
||
| 1018 | */ |
||
| 1019 | $row['init_inc'], |
||
| 1020 | /*******************************************/ |
||
| 1021 | $row['inc'], |
||
| 1022 | $row['precedence'], |
||
| 1023 | $row['prepend'], |
||
| 1024 | $row['strip'] |
||
| 1025 | ); |
||
| 1026 | } |
||
| 1027 | } |
||
| 1028 | |||
| 1029 | $this->fpdf->AliasNbPages(); |
||
| 1030 | $this->fpdf->AddPage(); |
||
| 1031 | $this->fpdf->SetFont('Arial', '', 15); |
||
| 1032 | $this->fpdf->SetXY(60, 5); |
||
| 1033 | $this->fpdf->Cell(100, 10, "Outbound Rates Report " . date('Y-m-d')); |
||
| 1034 | $this->fpdf->SetY(20); |
||
| 1035 | $this->fpdf->SetFont('Arial', '', 7); |
||
| 1036 | $this->fpdf->SetFillColor(255, 255, 255); |
||
| 1037 | $this->fpdf->lMargin = 2; |
||
| 1038 | $dimensions = $this->fpdf->export_pdf($outbound_array, "7"); |
||
| 1039 | $this->fpdf->Output('Termination_Rate_' . date("Y-m-d") . '.pdf', "D"); |
||
| 1040 | } |
||
| 1041 | |||
| 1042 | function origination_rate_export_cdr_xls() |
||
| 1043 | { |
||
| 1044 | $account_info = $accountinfo = $this->session->userdata('accountinfo'); |
||
| 1045 | $currency_id = $account_info['currency_id']; |
||
| 1046 | $currency = $this->common->get_field_name('currency', 'currency', $currency_id); |
||
| 1047 | $query = $this->rates_model->get_origination_rate(true, '', '', false); |
||
| 1048 | |||
| 1049 | // echo "<pre>";print_r($query);exit; |
||
| 1050 | |||
| 1617 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.