1
|
|
|
<?php |
2
|
|
|
############################################################################### |
3
|
|
|
# ASTPP - Open Source VoIP Billing Solution |
4
|
|
|
# |
5
|
|
|
# Copyright (C) 2016 iNextrix Technologies Pvt. Ltd. |
6
|
|
|
# Samir Doshi <[email protected]> |
7
|
|
|
# ASTPP Version 3.0 and above |
8
|
|
|
# License https://www.gnu.org/licenses/agpl-3.0.html |
9
|
|
|
# |
10
|
|
|
# This program is free software: you can redistribute it and/or modify |
11
|
|
|
# it under the terms of the GNU Affero General Public License as |
12
|
|
|
# published by the Free Software Foundation, either version 3 of the |
13
|
|
|
# License, or (at your option) any later version. |
14
|
|
|
# |
15
|
|
|
# This program is distributed in the hope that it will be useful, |
16
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
17
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18
|
|
|
# GNU Affero General Public License for more details. |
19
|
|
|
# |
20
|
|
|
# You should have received a copy of the GNU Affero General Public License |
21
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
22
|
|
|
############################################################################### |
23
|
|
|
class Rates extends MX_Controller { |
24
|
|
|
|
25
|
|
|
function Rates() { |
26
|
|
|
parent::__construct(); |
|
|
|
|
27
|
|
|
|
28
|
|
|
$this->load->helper('template_inheritance'); |
29
|
|
|
|
30
|
|
|
$this->load->library('session'); |
31
|
|
|
$this->load->library('rates_form'); |
32
|
|
|
$this->load->library('astpp/form'); |
33
|
|
|
$this->load->model('rates_model'); |
34
|
|
|
$this->load->library('csvreader'); |
35
|
|
|
ini_set("memory_limit", "2048M"); |
36
|
|
|
ini_set("max_execution_time", "259200"); |
37
|
|
|
ini_set("upload_max_filesize", "200M"); |
38
|
|
|
if ($this->session->userdata('user_login') == FALSE) |
39
|
|
|
redirect(base_url() . '/astpp/login'); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
View Code Duplication |
function termination_rates_list() { |
43
|
|
|
$data['username'] = $this->session->userdata('user_name'); |
|
|
|
|
44
|
|
|
$data['page_title'] = 'Termination Rates'; |
45
|
|
|
$data['search_flag'] = true; |
46
|
|
|
$data['batch_update_flag'] = true; |
47
|
|
|
/********* |
48
|
|
|
ASTPP 3.0 |
49
|
|
|
Batch Delete |
50
|
|
|
*********/ |
51
|
|
|
$data['delete_batch_flag'] = true; |
52
|
|
|
/***************/ |
53
|
|
|
$this->session->set_userdata('advance_search', 0); |
54
|
|
|
$data['grid_fields'] = $this->rates_form->build_termination_rate_for_admin(); |
55
|
|
|
$data["grid_buttons"] = $this->rates_form->build_grid_buttons(); |
56
|
|
|
$data['form_search'] = $this->form->build_serach_form($this->rates_form->get_termination_rate_search_form()); |
57
|
|
|
$data['form_batch_update'] = $this->form->build_batchupdate_form($this->rates_form->termination_rate_batch_update_form()); |
58
|
|
|
$this->load->view('view_termination_rates_list', $data); |
59
|
|
|
} |
60
|
|
|
/** |
61
|
|
|
* -------Here we write code for controller accounts functions account_list------ |
62
|
|
|
* Listing of Accounts table data through php function json_encode |
63
|
|
|
*/ |
64
|
|
|
function termination_rates_list_json() { |
65
|
|
|
$json_data = array(); |
66
|
|
|
$count_all = $this->rates_model->get_termination_rates_list(false); |
67
|
|
|
$paging_data = $this->form->load_grid_config($count_all, $_GET['rp'], $_GET['page']); |
68
|
|
|
$json_data = $paging_data["json_paging"]; |
69
|
|
|
|
70
|
|
|
$query = $this->rates_model->get_termination_rates_list(true, $paging_data["paging"]["start"], $paging_data["paging"]["page_no"]); |
71
|
|
|
$grid_fields = json_decode($this->rates_form->build_termination_rate_for_admin()); |
72
|
|
|
$json_data['rows'] = $this->form->build_grid($query, $grid_fields); |
73
|
|
|
|
74
|
|
|
echo json_encode($json_data); |
75
|
|
|
} |
76
|
|
View Code Duplication |
function termination_rates_list_delete($flag='') { |
|
|
|
|
77
|
|
|
$json_data = array(); |
78
|
|
|
$this->session->set_userdata('advance_batch_data_delete',1); |
79
|
|
|
$count_all = $this->rates_model->get_termination_rates_list(false); |
80
|
|
|
echo $count_all; |
81
|
|
|
} |
82
|
|
|
/****************/ |
83
|
|
|
function termination_rate_import() { |
84
|
|
|
$data['page_title'] = 'Import Termination Rates'; |
|
|
|
|
85
|
|
|
$this->session->set_userdata('import_termination_rate_csv',""); |
86
|
|
|
$this->session->set_userdata('import_termination_rate_csv_error',""); |
87
|
|
|
$this->load->view('view_import_termination_rate', $data); |
88
|
|
|
} |
89
|
|
|
function termination_rate_preview_file(){ |
90
|
|
|
$invalid_flag= false; |
91
|
|
|
$check_header=$this->input->post('check_header',true); |
92
|
|
|
$data['page_title'] = 'Import Termination Rates'; |
|
|
|
|
93
|
|
|
$new_final_arr_key = $this->config->item('Termination-rates-field'); |
94
|
|
|
if(empty($_FILES) || !isset($_FILES)){ |
95
|
|
|
redirect(base_url()."rates/termination_rates_list/"); |
96
|
|
|
} |
97
|
|
|
if (isset($_FILES['termination_rate_import']['name']) && $_FILES['termination_rate_import']['name'] != "" && isset($_POST['trunk_id']) && $_POST['trunk_id'] != '') { |
98
|
|
|
list($txt, $ext) = explode(".", $_FILES['termination_rate_import']['name']); |
|
|
|
|
99
|
|
|
if($ext == "csv" && $_FILES['termination_rate_import']['size'] > 0){ |
100
|
|
|
$error = $_FILES['termination_rate_import']['error']; |
101
|
|
|
if ($error == 0 ) { |
102
|
|
|
$uploadedFile = $_FILES["termination_rate_import"]["tmp_name"]; |
103
|
|
|
$csv_data=$this->csvreader->parse_file($uploadedFile,$new_final_arr_key,$check_header); |
104
|
|
|
if(!empty($csv_data)){ |
105
|
|
|
$full_path = $this->config->item('rates-file-path'); |
106
|
|
|
$actual_file_name = "ASTPP-TERMINATION-RATES-".date("Y-m-d H:i:s"). "." . $ext; |
107
|
|
View Code Duplication |
if (move_uploaded_file($uploadedFile,$full_path.$actual_file_name)) { |
108
|
|
|
$data['csv_tmp_data'] = $csv_data; |
109
|
|
|
$data['trunkid'] = $_POST['trunk_id']; |
110
|
|
|
$data['check_header']=$check_header; |
111
|
|
|
$data['page_title'] = 'Termination Rates Preview'; |
112
|
|
|
$this->session->set_userdata('import_termination_rate_csv',$actual_file_name); |
113
|
|
|
}else{ |
114
|
|
|
$data['error'] = "File Uploading Fail Please Try Again"; |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
else{ |
119
|
|
|
$data['error']=="File Uploading Fail Please Try Again"; |
120
|
|
|
} |
121
|
|
|
}else { |
122
|
|
|
$data['error'] = "Invalid file format : Only CSV file allows to import records(Can't import empty file)"; |
123
|
|
|
} |
124
|
|
|
}else{ |
125
|
|
|
$invalid_flag=true; |
126
|
|
|
} |
127
|
|
View Code Duplication |
if ($invalid_flag) { |
128
|
|
|
$str = ''; |
129
|
|
|
if (!isset($_POST['trunk_id']) || empty($_POST['trunk_id'])) { |
130
|
|
|
$str.= '<br/>Please Create Trunk.'; |
131
|
|
|
} |
132
|
|
|
if (empty($_FILES['termination_rate_import']['name'])) { |
133
|
|
|
$str.= '<br/>Please Select File.'; |
134
|
|
|
} |
135
|
|
|
$data['error']=$str; |
136
|
|
|
} |
137
|
|
|
$this->load->view('view_import_termination_rate', $data); |
138
|
|
|
} |
139
|
|
|
function termination_rate_rates_import($trunkID,$check_header=false) { |
140
|
|
|
$new_final_arr = array(); |
141
|
|
|
$invalid_array = array(); |
142
|
|
|
$new_final_arr_key = $this->config->item('Termination-rates-field'); |
143
|
|
|
$screen_path = $this->config->item('screen_path'); |
144
|
|
View Code Duplication |
if ($this->session->userdata('logintype') == 1 || $this->session->userdata('logintype') == 5) { |
145
|
|
|
$account_data = $this->session->userdata("accountinfo"); |
146
|
|
|
} |
147
|
|
|
$full_path = $this->config->item('rates-file-path'); |
148
|
|
|
$terminationrate_file_name = $this->session->userdata('import_termination_rate_csv'); |
149
|
|
|
$csv_tmp_data = $this->csvreader->parse_file($full_path.$terminationrate_file_name,$new_final_arr_key,$check_header); |
150
|
|
|
$i=0; |
151
|
|
|
foreach ($csv_tmp_data as $key => $csv_data) { |
152
|
|
|
if(isset($csv_data['pattern']) && $csv_data['pattern']!= '' && $i != 0){ |
153
|
|
|
$str=null; |
154
|
|
|
$csv_data['prepend']= isset($csv_data['prepend'])? $csv_data['prepend'] :''; |
155
|
|
|
$csv_data['comment']= isset($csv_data['comment'])? $csv_data['comment'] :''; |
156
|
|
|
$csv_data['connectcost']= isset($csv_data['connectcost']) ? $csv_data['connectcost'] :0; |
157
|
|
|
$csv_data['includedseconds']= isset($csv_data['includedseconds']) ? $csv_data['includedseconds'] :0; |
158
|
|
|
$csv_data['cost']= !empty($csv_data['cost']) && is_numeric( $csv_data['cost']) ? $csv_data['cost'] :0; |
159
|
|
|
$csv_data['inc']= isset($csv_data['inc']) ? $csv_data['inc'] :0; |
160
|
|
|
$csv_data['precedence']= isset($csv_data['precedence']) ? $csv_data['precedence'] :''; |
161
|
|
|
$csv_data['strip']= isset($csv_data['strip']) ? $csv_data['strip'] :''; |
162
|
|
|
$csv_data['last_modified_date'] = date("Y-m-d H:i:s"); |
163
|
|
|
$str=$this->data_validate($csv_data); |
164
|
|
|
if($str != ""){ |
165
|
|
|
$invalid_array[$i]=$csv_data; |
166
|
|
|
$invalid_array[$i]['error'] = $str; |
167
|
|
|
} |
168
|
|
|
else{ |
169
|
|
|
$csv_data['trunk_id']=$trunkID; |
170
|
|
|
$csv_data['pattern'] = "^" . $csv_data['pattern'] . ".*"; |
171
|
|
|
$new_final_arr[$i]=$csv_data; |
172
|
|
|
} |
173
|
|
|
} |
174
|
|
|
$i++; |
175
|
|
|
} |
176
|
|
|
if(!empty($new_final_arr)){ |
177
|
|
|
$result = $this->rates_model->bulk_insert_termination_rate($new_final_arr); |
178
|
|
|
} |
179
|
|
|
unlink($full_path.$terminationrate_file_name); |
180
|
|
|
$count=count($invalid_array); |
181
|
|
View Code Duplication |
if($count >0){ |
182
|
|
|
$session_id = "-1"; |
183
|
|
|
$fp = fopen($full_path.$session_id.'.csv', 'w'); |
184
|
|
|
foreach($new_final_arr_key as $key=>$value){ |
185
|
|
|
$custom_array[0][$key]=ucfirst($key); |
|
|
|
|
186
|
|
|
} |
187
|
|
|
$custom_array[0]['error']= "Error"; |
|
|
|
|
188
|
|
|
$invalid_array =array_merge($custom_array,$invalid_array); |
189
|
|
|
foreach($invalid_array as $err_data){ |
190
|
|
|
fputcsv($fp,$err_data); |
191
|
|
|
} |
192
|
|
|
fclose($fp); |
193
|
|
|
$this->session->set_userdata('import_termination_rate_csv_error', $session_id.".csv"); |
194
|
|
|
$data["error"] = $invalid_array; |
|
|
|
|
195
|
|
|
$data['trunkid'] = $trunkID; |
196
|
|
|
$data['impoted_count'] = count($new_final_arr); |
197
|
|
|
$data['failure_count'] = count($invalid_array)-1; |
198
|
|
|
$data['page_title'] = 'Termination Rates Import Error'; |
199
|
|
|
$this->load->view('view_import_error',$data); |
200
|
|
|
} else{ |
201
|
|
|
$this->session->set_flashdata('astpp_errormsg', 'Total '.count($new_final_arr).' Termination rates imported successfully!'); |
202
|
|
|
redirect(base_url()."rates/termination_rates_list/"); |
203
|
|
|
} |
204
|
|
|
} |
205
|
|
View Code Duplication |
function termination_rate_error_download(){ |
206
|
|
|
$this->load->helper('download'); |
207
|
|
|
$error_data = $this->session->userdata('import_termination_rate_csv_error'); |
208
|
|
|
$full_path = $this->config->item('rates-file-path'); |
209
|
|
|
$data = file_get_contents($full_path.$error_data); |
210
|
|
|
force_download("Termination_rate_error.csv", $data); |
211
|
|
|
|
212
|
|
|
} |
213
|
|
View Code Duplication |
function origination_rate_import() { |
214
|
|
|
$data['page_title'] = 'Import Origination Rates'; |
|
|
|
|
215
|
|
|
$this->session->set_userdata('import_origination_rate_csv',""); |
216
|
|
|
$error_data = $this->session->userdata('import_origination_rate_csv_error'); |
217
|
|
|
$full_path = $this->config->item('rates-file-path'); |
218
|
|
|
if(file_exists($full_path.$error_data) && $error_data != ""){ |
219
|
|
|
unlink($full_path.$error_data); |
220
|
|
|
$this->session->set_userdata('import_origination_rate_csv_error',""); |
221
|
|
|
} |
222
|
|
|
$this->load->view('view_import_origination_rate', $data); |
223
|
|
|
} |
224
|
|
|
function origination_rate_preview_file(){ |
225
|
|
|
$invalid_flag= false; |
226
|
|
|
$data=array(); |
227
|
|
|
$data['page_title'] = 'Import Origination Rates'; |
228
|
|
|
$check_header=$this->input->post('check_header',true); |
229
|
|
|
if(empty($_FILES) || !isset($_FILES)){ |
230
|
|
|
redirect(base_url()."rates/origination_rate_list/"); |
231
|
|
|
} |
232
|
|
|
$get_extension=strpos($_FILES['origination_rate_import']['name'],'.'); |
233
|
|
|
$new_final_arr_key = $this->config->item('Origination-rates-field'); |
234
|
|
|
if(!$get_extension){ |
235
|
|
|
$data['error']= "Please Upload File Atleast"; |
236
|
|
|
} |
237
|
|
|
if (isset($_FILES['origination_rate_import']['name']) && $_FILES['origination_rate_import']['name'] != "" && isset($_POST['pricelist_id']) && $_POST['pricelist_id'] != '') { |
238
|
|
|
list($txt,$ext) = explode(".", $_FILES['origination_rate_import']['name']); |
|
|
|
|
239
|
|
|
|
240
|
|
|
if($ext == "csv" && $_FILES['origination_rate_import']['size'] > 0){ |
241
|
|
|
$error = $_FILES['origination_rate_import']['error']; |
242
|
|
View Code Duplication |
if ($error == 0) { |
243
|
|
|
$uploadedFile = $_FILES["origination_rate_import"]["tmp_name"]; |
244
|
|
|
$csv_data=$this->csvreader->parse_file($uploadedFile,$new_final_arr_key,$check_header); |
245
|
|
|
if(!empty($csv_data)){ |
246
|
|
|
$full_path = $this->config->item('rates-file-path'); |
247
|
|
|
$actual_file_name = "ASTPP-ORIGIN-RATES-".date("Y-m-d H:i:s"). "." . $ext; |
248
|
|
|
if (move_uploaded_file($uploadedFile,$full_path.$actual_file_name)) { |
249
|
|
|
$flag=false; |
250
|
|
|
$data['trunkid']=isset($_POST['trunk_id']) && $_POST['trunk_id'] > 0 ? $_POST['trunk_id'] : 0; |
251
|
|
|
$data['csv_tmp_data'] = $csv_data; |
252
|
|
|
$data['pricelistid'] = $_POST['pricelist_id']; |
253
|
|
|
$data['page_title'] = "Origination Rates Preview"; |
254
|
|
|
$data['check_header']=$check_header; |
255
|
|
|
$this->session->set_userdata('import_origination_rate_csv',$actual_file_name); |
256
|
|
|
}else{ |
257
|
|
|
$data['error'] = "File Uploading Fail Please Try Again"; |
258
|
|
|
} |
259
|
|
|
} |
260
|
|
|
} |
261
|
|
|
else{ |
262
|
|
|
$data['error']=="File Uploading Fail Please Try Again"; |
263
|
|
|
} |
264
|
|
|
} |
265
|
|
|
else { |
266
|
|
|
$data['error'] = "Invalid file format : Only CSV file allows to import records(Can't import empty file)"; |
267
|
|
|
} |
268
|
|
|
}else{ |
269
|
|
|
$invalid_flag=true; |
270
|
|
|
} |
271
|
|
View Code Duplication |
if ($invalid_flag) { |
272
|
|
|
$str = ''; |
273
|
|
|
if (!isset($_POST['pricelist_id']) || empty($_POST['pricelist_id'])) { |
274
|
|
|
$str.= '<br/>Please Create Rate Group.'; |
275
|
|
|
} |
276
|
|
|
if (empty($_FILES['origination_rate_import']['name'])) { |
277
|
|
|
$str.= '<br/>Please Select File.'; |
278
|
|
|
} |
279
|
|
|
$data['error']=$str; |
280
|
|
|
} |
281
|
|
|
$this->load->view('view_import_origination_rate', $data); |
282
|
|
|
} |
283
|
|
|
function origination_rate_import_file($pricelistID,$trunkid,$check_header=false) { |
284
|
|
|
$new_final_arr = array(); |
285
|
|
|
$invalid_array = array(); |
286
|
|
|
$new_final_arr_key = $this->config->item('Origination-rates-field'); |
287
|
|
|
$screen_path = $this->config->item('screen_path'); |
288
|
|
|
$reseller_id=0; |
289
|
|
|
if ($this->session->userdata('logintype') == 1 || $this->session->userdata('logintype') == 5) { |
290
|
|
|
$reseller_id = $this->session->userdata["accountinfo"]['id']; |
291
|
|
|
} |
292
|
|
|
|
293
|
|
|
$full_path = $this->config->item('rates-file-path'); |
294
|
|
|
$originationrate_file_name = $this->session->userdata('import_origination_rate_csv'); |
295
|
|
|
$csv_tmp_data = $this->csvreader->parse_file($full_path.$originationrate_file_name,$new_final_arr_key,$check_header); |
296
|
|
|
//echo "<pre>";print_r($csv_tmp_data);exit; |
|
|
|
|
297
|
|
|
$i=0; |
298
|
|
|
foreach ($csv_tmp_data as $key => $csv_data) { |
299
|
|
|
if(isset($csv_data['pattern']) && $csv_data['pattern']!= '' && $i != 0){ |
300
|
|
|
$str=null; |
301
|
|
|
$csv_data['comment']= isset($csv_data['comment'])? $csv_data['comment'] :''; |
302
|
|
|
$csv_data['connectcost']= isset($csv_data['connectcost']) ? $csv_data['connectcost'] :0; |
303
|
|
|
$csv_data['includedseconds']= isset($csv_data['includedseconds']) ? $csv_data['includedseconds'] :0; |
304
|
|
|
$csv_data['cost']= !empty($csv_data['cost']) && is_numeric( $csv_data['cost']) ? $csv_data['cost'] :0; |
305
|
|
|
$csv_data['inc']= isset($csv_data['inc']) ? $csv_data['inc'] :0; |
306
|
|
|
$csv_data['precedence']= isset($csv_data['precedence']) ? $csv_data['precedence'] :''; |
307
|
|
|
$csv_data['last_modified_date'] = date("Y-m-d H:i:s"); |
308
|
|
|
$str=$this->data_validate($csv_data); |
309
|
|
|
if($str != ""){ |
310
|
|
|
$invalid_array[$i]=$csv_data; |
311
|
|
|
$invalid_array[$i]['error'] = $str; |
312
|
|
|
} |
313
|
|
|
else{ |
314
|
|
|
$csv_data['pricelist_id']=$pricelistID; |
315
|
|
|
$csv_data['trunk_id']=$trunkid; |
316
|
|
|
$csv_data['pattern'] = "^" . $csv_data['pattern'] . ".*"; |
317
|
|
|
$csv_data['reseller_id']= $reseller_id; |
318
|
|
|
$csv_data['creation_date'] = gmdate('Y-m-d H:i:s'); |
319
|
|
|
$new_final_arr[$i]=$csv_data; |
320
|
|
|
} |
321
|
|
|
} |
322
|
|
|
$i++; |
323
|
|
|
} |
324
|
|
|
if(!empty($new_final_arr)){ |
325
|
|
|
$result = $this->rates_model->bulk_insert_origination_rate($new_final_arr); |
326
|
|
|
} |
327
|
|
|
unlink($full_path.$originationrate_file_name); |
328
|
|
|
$count=count($invalid_array); |
329
|
|
View Code Duplication |
if($count >0){ |
330
|
|
|
$session_id = "-1"; |
331
|
|
|
$fp = fopen($full_path.$session_id.'.csv', 'w'); |
332
|
|
|
foreach($new_final_arr_key as $key=>$value){ |
333
|
|
|
$custom_array[0][$key]=ucfirst($key); |
|
|
|
|
334
|
|
|
} |
335
|
|
|
$custom_array[0]['error']= "Error"; |
|
|
|
|
336
|
|
|
$invalid_array =array_merge($custom_array,$invalid_array); |
337
|
|
|
foreach($invalid_array as $err_data){ |
338
|
|
|
fputcsv($fp,$err_data); |
339
|
|
|
} |
340
|
|
|
fclose($fp); |
341
|
|
|
$this->session->set_userdata('import_origination_rate_csv_error', $session_id.".csv"); |
342
|
|
|
$data["error"] = $invalid_array; |
|
|
|
|
343
|
|
|
$data['pricelistid'] = $pricelistID; |
344
|
|
|
$data['impoted_count'] = count($new_final_arr); |
345
|
|
|
$data['failure_count'] = count($invalid_array)-1; |
346
|
|
|
$data['page_title'] = 'Origination Rates Import Error'; |
347
|
|
|
$this->load->view('view_import_error',$data); |
348
|
|
|
} else{ |
349
|
|
|
$this->session->set_flashdata('astpp_errormsg', 'Total '.count($new_final_arr).' Origination rates imported successfully!'); |
350
|
|
|
redirect(base_url()."rates/origination_rates_list/"); |
351
|
|
|
} |
352
|
|
|
} |
353
|
|
|
function data_validate($csvdata){ |
354
|
|
|
$str=null; |
355
|
|
|
$alpha_regex = "/^[a-z ,.'-]+$/i"; |
356
|
|
|
$alpha_numeric_regex = "/^[a-z0-9 ,.'-]+$/i"; |
357
|
|
|
$email_regex = "/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/"; |
358
|
|
|
$str.= $csvdata['pattern']!= '' ? null : 'Code,'; |
359
|
|
|
$str=rtrim($str,','); |
360
|
|
|
if(!$str){ |
361
|
|
|
$str.= is_numeric($csvdata['pattern']) ? null : 'Code,'; |
362
|
|
|
|
363
|
|
|
$str.= !empty($csvdata['connectcost']) && is_numeric( $csvdata['connectcost']) ? null :( empty($csvdata['connectcost']) ? null : 'Connect Cost,'); |
364
|
|
|
$str.= !empty($csvdata['includedseconds']) && is_numeric( $csvdata['includedseconds']) ? null :( empty($csvdata['includedseconds']) ? null : 'Included Seconds,'); |
365
|
|
|
|
366
|
|
|
$str.= !empty($csvdata['inc']) && is_numeric( $csvdata['inc']) ? null :( empty($csvdata['inc']) ? null : 'Increment,'); |
367
|
|
|
$str.= !empty($csvdata['precedence']) && is_numeric( $csvdata['precedence']) ? null :( empty($csvdata['precedence']) ? null : 'Precedence,'); |
368
|
|
|
$str.= (isset($csvdata['strip']) && !empty($csvdata['strip'])) ? (is_numeric($csvdata['strip']) ? null :'Strip,') : null; |
369
|
|
View Code Duplication |
if($str){ |
370
|
|
|
$str=rtrim($str,','); |
371
|
|
|
$error_field=explode(',',$str); |
372
|
|
|
$count = count($error_field); |
373
|
|
|
$str.= $count > 1 ? ' are not valid' : ' is not Valid'; |
374
|
|
|
return $str; |
375
|
|
|
} |
376
|
|
|
else{ |
377
|
|
|
return false; |
378
|
|
|
} |
379
|
|
|
} |
380
|
|
|
else{ |
381
|
|
|
$str=rtrim($str,','); |
382
|
|
|
$error_field=explode(',',$str); |
383
|
|
|
$count = count($error_field); |
384
|
|
|
$str.= $count > 1 ? ' are required' : ' is Required'; |
385
|
|
|
return $str; |
386
|
|
|
} |
387
|
|
|
} |
388
|
|
View Code Duplication |
function origination_rate_error_download(){ |
389
|
|
|
$this->load->helper('download'); |
390
|
|
|
$error_data = $this->session->userdata('import_origination_rate_csv_error'); |
391
|
|
|
$full_path = $this->config->item('rates-file-path'); |
392
|
|
|
$data = file_get_contents($full_path.$error_data); |
393
|
|
|
force_download("Origination_rate_error.csv", $data); |
394
|
|
|
} |
395
|
|
View Code Duplication |
function origination_rate_add($type = "") { |
|
|
|
|
396
|
|
|
|
397
|
|
|
$data['username'] = $this->session->userdata('user_name'); |
|
|
|
|
398
|
|
|
$data['flag'] = 'create'; |
399
|
|
|
$data['page_title'] = 'Create Origination Rate'; |
400
|
|
|
$data['form'] = $this->form->build_form($this->rates_form->get_origination_rate_form_fields(), ''); |
401
|
|
|
|
402
|
|
|
$this->load->view('view_origination_rate_add_edit', $data); |
403
|
|
|
} |
404
|
|
|
|
405
|
|
|
function origination_rate_edit($edit_id = '') { |
406
|
|
|
$data['page_title'] = 'Edit Origination Rate'; |
|
|
|
|
407
|
|
|
if ($this->session->userdata('logintype') == 1 || $this->session->userdata('logintype') == 5) { |
408
|
|
|
$account_data = $this->session->userdata("accountinfo"); |
409
|
|
|
$reseller = $account_data['id']; |
410
|
|
|
$where = array('id' => $edit_id, "reseller_id" => $reseller); |
411
|
|
|
} else { |
412
|
|
|
$where = array('id' => $edit_id); |
413
|
|
|
} |
414
|
|
|
$account = $this->db_model->getSelect("*", "routes", $where); |
415
|
|
|
if ($account->num_rows > 0) { |
416
|
|
|
foreach ($account->result_array() as $key => $value) { |
417
|
|
|
$edit_data = $value; |
418
|
|
|
} |
419
|
|
|
$edit_data['connectcost'] = $this->common_model->to_calculate_currency($edit_data['connectcost'], '', '', true, false); |
|
|
|
|
420
|
|
|
$edit_data['cost'] = $this->common_model->to_calculate_currency($edit_data['cost'], '', '',true, false); |
421
|
|
|
$edit_data['pattern'] = filter_var($edit_data['pattern'], FILTER_SANITIZE_NUMBER_INT); |
422
|
|
|
|
423
|
|
|
$data['form'] = $this->form->build_form($this->rates_form->get_origination_rate_form_fields(), $edit_data); |
424
|
|
|
$this->load->view('view_origination_rate_add_edit', $data); |
425
|
|
|
} else { |
426
|
|
|
redirect(base_url() . 'rates/origination_rate_list/'); |
427
|
|
|
} |
428
|
|
|
} |
429
|
|
|
|
430
|
|
View Code Duplication |
function origination_rate_save() { |
431
|
|
|
$add_array = $this->input->post(); |
432
|
|
|
$data['form'] = $this->form->build_form($this->rates_form->get_origination_rate_form_fields(), $add_array); |
|
|
|
|
433
|
|
|
if ($add_array['id'] != '') { |
434
|
|
|
$data['page_title'] = 'Edit Origination Rate'; |
435
|
|
|
if ($this->form_validation->run() == FALSE) { |
436
|
|
|
$data['validation_errors'] = validation_errors(); |
437
|
|
|
echo $data['validation_errors']; |
438
|
|
|
exit; |
439
|
|
|
} else { |
440
|
|
|
$add_array['connectcost'] = $this->common_model->add_calculate_currency($add_array['connectcost'], '', '', false, false); |
441
|
|
|
$add_array['cost'] = $this->common_model->add_calculate_currency($add_array['cost'], '', '', false, false); |
442
|
|
|
$this->rates_model->edit_origination_rate($add_array, $add_array['id']); |
443
|
|
|
echo json_encode(array("SUCCESS"=> "Origination rate updated successfully!")); |
444
|
|
|
exit; |
445
|
|
|
} |
446
|
|
|
} else { |
447
|
|
|
$data['page_title'] = 'Add Origination Rate'; |
448
|
|
|
if ($this->form_validation->run() == FALSE) { |
449
|
|
|
$data['validation_errors'] = validation_errors(); |
450
|
|
|
echo $data['validation_errors']; |
451
|
|
|
exit; |
452
|
|
|
} else { |
453
|
|
|
|
454
|
|
|
$add_array['connectcost'] = $this->common_model->add_calculate_currency($add_array['connectcost'], '', '', false, false); |
455
|
|
|
$add_array['cost'] = $this->common_model->add_calculate_currency($add_array['cost'], '', '', false, false); |
456
|
|
|
$this->rates_model->add_origination_rate($add_array); |
457
|
|
|
echo json_encode(array("SUCCESS"=> "Origination rate added successfully!")); |
458
|
|
|
exit; |
459
|
|
|
} |
460
|
|
|
} |
461
|
|
|
} |
462
|
|
|
|
463
|
|
View Code Duplication |
function origination_rates_list_search() { |
464
|
|
|
$ajax_search = $this->input->post('ajax_search', 0); |
465
|
|
|
|
466
|
|
|
if ($this->input->post('advance_search', TRUE) == 1) { |
467
|
|
|
$this->session->set_userdata('advance_search', $this->input->post('advance_search')); |
468
|
|
|
$action = $this->input->post(); |
469
|
|
|
unset($action['action']); |
470
|
|
|
unset($action['advance_search']); |
471
|
|
|
$this->session->set_userdata('origination_rate_list_search', $action); |
472
|
|
|
} |
473
|
|
|
if (@$ajax_search != 1) { |
474
|
|
|
redirect(base_url() . 'rates/origination_rates_list/'); |
475
|
|
|
} |
476
|
|
|
} |
477
|
|
|
|
478
|
|
|
function origination_rates_list_clearsearchfilter() { |
479
|
|
|
$this->session->set_userdata('advance_search', 0); |
480
|
|
|
$this->session->set_userdata('account_search', ""); |
481
|
|
|
} |
482
|
|
|
|
483
|
|
|
function termination_rate_delete($id) { |
484
|
|
|
$this->rates_model->remove_termination_rate($id); |
485
|
|
|
$this->session->set_flashdata('astpp_notification', 'Termination removed successfully!'); |
486
|
|
|
redirect(base_url() . '/rates/termination_rates_list/'); |
487
|
|
|
} |
488
|
|
|
|
489
|
|
|
function origination_rate_delete($id) { |
490
|
|
|
$this->rates_model->remove_origination_rate($id); |
491
|
|
|
$this->session->set_flashdata('astpp_notification', 'Origination rate removed successfully!'); |
492
|
|
|
redirect(base_url() . 'rates/origination_rates_list/'); |
493
|
|
|
} |
494
|
|
|
|
495
|
|
View Code Duplication |
function origination_rates_list() { |
496
|
|
|
$data['username'] = $this->session->userdata('user_name'); |
|
|
|
|
497
|
|
|
$data['page_title'] = 'Origination Rates'; |
498
|
|
|
$data['search_flag'] = true; |
499
|
|
|
$data['batch_update_flag'] = true; |
500
|
|
|
/********* |
501
|
|
|
ASTPP 3.0 |
502
|
|
|
Batch Delete |
503
|
|
|
*********/ |
504
|
|
|
$data['delete_batch_flag'] = true; |
505
|
|
|
/***************/ |
506
|
|
|
$this->session->set_userdata('advance_search', 0); |
507
|
|
|
$data['grid_fields'] = $this->rates_form->build_origination_rate_list_for_admin(); |
508
|
|
|
$data["grid_buttons"] = $this->rates_form->build_grid_buttons_origination_rate(); |
509
|
|
|
$data['form_search'] = $this->form->build_serach_form($this->rates_form->get_origination_rate_search_form()); |
510
|
|
|
$data['form_batch_update'] = $this->form->build_batchupdate_form($this->rates_form->origination_rate_batch_update_form()); |
511
|
|
|
$this->load->view('view_origination_rate_list', $data); |
512
|
|
|
} |
513
|
|
|
|
514
|
|
|
/********* |
515
|
|
|
ASTPP 3.0 |
516
|
|
|
Batch Delete |
517
|
|
|
*********/ |
518
|
|
|
function origination_rates_list_json() { |
519
|
|
|
$json_data = array(); |
520
|
|
|
$count_all = $this->rates_model->get_origination_rate_list(false); |
521
|
|
|
$paging_data = $this->form->load_grid_config($count_all, $_GET['rp'], $_GET['page']); |
522
|
|
|
$json_data = $paging_data["json_paging"]; |
523
|
|
|
//echo "<pre>"; print_r($json_data); |
|
|
|
|
524
|
|
|
$query = $this->rates_model->get_origination_rate_list(true, $paging_data["paging"]["start"], $paging_data["paging"]["page_no"]); |
525
|
|
|
$grid_fields = json_decode($this->rates_form->build_origination_rate_list_for_admin()); |
526
|
|
|
$json_data['rows'] = $this->form->build_grid($query, $grid_fields); |
527
|
|
|
|
528
|
|
|
echo json_encode($json_data); |
529
|
|
|
} |
530
|
|
|
|
531
|
|
View Code Duplication |
function origination_rates_list_delete($flag='') { |
|
|
|
|
532
|
|
|
$json_data = array(); |
533
|
|
|
$this->session->set_userdata('advance_batch_data_delete',1); |
534
|
|
|
$count_all = $this->rates_model->get_origination_rate_list(false); |
535
|
|
|
echo $count_all; |
536
|
|
|
} |
537
|
|
|
/*******************/ |
538
|
|
View Code Duplication |
function termination_rate_add($type = "") { |
|
|
|
|
539
|
|
|
$data['username'] = $this->session->userdata('user_name'); |
|
|
|
|
540
|
|
|
$data['flag'] = 'create'; |
541
|
|
|
$data['page_title'] = 'Create Termination Rate'; |
542
|
|
|
$data['form'] = $this->form->build_form($this->rates_form->get_termination_rate_form_fields(), ''); |
543
|
|
|
$this->load->view('view_termination_rate_add_edit', $data); |
544
|
|
|
} |
545
|
|
|
|
546
|
|
|
function termination_rate_edit($edit_id = '') { |
547
|
|
|
|
548
|
|
|
$data['page_title'] = 'Edit Termination Rate'; |
|
|
|
|
549
|
|
|
$where = array('id' => $edit_id); |
550
|
|
|
$account = $this->db_model->getSelect("*", "outbound_routes", $where); |
551
|
|
|
foreach ($account->result_array() as $key => $value) { |
552
|
|
|
$edit_data = $value; |
553
|
|
|
} |
554
|
|
|
$edit_data['connectcost'] = $this->common_model->to_calculate_currency($edit_data['connectcost'], '', '', false, false); |
|
|
|
|
555
|
|
|
$edit_data['cost'] = $this->common_model->to_calculate_currency($edit_data['cost'], '', '', false, false); |
556
|
|
|
|
557
|
|
|
$edit_data['pattern'] = filter_var($edit_data['pattern'], FILTER_SANITIZE_NUMBER_INT); |
558
|
|
|
$data['form'] = $this->form->build_form($this->rates_form->get_termination_rate_form_fields(), $edit_data); |
559
|
|
|
$this->load->view('view_termination_rate_add_edit', $data); |
560
|
|
|
} |
561
|
|
|
|
562
|
|
View Code Duplication |
function termination_rate_save() { |
563
|
|
|
$add_array = $this->input->post(); |
564
|
|
|
$data['form'] = $this->form->build_form($this->rates_form->get_termination_rate_form_fields(), $add_array); |
|
|
|
|
565
|
|
|
if ($add_array['id'] != '') { |
566
|
|
|
$data['page_title'] = 'Edit Termination Rate'; |
567
|
|
|
if ($this->form_validation->run() == FALSE) { |
568
|
|
|
$data['validation_errors'] = validation_errors(); |
569
|
|
|
echo $data['validation_errors']; |
570
|
|
|
exit; |
571
|
|
|
} else { |
572
|
|
|
$add_array['connectcost'] = $this->common_model->add_calculate_currency($add_array['connectcost'], '', '', false, false); |
573
|
|
|
$add_array['cost'] = $this->common_model->add_calculate_currency($add_array['cost'], '', '', false, false); |
574
|
|
|
$this->rates_model->edit_termination_rate($add_array, $add_array['id']); |
575
|
|
|
echo json_encode(array("SUCCESS"=> "Termination updated successfully!")); |
576
|
|
|
exit; |
577
|
|
|
} |
578
|
|
|
} else { |
579
|
|
|
$data['page_title'] = 'Add Termination Rate'; |
580
|
|
|
if ($this->form_validation->run() == FALSE) { |
581
|
|
|
$data['validation_errors'] = validation_errors(); |
582
|
|
|
echo $data['validation_errors']; |
583
|
|
|
exit; |
584
|
|
|
} else { |
585
|
|
|
|
586
|
|
|
$add_array['connectcost'] = $this->common_model->add_calculate_currency($add_array['connectcost'], '', '', false, false); |
587
|
|
|
$add_array['cost'] = $this->common_model->add_calculate_currency($add_array['cost'], '', '', false, false); |
588
|
|
|
$this->rates_model->add_termination_rate($add_array); |
589
|
|
|
echo json_encode(array("SUCCESS"=> "Termination added successfully!")); |
590
|
|
|
exit; |
591
|
|
|
} |
592
|
|
|
} |
593
|
|
|
$this->load->view('view_termination_rate_add_edit', $data); |
|
|
|
|
594
|
|
|
} |
595
|
|
|
|
596
|
|
View Code Duplication |
function termination_rates_list_search() { |
597
|
|
|
$ajax_search = $this->input->post('ajax_search', 0); |
598
|
|
|
|
599
|
|
|
if ($this->input->post('advance_search', TRUE) == 1) { |
600
|
|
|
$this->session->set_userdata('advance_search', $this->input->post('advance_search')); |
601
|
|
|
$action = $this->input->post(); |
602
|
|
|
unset($action['action']); |
603
|
|
|
unset($action['advance_search']); |
604
|
|
|
$this->session->set_userdata('termination_rates_list_search', $action); |
605
|
|
|
} |
606
|
|
|
if (@$ajax_search != 1) { |
607
|
|
|
redirect(base_url() . 'rates/termination_rates_list/'); |
608
|
|
|
} |
609
|
|
|
} |
610
|
|
|
|
611
|
|
|
function termination_rates_list_clearsearchfilter() { |
612
|
|
|
$this->session->set_userdata('advance_search', 0); |
613
|
|
|
$this->session->set_userdata('account_search', ""); |
614
|
|
|
} |
615
|
|
|
|
616
|
|
View Code Duplication |
function customer_block_pattern_list($accountid,$accounttype) { |
617
|
|
|
$json_data = array(); |
618
|
|
|
$where = array('accountid' => $accountid); |
619
|
|
|
$instant_search=$this->session->userdata('left_panel_search_'.$accounttype.'_pattern'); |
620
|
|
|
$like_str=!empty($instant_search) ? "(blocked_patterns like '%$instant_search%' OR destination like '%$instant_search%' )" :null; |
621
|
|
|
if(!empty($like_str)) |
622
|
|
|
$this->db->where($like_str); |
623
|
|
|
$count_all = $this->db_model->countQuery("*", "block_patterns", $where); |
624
|
|
|
$paging_data = $this->form->load_grid_config($count_all, $_GET['rp'], $_GET['page']); |
625
|
|
|
$json_data = $paging_data["json_paging"]; |
626
|
|
|
if(!empty($like_str)) |
627
|
|
|
$this->db->where($like_str); |
628
|
|
|
$pattern_data = $this->db_model->getSelect("*", "block_patterns", $where, "id", "ASC", $paging_data["paging"]["page_no"], $paging_data["paging"]["start"]); |
629
|
|
|
$grid_fields = json_decode($this->rates_form->build_pattern_list_for_customer($accountid,$accounttype)); |
630
|
|
|
$json_data['rows'] = $this->form->build_grid($pattern_data, $grid_fields); |
631
|
|
|
echo json_encode($json_data); |
632
|
|
|
} |
633
|
|
|
|
634
|
|
|
function termination_rate_delete_multiple() { |
635
|
|
|
$ids = $this->input->post("selected_ids", true); |
636
|
|
|
$where = "id IN ($ids)"; |
637
|
|
|
$this->db->where($where); |
638
|
|
|
echo $this->db->delete("outbound_routes"); |
639
|
|
|
} |
640
|
|
|
|
641
|
|
|
function origination_rate_delete_multiple() { |
642
|
|
|
$ids = $this->input->post("selected_ids", true); |
643
|
|
|
$where = "id IN ($ids)"; |
644
|
|
|
$this->db->where($where); |
645
|
|
|
echo $this->db->delete("routes"); |
646
|
|
|
} |
647
|
|
|
|
648
|
|
|
function user_origination_rate_list_json() { |
649
|
|
|
$json_data = array(); |
650
|
|
|
$account_data = $this->session->userdata("accountinfo"); |
651
|
|
|
$markup = $this->common->get_field_name('markup', 'pricelists', array('id'=>$account_data["pricelist_id"])); |
652
|
|
|
$markup = ($markup > 0)?$markup:1; |
653
|
|
|
|
654
|
|
|
$count_all = $this->rates_model->get_origination_rate_list_for_user(false); |
655
|
|
|
$paging_data = $this->form->load_grid_config($count_all, $_GET['rp'], $_GET['page']); |
656
|
|
|
$json_data = $paging_data["json_paging"]; |
657
|
|
|
|
658
|
|
|
$query = $this->rates_model->get_origination_rate_list_for_user(true, $paging_data["paging"]["start"], $paging_data["paging"]["page_no"]); |
659
|
|
|
$grid_fields = json_decode($this->rates_form->build_origination_rate_list_for_user()); |
660
|
|
View Code Duplication |
foreach ($query->result_array() as $key => $value) { |
661
|
|
|
$json_data['rows'][] = array('cell' => array( |
662
|
|
|
$this->common->get_only_numeric_val("","",$value["pattern"]), |
663
|
|
|
$value['comment'], |
664
|
|
|
$value['inc'], |
665
|
|
|
$this->common_model->calculate_currency(($value['cost'] + ($value['cost']*$markup)/100),'','','',true), |
666
|
|
|
$this->common_model->calculate_currency($value['connectcost'],'','','',true), |
667
|
|
|
$value['includedseconds'] |
668
|
|
|
)); |
669
|
|
|
} |
670
|
|
|
// $json_data['rows'] = $this->form->build_grid($query, $grid_fields); |
|
|
|
|
671
|
|
|
echo json_encode($json_data); |
672
|
|
|
} |
673
|
|
|
|
674
|
|
View Code Duplication |
function user_origination_rate_list_search() { |
675
|
|
|
$ajax_search = $this->input->post('ajax_search', 0); |
676
|
|
|
|
677
|
|
|
if ($this->input->post('advance_search', TRUE) == 1) { |
678
|
|
|
$this->session->set_userdata('advance_search', $this->input->post('advance_search')); |
679
|
|
|
$action = $this->input->post(); |
680
|
|
|
unset($action['action']); |
681
|
|
|
unset($action['advance_search']); |
682
|
|
|
$this->session->set_userdata('origination_rate_list_search', $action); |
683
|
|
|
} |
684
|
|
|
if (@$ajax_search != 1) { |
685
|
|
|
redirect(base_url() . 'user/user_rates_list/'); |
686
|
|
|
} |
687
|
|
|
} |
688
|
|
|
|
689
|
|
|
function user_origination_rate_list_clearsearchfilter() { |
690
|
|
|
$this->session->set_userdata('advance_search', 0); |
691
|
|
|
$this->session->set_userdata('account_search', ""); |
692
|
|
|
} |
693
|
|
View Code Duplication |
function customer_rates_download_sample_file($file_name){ |
694
|
|
|
$this->load->helper('download'); |
695
|
|
|
$full_path = base_url()."assets/Rates_File/".$file_name.".csv"; |
696
|
|
|
$arrContextOptions=array( |
697
|
|
|
"ssl"=>array( |
698
|
|
|
"verify_peer"=>false, |
699
|
|
|
"verify_peer_name"=>false, |
700
|
|
|
), |
701
|
|
|
); |
702
|
|
|
$file = file_get_contents($full_path, false, stream_context_create($arrContextOptions)); |
703
|
|
|
force_download("samplefile.csv", $file); |
704
|
|
|
} |
705
|
|
|
function termination_rate_batch_update(){ |
706
|
|
|
$batch_update_arr = $this->input->post(); |
707
|
|
|
$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"; |
708
|
|
|
$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"; |
709
|
|
|
// $batch_update_arr = array("inc"=> array("inc"=>"1","operator"=>"3"),"cost"=> array("cost"=>"1","operator"=>"4")); |
|
|
|
|
710
|
|
|
$result = $this->rates_model->termination_rate_batch_update($batch_update_arr); |
711
|
|
|
echo json_encode(array("SUCCESS"=> "Termination rates batch updated successfully!")); |
712
|
|
|
exit; |
713
|
|
|
} |
714
|
|
|
|
715
|
|
|
function origination_rate_batch_update(){ |
716
|
|
|
$batch_update_arr = $this->input->post(); |
717
|
|
|
$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"; |
718
|
|
|
// $batch_update_arr = array("inc"=> array("inc"=>"1","operator"=>"3"),"cost"=> array("cost"=>"1","operator"=>"4")); |
|
|
|
|
719
|
|
|
$result = $this->rates_model->origination_rate_batch_update($batch_update_arr); |
720
|
|
|
echo json_encode(array("SUCCESS"=> "Origination rates batch updated successfully!")); |
721
|
|
|
exit; |
722
|
|
|
} |
723
|
|
|
|
724
|
|
|
function termination_rate_export_cdr_xls() { |
725
|
|
|
$account_info = $accountinfo = $this->session->userdata('accountinfo'); |
726
|
|
|
$currency_id=$account_info['currency_id']; |
727
|
|
|
$currency=$this->common->get_field_name('currency', 'currency', $currency_id); |
728
|
|
|
$query = $this->rates_model->get_termination_rate(true, '', '', false); |
729
|
|
|
$outbound_array = array(); |
730
|
|
|
ob_clean(); |
731
|
|
|
$outbound_array[] = array("Code", "Destination", "Connect Cost($currency)", "Included Seconds","Per Minute Cost($currency)","Initial Increment", "Increment","Priority","Strip","Prepend","Trunk","Status","Created Date"); |
732
|
|
|
if ($query->num_rows() > 0) { |
733
|
|
|
|
734
|
|
|
foreach ($query->result_array() as $row) { |
735
|
|
|
//echo"<pre>";print_r($row);exit; |
|
|
|
|
736
|
|
|
$outbound_array[] = array( |
737
|
|
|
$row['pattern']=$this->common->get_only_numeric_val("","",$row["pattern"]), |
738
|
|
|
$row['comment'], |
739
|
|
|
$this->common_model->calculate_currency($row['connectcost'],'','',TRUE,false), |
740
|
|
|
|
741
|
|
|
$row['includedseconds'], |
742
|
|
|
$this->common_model->calculate_currency($row['cost'],'','',TRUE,false), |
743
|
|
|
/** |
744
|
|
|
ASTPP 3.0 |
745
|
|
|
For Add Initial Increment field |
746
|
|
|
**/ |
747
|
|
|
$row['init_inc'], |
748
|
|
|
/****************************************/ |
749
|
|
|
$row['inc'], |
750
|
|
|
$row['precedence'], |
751
|
|
|
$row['strip'], |
752
|
|
|
$row['prepend'], |
753
|
|
|
//$row['trunk_id'], |
754
|
|
|
$this->common->get_field_name('name','trunks',$row["trunk_id"]), |
755
|
|
|
$this->common->get_status('export', '', $row['status']), |
756
|
|
|
$row['creation_date'], |
757
|
|
|
|
758
|
|
|
); |
759
|
|
|
} |
760
|
|
|
} |
761
|
|
|
$this->load->helper('csv'); |
762
|
|
|
|
763
|
|
|
array_to_csv($outbound_array, 'Termination_Rates_' . date("Y-m-d") . '.csv'); |
764
|
|
|
|
765
|
|
|
} |
766
|
|
|
|
767
|
|
|
function termination_rate_export_cdr_pdf() { |
768
|
|
|
$query = $this->rates_model->get_termination_rate(true, '', '', false); |
769
|
|
|
$outbound_array = array(); |
770
|
|
|
$this->load->library('fpdf'); |
771
|
|
|
$this->load->library('pdf'); |
772
|
|
|
$this->fpdf = new PDF('P', 'pt'); |
|
|
|
|
773
|
|
|
$this->fpdf->initialize('P', 'mm', 'A4'); |
774
|
|
|
$this->fpdf->tablewidths = array(20, 30, 20, 20, 20, 20, 20,20,20); |
775
|
|
|
$outbound_array[] = array("Code", "Destination", "Connect Cost","Included Seconds","Per Minute Cost","Initial Increment", "Increment","Precedence","Prepend","Strip"); |
776
|
|
|
if ($query->num_rows() > 0) { |
777
|
|
|
|
778
|
|
|
foreach ($query->result_array() as $row) { |
779
|
|
|
$outbound_array[] = array( |
780
|
|
|
$row['pattern']=$this->common->get_only_numeric_val("","",$row["pattern"]), |
781
|
|
|
$row['comment'], |
782
|
|
|
$row['connectcost'], |
783
|
|
|
$row['includedseconds'], |
784
|
|
|
$this->common_model->calculate_currency($row['cost']), |
785
|
|
|
/** |
786
|
|
|
ASTPP 3.0 |
787
|
|
|
For Add Initial Increment field |
788
|
|
|
**/ |
789
|
|
|
$row['init_inc'], |
790
|
|
|
/*******************************************/ |
791
|
|
|
$row['inc'], |
792
|
|
|
$row['precedence'], |
793
|
|
|
$row['prepend'], |
794
|
|
|
$row['strip'] |
795
|
|
|
); |
796
|
|
|
} |
797
|
|
|
} |
798
|
|
|
$this->fpdf->AliasNbPages(); |
799
|
|
|
$this->fpdf->AddPage(); |
800
|
|
|
|
801
|
|
|
$this->fpdf->SetFont('Arial', '', 15); |
802
|
|
|
$this->fpdf->SetXY(60, 5); |
803
|
|
|
$this->fpdf->Cell(100, 10, "Outbound Rates Report " . date('Y-m-d')); |
804
|
|
|
|
805
|
|
|
$this->fpdf->SetY(20); |
806
|
|
|
$this->fpdf->SetFont('Arial', '', 7); |
807
|
|
|
$this->fpdf->SetFillColor(255, 255, 255); |
808
|
|
|
$this->fpdf->lMargin = 2; |
809
|
|
|
|
810
|
|
|
$dimensions = $this->fpdf->export_pdf($outbound_array, "7"); |
|
|
|
|
811
|
|
|
$this->fpdf->Output('Termination_Rate_' . date("Y-m-d") . '.pdf', "D"); |
812
|
|
|
} |
813
|
|
|
|
814
|
|
|
|
815
|
|
|
function origination_rate_export_cdr_xls() { |
816
|
|
|
$account_info = $accountinfo = $this->session->userdata('accountinfo'); |
817
|
|
|
$currency_id=$account_info['currency_id']; |
818
|
|
|
$currency=$this->common->get_field_name('currency', 'currency', $currency_id); |
819
|
|
|
$query = $this->rates_model->get_origination_rate(true, '', '', false); |
820
|
|
|
//echo "<pre>";print_r($query);exit; |
|
|
|
|
821
|
|
|
$inbound_array = array(); |
822
|
|
|
ob_clean(); |
823
|
|
|
$inbound_array[] = array("Code", "Destination","Connect Cost($currency)","Included Seconds","Per Minute Cost($currency)", "Initial Increment", "Increment","Rate Group","Status","Created Date"); |
824
|
|
|
if ($query->num_rows() > 0) { |
825
|
|
|
|
826
|
|
|
foreach ($query->result_array() as $row) { |
827
|
|
|
//echo"<pre>";print_r($row);exit; |
|
|
|
|
828
|
|
|
$inbound_array[] = array( |
829
|
|
|
$row['pattern']=$this->common->get_only_numeric_val("","",$row["pattern"]), |
830
|
|
|
$row['comment'], |
831
|
|
|
$this->common_model->calculate_currency($row['connectcost'],'','',TRUE,false), |
832
|
|
|
$row['includedseconds'], |
833
|
|
|
$this->common_model->calculate_currency($row['cost'],'','',TRUE,false), |
834
|
|
|
/** |
835
|
|
|
ASTPP 3.0 |
836
|
|
|
For Add Initial Increment field |
837
|
|
|
**/ |
838
|
|
|
$row['init_inc'], |
839
|
|
|
/********************************************/ |
840
|
|
|
$row['inc'], |
841
|
|
|
// $row['precedence'], |
|
|
|
|
842
|
|
|
$this->common->get_field_name('name', 'pricelists', $row['pricelist_id']), |
843
|
|
|
$this->common->get_status('export', '', $row['status']), |
844
|
|
|
$row['creation_date'], |
845
|
|
|
); |
846
|
|
|
} |
847
|
|
|
} |
848
|
|
|
$this->load->helper('csv'); |
849
|
|
|
array_to_csv($inbound_array, 'Origination_Rates_' . date("Y-m-d") . '.csv'); |
850
|
|
|
} |
851
|
|
|
function origination_rate_export_cdr_pdf() { |
852
|
|
|
$query = $this->rates_model->get_origination_rate(true, '', '', false); |
853
|
|
|
|
854
|
|
|
$inbound_array = array(); |
855
|
|
|
$this->load->library('fpdf'); |
856
|
|
|
$this->load->library('pdf'); |
857
|
|
|
$this->fpdf = new PDF('P', 'pt'); |
|
|
|
|
858
|
|
|
$this->fpdf->initialize('P', 'mm', 'A4'); |
859
|
|
|
$this->fpdf->tablewidths = array(20, 20, 20, 20, 20, 20); |
860
|
|
|
$inbound_array[] = array("Code", "Destination","Connect Cost","Included Seconds","Per Minute Cost","Initial Increment","Increment"); |
861
|
|
|
if ($query->num_rows() > 0) { |
862
|
|
|
foreach ($query->result_array() as $row) { |
863
|
|
|
$inbound_array[] = array( |
864
|
|
|
$row['pattern']=$this->common->get_only_numeric_val("","",$row["pattern"]), |
865
|
|
|
$row['comment'], |
866
|
|
|
$row['connectcost'], |
867
|
|
|
$row['includedseconds'], |
868
|
|
|
$this->common_model->calculate_currency($row['cost'],'','','',false), |
869
|
|
|
/** |
870
|
|
|
ASTPP 3.0 |
871
|
|
|
For Add Initial Increment field |
872
|
|
|
**/ |
873
|
|
|
$row['init_inc'], |
874
|
|
|
/*************************************************/ |
875
|
|
|
$row['inc'] |
876
|
|
|
); |
877
|
|
|
} |
878
|
|
|
} |
879
|
|
|
$this->fpdf->AliasNbPages(); |
880
|
|
|
$this->fpdf->AddPage(); |
881
|
|
|
|
882
|
|
|
$this->fpdf->SetFont('Arial', '', 15); |
883
|
|
|
$this->fpdf->SetXY(60, 5); |
884
|
|
|
$this->fpdf->Cell(100, 10, "Origination Rates Report " . date('Y-m-d')); |
885
|
|
|
|
886
|
|
|
$this->fpdf->SetY(20); |
887
|
|
|
$this->fpdf->SetFont('Arial', '', 7); |
888
|
|
|
$this->fpdf->SetFillColor(255, 255, 255); |
889
|
|
|
$this->fpdf->lMargin = 2; |
890
|
|
|
|
891
|
|
|
$dimensions = $this->fpdf->export_pdf($inbound_array, "5"); |
|
|
|
|
892
|
|
|
$this->fpdf->Output('Origination_Rate_' . date("Y-m-d") . '.pdf', "D"); |
893
|
|
|
} |
894
|
|
|
|
895
|
|
|
|
896
|
|
|
function user_origination_rate_cdr_pdf() { |
897
|
|
|
$query = $this->rates_model->get_origination_rate_for_user(true, '', '', false); |
898
|
|
|
$inbound_array = array(); |
899
|
|
|
$this->load->library('fpdf'); |
900
|
|
|
$this->load->library('pdf'); |
901
|
|
|
$this->fpdf = new PDF('P', 'pt'); |
|
|
|
|
902
|
|
|
$this->fpdf->initialize('P', 'mm', 'A4'); |
903
|
|
|
$this->fpdf->tablewidths = array(20, 20, 20, 20, 20, 20); |
904
|
|
|
$inbound_array[] = array("Code", "Destination", "Increment","Cost Per Minutes", "Connect Charge", "Included Seconds"); |
905
|
|
View Code Duplication |
if ($query->num_rows() > 0) { |
906
|
|
|
foreach ($query->result_array() as $row) { |
907
|
|
|
$inbound_array[] = array( |
908
|
|
|
$row['pattern']=$this->common->get_only_numeric_val("","",$row["pattern"]), |
909
|
|
|
$row['comment'], |
910
|
|
|
$row['inc'], |
911
|
|
|
$this->common_model->calculate_currency($row['cost'],'','','',false), |
912
|
|
|
$row['connectcost'], |
913
|
|
|
$row['includedseconds'] |
914
|
|
|
); |
915
|
|
|
} |
916
|
|
|
} |
917
|
|
|
|
918
|
|
|
$this->fpdf->AliasNbPages(); |
919
|
|
|
$this->fpdf->AddPage(); |
920
|
|
|
|
921
|
|
|
$this->fpdf->SetFont('Arial', '', 15); |
922
|
|
|
$this->fpdf->SetXY(60, 5); |
923
|
|
|
$this->fpdf->Cell(100, 10, "Rates Report " . date('Y-m-d')); |
924
|
|
|
|
925
|
|
|
$this->fpdf->SetY(20); |
926
|
|
|
$this->fpdf->SetFont('Arial', '', 7); |
927
|
|
|
$this->fpdf->SetFillColor(255, 255, 255); |
928
|
|
|
$this->fpdf->lMargin = 2; |
929
|
|
|
|
930
|
|
|
$dimensions = $this->fpdf->export_pdf($inbound_array, "5"); |
|
|
|
|
931
|
|
|
$this->fpdf->Output('Rates_' . date("Y-m-d") . '.pdf', "D"); |
932
|
|
|
} |
933
|
|
|
function resellersrates_list(){ |
934
|
|
|
$accountinfo=$this->session->userdata('accountinfo'); |
935
|
|
|
$data['username'] = $this->session->userdata('user_name'); |
|
|
|
|
936
|
|
|
$data['page_title'] = 'My Rates' ; |
937
|
|
|
$data['search_flag'] = true; |
938
|
|
|
$this->session->set_userdata('advance_search', 0); |
939
|
|
|
$data['grid_fields'] = $this->rates_form->build_rates_list_for_reseller(); |
940
|
|
|
$data["grid_buttons"] = $this->rates_form->build_grid_buttons_rates(); |
941
|
|
|
$data['form_search'] = $this->form->build_serach_form($this->rates_form->get_reseller_origination_rate_search_form()); |
942
|
|
|
$this->load->view('view_resellersrates_list', $data); |
943
|
|
|
} |
944
|
|
|
function resellersrates_list_json() { |
945
|
|
|
$json_data = array(); |
946
|
|
|
$account_data = $this->session->userdata("accountinfo"); |
947
|
|
|
$markup = $this->common->get_field_name('markup', 'pricelists', array('id'=>$account_data["pricelist_id"])); |
948
|
|
|
//$markup = ($markup > 0)?$markup:1; |
|
|
|
|
949
|
|
|
$count_all = $this->rates_model->getreseller_rates_list(false); |
950
|
|
|
$paging_data = $this->form->load_grid_config($count_all, $_GET['rp'], $_GET['page']); |
951
|
|
|
$json_data = $paging_data["json_paging"]; |
952
|
|
|
$query = $this->rates_model->getreseller_rates_list(true, $paging_data["paging"]["start"], $paging_data["paging"]["page_no"]); |
953
|
|
|
$grid_fields = json_decode($this->rates_form->build_rates_list_for_reseller()); |
954
|
|
View Code Duplication |
foreach ($query->result_array() as $key => $value) { |
955
|
|
|
$json_data['rows'][] = array('cell' => array( |
956
|
|
|
$this->common->get_only_numeric_val("","",$value["pattern"]), |
957
|
|
|
$value['comment'], |
958
|
|
|
$this->common_model->calculate_currency($value['connectcost'],'','','true',true), |
959
|
|
|
$value['includedseconds'], |
960
|
|
|
$this->common_model->calculate_currency(($value['cost'] + ($value['cost']*$markup)/100),'','','true',true), |
961
|
|
|
$value['inc'], |
962
|
|
|
$value['precedence'], |
963
|
|
|
)); |
964
|
|
|
} |
965
|
|
|
// $json_data['rows'] = $this->form->build_grid($query, $grid_fields); |
|
|
|
|
966
|
|
|
echo json_encode($json_data); |
967
|
|
|
} |
968
|
|
View Code Duplication |
function resellersrates_list_search() { |
969
|
|
|
$ajax_search = $this->input->post('ajax_search', 0); |
970
|
|
|
|
971
|
|
|
if ($this->input->post('advance_search', TRUE) == 1) { |
972
|
|
|
$this->session->set_userdata('advance_search', $this->input->post('advance_search')); |
973
|
|
|
$action = $this->input->post(); |
974
|
|
|
|
975
|
|
|
unset($action['action']); |
976
|
|
|
unset($action['advance_search']); |
977
|
|
|
$this->session->set_userdata('resellerrates_list_search', $action); |
978
|
|
|
} |
979
|
|
|
if (@$ajax_search != 1) { |
980
|
|
|
redirect(base_url() . 'rates/resellersrates_list/'); |
981
|
|
|
} |
982
|
|
|
} |
983
|
|
|
function resellersrates_list_clearsearchfilter() { |
984
|
|
|
$this->session->set_userdata('advance_search', 0); |
985
|
|
|
$this->session->set_userdata('resellerrates_list_search', ""); |
986
|
|
|
} |
987
|
|
|
function resellersrates_xls() |
988
|
|
|
{ |
989
|
|
|
$account_info = $accountinfo = $this->session->userdata('accountinfo'); |
990
|
|
|
$currency_id = $account_info['currency_id']; |
991
|
|
|
$currency = $this->common->get_field_name('currency', 'currency', $currency_id); |
992
|
|
|
$query = $this->rates_model->getreseller_rates_list(true, '0', '0', '1'); |
993
|
|
|
$customer_array = array(); |
994
|
|
|
ob_clean(); |
995
|
|
|
|
996
|
|
|
$customer_array[] = array("Code", "Destination", "Connect Cost($currency)", "Included Seconds", "Per Minute Cost($currency)", "Increment", "Precedence"); |
997
|
|
|
|
998
|
|
|
|
999
|
|
View Code Duplication |
if ($query->num_rows() > 0) { |
1000
|
|
|
|
1001
|
|
|
foreach ($query->result_array() as $row) { |
1002
|
|
|
|
1003
|
|
|
$customer_array[] = array( |
1004
|
|
|
$row['pattern']=$this->common->get_only_numeric_val("","",$row["pattern"]), |
1005
|
|
|
$row['comment'], |
1006
|
|
|
$row['connectcost'], |
1007
|
|
|
$row['includedseconds'], |
1008
|
|
|
$this->common_model->calculate_currency($row['cost']), |
1009
|
|
|
$row['inc'], |
1010
|
|
|
$row['precedence'] |
1011
|
|
|
); |
1012
|
|
|
|
1013
|
|
|
} |
1014
|
|
|
} |
1015
|
|
|
$this->load->helper('csv'); |
1016
|
|
|
array_to_csv($customer_array, 'My_Own_Rate_' . date("Y-m-d") . '.csv'); |
1017
|
|
|
exit; |
1018
|
|
|
} |
1019
|
|
|
/*********** |
1020
|
|
|
ASTPP 3.0 |
1021
|
|
|
Batch delete |
1022
|
|
|
***********/ |
1023
|
|
View Code Duplication |
function termination_rates_list_batch_delete() { |
1024
|
|
|
$ajax_search = $this->input->post('ajax_search', 0); |
1025
|
|
|
if ($this->input->post('advance_search', TRUE) == 1) { |
1026
|
|
|
$this->session->set_userdata('advance_batch_delete', $this->input->post('advance_search')); |
1027
|
|
|
$action = $this->input->post(); |
1028
|
|
|
unset($action['action']); |
1029
|
|
|
unset($action['advance_search']); |
1030
|
|
|
$this->session->set_userdata('termination_rates_list_search', $action); |
1031
|
|
|
} |
1032
|
|
|
if (@$ajax_search != 1) { |
1033
|
|
|
redirect(base_url() . 'rates/termination_rates_list/'); |
1034
|
|
|
} |
1035
|
|
|
} |
1036
|
|
View Code Duplication |
function origination_rates_list_batch_delete() { |
1037
|
|
|
$ajax_search = $this->input->post('ajax_search', 0); |
1038
|
|
|
if ($this->input->post('advance_search', TRUE) == 1) { |
1039
|
|
|
$this->session->set_userdata('advance_batch_delete', $this->input->post('advance_search')); |
1040
|
|
|
$action = $this->input->post(); |
1041
|
|
|
unset($action['action']); |
1042
|
|
|
unset($action['advance_search']); |
1043
|
|
|
$this->session->set_userdata('origination_rate_list_search', $action); |
1044
|
|
|
} |
1045
|
|
|
if (@$ajax_search != 1) { |
1046
|
|
|
redirect(base_url() . 'rates/origination_rates_list/'); |
1047
|
|
|
} |
1048
|
|
|
} |
1049
|
|
|
|
1050
|
|
|
/*************************/ |
1051
|
|
|
/********* Import Mapper Code - ISSUE-142 **********/ |
1052
|
|
|
function termination_rate_import_mapper() |
1053
|
|
|
{ |
1054
|
|
|
$data['page_title'] = 'Import Termination Rates using field mapper'; |
|
|
|
|
1055
|
|
|
$this->session->set_userdata('import_termination_rate_mapper_csv', ""); |
1056
|
|
|
$this->session->set_userdata('import_termination_rate_mapper_csv_error', ""); |
1057
|
|
|
$this->load->view('view_import_termination_rate_mapper', $data); |
1058
|
|
|
} |
1059
|
|
|
|
1060
|
|
|
function csv_to_array($filename = '', $delimiter = ',') |
1061
|
|
|
{ |
1062
|
|
|
if (!file_exists($filename) || !is_readable($filename)) return FALSE; |
1063
|
|
|
$header = NULL; |
1064
|
|
|
$data = array(); |
1065
|
|
|
if (($handle = fopen($filename, 'r')) !== FALSE) |
1066
|
|
|
{ |
1067
|
|
|
while (($row = fgetcsv($handle, 1000, $delimiter)) !== FALSE) |
1068
|
|
|
{ |
1069
|
|
|
if (!$header) $header = $row; |
1070
|
|
|
else $data[] = array_combine($header, $row); |
1071
|
|
|
} |
1072
|
|
|
|
1073
|
|
|
fclose($handle); |
1074
|
|
|
} |
1075
|
|
|
|
1076
|
|
|
return $data; |
1077
|
|
|
} |
1078
|
|
|
|
1079
|
|
|
function utf8_converter($array) |
1080
|
|
|
{ |
1081
|
|
|
array_walk_recursive($array, |
1082
|
|
|
function (&$item, $key) |
|
|
|
|
1083
|
|
|
{ |
1084
|
|
|
if (!mb_detect_encoding($item, 'utf-8', true)) |
1085
|
|
|
{ |
1086
|
|
|
$item = utf8_encode($item); |
1087
|
|
|
} |
1088
|
|
|
}); |
1089
|
|
|
return $array; |
1090
|
|
|
} |
1091
|
|
|
|
1092
|
|
|
function termination_rate_mapper_preview_file() |
1093
|
|
|
{ |
1094
|
|
|
$invalid_flag = false; |
1095
|
|
|
$check_header = $this->input->post('check_header', true); |
1096
|
|
|
$data['page_title'] = 'Import Termination Rates'; |
|
|
|
|
1097
|
|
|
$new_final_arr_key = $this->config->item('Termination-rates-field'); |
1098
|
|
|
if (empty($_FILES) || !isset($_FILES)) |
1099
|
|
|
{ |
1100
|
|
|
redirect(base_url() . "rates/termination_rates_list/"); |
1101
|
|
|
} |
1102
|
|
|
|
1103
|
|
|
$data['mapto_fields'] = $new_final_arr_key; |
1104
|
|
|
if (isset($_FILES['termination_rate_import_mapper']['name']) && $_FILES['termination_rate_import_mapper']['name'] != "" && isset($_POST['trunk_id']) && $_POST['trunk_id'] != '') |
1105
|
|
|
{ |
1106
|
|
|
list($txt, $ext) = explode(".", $_FILES['termination_rate_import_mapper']['name']); |
|
|
|
|
1107
|
|
|
if ($ext == "csv" && $_FILES['termination_rate_import_mapper']['size'] > 0) |
1108
|
|
|
{ |
1109
|
|
|
$error = $_FILES['termination_rate_import_mapper']['error']; |
1110
|
|
|
if ($error == 0) |
1111
|
|
|
{ |
1112
|
|
|
$uploadedFile = $_FILES["termination_rate_import_mapper"]["tmp_name"]; |
1113
|
|
|
$file_data = $this->csv_to_array($uploadedFile); |
1114
|
|
|
$field_select = (array_keys($file_data[0])); |
1115
|
|
|
$data['file_data'] = $field_select; |
1116
|
|
|
|
1117
|
|
|
// $csv_data = $this->csvreader->parse_file($uploadedFile, $new_final_arr_key, $check_header); |
|
|
|
|
1118
|
|
|
|
1119
|
|
|
$csv_data = $this->utf8_converter($this->csvreader->parse_file($uploadedFile, $field_select, $check_header)); |
1120
|
|
|
if (!empty($csv_data)) |
1121
|
|
|
{ |
1122
|
|
|
$full_path = $this->config->item('rates-file-path'); |
1123
|
|
|
$actual_file_name = "ASTPP-TERMINATION-RATES-" . date("Y-m-d H:i:s") . "." . $ext; |
1124
|
|
|
$actual_file_name = str_replace(' ', '-', $actual_file_name); |
1125
|
|
|
$actual_file_name = str_replace(':', '-', $actual_file_name); |
1126
|
|
View Code Duplication |
if (move_uploaded_file($uploadedFile, $full_path . $actual_file_name)) |
1127
|
|
|
{ |
1128
|
|
|
$data['field_select'] = serialize($field_select); |
1129
|
|
|
$data['csv_tmp_data'] = $csv_data; |
1130
|
|
|
$data['trunkid'] = $_POST['trunk_id']; |
1131
|
|
|
$data['check_header'] = $check_header; |
1132
|
|
|
$data['page_title'] = 'Map CSV to Termination Rates'; |
1133
|
|
|
$this->session->set_userdata('import_termination_rate_mapper_csv', $actual_file_name); |
1134
|
|
|
} |
1135
|
|
|
else |
1136
|
|
|
{ |
1137
|
|
|
$data['error'] = "File Uploading Fail Please Try Again"; |
1138
|
|
|
} |
1139
|
|
|
} |
1140
|
|
|
} |
1141
|
|
|
else |
1142
|
|
|
{ |
1143
|
|
|
$data['error'] == "File Uploading Fail Please Try Again"; |
1144
|
|
|
} |
1145
|
|
|
} |
1146
|
|
|
else |
1147
|
|
|
{ |
1148
|
|
|
$data['error'] = "Invalid file format : Only CSV file allows to import records(Can't import empty file)"; |
1149
|
|
|
$data['error'] = var_dump($_FILES); |
|
|
|
|
1150
|
|
|
} |
1151
|
|
|
} |
1152
|
|
|
else |
1153
|
|
|
{ |
1154
|
|
|
$invalid_flag = true; |
1155
|
|
|
} |
1156
|
|
|
|
1157
|
|
|
if ($invalid_flag) |
1158
|
|
|
{ |
1159
|
|
|
$str = ''; |
1160
|
|
|
if (!isset($_POST['trunk_id']) || empty($_POST['trunk_id'])) |
1161
|
|
|
{ |
1162
|
|
|
$str.= '<br/>Please Create Trunk.'; |
1163
|
|
|
} |
1164
|
|
|
|
1165
|
|
|
if (empty($_FILES['termination_rate_import_mapper']['name'])) |
1166
|
|
|
{ |
1167
|
|
|
$str.= '<br/>Please Select File.'; |
1168
|
|
|
} |
1169
|
|
|
|
1170
|
|
|
$data['error'] = $str; |
1171
|
|
|
} |
1172
|
|
|
|
1173
|
|
|
$this->load->view('view_import_termination_rate_mapper', $data); |
1174
|
|
|
} |
1175
|
|
|
|
1176
|
|
|
function termination_rate_rates_mapper_import() |
1177
|
|
|
{ |
1178
|
|
|
|
1179
|
|
|
// var_dump($this->input->post()); |
|
|
|
|
1180
|
|
|
|
1181
|
|
|
$trunkID = $this->input->post("trunkid"); |
1182
|
|
|
$check_header = $this->input->post("check_header"); |
1183
|
|
|
$pattern_prefix = $this->input->post("pattern-prefix"); |
1184
|
|
|
$filefields = unserialize($this->input->post("filefields")); |
1185
|
|
|
$new_final_arr = array(); |
1186
|
|
|
$invalid_array = array(); |
1187
|
|
|
$new_final_arr_key = array(); |
1188
|
|
|
foreach($filefields as $item) |
1189
|
|
|
{ |
1190
|
|
|
$new_final_arr_key[$item] = $item; |
1191
|
|
|
} |
1192
|
|
|
|
1193
|
|
|
|
1194
|
|
|
$screen_path = $this->config->item('screen_path'); |
1195
|
|
View Code Duplication |
if ($this->session->userdata('logintype') == 1 || $this->session->userdata('logintype') == 5) |
1196
|
|
|
{ |
1197
|
|
|
$account_data = $this->session->userdata("accountinfo"); |
1198
|
|
|
} |
1199
|
|
|
|
1200
|
|
|
$full_path = $this->config->item('rates-file-path'); |
1201
|
|
|
$terminationrate_file_name = $this->session->userdata('import_termination_rate_mapper_csv'); |
1202
|
|
|
$csv_tmp_data = $this->csvreader->parse_file($full_path . $terminationrate_file_name, $new_final_arr_key, $check_header); |
1203
|
|
|
$i = 0; |
1204
|
|
|
foreach($csv_tmp_data as $key => $csv_data) |
1205
|
|
|
{ |
1206
|
|
|
if (isset($csv_data[$this->input->post("pattern-select") ]) && $csv_data[$this->input->post("pattern-select") ] != '' && $i != 0) |
1207
|
|
|
{ |
1208
|
|
|
$str = null; |
1209
|
|
|
$csv_data['pattern'] = ($this->input->post("pattern-prefix")) ? $this->input->post("pattern-prefix") . $csv_data[$this->input->post("pattern-select") ] : $csv_data[$this->input->post("pattern-select") ]; |
1210
|
|
|
$csv_data['cost'] = ($this->input->post("cost-select")) ? $csv_data[$this->input->post("cost-select") ] : ""; |
1211
|
|
|
$csv_data['cost'] = ($this->input->post("cost-prefix")) ? $this->input->post("cost-prefix") . $csv_data['cost'] : $csv_data['cost']; |
1212
|
|
|
$csv_data['prepend'] = ($this->input->post("prepend-select")) ? $csv_data[$this->input->post("prepend-select") ] : ""; |
1213
|
|
|
$csv_data['prepend'] = ($this->input->post("prepend-prefix")) ? $this->input->post("prepend-prefix") . $csv_data['prepend'] : $csv_data['prepend']; |
1214
|
|
|
$csv_data['comment'] = ($this->input->post("comment-select")) ? $csv_data[$this->input->post("comment-select") ] : ""; |
1215
|
|
|
$csv_data['comment'] = ($this->input->post("comment-prefix")) ? $this->input->post("comment-prefix") . $csv_data['comment'] : $csv_data['comment']; |
1216
|
|
|
$csv_data['connectcost'] = ($this->input->post("connectcost-select")) ? $csv_data[$this->input->post("connectcost-select") ] : "0"; |
1217
|
|
|
$csv_data['connectcost'] = ($this->input->post("connectcost-prefix")) ? $this->input->post("connectcost-prefix") . $csv_data['connectcost'] : $csv_data['connectcost']; |
1218
|
|
|
$csv_data['includedseconds'] = ($this->input->post("includedseconds-select")) ? $csv_data[$this->input->post("includedseconds-select") ] : "0"; |
1219
|
|
|
$csv_data['includedseconds'] = ($this->input->post("includedseconds-prefix")) ? $this->input->post("includedseconds-prefix") . $csv_data['includedseconds'] : $csv_data['includedseconds']; |
1220
|
|
|
$csv_data['inc'] = ($this->input->post("inc-select")) ? $csv_data[$this->input->post("inc-select") ] : "0"; |
1221
|
|
|
$csv_data['inc'] = ($this->input->post("inc-prefix")) ? $this->input->post("inc-prefix") . $csv_data['inc'] : $csv_data['inc']; |
1222
|
|
|
$csv_data['precedence'] = ($this->input->post("precedence-select")) ? $csv_data[$this->input->post("precedence-select") ] : ""; |
1223
|
|
|
$csv_data['precedence'] = ($this->input->post("precedence-prefix")) ? $this->input->post("precedence-prefix") . $csv_data['precedence'] : $csv_data['precedence']; |
1224
|
|
|
$csv_data['strip'] = ($this->input->post("strip-select")) ? $csv_data[$this->input->post("strip-select") ] : ""; |
1225
|
|
|
$csv_data['strip'] = ($this->input->post("strip-prefix")) ? $this->input->post("strip-prefix") . $csv_data['strip'] : $csv_data['strip']; |
1226
|
|
|
$csv_data['last_modified_date'] = date("Y-m-d H:i:s"); |
1227
|
|
|
$str = $this->data_validate($csv_data); |
1228
|
|
|
if ($str != "") |
1229
|
|
|
{ |
1230
|
|
|
$invalid_array[$i] = $csv_data; |
1231
|
|
|
$invalid_array[$i]['error'] = $str; |
1232
|
|
|
} |
1233
|
|
|
else |
1234
|
|
|
{ |
1235
|
|
|
$new_final_arr[$i]['trunk_id'] = $trunkID; |
1236
|
|
|
$new_final_arr[$i]['pattern'] = "^" . $csv_data['pattern'] . ".*"; |
1237
|
|
|
$new_final_arr[$i]['prepend'] = $csv_data['prepend']; |
1238
|
|
|
$new_final_arr[$i]['last_modified_date'] = $csv_data['last_modified_date']; |
1239
|
|
|
$new_final_arr[$i]['comment'] = $csv_data['comment']; |
1240
|
|
|
$new_final_arr[$i]['connectcost'] = $csv_data['connectcost']; |
1241
|
|
|
$new_final_arr[$i]['includedseconds'] = $csv_data['includedseconds']; |
1242
|
|
|
$new_final_arr[$i]['cost'] = !empty($csv_data['cost']) && is_numeric($csv_data['cost']) ? $csv_data['cost'] : 0; |
1243
|
|
|
$new_final_arr[$i]['inc'] = isset($csv_data['inc']) ? $csv_data['inc'] : 0; |
1244
|
|
|
$new_final_arr[$i]['precedence'] = isset($csv_data['precedence']) ? $csv_data['precedence'] : ''; |
1245
|
|
|
$new_final_arr[$i]['strip'] = isset($csv_data['strip']) ? $csv_data['strip'] : ''; |
1246
|
|
|
} |
1247
|
|
|
} |
1248
|
|
|
|
1249
|
|
|
$i++; |
1250
|
|
|
} |
1251
|
|
|
|
1252
|
|
|
if (!empty($new_final_arr)) |
1253
|
|
|
{ |
1254
|
|
|
$result = $this->rates_model->bulk_insert_termination_rate($new_final_arr); |
1255
|
|
|
} |
1256
|
|
|
else |
1257
|
|
|
{ |
1258
|
|
|
|
1259
|
|
|
$this->session->set_flashdata('astpp_errormsg', 'Error - Nothing selected to import/process!'); |
1260
|
|
|
redirect(base_url() . 'rates/termination_rates_list/'); |
1261
|
|
|
} |
1262
|
|
|
|
1263
|
|
|
unlink($full_path . $terminationrate_file_name); |
1264
|
|
|
$count = count($invalid_array); |
1265
|
|
View Code Duplication |
if ($count > 0) |
1266
|
|
|
{ |
1267
|
|
|
$session_id = "-1"; |
1268
|
|
|
$fp = fopen($full_path . $session_id . '.csv', 'w'); |
1269
|
|
|
foreach($new_final_arr_key as $key => $value) |
1270
|
|
|
{ |
1271
|
|
|
$custom_array[0][$key] = ucfirst($key); |
|
|
|
|
1272
|
|
|
} |
1273
|
|
|
|
1274
|
|
|
$custom_array[0]['error'] = "Error"; |
|
|
|
|
1275
|
|
|
$invalid_array = array_merge($custom_array, $invalid_array); |
1276
|
|
|
foreach($invalid_array as $err_data) |
1277
|
|
|
{ |
1278
|
|
|
fputcsv($fp, $err_data); |
1279
|
|
|
} |
1280
|
|
|
|
1281
|
|
|
fclose($fp); |
1282
|
|
|
$this->session->set_userdata('import_termination_rate_mapper_csv_error', $session_id . ".csv"); |
1283
|
|
|
$data["error"] = $invalid_array; |
|
|
|
|
1284
|
|
|
$data['trunkid'] = $trunkID; |
1285
|
|
|
$data['impoted_count'] = count($new_final_arr); |
1286
|
|
|
$data['failure_count'] = count($invalid_array) - 1; |
1287
|
|
|
$data['page_title'] = 'Termination Rates Import Error'; |
1288
|
|
|
$this->load->view('view_import_error', $data); |
1289
|
|
|
} |
1290
|
|
|
else |
1291
|
|
|
{ |
1292
|
|
|
$this->session->set_flashdata('astpp_errormsg', 'Total ' . count($new_final_arr) . ' Termination rates imported successfully!'); |
1293
|
|
|
redirect(base_url() . "rates/termination_rate_list/"); |
1294
|
|
|
} |
1295
|
|
|
} |
1296
|
|
|
|
1297
|
|
|
/*************************/ |
1298
|
|
|
} |
1299
|
|
|
?> |
|
|
|
|
1300
|
|
|
|
1301
|
|
|
|
This check looks for a call to a parent method whose name is different than the method from which it is called.
Consider the following code:
The
getFirstName()
method in theSon
calls the wrong method in the parent class.