Passed
Push — v3.0 ( 598da8...3ea724 )
by Samir
12:59
created
web_interface/astpp/application/modules/user/controllers/user.php 1 patch
Spacing   +398 added lines, -398 removed lines patch added patch discarded remove patch
@@ -37,31 +37,31 @@  discard block
 block discarded – undo
37 37
 
38 38
 	function index() {
39 39
 		if ($this->session->userdata('user_login') == FALSE)
40
-			redirect(base_url() . 'login/login');
40
+			redirect(base_url().'login/login');
41 41
 		$data['page_title'] = 'Dashboard';
42 42
 		$this->load->view('view_user_dashboard', $data);
43 43
 	}
44 44
 
45 45
 	function user_dashboard_recent_payments() {
46
-		$result=$this->user_model->user_dashboard_recent_recharge_info();
47
-	$gmtoffset=$this->common->get_timezone_offset();
48
-		$i=0;
49
-		$json_data=array();
50
-		if($result->num_rows() > 0)
46
+		$result = $this->user_model->user_dashboard_recent_recharge_info();
47
+	$gmtoffset = $this->common->get_timezone_offset();
48
+		$i = 0;
49
+		$json_data = array();
50
+		if ($result->num_rows() > 0)
51 51
 	{
52
-		 $account_arr = $this->common->get_array('id,number,first_name,last_name', 'accounts','');
53
-		 $json_data[0]['accountid']='Accounts';
54
-		 $json_data[0]['credit']='Amount';
55
-		 $json_data[0]['payment_date']='Date';
56
-		 $json_data[0]['notes']='Notes';
57
-		 foreach($result->result_array() as $key=>$data){
58
-			  $current_timestamp=strtotime($data['payment_date']);
59
-			  $modified_date=$current_timestamp+$gmtoffset;
60
-		  		  $data['accountid'] = ($data['accountid'] != '' && isset($account_arr[$data['accountid']])) ? $account_arr[$data['accountid']] :"Anonymous";
61
-			  $json_data[$i]['accountid']=$data['accountid'];
62
-			  $json_data[$i]['credit']=$this->common_model->calculate_currency($data['credit'],'','',true,false);
63
-			  $json_data[$i]['payment_date']=date('Y-m-d H:i:s',strtotime($data['payment_date'])+$gmtoffset);
64
-			   $json_data[$i]['notes']=$data['notes'];
52
+		 $account_arr = $this->common->get_array('id,number,first_name,last_name', 'accounts', '');
53
+		 $json_data[0]['accountid'] = 'Accounts';
54
+		 $json_data[0]['credit'] = 'Amount';
55
+		 $json_data[0]['payment_date'] = 'Date';
56
+		 $json_data[0]['notes'] = 'Notes';
57
+		 foreach ($result->result_array() as $key=>$data) {
58
+			  $current_timestamp = strtotime($data['payment_date']);
59
+			  $modified_date = $current_timestamp + $gmtoffset;
60
+		  		  $data['accountid'] = ($data['accountid'] != '' && isset($account_arr[$data['accountid']])) ? $account_arr[$data['accountid']] : "Anonymous";
61
+			  $json_data[$i]['accountid'] = $data['accountid'];
62
+			  $json_data[$i]['credit'] = $this->common_model->calculate_currency($data['credit'], '', '', true, false);
63
+			  $json_data[$i]['payment_date'] = date('Y-m-d H:i:s', strtotime($data['payment_date']) + $gmtoffset);
64
+			   $json_data[$i]['notes'] = $data['notes'];
65 65
 			  $i++;
66 66
 		  	}
67 67
 		  }
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
 	}   
92 92
 	function user_dashboard_invoices_data() {
93 93
 		$accountinfo = $this->session->userdata('accountinfo');
94
-		$currency=$this->common->get_field_name('currency','currency',array("id"=>$accountinfo['currency_id']));
94
+		$currency = $this->common->get_field_name('currency', 'currency', array("id"=>$accountinfo['currency_id']));
95 95
 		$this->db->where('accountid', $accountinfo['id']);
96 96
 		$this->db->where('confirm', 1);
97 97
 		$this->db->select('*');
@@ -108,20 +108,20 @@  discard block
 block discarded – undo
108 108
 			$json_data[0]['amount'] = 'Amount ('.$currency.')';
109 109
 			$i = 1;
110 110
 			foreach ($result as $key => $data) {
111
-			$invoice_prefix= $entity_type =$this->common->get_field_name('invoice_prefix','invoices',array('id'=>$data['id']));
111
+			$invoice_prefix = $entity_type = $this->common->get_field_name('invoice_prefix', 'invoices', array('id'=>$data['id']));
112 112
 
113
-			$invoiceid= $entity_type =$this->common->get_field_name('invoiceid','invoices',array('id'=>$data['id']));
114
-			$invoice_num=$invoice_prefix.$invoiceid;
115
-			$inv_type=$this->common->get_invoice_total('item_type', '', $data['id']);
116
-			if($inv_type == ''){
117
-			  $inv_type='Automatically';
113
+			$invoiceid = $entity_type = $this->common->get_field_name('invoiceid', 'invoices', array('id'=>$data['id']));
114
+			$invoice_num = $invoice_prefix.$invoiceid;
115
+			$inv_type = $this->common->get_invoice_total('item_type', '', $data['id']);
116
+			if ($inv_type == '') {
117
+			  $inv_type = 'Automatically';
118 118
 			}
119
-			if($inv_type == 'manual_inv'){
120
-			  $inv_type='Manually';
119
+			if ($inv_type == 'manual_inv') {
120
+			  $inv_type = 'Manually';
121 121
 			}
122
-			$inv_debit=$this->common->convert_to_currency('', '', $data['amount']);
123
-			if($inv_debit == ''){
124
-			  $inv_debit=$this->common->convert_to_currency('', '',0);
122
+			$inv_debit = $this->common->convert_to_currency('', '', $data['amount']);
123
+			if ($inv_debit == '') {
124
+			  $inv_debit = $this->common->convert_to_currency('', '', 0);
125 125
 			}
126 126
 			$json_data[$i]['type'] = $data['type'];
127 127
 			$json_data[$i]['id'] = $invoice_num;
@@ -134,54 +134,54 @@  discard block
 block discarded – undo
134 134
 		echo json_encode($json_data);
135 135
 	}
136 136
     
137
-	function user_dashboard_subscription_data(){
138
-		$accountinfo=$this->session->userdata('accountinfo');
139
-		$this->db->where('accountid',$accountinfo['id']);
137
+	function user_dashboard_subscription_data() {
138
+		$accountinfo = $this->session->userdata('accountinfo');
139
+		$this->db->where('accountid', $accountinfo['id']);
140 140
 		$this->db->select('*');
141
-		$this->db->order_by('assign_date','desc');
142
-		$result=$this->db->get('charge_to_account',10);
143
-		$json_data=array();
141
+		$this->db->order_by('assign_date', 'desc');
142
+		$result = $this->db->get('charge_to_account', 10);
143
+		$json_data = array();
144 144
       
145
-		$gmtoffset=$this->common->get_timezone_offset();
146
-		if($result->num_rows()> 0 ){
147
-		$result=$result->result_array();
148
-		$charge_str=null;
149
-		$charges_arr=array();
150
-		foreach($result as $charges_data){
151
-			$charge_str.=$charges_data['charge_id'].",";
152
-		}
153
-		$charge_str=rtrim($charge_str,",");
145
+		$gmtoffset = $this->common->get_timezone_offset();
146
+		if ($result->num_rows() > 0) {
147
+		$result = $result->result_array();
148
+		$charge_str = null;
149
+		$charges_arr = array();
150
+		foreach ($result as $charges_data) {
151
+			$charge_str .= $charges_data['charge_id'].",";
152
+		}
153
+		$charge_str = rtrim($charge_str, ",");
154 154
 		$where = "id IN ($charge_str)";
155 155
 		$this->db->where($where);
156 156
 		$this->db->select('id,description,sweep_id');
157
-		$charge_result=$this->db->get('charges');
158
-		foreach($charge_result->result_array() as $data){
159
-			$charges_arr[$data['id']]['description']=$data['description'];
160
-			$charges_arr[$data['id']]['sweep_id']=$data['sweep_id'];
161
-		}
162
-		$json_data[0]['charge_id']='Charge Name';
163
-		$json_data[0]['assign_date']='Assign Date';
164
-		$json_data[0]['sweep_id']='Billing Cycle';
165
-		$i=1;
166
-		foreach($result as $key=>$data){
167
-		if(isset($charges_arr[$data['charge_id']]['sweep_id'])){
168
-			$sweep_id= $charges_arr[$data['charge_id']]['sweep_id'];
169
-		}
170
-		$data['charge_id'] =isset($charges_arr[$data['charge_id']]['description']) ? $charges_arr[$data['charge_id']]['description'] :"Anonymous";
171
-		$json_data[$i]['charge_id']=$data['charge_id'];
172
-		if($data['assign_date'] != '0000-00-00 00:00:00'){
173
-			$json_data[$i]['assign_date']=date('Y-m-d H:i:s',strtotime($data['assign_date'])+$gmtoffset);
174
-		} else{
175
-			$json_data[$i]['assign_date']=$data['assign_date'];
176
-		}
177
-		if(isset($sweep_id)){
178
-			if($sweep_id ==0){
179
-				$json_data[$i]['sweep_id']='Daily';
180
-			} else{
181
-				$json_data[$i]['sweep_id']='Monthly';			
157
+		$charge_result = $this->db->get('charges');
158
+		foreach ($charge_result->result_array() as $data) {
159
+			$charges_arr[$data['id']]['description'] = $data['description'];
160
+			$charges_arr[$data['id']]['sweep_id'] = $data['sweep_id'];
161
+		}
162
+		$json_data[0]['charge_id'] = 'Charge Name';
163
+		$json_data[0]['assign_date'] = 'Assign Date';
164
+		$json_data[0]['sweep_id'] = 'Billing Cycle';
165
+		$i = 1;
166
+		foreach ($result as $key=>$data) {
167
+		if (isset($charges_arr[$data['charge_id']]['sweep_id'])) {
168
+			$sweep_id = $charges_arr[$data['charge_id']]['sweep_id'];
169
+		}
170
+		$data['charge_id'] = isset($charges_arr[$data['charge_id']]['description']) ? $charges_arr[$data['charge_id']]['description'] : "Anonymous";
171
+		$json_data[$i]['charge_id'] = $data['charge_id'];
172
+		if ($data['assign_date'] != '0000-00-00 00:00:00') {
173
+			$json_data[$i]['assign_date'] = date('Y-m-d H:i:s', strtotime($data['assign_date']) + $gmtoffset);
174
+		} else {
175
+			$json_data[$i]['assign_date'] = $data['assign_date'];
176
+		}
177
+		if (isset($sweep_id)) {
178
+			if ($sweep_id == 0) {
179
+				$json_data[$i]['sweep_id'] = 'Daily';
180
+			} else {
181
+				$json_data[$i]['sweep_id'] = 'Monthly';			
182 182
 			}
183
-		} else{
184
-			$json_data[$i]['sweep_id']='Anonymous';
183
+		} else {
184
+			$json_data[$i]['sweep_id'] = 'Anonymous';
185 185
 		}
186 186
 		$i++;
187 187
 		}
@@ -192,7 +192,7 @@  discard block
 block discarded – undo
192 192
 	function user_edit_account() {
193 193
 		if ($add_array['id'] != '') {
194 194
 			$data['form'] = $this->form->build_form($this->accounts->accounts_form->get_user_form_fields($add_array['id']), $add_array);
195
-			$data['page_title'] = 'Edit ' . $entity_name;
195
+			$data['page_title'] = 'Edit '.$entity_name;
196 196
 			if ($this->form_validation->run() == FALSE) {
197 197
 				$data['validation_errors'] = validation_errors();
198 198
 			} else {
@@ -201,14 +201,14 @@  discard block
 block discarded – undo
201 201
 				$this->accounts->accounts_model->edit_account($add_array, $add_array['id']);
202 202
 				$accountinfo = $this->session->userdata('accountinfo');
203 203
 				if ($add_array['id'] == $accountinfo['id']) {
204
-					$this->session->set_userdata('accountinfo',(array)$this->db->get_where('accounts', array('id' => $add_array['id']))->first_row());
204
+					$this->session->set_userdata('accountinfo', (array)$this->db->get_where('accounts', array('id' => $add_array['id']))->first_row());
205 205
 				}
206
-				$this->session->set_flashdata('astpp_errormsg', ucfirst($entity_name) . ' updated successfully!');
207
-				redirect(base_url() . 'user/user/');
206
+				$this->session->set_flashdata('astpp_errormsg', ucfirst($entity_name).' updated successfully!');
207
+				redirect(base_url().'user/user/');
208 208
 			}
209 209
 			$this->load->view('view_user_details', $data);
210 210
 		} else {
211
-			$data['page_title'] = 'Edit ' . $entity_name;
211
+			$data['page_title'] = 'Edit '.$entity_name;
212 212
 			$where = array('id' => $account_data["id"]);
213 213
 			$account = $this->db_model->getSelect("*", "accounts", $where);
214 214
 			$data["account_data"] = $account->result_array();
@@ -225,52 +225,52 @@  discard block
 block discarded – undo
225 225
 	function user_did_edit($edit_id = '') {
226 226
 		$data['page_title'] = 'Edit DIDs';
227 227
 		$account_data = $this->session->userdata("accountinfo");
228
-		$this->db->where('id',$edit_id);
228
+		$this->db->where('id', $edit_id);
229 229
 		$this->db->select('id,call_type,extensions,number');
230
-		$did_info=(array)$this->db->get('dids')->first_row();
231
-		$did_info['free_didlist']=$did_info['id'];
232
-		$data['form'] = $this->form->build_form($this->user_form->build_user_did_form(),$did_info);
230
+		$did_info = (array)$this->db->get('dids')->first_row();
231
+		$did_info['free_didlist'] = $did_info['id'];
232
+		$data['form'] = $this->form->build_form($this->user_form->build_user_did_form(), $did_info);
233 233
 		$this->load->view('view_user_did_edit', $data);
234 234
 	}
235 235
 
236
-	function user_dids_action($action,$did_id = "") {
236
+	function user_dids_action($action, $did_id = "") {
237 237
 		$accountinfo = $this->session->userdata('accountinfo');
238 238
 		$reseller_id = $accountinfo['reseller_id'];
239 239
 		$did_id = empty($did_id) ? $this->input->post("free_didlist", true) : $did_id;
240 240
           
241
-		if($did_id !=''){
242
-			$account_query = $this->db_model->getSelect("*", "accounts",array('id' => $accountinfo['id']));
243
-			$account_arr = (array) $account_query->first_row();
241
+		if ($did_id != '') {
242
+			$account_query = $this->db_model->getSelect("*", "accounts", array('id' => $accountinfo['id']));
243
+			$account_arr = (array)$account_query->first_row();
244 244
 			$did_query = $this->db_model->getSelect("*", "dids", array("id" => $did_id));
245
-			$did_arr = (array) $did_query->first_row();
246
-		if ($action == "add"){
247
-			if($did_arr['accountid'] == 0 && $did_arr['parent_id'] == $reseller_id ) {
248
-			 $setup_cost=$did_arr['setup'];
245
+			$did_arr = (array)$did_query->first_row();
246
+		if ($action == "add") {
247
+			if ($did_arr['accountid'] == 0 && $did_arr['parent_id'] == $reseller_id) {
248
+			 $setup_cost = $did_arr['setup'];
249 249
 				if ($accountinfo["reseller_id"] > 0) {
250
-					$reseller_pricing_res = $this->db_model->getSelect("*", "reseller_pricing", array("note" => $did_arr['number'],"reseller_id"=>$accountinfo['reseller_id']));
250
+					$reseller_pricing_res = $this->db_model->getSelect("*", "reseller_pricing", array("note" => $did_arr['number'], "reseller_id"=>$accountinfo['reseller_id']));
251 251
 					$reseller_pricing_arr = (array)$reseller_pricing_res->first_row();
252
-					$setup_cost=$reseller_pricing_arr['setup'];
252
+					$setup_cost = $reseller_pricing_arr['setup'];
253 253
 				}
254 254
 				$available_bal = $this->db_model->get_available_bal($account_arr);
255 255
 				if ($available_bal >= $setup_cost) {
256
-					$available_bal = $this->db_model->update_balance($setup_cost,$accountinfo["id"], "debit");
257
-					$accountinfo=(array)$this->db->get_where('accounts',array("id"=>$accountinfo['id']))->first_row();
258
-					$this->common->add_invoice_details($accountinfo,"DIDCHRG",$setup_cost,$did_arr['number']);
259
-					$this->db_model->update("dids", array("accountid" => $accountinfo["id"],"assign_date" => gmdate('Y-m-d H:i:s')), array("id" => $did_id));
260
-					$this->common->mail_to_users('email_add_did', $account_arr,"",$did_arr['number']);
256
+					$available_bal = $this->db_model->update_balance($setup_cost, $accountinfo["id"], "debit");
257
+					$accountinfo = (array)$this->db->get_where('accounts', array("id"=>$accountinfo['id']))->first_row();
258
+					$this->common->add_invoice_details($accountinfo, "DIDCHRG", $setup_cost, $did_arr['number']);
259
+					$this->db_model->update("dids", array("accountid" => $accountinfo["id"], "assign_date" => gmdate('Y-m-d H:i:s')), array("id" => $did_id));
260
+					$this->common->mail_to_users('email_add_did', $account_arr, "", $did_arr['number']);
261 261
 					$this->session->set_flashdata('astpp_errormsg', 'Did added successfully.');
262
-					redirect(base_url() . "user/user_didlist/");
262
+					redirect(base_url()."user/user_didlist/");
263 263
 				} else {
264 264
 					$this->session->set_flashdata('astpp_notification', 'Insuffiecient fund to purchase this did');
265
-					redirect(base_url() . "user/user_didlist/");
265
+					redirect(base_url()."user/user_didlist/");
266 266
 				}
267
-		}else{
267
+		} else {
268 268
 				$this->session->set_flashdata('astpp_notification', 'This DID already purchased by someone.');
269
-				redirect(base_url() . "user/user_didlist/");
269
+				redirect(base_url()."user/user_didlist/");
270 270
 		}
271 271
 		}
272 272
 		if ($action == "edit") {
273
-			$add_array=$this->input->post();
273
+			$add_array = $this->input->post();
274 274
 		$data['form'] = $this->form->build_form($this->user_form->build_user_did_form($add_array['free_didlist']), $add_array);
275 275
 		if ($this->form_validation->run() == FALSE) {
276 276
 				$data['validation_errors'] = validation_errors();
@@ -278,27 +278,27 @@  discard block
 block discarded – undo
278 278
 				exit;
279 279
 			} else {
280 280
 		  $update_arr = array("call_type" => $add_array['call_type'],
281
-		  "extensions" => $add_array['extensions'],"last_modified_date"=>gmdate("Y-m-d H:i:s")
281
+		  "extensions" => $add_array['extensions'], "last_modified_date"=>gmdate("Y-m-d H:i:s")
282 282
 		  );
283 283
 		  $this->db->update("dids", $update_arr, array("id" => $did_id));
284
-		  if($accountinfo['reseller_id'] > 0 ){
284
+		  if ($accountinfo['reseller_id'] > 0) {
285 285
 		  
286
-		  $this->db->update('reseller_pricing',$update_arr,array('note'=>$did_arr['number']));
286
+		  $this->db->update('reseller_pricing', $update_arr, array('note'=>$did_arr['number']));
287 287
 		  }
288
-		  echo json_encode(array("SUCCESS" => $did_arr['number'] . " DID Updated Successfully!"));
288
+		  echo json_encode(array("SUCCESS" => $did_arr['number']." DID Updated Successfully!"));
289 289
 		  exit;
290 290
 			}
291 291
 			$this->load->view('view_user_did_edit', $data);
292 292
 		}
293 293
 		if ($action == "delete") {
294
-			$this->db->update("dids", array("accountid" =>0,"assign_date" =>"0000-00-00 00:00:00" , 'charge_upto'=>"0000-00-00 00:00:00"),array("id" => $did_id));
295
-			$this->common->mail_to_users('email_remove_did', $account_arr,"",$did_arr['number']);
294
+			$this->db->update("dids", array("accountid" =>0, "assign_date" =>"0000-00-00 00:00:00", 'charge_upto'=>"0000-00-00 00:00:00"), array("id" => $did_id));
295
+			$this->common->mail_to_users('email_remove_did', $account_arr, "", $did_arr['number']);
296 296
 			$this->session->set_flashdata('astpp_notification', 'DID Removed Successfully.');
297
-			redirect(base_url() . "user/user_didlist/");
297
+			redirect(base_url()."user/user_didlist/");
298 298
 		}
299
-		}else{
299
+		} else {
300 300
 	  $this->session->set_flashdata('astpp_notification', 'DID not found.');
301
-	  redirect(base_url() . "user/user_didlist/");
301
+	  redirect(base_url()."user/user_didlist/");
302 302
 		}
303 303
 	}
304 304
 
@@ -324,13 +324,13 @@  discard block
 block discarded – undo
324 324
 		$query = $this->user_model->get_user_rates_list(true, $paging_data["paging"]["start"], $paging_data["paging"]["page_no"]);
325 325
 		$grid_fields = json_decode($this->user_form->user_rates_list());
326 326
 		foreach ($query->result_array() as $key => $value) {
327
-			$cost=$account_data['type']!=3 ? ($value['cost'] + (($value['cost']*$markup)/100)) : $value['cost'];
327
+			$cost = $account_data['type'] != 3 ? ($value['cost'] + (($value['cost'] * $markup) / 100)) : $value['cost'];
328 328
 			$json_data['rows'][] = array('cell' => array(
329
-					$this->common->get_only_numeric_val("","",$value["pattern"]),
329
+					$this->common->get_only_numeric_val("", "", $value["pattern"]),
330 330
 					$value['comment'],
331
-					$this->common_model->calculate_currency($value['connectcost'],'','',true,false),
331
+					$this->common_model->calculate_currency($value['connectcost'], '', '', true, false),
332 332
 					$value['includedseconds'],
333
-					$this->common_model->calculate_currency(($cost),'','',true,false),
333
+					$this->common_model->calculate_currency(($cost), '', '', true, false),
334 334
 					$value['init_inc'],
335 335
 					$value['inc']                   
336 336
 			));
@@ -344,22 +344,22 @@  discard block
 block discarded – undo
344 344
 		if ($this->input->post('advance_search', TRUE) == 1) {
345 345
 			$this->session->set_userdata('advance_search', $this->input->post('advance_search'));
346 346
 			$action = $this->input->post();
347
-			unset($action['action'],$action['advance_search']);
347
+			unset($action['action'], $action['advance_search']);
348 348
 			if (isset($action['connectcost']['connectcost']) && $action['connectcost']['connectcost'] != '') {
349 349
 				$action['connectcost']['connectcost'] = $this->common_model->add_calculate_currency($action['connectcost']['connectcost'], "", '', true, false);
350 350
 			}
351 351
 			if (isset($action['cost']['cost']) && $action['cost']['cost'] != '') {
352 352
 				$account_data = $this->session->userdata("accountinfo");
353 353
 				$markup = $this->common->get_field_name('markup', 'pricelists', array('id'=>$account_data["pricelist_id"]));
354
-				$markup = ($markup > 0)?$markup:1;
354
+				$markup = ($markup > 0) ? $markup : 1;
355 355
 				$action['cost']['cost'] = $this->common_model->add_calculate_currency($action['cost']['cost'], "", '', true, false);
356
-				if($account_data['type']!=3)
357
-					$action['cost']['cost']=($action['cost']['cost'] - ($action['cost']['cost']*$markup)/100);
356
+				if ($account_data['type'] != 3)
357
+					$action['cost']['cost'] = ($action['cost']['cost'] - ($action['cost']['cost'] * $markup) / 100);
358 358
 			}
359 359
 			$this->session->set_userdata('user_rates_list_search', $action);
360 360
 		}
361 361
 		if ($ajax_search != 1) {
362
-			redirect(base_url() . 'user/user_rates_list/');
362
+			redirect(base_url().'user/user_rates_list/');
363 363
 		}
364 364
 	}
365 365
 
@@ -369,34 +369,34 @@  discard block
 block discarded – undo
369 369
 	}
370 370
     
371 371
 	function user_rates_list_export() {
372
-	$account_data=$this->session->userdata('accountinfo');
373
-		$currency_id=$account_data['currency_id'];
374
-		$currency=$this->common->get_field_name('currency', 'currency', $currency_id);
372
+	$account_data = $this->session->userdata('accountinfo');
373
+		$currency_id = $account_data['currency_id'];
374
+		$currency = $this->common->get_field_name('currency', 'currency', $currency_id);
375 375
 		$query = $this->user_model->get_user_rates_list(true, '', '', false);
376 376
 		$markup = $this->common->get_field_name('markup', 'pricelists', array('id'=>$account_data["pricelist_id"]));
377 377
 		ob_clean();
378
-		$inbound_array[] = array("Code", "Destination","Connect Cost($currency)","Included Seconds","Per Minute Cost($currency)","Initital Increment","Increment");
378
+		$inbound_array[] = array("Code", "Destination", "Connect Cost($currency)", "Included Seconds", "Per Minute Cost($currency)", "Initital Increment", "Increment");
379 379
 		if ($query->num_rows() > 0) {
380 380
 			foreach ($query->result_array() as $row) {
381
-		$cost=$account_data['type']!=3 ? ($row['cost'] + ($row['cost']*$markup)/100) :$row['cost'];
381
+		$cost = $account_data['type'] != 3 ? ($row['cost'] + ($row['cost'] * $markup) / 100) : $row['cost'];
382 382
 		$inbound_array[] = array(
383
-						$row['pattern']=$this->common->get_only_numeric_val("","",$row["pattern"]),
383
+						$row['pattern'] = $this->common->get_only_numeric_val("", "", $row["pattern"]),
384 384
 						$row['comment'],
385
-						$this->common_model->calculate_currency($row['connectcost'],'','',true,false),
385
+						$this->common_model->calculate_currency($row['connectcost'], '', '', true, false),
386 386
 						$row['includedseconds'],
387
-			$this->common_model->calculate_currency($cost,'','',true,false),
387
+			$this->common_model->calculate_currency($cost, '', '', true, false),
388 388
 			$row['init_inc'],
389 389
 						$row['inc']
390 390
 					);
391 391
 			}
392 392
 		}
393 393
 		$this->load->helper('csv');
394
-		array_to_csv($inbound_array, 'Rates_' . date("Y-m-d") . '.csv');
394
+		array_to_csv($inbound_array, 'Rates_'.date("Y-m-d").'.csv');
395 395
 	} 
396 396
 
397 397
 	function user_refill($action = "") {
398 398
 		if (common_model::$global_config['system_config']['paypal_status'] == 1) {
399
-			redirect(base_url() . 'user/user/');
399
+			redirect(base_url().'user/user/');
400 400
 		}
401 401
 		$this->load->module("user/refill");
402 402
 		if ($action == "GET_AMT") {
@@ -438,14 +438,14 @@  discard block
 block discarded – undo
438 438
 				$this->load->model('user_model');
439 439
 				$this->user_model->change_db_password($update, $id);
440 440
 				$this->session->set_flashdata('astpp_errormsg', "Password changed Sucessfully....!!!");
441
-				redirect(base_url() . 'user/user/changepassword/');
441
+				redirect(base_url().'user/user/changepassword/');
442 442
 			} else {
443 443
 				$this->session->set_flashdata('astpp_notification', "New Password & Conformpassword not match.");
444
-				redirect(base_url() . 'user/user/changepassword/');
444
+				redirect(base_url().'user/user/changepassword/');
445 445
 			}
446 446
 		} else {
447 447
 			$this->session->set_flashdata('astpp_notification', "Invalid old passwword.");
448
-			redirect(base_url() . 'user/user/changepassword/');
448
+			redirect(base_url().'user/user/changepassword/');
449 449
 		}
450 450
 	}
451 451
 
@@ -471,7 +471,7 @@  discard block
 block discarded – undo
471 471
 		$acc_data = $this->session->userdata("accountinfo");
472 472
 		$reseller_id = $acc_data['reseller_id'];
473 473
 
474
-		$drp_data = $this->db->query("SELECT id,CONCAT(number,'(',amount,')') as details,number FROM refill_coupon WHERE status = '0' and reseller_id='" . $reseller_id . "'");
474
+		$drp_data = $this->db->query("SELECT id,CONCAT(number,'(',amount,')') as details,number FROM refill_coupon WHERE status = '0' and reseller_id='".$reseller_id."'");
475 475
 		$reseller_data = array();
476 476
 		$data['refill_coupon_list'] = form_dropdown_all('refill_coupon_list', $reseller_data, '');
477 477
 		$this->load->view('view_refill_coupon_list', $data);
@@ -501,11 +501,11 @@  discard block
 block discarded – undo
501 501
 				echo json_encode(2);
502 502
 			} else {
503 503
 				$this->db->select('balance');
504
-				$result = (array)$this->db->get_where('accounts',array('id'=>$customer_id))->first_row();
505
-				$user_balance=$this->db_model->get_available_bal($accountinfo);
506
-				$original_balance=$refill_coupon_result['amount'];
507
-				$refill_coupon_result['amount'] = $this->common_model->to_calculate_currency($original_balance,'','',TRUE,TRUE);
508
-				$refill_coupon_result['new_balance'] = $this->common_model->to_calculate_currency($user_balance+$original_balance,'','',TRUE,TRUE);
504
+				$result = (array)$this->db->get_where('accounts', array('id'=>$customer_id))->first_row();
505
+				$user_balance = $this->db_model->get_available_bal($accountinfo);
506
+				$original_balance = $refill_coupon_result['amount'];
507
+				$refill_coupon_result['amount'] = $this->common_model->to_calculate_currency($original_balance, '', '', TRUE, TRUE);
508
+				$refill_coupon_result['new_balance'] = $this->common_model->to_calculate_currency($user_balance + $original_balance, '', '', TRUE, TRUE);
509 509
 				echo json_encode($refill_coupon_result);
510 510
 			}
511 511
 		} else {
@@ -539,10 +539,10 @@  discard block
 block discarded – undo
539 539
 			$this->db->where('number', $refill_coupon_no);
540 540
 			$refill_coupon_data = array('status' => 2, "account_id" => $customer_id, 'firstused' => $date);
541 541
 			$this->db->update('refill_coupon', $refill_coupon_data);
542
-			$payment_arr = array("accountid" => $customer_id, 'type' => 'refill_coupon', 'credit' => $amount, 'payment_by' => $reseller_id, 'payment_date' => $date, 'refill_coupon_number' => $refill_coupon_no, 'notes' => 'Recharge using Refill coupon,Refill coupon No. ' . $refill_coupon_no . '');
542
+			$payment_arr = array("accountid" => $customer_id, 'type' => 'refill_coupon', 'credit' => $amount, 'payment_by' => $reseller_id, 'payment_date' => $date, 'refill_coupon_number' => $refill_coupon_no, 'notes' => 'Recharge using Refill coupon,Refill coupon No. '.$refill_coupon_no.'');
543 543
 			$this->db->insert('payments', $payment_arr);
544 544
 		}
545
-		redirect(base_url() . "user/user_refill_coupon_list/");
545
+		redirect(base_url()."user/user_refill_coupon_list/");
546 546
 	}
547 547
 
548 548
 	function user_packages() {
@@ -553,7 +553,7 @@  discard block
 block discarded – undo
553 553
 
554 554
 	function user_packages_json() {
555 555
 		$json_data = array();
556
-		$count_all = $this->user_model->get_user_packages_list(false,'','');
556
+		$count_all = $this->user_model->get_user_packages_list(false, '', '');
557 557
 		$paging_data = $this->form->load_grid_config($count_all, $_GET['rp'], $_GET['page']);
558 558
 		$json_data = $paging_data["json_paging"];
559 559
 		$query = $this->user_model->get_user_packages_list(true, $paging_data["paging"]["start"], $paging_data["paging"]["page_no"]);
@@ -596,19 +596,19 @@  discard block
 block discarded – undo
596 596
 		$json_data['rows'] = $this->form->build_grid($query, $grid_fields);
597 597
 		echo json_encode($json_data);
598 598
 	}
599
-	function user_emails_search(){
599
+	function user_emails_search() {
600 600
 		$ajax_search = $this->input->post('ajax_search', 0);
601 601
 		if ($this->input->post('advance_search', TRUE) == 1) {
602 602
 			$this->session->set_userdata('advance_search', $this->input->post('advance_search'));
603 603
 			$action = $this->input->post();
604
-			unset($action['action'],$action['advance_search']);
604
+			unset($action['action'], $action['advance_search']);
605 605
 			$this->session->set_userdata('user_emails_search', $action);
606 606
 		}
607 607
 		if (@$ajax_search != 1) {
608
-			redirect(base_url() . 'user/user_emails/');
608
+			redirect(base_url().'user/user_emails/');
609 609
 		}
610 610
 	}
611
-	function user_emails_clearsearchfilter(){
611
+	function user_emails_clearsearchfilter() {
612 612
 		$this->session->set_userdata('advance_search', 0);
613 613
 		$this->session->set_userdata('user_emails_search', "");
614 614
 	}
@@ -620,30 +620,30 @@  discard block
 block discarded – undo
620 620
 		if (isset($add_array['submit'])) {
621 621
 			if ($_FILES['file']['name'] == '') {
622 622
 				$invoiceconf = $this->user_model->get_invoiceconf();
623
-				$file_name=($invoiceconf['logo'] != '') ? $invoiceconf['logo'] : '';
623
+				$file_name = ($invoiceconf['logo'] != '') ? $invoiceconf['logo'] : '';
624 624
 			}
625 625
 			if (isset($_FILES['file']['name']) && $_FILES['file']['name'] != '') {
626 626
 				$files = $_FILES['file'];
627 627
 				if ($files['size'] < 0) {
628 628
 					$this->session->set_flashdata('astpp_notification', 'PLease upload maximum file');
629
-				redirect(base_url() . "accounts/reseller_invoice_config/". $add_array['accountid']."/");
629
+				redirect(base_url()."accounts/reseller_invoice_config/".$add_array['accountid']."/");
630 630
 				}
631 631
 				$file = $_FILES['file'];
632 632
 				$uploadedFile = $file["tmp_name"];
633 633
 				$file_name = $file['name'];
634 634
 				$file_type = $file['type'];
635 635
 				if ($file_type == 'image/jpg' || $file_type == 'image/png' || $file_type == 'image/jpeg') {
636
-					$dir_path = FCPATH. "upload/";
637
-					$path = $dir_path . $add_array['accountid']."_".$file['name'];
636
+					$dir_path = FCPATH."upload/";
637
+					$path = $dir_path.$add_array['accountid']."_".$file['name'];
638 638
 					if (move_uploaded_file($uploadedFile, $path)) {
639 639
 						$this->session->set_flashdata('astpp_errormsg', gettext('files added successfully!'));
640 640
 					} else {
641 641
 						$this->session->set_flashdata('astpp_notification', "File Uploading Fail Please Try Again");
642
-						redirect(base_url() . 'user/user_invoice_config/');
642
+						redirect(base_url().'user/user_invoice_config/');
643 643
 					}
644 644
 				} else {
645 645
 					$this->session->set_flashdata('astpp_notification', 'Please upload only image!');
646
-					redirect(base_url() . 'user/user_invoice_config/');
646
+					redirect(base_url().'user/user_invoice_config/');
647 647
 				}
648 648
 			}
649 649
 			$add_array['logo'] = $file_name;
@@ -655,24 +655,24 @@  discard block
 block discarded – undo
655 655
 				$this->user_model->edit_invoice_config($add_array, $add_array['id']);
656 656
 			}
657 657
 			$this->session->set_flashdata('astpp_errormsg', 'Invoice config updated successfully!');
658
-			redirect(base_url() . 'user/user_invoice_config/');
658
+			redirect(base_url().'user/user_invoice_config/');
659 659
 		} else {
660
-			$data["account_data"] =(array)$this->db->get_where('invoice_conf',array("accountid"=>$accountinfo['id']))->first_row();
661
-			if(isset($data["account_data"]['logo'])){
662
-				$data["account_data"]['file']=$accountinfo['id']."_".$data["account_data"]['logo'];
660
+			$data["account_data"] = (array)$this->db->get_where('invoice_conf', array("accountid"=>$accountinfo['id']))->first_row();
661
+			if (isset($data["account_data"]['logo'])) {
662
+				$data["account_data"]['file'] = $accountinfo['id']."_".$data["account_data"]['logo'];
663 663
 		}
664 664
 			$this->load->view('view_user_invoices_config', $data);
665 665
 		}
666 666
 	}
667 667
 
668
-	 function user_invoice_logo_delete($accountid){
669
-	$invoiceconf  = $this->db_model->getSelect("*", "invoice_conf", array("accountid"=> $accountid));
670
-	$result=$invoiceconf->result_array();
671
-	$logo=$result[0]['logo'];
672
-	$post_arr=array('logo'=>'');
673
-	$where_arr=array('logo'=>$logo);
668
+	 function user_invoice_logo_delete($accountid) {
669
+	$invoiceconf = $this->db_model->getSelect("*", "invoice_conf", array("accountid"=> $accountid));
670
+	$result = $invoiceconf->result_array();
671
+	$logo = $result[0]['logo'];
672
+	$post_arr = array('logo'=>'');
673
+	$where_arr = array('logo'=>$logo);
674 674
 	$this->db->where($where_arr);
675
-	$this->db->update('invoice_conf',$post_arr);
675
+	$this->db->update('invoice_conf', $post_arr);
676 676
 	 }
677 677
     
678 678
 	function user_myprofile() {
@@ -691,9 +691,9 @@  discard block
 block discarded – undo
691 691
 					$result = $this->db->get_where('accounts', array('id' => $add_array['id']));
692 692
 					$result = $result->result_array();
693 693
 					$this->session->set_userdata('accountinfo', $result[0]);
694
-					$this->session->set_flashdata('astpp_errormsg',' Your profile updated successfully!');
695
-					redirect(base_url() . 'user/user_myprofile/');
696
-				}else{
694
+					$this->session->set_flashdata('astpp_errormsg', ' Your profile updated successfully!');
695
+					redirect(base_url().'user/user_myprofile/');
696
+				} else {
697 697
 					$this->session->set_flashdata('astpp_notification', 'Something wrong.Please contact to administrator.');
698 698
 				}
699 699
 			}
@@ -715,35 +715,35 @@  discard block
 block discarded – undo
715 715
 		$accountinfo = $this->session->userdata("accountinfo");
716 716
 		$data['page_title'] = "Change Password";
717 717
 		$add_array = $this->input->post();    
718
-		if(!empty($add_array)) {
718
+		if ( ! empty($add_array)) {
719 719
 			$data['form'] = $this->form->build_form($this->user_form->get_userprofile_change_password(), $add_array);
720 720
 			if ($this->form_validation->run() == FALSE) {
721 721
 				$data['validation_errors'] = validation_errors();
722 722
 			} else {
723 723
 				$password_encode = $this->common->encode($add_array['new_password']);
724 724
 				$data = array('password' => $password_encode);
725
-				$this->db->where('id',$add_array['id']);
725
+				$this->db->where('id', $add_array['id']);
726 726
 				$this->db->update('accounts', $data);
727 727
 				$this->session->set_flashdata('astpp_errormsg', 'Password updated successfully!');
728
-				redirect(base_url() . 'user/user_change_password/');
728
+				redirect(base_url().'user/user_change_password/');
729 729
 			}
730
-		}else{
731
-			$data_array['id']=$accountinfo['id'];
732
-			$data['form'] = $this->form->build_form($this->user_form->get_userprofile_change_password(),$data_array);
730
+		} else {
731
+			$data_array['id'] = $accountinfo['id'];
732
+			$data['form'] = $this->form->build_form($this->user_form->get_userprofile_change_password(), $data_array);
733 733
 		}
734 734
 		$this->load->view('view_user_change_password', $data);
735 735
 	}
736 736
 
737 737
 	function user_refill_report() {
738
-		$accountinfo=$this->session->userdata('accountinfo');
738
+		$accountinfo = $this->session->userdata('accountinfo');
739 739
 		$data['page_title'] = 'Refill Report';
740 740
 		$data['search_flag'] = true;
741 741
 		$this->session->set_userdata('advance_search', 0);
742 742
 		$data['grid_fields'] = $this->user_form->build_user_refill_report();
743 743
 		$data['form_search'] = $this->form->build_serach_form($this->user_form->build_user_refill_report_search());
744
-		if($accountinfo['type'] == 1){
744
+		if ($accountinfo['type'] == 1) {
745 745
 			$this->load->view('view_reseller_refill_report', $data);
746
-		}else{
746
+		} else {
747 747
 			$this->load->view('view_user_refill_report', $data);
748 748
 		}
749 749
 	}
@@ -751,7 +751,7 @@  discard block
 block discarded – undo
751 751
 	function user_refill_report_json() {
752 752
 		$json_data = array();
753 753
 		$count_all = $this->user_model->get_user_refill_list(false);
754
-		$paging_data = $this->form->load_grid_config($count_all,$_GET['rp'], $_GET['page']);
754
+		$paging_data = $this->form->load_grid_config($count_all, $_GET['rp'], $_GET['page']);
755 755
 		$json_data = $paging_data["json_paging"];
756 756
 		$query = $this->user_model->get_user_refill_list(true, $paging_data["paging"]["start"], $paging_data["paging"]["page_no"]);
757 757
 		$grid_fields = json_decode($this->user_form->build_user_refill_report());
@@ -764,14 +764,14 @@  discard block
 block discarded – undo
764 764
 		if ($this->input->post('advance_search', TRUE) == 1) {
765 765
 			$this->session->set_userdata('advance_search', $this->input->post('advance_search'));
766 766
 			$action = $this->input->post();
767
-			unset($action['action'],$action['advance_search']);
767
+			unset($action['action'], $action['advance_search']);
768 768
 			if (isset($action['credit']['credit']) && $action['credit']['credit'] != '') {
769 769
 			 $action['credit']['credit'] = $this->common_model->add_calculate_currency($action['credit']['credit'], "", '', true, false);
770 770
 			}
771 771
 			$this->session->set_userdata('user_refill_report_search', $action);
772 772
 		}
773 773
 		if (@$ajax_search != 1) {
774
-			redirect(base_url() . 'user/user_refill_report/');
774
+			redirect(base_url().'user/user_refill_report/');
775 775
 		}
776 776
 	}
777 777
     
@@ -794,7 +794,7 @@  discard block
 block discarded – undo
794 794
 		$count_all = $this->user_model->get_user_invoice_list(false, '', '', $where);
795 795
 		$paging_data = $this->form->load_grid_config($count_all, $_GET['rp'], $_GET['page']);
796 796
 		$json_data = $paging_data["json_paging"];
797
-		$user_currency=$this->common->get_field_name('currency','currency',$accountinfo['currency_id']);
797
+		$user_currency = $this->common->get_field_name('currency', 'currency', $accountinfo['currency_id']);
798 798
 		$invoices_query = $this->user_model->get_user_invoice_list(true, $paging_data["paging"]["start"], $paging_data["paging"]["page_no"], $where);
799 799
 		$invoices_result = $invoices_query->result_array();
800 800
 		$ountstanding_value = 0;
@@ -805,7 +805,7 @@  discard block
 block discarded – undo
805 805
 		$total_credit = (array)$invoice_details_result->first_row();
806 806
 		$total_credit = $total_credit['total_credit'];
807 807
 		foreach ($invoices_result as $key => $value) {
808
-			$total_amount+=$value['amount'];
808
+			$total_amount += $value['amount'];
809 809
 			$invoice_date = date("Y-m-d", strtotime($value['invoice_date']));
810 810
 			$from_date = date("Y-m-d", strtotime($value['from_date']));
811 811
 			$due_date = date("Y-m-d", strtotime($value['due_date']));
@@ -820,23 +820,23 @@  discard block
 block discarded – undo
820 820
 			if ($invoice_total_query->num_rows() > 0) {
821 821
 				$invoice_total_result = $invoice_total_query->result_array();
822 822
 			}
823
-			$download = '<a href="' . base_url() . '/user/user_invoice_download/' . $value['id'] . '/00' . $value['invoice_prefix'] . $value['invoiceid'] . '" class="btn btn-royelblue btn-sm"  title="Download Invoice" ><i class="fa fa-cloud-download fa-fw"></i></a>&nbsp';
824
-		  if($value['type'] == 'I'){
823
+			$download = '<a href="'.base_url().'/user/user_invoice_download/'.$value['id'].'/00'.$value['invoice_prefix'].$value['invoiceid'].'" class="btn btn-royelblue btn-sm"  title="Download Invoice" ><i class="fa fa-cloud-download fa-fw"></i></a>&nbsp';
824
+		  if ($value['type'] == 'I') {
825 825
 			if ($outstanding > 0) {
826
-				$payment = ' <a style="padding: 0 8px;" href="' . base_url() . 'user/user_invoice_payment/' . $value['id'] . '" class="btn btn-warning"  title="Payment">Unpaid</a>';
826
+				$payment = ' <a style="padding: 0 8px;" href="'.base_url().'user/user_invoice_payment/'.$value['id'].'" class="btn btn-warning"  title="Payment">Unpaid</a>';
827 827
 			} else {
828 828
 				$payment = ' <button style="padding: 0 8px;" class="btn btn-success" type="button">Paid</button>';
829 829
 			}
830
-	   }else{
830
+	   } else {
831 831
 				$payment = '';
832 832
 	   }
833
-			if($value['generate_type'] == 1){
834
-		$invoice_type='Manually';
835
-	   }else{
836
-		$invoice_type='Automatically';
833
+			if ($value['generate_type'] == 1) {
834
+		$invoice_type = 'Manually';
835
+	   } else {
836
+		$invoice_type = 'Automatically';
837 837
 	   } 
838 838
 	   
839
-	   if($value['type'] == 'R'){
839
+	   if ($value['type'] == 'R') {
840 840
 		$icon = '<div class="flx_font flx_magenta">R</div>';
841 841
 		}
842 842
 		else
@@ -869,13 +869,13 @@  discard block
 block discarded – undo
869 869
 			print_r($action);
870 870
 			unset($action['action']);
871 871
 			unset($action['advance_search']);
872
-			$action['from_date'][0] = $action['from_date'][0] ? $action['from_date'][0] . " 00:00:00" : '';
873
-			$action['to_date'][1] = $action['to_date'][1] ? $action['to_date'][1] . " 23:59:59" : '';
874
-			$action['invoice_date'][0] = $action['invoice_date'][0] ? $action['invoice_date'][0] . " 00:00:00" : '';
872
+			$action['from_date'][0] = $action['from_date'][0] ? $action['from_date'][0]." 00:00:00" : '';
873
+			$action['to_date'][1] = $action['to_date'][1] ? $action['to_date'][1]." 23:59:59" : '';
874
+			$action['invoice_date'][0] = $action['invoice_date'][0] ? $action['invoice_date'][0]." 00:00:00" : '';
875 875
 			$this->session->set_userdata('user_invoice_list_search', $action);
876 876
 		}
877 877
 		if (@$ajax_search != 1) {
878
-			redirect(base_url() . 'user/user_invoice_list/');
878
+			redirect(base_url().'user/user_invoice_list/');
879 879
 		}
880 880
 	}
881 881
 
@@ -888,25 +888,25 @@  discard block
 block discarded – undo
888 888
 		$this->load->module('invoices/invoices');
889 889
 		$this->invoices->invoice_main_download($invoiceid);
890 890
 	}
891
-	function user_list_responce(){
891
+	function user_list_responce() {
892 892
 	$this->load->module('invoices/invoices');
893 893
 		$this->invoices->invoice_list_responce();
894 894
 	}
895
-	 function user_invoice_payment($invoiceid){
895
+	 function user_invoice_payment($invoiceid) {
896 896
 	$this->load->module('invoices/invoices');
897 897
 		$this->invoices->invoice_summary($invoiceid);
898 898
 	}	
899
-	function user_invoice_payment_pay($action=""){
899
+	function user_invoice_payment_pay($action = "") {
900 900
 		$this->load->module("user/payment");
901
-		if($action=="GET_AMT"){
902
-			$amount = $this->input->post("value",true);
903
-	   $amount = $this->common_model->add_calculate_currency($amount,"","",true,false);
904
-	   echo number_format($amount,2);
905
-		}else{
901
+		if ($action == "GET_AMT") {
902
+			$amount = $this->input->post("value", true);
903
+	   $amount = $this->common_model->add_calculate_currency($amount, "", "", true, false);
904
+	   echo number_format($amount, 2);
905
+		} else {
906 906
 			$this->payment->index();
907 907
 		}
908 908
 	}
909
-	function user_invoice_download($invoiceid){
909
+	function user_invoice_download($invoiceid) {
910 910
 	$this->load->module('invoices/invoices');
911 911
 		$this->invoices->invoice_download($invoiceid);
912 912
 	}    
@@ -925,43 +925,43 @@  discard block
 block discarded – undo
925 925
 		$json_data = $paging_data["json_paging"];
926 926
 		$query = $this->user_model->get_user_charge_history(true, $paging_data["paging"]["start"], $paging_data["paging"]["page_no"]);
927 927
 
928
-	$result= $query->result_array();
929
-		$query1 = $this->user_model->get_user_charge_history(true,'','');
930
-	$res= $query1->result_array();
931
-	$debit=0;
932
-	$credit=0;
933
-	$before_balance=0;
934
-	$after_balance=0;
935
-	$i=0;
928
+	$result = $query->result_array();
929
+		$query1 = $this->user_model->get_user_charge_history(true, '', '');
930
+	$res = $query1->result_array();
931
+	$debit = 0;
932
+	$credit = 0;
933
+	$before_balance = 0;
934
+	$after_balance = 0;
935
+	$i = 0;
936 936
 		foreach ($result as $key => $value) {
937
-   		 $date=$this->common->convert_GMT_to('','',$value['created_date']);
937
+   		 $date = $this->common->convert_GMT_to('', '', $value['created_date']);
938 938
  		 $cust_type = $this->common->get_field_name('posttoexternal', 'accounts', $value['accountid']);	    
939
-			$invoice_prefix= $entity_type =$this->common->get_field_name('invoice_prefix','invoices',array('id'=>$value['invoiceid']));
940
-			$invoiceid= $entity_type =$this->common->get_field_name('invoiceid','invoices',array('id'=>$value['invoiceid']));
941
-		$invoice_num=$invoice_prefix.$invoiceid;
942
-		$account=$this->common->get_field_name_coma_new('first_name,last_name,number','accounts',$value['accountid']);
943
-		$reseller=$this->common->reseller_select_value('first_name,last_name,number','accounts',$value['reseller_id']);
944
-		$item_type=$value['item_type'];
945
-		if($value['before_balance'] == '-'){
946
-			$before_balance='-';
947
-		} else{		
948
-			$before_balance=$this->common->convert_to_currency('','',$value['before_balance']);
949
-		}
950
-		if($value['debit'] == '-'){
951
-			$debit='-';
952
-		} else{		
953
-			$debit=$this->common->convert_to_currency('','',$value['debit']);
954
-		}
955
-		$credit=$this->common->convert_to_currency('','',$value['credit']);
956
-			 if($cust_type == 0 && $value['item_type'] == 'INVPAY'){
939
+			$invoice_prefix = $entity_type = $this->common->get_field_name('invoice_prefix', 'invoices', array('id'=>$value['invoiceid']));
940
+			$invoiceid = $entity_type = $this->common->get_field_name('invoiceid', 'invoices', array('id'=>$value['invoiceid']));
941
+		$invoice_num = $invoice_prefix.$invoiceid;
942
+		$account = $this->common->get_field_name_coma_new('first_name,last_name,number', 'accounts', $value['accountid']);
943
+		$reseller = $this->common->reseller_select_value('first_name,last_name,number', 'accounts', $value['reseller_id']);
944
+		$item_type = $value['item_type'];
945
+		if ($value['before_balance'] == '-') {
946
+			$before_balance = '-';
947
+		} else {		
948
+			$before_balance = $this->common->convert_to_currency('', '', $value['before_balance']);
949
+		}
950
+		if ($value['debit'] == '-') {
951
+			$debit = '-';
952
+		} else {		
953
+			$debit = $this->common->convert_to_currency('', '', $value['debit']);
954
+		}
955
+		$credit = $this->common->convert_to_currency('', '', $value['credit']);
956
+			 if ($cust_type == 0 && $value['item_type'] == 'INVPAY') {
957 957
 		$credit = '(-) '.$credit;
958 958
 		 }
959
-		if($value['after_balance'] == '-'){
960
-			$after_balance='-';
961
-		} else{		
962
-			$after_balance=$this->common->convert_to_currency('','',$value['after_balance']);
959
+		if ($value['after_balance'] == '-') {
960
+			$after_balance = '-';
961
+		} else {		
962
+			$after_balance = $this->common->convert_to_currency('', '', $value['after_balance']);
963 963
 		}
964
-		$description=$value['description'];
964
+		$description = $value['description'];
965 965
 			$cust_type = $this->common->get_field_name('posttoexternal', 'accounts', $value['accountid']);	    
966 966
 			$json_data['rows'][] = array('cell' => array(
967 967
 							$date,
@@ -977,7 +977,7 @@  discard block
 block discarded – undo
977 977
 		}
978 978
 	$debit_sum = 0;
979 979
 	$credit_sum = 0;
980
-	foreach($res as $value){
980
+	foreach ($res as $value) {
981 981
  		 $cust_type = $this->common->get_field_name('posttoexternal', 'accounts', $value['accountid']);	    
982 982
  		 $cust_type = $this->common->get_field_name('posttoexternal', 'accounts', $value['accountid']);	    
983 983
 		$debit_sum += $value['debit'];
@@ -985,7 +985,7 @@  discard block
 block discarded – undo
985 985
 		$before_balance += $value['before_balance'];
986 986
 		$after_balance += $value['after_balance'];
987 987
 	}
988
-			$json_data['rows'][$count_all]['cell']=array('<b>Total</b>','-','-','-','<b>'.$this->common->convert_to_currency('','',$debit_sum).'</b>','<b>'.$this->common->convert_to_currency('','',$credit_sum).'</b>','-','-');
988
+			$json_data['rows'][$count_all]['cell'] = array('<b>Total</b>', '-', '-', '-', '<b>'.$this->common->convert_to_currency('', '', $debit_sum).'</b>', '<b>'.$this->common->convert_to_currency('', '', $credit_sum).'</b>', '-', '-');
989 989
 	  echo json_encode($json_data);
990 990
 
991 991
 
@@ -997,8 +997,8 @@  discard block
 block discarded – undo
997 997
 			$action = $this->input->post();
998 998
 			unset($action['action']);
999 999
 			unset($action['advance_search']);
1000
-			$action['created_date'][0] = $action['created_date'][0] ? $action['created_date'][0] . " 00:00:00" : '';
1001
-			$action['created_date'][1] = $action['created_date'][1] ? $action['created_date'][1] . " 23:59:59" : '';
1000
+			$action['created_date'][0] = $action['created_date'][0] ? $action['created_date'][0]." 00:00:00" : '';
1001
+			$action['created_date'][1] = $action['created_date'][1] ? $action['created_date'][1]." 23:59:59" : '';
1002 1002
 			if (isset($action['debit']['debit']) && $action['debit']['debit'] != '') {
1003 1003
 				$action['debit']['debit'] = $this->common_model->add_calculate_currency($action['debit']['debit'], "", '', true, false);
1004 1004
 			}
@@ -1008,7 +1008,7 @@  discard block
 block discarded – undo
1008 1008
 			$this->session->set_userdata('user_charge_history_search', $action);
1009 1009
 		}
1010 1010
 		if (@$ajax_search != 1) {
1011
-			redirect(base_url() . 'user/user_charges_history/');
1011
+			redirect(base_url().'user/user_charges_history/');
1012 1012
 		}
1013 1013
 	}
1014 1014
 
@@ -1026,7 +1026,7 @@  discard block
 block discarded – undo
1026 1026
 
1027 1027
 	function user_subscriptions_json() {
1028 1028
         
1029
-		$accountinfo=$this->session->userdata('accountinfo');
1029
+		$accountinfo = $this->session->userdata('accountinfo');
1030 1030
 		$json_data = array();
1031 1031
 		$select = "charge_to_account.id,charges.description,charges.charge,charges.sweep_id";
1032 1032
 		$table = "charges";
@@ -1057,14 +1057,14 @@  discard block
 block discarded – undo
1057 1057
 			if (isset($action['charge']['charge']) && $action['charge']['charge'] != '') {
1058 1058
 				$action['charge']['charge'] = $this->common_model->add_calculate_currency($action['charge']['charge'], "", '', true, false);
1059 1059
 			}
1060
-			if(isset($action['sweep_id']) && $action['sweep_id'] != ''){
1061
-				$action['charges.sweep_id']=$action['sweep_id'];
1060
+			if (isset($action['sweep_id']) && $action['sweep_id'] != '') {
1061
+				$action['charges.sweep_id'] = $action['sweep_id'];
1062 1062
 				unset($action['sweep_id']);
1063 1063
 			}
1064 1064
 			$this->session->set_userdata('user_subscription_search', $action);
1065 1065
 		}
1066 1066
 		if (@$ajax_search != 1) {
1067
-			redirect(base_url() . 'user/user_subscriptions/');
1067
+			redirect(base_url().'user/user_subscriptions/');
1068 1068
 		}
1069 1069
 	}
1070 1070
 
@@ -1074,7 +1074,7 @@  discard block
 block discarded – undo
1074 1074
 	}
1075 1075
 
1076 1076
 	function user_didlist() {
1077
-		$accountinfo=$this->session->userdata('accountinfo');
1077
+		$accountinfo = $this->session->userdata('accountinfo');
1078 1078
 		$data['page_title'] = 'Purchase DIDs';
1079 1079
 		$data['search_flag'] = true;
1080 1080
 		$data['grid_fields'] = $this->user_form->build_user_didlist();
@@ -1082,38 +1082,38 @@  discard block
 block discarded – undo
1082 1082
 		$data["grid_buttons"] = array();
1083 1083
 		$acc_data = $this->session->userdata("accountinfo");
1084 1084
 		$data['accountid'] = $acc_data['id'];
1085
-		$data['country_id']=$acc_data['country_id'];
1085
+		$data['country_id'] = $acc_data['country_id'];
1086 1086
 		$result_did_final = array();
1087
-		if($accountinfo['reseller_id'] > 0){
1087
+		if ($accountinfo['reseller_id'] > 0) {
1088 1088
 	  $this->db->select('dids.id, dids.number, reseller_pricing.setup, reseller_pricing.monthlycost');
1089
-	  $this->db->where('dids.accountid',0);
1090
-	  $this->db->where('reseller_pricing.note','dids.number',false);
1091
-	  $this->db->where('reseller_pricing.reseller_id',$accountinfo['reseller_id']);
1089
+	  $this->db->where('dids.accountid', 0);
1090
+	  $this->db->where('reseller_pricing.note', 'dids.number', false);
1091
+	  $this->db->where('reseller_pricing.reseller_id', $accountinfo['reseller_id']);
1092 1092
 	  $this->db->from('dids,reseller_pricing');
1093
-		}else{
1094
-	  $this->db->where('parent_id',0);
1095
-	  $this->db->where('accountid',0);
1093
+		} else {
1094
+	  $this->db->where('parent_id', 0);
1095
+	  $this->db->where('accountid', 0);
1096 1096
 	  $this->db->select('id,number,setup,monthlycost');
1097 1097
 	  $this->db->from('dids');
1098 1098
 		}
1099
-		$dids_array=(array)$this->db->get()->result_array();
1100
-		$drp_list=array();
1101
-		if(!empty($dids_array)){
1099
+		$dids_array = (array)$this->db->get()->result_array();
1100
+		$drp_list = array();
1101
+		if ( ! empty($dids_array)) {
1102 1102
 	  foreach ($dids_array as $drp_value) {
1103
-		if (!empty($drp_value['monthlycost']) && $drp_value['monthlycost'] != 0) {
1104
-		  $did_cost = $this->common_model->to_calculate_currency($drp_value['monthlycost'],'','',true,true);
1103
+		if ( ! empty($drp_value['monthlycost']) && $drp_value['monthlycost'] != 0) {
1104
+		  $did_cost = $this->common_model->to_calculate_currency($drp_value['monthlycost'], '', '', true, true);
1105 1105
 		} else {
1106 1106
 		$did_cost = 0;
1107 1107
 		}
1108
-		if (!empty($drp_value['setup']) && $drp_value['setup'] != 0) {
1109
-		$did_setup = $this->common_model->to_calculate_currency($drp_value['setup'],'','',true,true);
1108
+		if ( ! empty($drp_value['setup']) && $drp_value['setup'] != 0) {
1109
+		$did_setup = $this->common_model->to_calculate_currency($drp_value['setup'], '', '', true, true);
1110 1110
 		} else {
1111 1111
 		$did_setup = 0;
1112 1112
 		}
1113
-		$drp_list[$drp_value['id']] = $drp_value['number'] . ' ( Setup : ' . $did_setup . ')' . '( Monthly : ' . $did_cost . ' )';
1113
+		$drp_list[$drp_value['id']] = $drp_value['number'].' ( Setup : '.$did_setup.')'.'( Monthly : '.$did_cost.' )';
1114 1114
 	  }
1115 1115
 		}
1116
-		$data['didlist'] = form_dropdown_all(array("name"=>"free_didlist","id"=>"free_didlist","class"=>"did_dropdown"), $drp_list, '');
1116
+		$data['didlist'] = form_dropdown_all(array("name"=>"free_didlist", "id"=>"free_didlist", "class"=>"did_dropdown"), $drp_list, '');
1117 1117
 		$this->load->view('view_user_did_list', $data);
1118 1118
 	}
1119 1119
 
@@ -1153,9 +1153,9 @@  discard block
 block discarded – undo
1153 1153
 		if ($this->input->post('advance_search', TRUE) == 1) {
1154 1154
 			$this->session->set_userdata('advance_search', $this->input->post('advance_search'));
1155 1155
 			$action = $this->input->post();
1156
-			$accountinfo=$this->session->userdata('accountinfo');
1157
-			if($accountinfo['reseller_id'] > 0 && $action['call_type'] > 0){
1158
-		  $action['dids.call_type']=$action['call_type'];
1156
+			$accountinfo = $this->session->userdata('accountinfo');
1157
+			if ($accountinfo['reseller_id'] > 0 && $action['call_type'] > 0) {
1158
+		  $action['dids.call_type'] = $action['call_type'];
1159 1159
 		  unset($action['call_type']);
1160 1160
 			}
1161 1161
 			unset($action['action']);
@@ -1163,7 +1163,7 @@  discard block
 block discarded – undo
1163 1163
 			$this->session->set_userdata('user_did_search', $action);
1164 1164
 		}
1165 1165
 		if (@$ajax_search != 1) {
1166
-			redirect(base_url() . 'user/user_didlist/');
1166
+			redirect(base_url().'user/user_didlist/');
1167 1167
 		}
1168 1168
 	}
1169 1169
 
@@ -1172,14 +1172,14 @@  discard block
 block discarded – undo
1172 1172
 		$this->session->set_userdata('user_did_search', "");
1173 1173
 	}
1174 1174
     
1175
-	function user_ipmap(){
1175
+	function user_ipmap() {
1176 1176
 		$this->session->set_userdata('advance_search', 0);
1177 1177
 		$data['grid_fields'] = $this->user_form->build_user_ipmap();
1178 1178
 		$data['form_search'] = $this->form->build_serach_form($this->user_form->build_user_ipmap_search());
1179 1179
 		$this->load->view('view_user_ipmap_list', $data);
1180 1180
 	}
1181 1181
     
1182
-	function user_ipmap_json(){
1182
+	function user_ipmap_json() {
1183 1183
 		$json_data = array();
1184 1184
 		$account_data = $this->session->userdata("accountinfo");
1185 1185
 		$count_all = $this->user_model->user_ipmap_list(false);
@@ -1191,7 +1191,7 @@  discard block
 block discarded – undo
1191 1191
 		echo json_encode($json_data);
1192 1192
 	}
1193 1193
 
1194
-	function user_ipmap_search(){
1194
+	function user_ipmap_search() {
1195 1195
 		$ajax_search = $this->input->post('ajax_search', 0);
1196 1196
 		if ($this->input->post('advance_search', TRUE) == 1) {
1197 1197
 			$this->session->set_userdata('advance_search', $this->input->post('advance_search'));
@@ -1201,24 +1201,24 @@  discard block
 block discarded – undo
1201 1201
 			$this->session->set_userdata('user_ipmap_search', $action);
1202 1202
 		}
1203 1203
 		if (@$ajax_search != 1) {
1204
-			redirect(base_url() . 'user/user_ipmap/');
1204
+			redirect(base_url().'user/user_ipmap/');
1205 1205
 		}
1206 1206
 	}
1207 1207
     
1208
-	function user_ipmap_clearsearchfilter(){
1208
+	function user_ipmap_clearsearchfilter() {
1209 1209
 		$this->session->set_userdata('advance_search', 0);
1210 1210
 		$this->session->set_userdata('user_ipmap_search', "");
1211 1211
 	}
1212 1212
     
1213
-	function user_ipmap_action($action='delete',$id=false){
1214
-		$add_array=$this->input->post();
1215
-		$accountinfo=$this->session->userdata('accountinfo');
1216
-		if($action == 'add'){
1213
+	function user_ipmap_action($action = 'delete', $id = false) {
1214
+		$add_array = $this->input->post();
1215
+		$accountinfo = $this->session->userdata('accountinfo');
1216
+		if ($action == 'add') {
1217 1217
 			  $ip = $add_array['ip'];
1218 1218
 			  if (strpos($ip, '/') !== false) {
1219 1219
 				 $add_array['ip'] = $add_array['ip'];
1220 1220
 			  } else {
1221
-				$add_array['ip'] = $add_array['ip'] . '/32';
1221
+				$add_array['ip'] = $add_array['ip'].'/32';
1222 1222
 			  }
1223 1223
 			  $where = array("ip" => trim($add_array['ip']), "prefix" => trim($add_array['prefix']));
1224 1224
 			  $getdata = $this->db_model->countQuery("*", "ip_map", $where);
@@ -1239,8 +1239,8 @@  discard block
 block discarded – undo
1239 1239
 				$this->session->set_flashdata('astpp_errormsg', 'IP Added Sucessfully.');
1240 1240
 			}
1241 1241
 			}
1242
-		if($action =='delete'){
1243
-			$this->db->delete('ip_map',array('id'=>$id));
1242
+		if ($action == 'delete') {
1243
+			$this->db->delete('ip_map', array('id'=>$id));
1244 1244
 			$this->session->set_flashdata('astpp_notification', 'IP Removed Sucessfully.');
1245 1245
 		}
1246 1246
 		redirect(base_url()."user/user_ipmap/");
@@ -1261,23 +1261,23 @@  discard block
 block discarded – undo
1261 1261
 		$paging_data = $this->form->load_grid_config($count_all, $_GET['rp'], $_GET['page']);
1262 1262
 		$json_data = $paging_data["json_paging"];
1263 1263
 		$devices_result = array();
1264
-		$query = $this->user_model->user_sipdevices_list(true,$account_data['id'], $paging_data["paging"]["start"], $paging_data["paging"]["page_no"]);
1264
+		$query = $this->user_model->user_sipdevices_list(true, $account_data['id'], $paging_data["paging"]["start"], $paging_data["paging"]["page_no"]);
1265 1265
 		foreach ($query as $key => $value) {
1266 1266
 	$path_true = base_url().'/assets/images/true.png';
1267 1267
 	$path_false = base_url().'/assets/images/false.png';
1268
-	$voicemail_enabled = $value['voicemail_enabled'] == 'true'? '<img src='.$path_true.' style="height:20px;width:20px;" title="Enable">' : '<img src='.$path_false.' style="height:20px;width:20px;" title="Disable">';
1268
+	$voicemail_enabled = $value['voicemail_enabled'] == 'true' ? '<img src='.$path_true.' style="height:20px;width:20px;" title="Enable">' : '<img src='.$path_false.' style="height:20px;width:20px;" title="Disable">';
1269 1269
 		$json_data['rows'][] = array('cell' => array(
1270
-			'<input type="checkbox" name="chkAll" id="'.$value['id'].'" class="ace chkRefNos" onclick="clickchkbox('.$value['id'].')" value=' .$value['id'].'><lable class="lbl"></lable>',
1270
+			'<input type="checkbox" name="chkAll" id="'.$value['id'].'" class="ace chkRefNos" onclick="clickchkbox('.$value['id'].')" value='.$value['id'].'><lable class="lbl"></lable>',
1271 1271
 					$value['username'],
1272 1272
 					$value['password'],
1273 1273
 					$value['effective_caller_id_name'],
1274 1274
 					$value['effective_caller_id_number'],
1275
-					$this->common->get_status('status', 'sip_devices',$value),
1276
-					$this->common->convert_GMT_to('','',$value['creation_date']),
1277
-					$this->common->convert_GMT_to('','',$value['last_modified_date']),
1275
+					$this->common->get_status('status', 'sip_devices', $value),
1276
+					$this->common->convert_GMT_to('', '', $value['creation_date']),
1277
+					$this->common->convert_GMT_to('', '', $value['last_modified_date']),
1278 1278
 					$voicemail_enabled,
1279
-					'<a href="'. base_url() .'user/user_sipdevices_edit/' . $value['id'] . '/" class="btn btn-royelblue btn-sm"  rel="facebox" title="Edit">&nbsp;<i class="fa fa-pencil-square-o fa-fw"></i></a>&nbsp;'.
1280
-					'<a href="'. base_url() .'user/user_sipdevices_delete/' .$value['id']. '/" class="btn btn-royelblue btn-sm" title="Delete" onClick="return get_alert_msg();">&nbsp;<i class="fa fa-trash fa-fw"></i></a>'
1279
+					'<a href="'.base_url().'user/user_sipdevices_edit/'.$value['id'].'/" class="btn btn-royelblue btn-sm"  rel="facebox" title="Edit">&nbsp;<i class="fa fa-pencil-square-o fa-fw"></i></a>&nbsp;'.
1280
+					'<a href="'.base_url().'user/user_sipdevices_delete/'.$value['id'].'/" class="btn btn-royelblue btn-sm" title="Delete" onClick="return get_alert_msg();">&nbsp;<i class="fa fa-trash fa-fw"></i></a>'
1281 1281
 					));
1282 1282
 		}
1283 1283
 		echo json_encode($json_data);
@@ -1292,7 +1292,7 @@  discard block
 block discarded – undo
1292 1292
 			$this->session->set_userdata('user_sipdevices_search', $action);
1293 1293
 		}
1294 1294
 		if (@$ajax_search != 1) {
1295
-			redirect(base_url() . 'user/user_sipdevices/');
1295
+			redirect(base_url().'user/user_sipdevices/');
1296 1296
 		}
1297 1297
 	}
1298 1298
     
@@ -1301,12 +1301,12 @@  discard block
 block discarded – undo
1301 1301
 		$this->session->set_userdata('user_sipdevices_search', "");
1302 1302
 	}
1303 1303
         
1304
-	function user_sipdevices_add(){
1304
+	function user_sipdevices_add() {
1305 1305
 		$data['page_title'] = 'Create SIP Device';
1306
-		$data['form'] = $this->form->build_form($this->user_form->build_user_sipdevices_form(),"");
1306
+		$data['form'] = $this->form->build_form($this->user_form->build_user_sipdevices_form(), "");
1307 1307
 		$this->load->view('view_user_sipdevices_add_edit', $data);
1308 1308
 	}
1309
-	function user_sipdevices_edit($edit_id=''){
1309
+	function user_sipdevices_edit($edit_id = '') {
1310 1310
 		$account_data = $this->session->userdata("accountinfo");
1311 1311
 		$data['page_title'] = 'Edit SIP Device';
1312 1312
 		$where = array('id' => $edit_id);
@@ -1314,7 +1314,7 @@  discard block
 block discarded – undo
1314 1314
 		$data['form'] = $this->form->build_form($this->user_form->build_user_sipdevices_form($edit_id), $sipdevice_info);
1315 1315
 		$this->load->view('view_user_sipdevices_add_edit', $data);
1316 1316
 	}
1317
-	function user_sipdevices_save(){
1317
+	function user_sipdevices_save() {
1318 1318
 		$add_array = $this->input->post();
1319 1319
 		$data['form'] = $this->form->build_form($this->user_form->build_user_sipdevices_form($add_array['id']), $add_array);
1320 1320
 		if ($add_array['id'] != '') {
@@ -1342,15 +1342,15 @@  discard block
 block discarded – undo
1342 1342
 		}
1343 1343
 	}
1344 1344
 	function user_sipdevices_delete($id) {
1345
-		$this->db->delete('sip_devices',array('id'=>$id));
1345
+		$this->db->delete('sip_devices', array('id'=>$id));
1346 1346
 		$this->session->set_flashdata('astpp_notification', 'SIP Device Removed Sucessfully!');
1347
-		redirect(base_url() . "user/user_sipdevices/");
1347
+		redirect(base_url()."user/user_sipdevices/");
1348 1348
 	}
1349 1349
     
1350
-	function user_sipdevices_delete_multiple(){
1350
+	function user_sipdevices_delete_multiple() {
1351 1351
 		$ids = $this->input->post("selected_ids", true);
1352 1352
 		$where = "id IN ($ids)";
1353
-		$this->db->delete("sip_devices",$where);
1353
+		$this->db->delete("sip_devices", $where);
1354 1354
 		echo TRUE;    
1355 1355
 	}
1356 1356
     
@@ -1383,7 +1383,7 @@  discard block
 block discarded – undo
1383 1383
 			$cnt_result = $cnt_result->result_array();
1384 1384
 			$count = $cnt_result[0]['count'];
1385 1385
 			if ($count == 0) {
1386
-				if($add_array['number'] != ""){
1386
+				if ($add_array['number'] != "") {
1387 1387
 				$accountinfo = $this->session->userdata("accountinfo");
1388 1388
 				$insert_arr = array("number" => $add_array['number'],
1389 1389
 									"accountid" => $accountinfo['id'],
@@ -1391,7 +1391,7 @@  discard block
 block discarded – undo
1391 1391
 									);
1392 1392
 				$this->db->insert("ani_map", $insert_arr);
1393 1393
 				$this->session->set_flashdata('astpp_errormsg', 'Add Caller ID Sucessfully!');
1394
-				}else{
1394
+				} else {
1395 1395
 					 $this->session->set_flashdata('astpp_notification', 'Please Enter Caller ID value.');
1396 1396
 				}
1397 1397
 			} else {
@@ -1403,28 +1403,28 @@  discard block
 block discarded – undo
1403 1403
 			$this->db_model->delete("ani_map", array("id" => $aniid));
1404 1404
             
1405 1405
 		}
1406
-		redirect(base_url() . "user/user_animap_list/");
1406
+		redirect(base_url()."user/user_animap_list/");
1407 1407
 	}
1408 1408
     
1409 1409
 	function user_alert_threshold() {
1410 1410
 		$data['page_title'] = 'Alert Threshold';
1411 1411
 		$accountinfo = $this->session->userdata("accountinfo");
1412 1412
 		$add_array = $this->input->post();
1413
-		if (!empty($add_array)) {
1414
-			unset($add_array['action'],$add_array['id']);
1413
+		if ( ! empty($add_array)) {
1414
+			unset($add_array['action'], $add_array['id']);
1415 1415
 			$this->user_model->edit_alert_threshold($add_array, $accountinfo['id']);
1416 1416
 			$this->session->set_flashdata('astpp_errormsg', 'Alert Threshold updated successfully!');
1417
-			redirect(base_url() . 'user/user_alert_threshold/');
1417
+			redirect(base_url().'user/user_alert_threshold/');
1418 1418
 		} else {
1419 1419
 			$where = array('id' => $accountinfo["id"]);
1420 1420
 			$account = $this->db_model->getSelect("notify_credit_limit,notify_flag,notify_email", "accounts", $where);
1421
-			$data['form'] = $this->form->build_form($this->user_form->user_alert_threshold(),(array)$account->first_row());
1421
+			$data['form'] = $this->form->build_form($this->user_form->user_alert_threshold(), (array)$account->first_row());
1422 1422
 			$this->load->view('view_user_alert_threshold', $data);
1423 1423
 		}
1424 1424
 	}
1425 1425
     
1426 1426
 	function user_cdrs_report() {
1427
-		$accountinfo=$this->session->userdata('accountinfo');
1427
+		$accountinfo = $this->session->userdata('accountinfo');
1428 1428
 		$data['page_title'] = 'CDRs';
1429 1429
 		$data['search_flag'] = true;
1430 1430
 		$data["grid_buttons"] = $this->user_form->build_cdrs_report_buttons();
@@ -1434,10 +1434,10 @@  discard block
 block discarded – undo
1434 1434
 	}
1435 1435
 
1436 1436
 	function user_cdrs_report_json() {
1437
-		$accountinfo=$this->session->userdata('accountinfo');
1438
-		$variable=$accountinfo['type'] != 3 ?'total_debit':'total_cost';
1437
+		$accountinfo = $this->session->userdata('accountinfo');
1438
+		$variable = $accountinfo['type'] != 3 ? 'total_debit' : 'total_cost';
1439 1439
 		$count_res = $this->user_model->getuser_cdrs_list(false, "", "");
1440
-		$count_all = (array) $count_res->first_row();
1440
+		$count_all = (array)$count_res->first_row();
1441 1441
 		$paging_data = $this->form->load_grid_config($count_all['count'], $_GET['rp'], $_GET['page']);
1442 1442
 		$json_data = $paging_data["json_paging"];
1443 1443
 		$query = $this->user_model->getuser_cdrs_list(true, $paging_data["paging"]["start"], $paging_data["paging"]["page_no"], false);
@@ -1445,16 +1445,16 @@  discard block
 block discarded – undo
1445 1445
 		$json_data['rows'] = $this->form->build_grid($query, $grid_fields);
1446 1446
 		if ($count_all['count'] > 0) {
1447 1447
 			$search_arr = $this->session->userdata('user_cdrs_report_search');
1448
-			$show_seconds = (!empty($search_arr['search_in'])) ? $search_arr['search_in'] : 'minutes';
1449
-			$duration = ($show_seconds == 'minutes') ? ($count_all['billseconds'] > 0 ) ?
1450
-			floor($count_all['billseconds'] / 60) . ":" . sprintf("%02d", $count_all['billseconds'] % 60) : "00:00"  : $count_all['billseconds'];
1448
+			$show_seconds = ( ! empty($search_arr['search_in'])) ? $search_arr['search_in'] : 'minutes';
1449
+			$duration = ($show_seconds == 'minutes') ? ($count_all['billseconds'] > 0) ?
1450
+			floor($count_all['billseconds'] / 60).":".sprintf("%02d", $count_all['billseconds'] % 60) : "00:00" : $count_all['billseconds'];
1451 1451
 			$json_data['rows'][] = array("cell" => array(
1452 1452
 					"<b>Grand Total</b>",
1453 1453
 					"",
1454 1454
 					"",
1455 1455
 					"",
1456 1456
 					$duration,
1457
-					"<b>".$this->common_model->calculate_currency($count_all[$variable],"","",true,false)."</b>",
1457
+					"<b>".$this->common_model->calculate_currency($count_all[$variable], "", "", true, false)."</b>",
1458 1458
 					"",
1459 1459
 					"",
1460 1460
 					));
@@ -1475,7 +1475,7 @@  discard block
 block discarded – undo
1475 1475
 			$this->session->set_userdata('user_cdrs_report_search', $action);
1476 1476
 		}
1477 1477
 		if (@$ajax_search != 1) {
1478
-			redirect(base_url() . 'user/user_cdrs_report/');
1478
+			redirect(base_url().'user/user_cdrs_report/');
1479 1479
 		}
1480 1480
 	}
1481 1481
 
@@ -1486,20 +1486,20 @@  discard block
 block discarded – undo
1486 1486
 
1487 1487
 	function user_cdrreport_export() {
1488 1488
 		$account_info = $accountinfo = $this->session->userdata('accountinfo');
1489
-		$currency_id=$account_info['currency_id'];
1490
-		$currency=$this->common->get_field_name('currency', 'currency', $currency_id);
1489
+		$currency_id = $account_info['currency_id'];
1490
+		$currency = $this->common->get_field_name('currency', 'currency', $currency_id);
1491 1491
 		$count_res = $this->user_model->getuser_cdrs_list(false, "", "");
1492
-		$count_all = (array) $count_res->first_row();
1492
+		$count_all = (array)$count_res->first_row();
1493 1493
 		ob_clean();
1494
-		$customer_array[] = array("Date", "CallerID", "Called Number","Code", "Destination", "Duration", "Debit($currency)", "Disposition", "Call Type");
1494
+		$customer_array[] = array("Date", "CallerID", "Called Number", "Code", "Destination", "Duration", "Debit($currency)", "Disposition", "Call Type");
1495 1495
 		if ($count_all['count'] > 0) {
1496 1496
 			$query = $this->user_model->getuser_cdrs_list(true, '', '', true);
1497 1497
 			$currency_info = $this->common->get_currency_info();
1498 1498
 			$search_arr = $this->session->userdata('user_cdrs_report_search');
1499
-			$show_seconds = (!empty($search_arr['search_in'])) ? $search_arr['search_in'] : 'minutes';
1499
+			$show_seconds = ( ! empty($search_arr['search_in'])) ? $search_arr['search_in'] : 'minutes';
1500 1500
 			foreach ($query->result_array() as $value) {
1501
-				$duration = ($show_seconds == 'minutes') ? ($value['billseconds'] > 0 ) ?
1502
-								floor($value['billseconds'] / 60) . ":" . sprintf("%02d", $value['billseconds'] % 60) : "00:00"  : $value['billseconds'];
1501
+				$duration = ($show_seconds == 'minutes') ? ($value['billseconds'] > 0) ?
1502
+								floor($value['billseconds'] / 60).":".sprintf("%02d", $value['billseconds'] % 60) : "00:00" : $value['billseconds'];
1503 1503
 				$customer_array[] = array(
1504 1504
 					$this->common->convert_GMT_to('', '', $value['callstart']),
1505 1505
 					$value['callerid'],
@@ -1507,13 +1507,13 @@  discard block
 block discarded – undo
1507 1507
 					filter_var($value['pattern'], FILTER_SANITIZE_NUMBER_INT),
1508 1508
 					$value['notes'],
1509 1509
 					$duration,
1510
-					$this->common->calculate_currency_manually($currency_info, $value['debit'],false),
1510
+					$this->common->calculate_currency_manually($currency_info, $value['debit'], false),
1511 1511
 					$value['disposition'],
1512 1512
 					$value['calltype']
1513 1513
 				);
1514 1514
 			}
1515
-			$duration = ($show_seconds == 'minutes') ? ($count_all['billseconds'] > 0 ) ?
1516
-							floor($count_all['billseconds'] / 60) . ":" . sprintf("%02d", $count_all['billseconds'] % 60) : "00:00"  : $count_all['billseconds'];
1515
+			$duration = ($show_seconds == 'minutes') ? ($count_all['billseconds'] > 0) ?
1516
+							floor($count_all['billseconds'] / 60).":".sprintf("%02d", $count_all['billseconds'] % 60) : "00:00" : $count_all['billseconds'];
1517 1517
 			$customer_array[] = array("Grand Total",
1518 1518
 				"",
1519 1519
 				"",
@@ -1526,26 +1526,26 @@  discard block
 block discarded – undo
1526 1526
 			);
1527 1527
 		}
1528 1528
 		$this->load->helper('csv');
1529
-		array_to_csv($customer_array, 'Customer_CDR_' . date("Y-m-d") . '.csv');
1529
+		array_to_csv($customer_array, 'Customer_CDR_'.date("Y-m-d").'.csv');
1530 1530
 	}
1531
-	function user_payment($action=""){
1532
-	  if(common_model::$global_config['system_config']['paypal_status'] == 1){
1533
-		redirect(base_url() . 'user/user/');  
1531
+	function user_payment($action = "") {
1532
+	  if (common_model::$global_config['system_config']['paypal_status'] == 1) {
1533
+		redirect(base_url().'user/user/');  
1534 1534
 	  }
1535 1535
 		$this->load->module("user/payment");
1536
-		if($action=="GET_AMT"){
1537
-			$amount = $this->input->post("value",true);
1536
+		if ($action == "GET_AMT") {
1537
+			$amount = $this->input->post("value", true);
1538 1538
 			$this->payment->convert_amount($amount);
1539
-		}else{
1539
+		} else {
1540 1540
 			$this->payment->index();
1541 1541
 		}
1542 1542
 	}
1543 1543
     
1544
-	function user_fund_transfer(){
1544
+	function user_fund_transfer() {
1545 1545
 		$data['page_title'] = 'Fund Transfer';
1546 1546
 		$accountinfo = $this->session->userdata('accountinfo');
1547
-		$account=(array)$this->db->get_where('accounts',array("id"=>$accountinfo['id']))->first_row();
1548
-		$currency = (array)$this->db->get_where('currency',array("id"=>$account['currency_id']))->first_row();
1547
+		$account = (array)$this->db->get_where('accounts', array("id"=>$accountinfo['id']))->first_row();
1548
+		$currency = (array)$this->db->get_where('currency', array("id"=>$account['currency_id']))->first_row();
1549 1549
 		$data['form'] = $this->form->build_form($this->user_form->build_user_fund_transfer_form($account['number'], $currency['currency'], $accountinfo['id']), '');
1550 1550
 		$this->load->view('view_user_fund_transfer', $data);
1551 1551
 	}
@@ -1554,8 +1554,8 @@  discard block
 block discarded – undo
1554 1554
 		$data['page_title'] = 'Fund Transfer';
1555 1555
 		$post_array = $this->input->post();
1556 1556
 		$accountinfo = $this->session->userdata('accountinfo');
1557
-		$account=(array)$this->db->get_where('accounts',array("id"=>$accountinfo['id']))->first_row();
1558
-		$currency = (array)$this->db->get_where('currency',array("id"=>$account['currency_id']))->first_row();
1557
+		$account = (array)$this->db->get_where('accounts', array("id"=>$accountinfo['id']))->first_row();
1558
+		$currency = (array)$this->db->get_where('currency', array("id"=>$account['currency_id']))->first_row();
1559 1559
 		$data['form'] = $this->form->build_form($this->user_form->build_user_fund_transfer_form($account['number'], $currency['currency'], $accountinfo['id']), $post_array);
1560 1560
 		if ($this->form_validation->run() == FALSE) {
1561 1561
 			$data['validation_errors'] = validation_errors();
@@ -1564,11 +1564,11 @@  discard block
 block discarded – undo
1564 1564
 				$account_info = $this->session->userdata('accountinfo');
1565 1565
 				$balance = $this->common->get_field_name('balance', 'accounts', array('id' => $account_info['id'], 'status' => 0, 'type' => 0, 'deleted' => 0));                
1566 1566
 				$toid = $this->common->get_field_name('id', 'accounts', array('number' => $post_array['toaccountid'], 'status' => 0, 'type' => 0, 'deleted' => 0));
1567
-				$toaccountinfo=(array)$this->db->get_where('accounts',array('number' => $post_array['toaccountid'], 'status' => 0, 'type' => 0, 'deleted' => 0),1)->first_row();
1568
-				if($toaccountinfo){
1567
+				$toaccountinfo = (array)$this->db->get_where('accounts', array('number' => $post_array['toaccountid'], 'status' => 0, 'type' => 0, 'deleted' => 0), 1)->first_row();
1568
+				if ($toaccountinfo) {
1569 1569
 				$reseller_id = $toaccountinfo['reseller_id'];
1570 1570
 				$post_array['credit'] = $this->common_model->add_calculate_currency($post_array['credit'], '', '', false, false);
1571
-				$minimum_fund=(array)$this->db->get_where('system',array("name"=>"minimum_fund_transfer"),1)->first_row();
1571
+				$minimum_fund = (array)$this->db->get_where('system', array("name"=>"minimum_fund_transfer"), 1)->first_row();
1572 1572
 				if ($post_array['toaccountid'] == $account_info['number']) {
1573 1573
 					$this->session->set_flashdata('astpp_notification', 'You can not transfer fund in same account.');
1574 1574
 				}
@@ -1584,21 +1584,21 @@  discard block
 block discarded – undo
1584 1584
 				elseif ($post_array['credit'] > $balance) {
1585 1585
 					$this->session->set_flashdata('astpp_notification', 'You have insufficient balance.');
1586 1586
 				}
1587
-				elseif ($toid <= 0 || !isset($post_array['toaccountid'])) {
1587
+				elseif ($toid <= 0 || ! isset($post_array['toaccountid'])) {
1588 1588
 					$this->session->set_flashdata('astpp_notification', 'Please enter valid account number.');
1589 1589
 				}
1590 1590
 				elseif ($post_array['credit'] < 0) {
1591 1591
 					$this->session->set_flashdata('astpp_notification', 'Please enter amount greater then 0.');
1592 1592
 				}
1593 1593
 				elseif ($minimum_fund['value'] >= $post_array['credit']) {
1594
-					$this->session->set_flashdata('astpp_notification', 'You need to enter minimum amount of fund transfer ' . $minimum_fund['value'] . ' .');
1594
+					$this->session->set_flashdata('astpp_notification', 'You need to enter minimum amount of fund transfer '.$minimum_fund['value'].' .');
1595 1595
 				}
1596
-				elseif (!isset($toid) || !isset($post_array['toaccountid'])) {
1596
+				elseif ( ! isset($toid) || ! isset($post_array['toaccountid'])) {
1597 1597
 					$this->session->set_flashdata('astpp_notification', 'Please enter valid account number!');
1598 1598
 				}
1599 1599
 				elseif ($post_array['credit'] < 0 || $post_array['credit'] > $balance) {
1600 1600
 					$this->session->set_flashdata('astpp_notification', 'Insuffiecient amount !');
1601
-				}else{
1601
+				} else {
1602 1602
 					$from['id'] = $post_array['id'];
1603 1603
 					$from['account_currency'] = $post_array['account_currency'];
1604 1604
 					$from['accountid'] = $post_array['fromaccountid'];
@@ -1633,13 +1633,13 @@  discard block
 block discarded – undo
1633 1633
 						$this->session->set_flashdata('astpp_notification', 'Sorry We are not able to process this request.');
1634 1634
 					}
1635 1635
 				}
1636
-			}else{
1636
+			} else {
1637 1637
 		$this->session->set_flashdata('astpp_notification', 'Account number not found.');
1638 1638
 			}
1639 1639
 			} else {
1640 1640
 				$this->session->set_flashdata('astpp_notification', 'You can not transfer fund in same account.');
1641 1641
 			}
1642
-			redirect(base_url() . 'user/user_fund_transfer/');
1642
+			redirect(base_url().'user/user_fund_transfer/');
1643 1643
 		}
1644 1644
 		$this->load->view('view_user_fund_transfer', $data);
1645 1645
 	}
@@ -1657,7 +1657,7 @@  discard block
 block discarded – undo
1657 1657
 		$accountinfo = $this->session->userdata("accountinfo");
1658 1658
 		$json_data = array();
1659 1659
 		$count_all = $this->user_model->get_user_opensips(false, $accountinfo['number']);
1660
-		$paging_data = $this->form->load_grid_config($count_all,$_GET['rp'],$_GET['page']);
1660
+		$paging_data = $this->form->load_grid_config($count_all, $_GET['rp'], $_GET['page']);
1661 1661
 		$json_data = $paging_data["json_paging"];
1662 1662
 		$query = $this->user_model->get_user_opensips(true, $accountinfo['number'], $paging_data["paging"]["start"], $paging_data["paging"]["page_no"]);
1663 1663
 		$grid_fields = json_decode($this->user_form->build_user_opensips());
@@ -1681,7 +1681,7 @@  discard block
 block discarded – undo
1681 1681
 			$this->session->set_userdata('user_opensips_search', $action);
1682 1682
 		}
1683 1683
 		if ($ajax_search != 1) {
1684
-			redirect(base_url() . 'user/user_opensips/');
1684
+			redirect(base_url().'user/user_opensips/');
1685 1685
 		}
1686 1686
 	}
1687 1687
 
@@ -1694,10 +1694,10 @@  discard block
 block discarded – undo
1694 1694
 		$this->load->view('view_opensips_add_edit', $data);
1695 1695
 	}
1696 1696
     
1697
-	function user_opensips_edit($edit_id){
1697
+	function user_opensips_edit($edit_id) {
1698 1698
 	$data['page_title'] = 'Edit Opensips';
1699 1699
 		$db_config = Common_model::$global_config['system_config'];
1700
-		$opensipdsn = "mysql://" . $db_config['opensips_dbuser'] . ":" . $db_config['opensips_dbpass'] . "@" . $db_config['opensips_dbhost'] . "/" . $db_config['opensips_dbname'] . "?char_set=utf8&dbcollat=utf8_general_ci&cache_on=true&cachedir=";
1700
+		$opensipdsn = "mysql://".$db_config['opensips_dbuser'].":".$db_config['opensips_dbpass']."@".$db_config['opensips_dbhost']."/".$db_config['opensips_dbname']."?char_set=utf8&dbcollat=utf8_general_ci&cache_on=true&cachedir=";
1701 1701
 		$this->opensips_db = $this->load->database($opensipdsn, true);
1702 1702
 		$where = array('id' => $edit_id);
1703 1703
 		$this->opensips_db->where($where);
@@ -1710,7 +1710,7 @@  discard block
 block discarded – undo
1710 1710
     
1711 1711
 	}
1712 1712
     
1713
-	function user_opensips_save(){
1713
+	function user_opensips_save() {
1714 1714
 	$add_array = $this->input->post();
1715 1715
 		$data['form'] = $this->form->build_form($this->user_form->build_user_opensips_form(), $add_array);
1716 1716
 		if ($add_array['id'] != '') {
@@ -1721,11 +1721,11 @@  discard block
 block discarded – undo
1721 1721
 				exit;
1722 1722
 			} else {
1723 1723
 				$auth_flag = $this->validate_device_data($add_array);
1724
-				if($auth_flag == "TRUE"){
1724
+				if ($auth_flag == "TRUE") {
1725 1725
 						$this->user_model->user_opensips_edit($add_array, $add_array['id']);
1726 1726
 						echo json_encode(array("SUCCESS"=> " OpenSips updated successfully!"));
1727 1727
 						exit;
1728
-				}else{
1728
+				} else {
1729 1729
 					   echo json_encode($auth_flag);
1730 1730
 					   exit;
1731 1731
 				}
@@ -1738,48 +1738,48 @@  discard block
 block discarded – undo
1738 1738
 				exit;
1739 1739
 			} else {
1740 1740
 				$auth_flag = $this->validate_device_data($add_array);
1741
-				if($auth_flag == "TRUE"){
1741
+				if ($auth_flag == "TRUE") {
1742 1742
 						$this->user_model->user_opensips_add($add_array);
1743 1743
 						echo json_encode(array("SUCCESS"=> "OpenSips added successfully!"));
1744 1744
 						exit;
1745
-				}else{
1745
+				} else {
1746 1746
 					   echo json_encode($auth_flag);
1747 1747
 						exit;
1748 1748
 				}
1749 1749
 			}
1750 1750
 		}
1751 1751
 	}
1752
-	function validate_device_data($data){
1753
-		if(isset($data["username"]) && $data["username"] != ""){
1752
+	function validate_device_data($data) {
1753
+		if (isset($data["username"]) && $data["username"] != "") {
1754 1754
 				$db_config = Common_model::$global_config['system_config'];
1755
-				$opensipdsn = "mysql://" . $db_config['opensips_dbuser'] . ":" . $db_config['opensips_dbpass'] . "@" . $db_config['opensips_dbhost'] . "/" . $db_config['opensips_dbname'] . "?char_set=utf8&dbcollat=utf8_general_ci&cache_on=true&cachedir=";
1755
+				$opensipdsn = "mysql://".$db_config['opensips_dbuser'].":".$db_config['opensips_dbpass']."@".$db_config['opensips_dbhost']."/".$db_config['opensips_dbname']."?char_set=utf8&dbcollat=utf8_general_ci&cache_on=true&cachedir=";
1756 1756
 				$this->opensips_db = $this->load->database($opensipdsn, true);
1757 1757
 				$where = array("username"=>$data["username"]);
1758
-				if($data['id'] != ""){
1759
-					$this->opensips_db->where("id <>",$data['id']);
1758
+				if ($data['id'] != "") {
1759
+					$this->opensips_db->where("id <>", $data['id']);
1760 1760
 				}
1761 1761
 				$this->opensips_db->where($where);
1762 1762
 				$auth_flag = $this->opensips_db->get("subscriber");
1763 1763
 				$auth_flag = $auth_flag->num_rows();
1764
-				if($auth_flag == 0){
1764
+				if ($auth_flag == 0) {
1765 1765
 					return "TRUE";
1766
-				}else{
1766
+				} else {
1767 1767
 					return array("username_error"=>"Duplicate Username Found.Username Must be Unique");
1768 1768
 				}
1769
-		}else{
1769
+		} else {
1770 1770
 		  return array("username_error"=>"User name is required field.");
1771 1771
 		}
1772 1772
 		return "0";
1773 1773
 	}
1774 1774
     
1775
-	function user_opensips_delete($id){
1775
+	function user_opensips_delete($id) {
1776 1776
 	  $this->user_model->user_opensips_delete($id);
1777 1777
 	  $this->session->set_flashdata('astpp_errormsg', 'Opensips Device Removed Successfully!.');
1778
-	  redirect(base_url() . "user/user_opensips/");
1778
+	  redirect(base_url()."user/user_opensips/");
1779 1779
 	}
1780
-	function user_opensips_delete_multiple(){
1780
+	function user_opensips_delete_multiple() {
1781 1781
 	  $db_config = Common_model::$global_config['system_config'];
1782
-	  $opensipdsn = "mysql://" . $db_config['opensips_dbuser'] . ":" . $db_config['opensips_dbpass'] . "@" . $db_config['opensips_dbhost'] . "/" . $db_config['opensips_dbname'] . "?char_set=utf8&dbcollat=utf8_general_ci&cache_on=true&cachedir=";
1782
+	  $opensipdsn = "mysql://".$db_config['opensips_dbuser'].":".$db_config['opensips_dbpass']."@".$db_config['opensips_dbhost']."/".$db_config['opensips_dbname']."?char_set=utf8&dbcollat=utf8_general_ci&cache_on=true&cachedir=";
1783 1783
 	  $this->opensips_db = $this->load->database($opensipdsn, true);
1784 1784
 	  $ids = $this->input->post("selected_ids", true);
1785 1785
 	  $where = "id IN ($ids)";
@@ -1788,27 +1788,27 @@  discard block
 block discarded – undo
1788 1788
 	  echo TRUE;
1789 1789
 	}
1790 1790
     
1791
-	function user_cdrs(){
1791
+	function user_cdrs() {
1792 1792
 	  $data['username'] = $this->session->userdata('user_name');
1793
-	  $accountinfo=$this->session->userdata('accountinfo');
1793
+	  $accountinfo = $this->session->userdata('accountinfo');
1794 1794
 	  $data['page_title'] = 'CDRs';
1795 1795
 	  $accounttype = strtolower($this->common->get_entity_type('', '', $accountinfo['type']));
1796 1796
 	  $this->load->module('reports/reports');
1797 1797
 	  $data['grid_fields'] = $this->reports->reports_form->build_report_list_for_user($accounttype);
1798 1798
 	  $data['form_search'] = $this->form->build_serach_form($this->user_form->build_user_opensips_search());
1799
-	  $data['accounttype']=$accounttype;
1799
+	  $data['accounttype'] = $accounttype;
1800 1800
 	  $this->load->view('view_user_cdrs', $data);    
1801 1801
 	}
1802
-	function user_cdrs_json(){
1803
-	  $accountinfo=$this->session->userdata('accountinfo');
1802
+	function user_cdrs_json() {
1803
+	  $accountinfo = $this->session->userdata('accountinfo');
1804 1804
 	  $accounttype = strtolower($this->common->get_entity_type('', '', $accountinfo['type']));
1805 1805
 	  $this->load->module('reports/reports');
1806 1806
 	  $this->reports->customer_cdrreport($accountinfo['id'], $accounttype);     
1807 1807
 	}
1808
-	function user_details_search($module_name){
1808
+	function user_details_search($module_name) {
1809 1809
 		$action = $this->input->post();
1810
-		$this->session->set_userdata('left_panel_search_'.$module_name,"");
1811
-		if(!empty($action['left_panel_search'])){
1810
+		$this->session->set_userdata('left_panel_search_'.$module_name, "");
1811
+		if ( ! empty($action['left_panel_search'])) {
1812 1812
 			$this->session->set_userdata('left_panel_search_'.$module_name, $action['left_panel_search']);
1813 1813
 	}
1814 1814
 	}
@@ -1820,7 +1820,7 @@  discard block
 block discarded – undo
1820 1820
     
1821 1821
     
1822 1822
 	function user_provider_cdrs_report() {
1823
-		$accountinfo=$this->session->userdata('accountinfo');
1823
+		$accountinfo = $this->session->userdata('accountinfo');
1824 1824
 		$data['page_title'] = 'Provider CDRs Report';
1825 1825
 		$data['search_flag'] = true;
1826 1826
 		$data["grid_buttons"] = $this->user_form->build_provider_report_buttons();
@@ -1830,10 +1830,10 @@  discard block
 block discarded – undo
1830 1830
 	}
1831 1831
 
1832 1832
 	function user_provider_cdrs_report_json() {
1833
-		$accountinfo=$this->session->userdata('accountinfo');
1834
-		$variable=$accountinfo['type'] != 3 ?'total_debit':'total_cost';
1833
+		$accountinfo = $this->session->userdata('accountinfo');
1834
+		$variable = $accountinfo['type'] != 3 ? 'total_debit' : 'total_cost';
1835 1835
 		$count_res = $this->user_model->getprovider_cdrs_list(false, "", "");
1836
-		$count_all = (array) $count_res->first_row();
1836
+		$count_all = (array)$count_res->first_row();
1837 1837
 		$paging_data = $this->form->load_grid_config($count_all['count'], $_GET['rp'], $_GET['page']);
1838 1838
 		$json_data = $paging_data["json_paging"];
1839 1839
 		$query = $this->user_model->getprovider_cdrs_list(true, $paging_data["paging"]["start"], $paging_data["paging"]["page_no"], false);
@@ -1841,16 +1841,16 @@  discard block
 block discarded – undo
1841 1841
 		$json_data['rows'] = $this->form->build_grid($query, $grid_fields);
1842 1842
 		if ($count_all['count'] > 0) {
1843 1843
 			$search_arr = $this->session->userdata('user_provider_cdrs_report_search');
1844
-			$show_seconds = (!empty($search_arr['search_in'])) ? $search_arr['search_in'] : 'minutes';
1845
-			$duration = ($show_seconds == 'minutes') ? ($count_all['billseconds'] > 0 ) ?
1846
-			floor($count_all['billseconds'] / 60) . ":" . sprintf("%02d", $count_all['billseconds'] % 60) : "00:00"  : $count_all['billseconds'];
1844
+			$show_seconds = ( ! empty($search_arr['search_in'])) ? $search_arr['search_in'] : 'minutes';
1845
+			$duration = ($show_seconds == 'minutes') ? ($count_all['billseconds'] > 0) ?
1846
+			floor($count_all['billseconds'] / 60).":".sprintf("%02d", $count_all['billseconds'] % 60) : "00:00" : $count_all['billseconds'];
1847 1847
 			$json_data['rows'][] = array("cell" => array(
1848 1848
 					"<b>Grand Total</b>",
1849 1849
 					"",
1850 1850
 					"",
1851 1851
 					"",
1852 1852
 					$duration,
1853
-					"<b>".$this->common_model->calculate_currency($count_all[$variable],"","",true,false)."</b>",
1853
+					"<b>".$this->common_model->calculate_currency($count_all[$variable], "", "", true, false)."</b>",
1854 1854
 					"",
1855 1855
 					"",
1856 1856
 					));
@@ -1871,7 +1871,7 @@  discard block
 block discarded – undo
1871 1871
 			$this->session->set_userdata('user_provider_cdrs_report_search', $action);
1872 1872
 		}
1873 1873
 		if ($ajax_search != 1) {
1874
-			redirect(base_url() . 'user/user_provider_cdrs_report/');
1874
+			redirect(base_url().'user/user_provider_cdrs_report/');
1875 1875
 		}
1876 1876
 	}
1877 1877
 
@@ -1882,53 +1882,53 @@  discard block
 block discarded – undo
1882 1882
 
1883 1883
 	function user_provider_cdrreport_export() {
1884 1884
 	$account_info = $accountinfo = $this->session->userdata('accountinfo');
1885
-	$currency_id=$account_info['currency_id'];
1886
-	$currency=$this->common->get_field_name('currency', 'currency', $currency_id);
1885
+	$currency_id = $account_info['currency_id'];
1886
+	$currency = $this->common->get_field_name('currency', 'currency', $currency_id);
1887 1887
 		$count_res = $this->user_model->getprovider_cdrs_list(false, "", "");
1888
-		$count_all = (array) $count_res->first_row();
1888
+		$count_all = (array)$count_res->first_row();
1889 1889
 		ob_clean();
1890 1890
 		$customer_array[] = array("Date", "CallerID", "Called Number", "Destination", "Duration", "Cost($currency)", "Disposition", "Call Type");
1891 1891
 		if ($count_all['count'] > 0) {
1892 1892
 			$query = $this->user_model->getuser_cdrs_list(true, '', '', true);
1893 1893
 			$currency_info = $this->common->get_currency_info();
1894 1894
 			$search_arr = $this->session->userdata('user_provider_cdrs_report_search');
1895
-			$show_seconds = (!empty($search_arr['search_in'])) ? $search_arr['search_in'] : 'minutes';
1895
+			$show_seconds = ( ! empty($search_arr['search_in'])) ? $search_arr['search_in'] : 'minutes';
1896 1896
 			foreach ($query->result_array() as $value) {
1897
-				$duration = ($show_seconds == 'minutes') ? ($value['billseconds'] > 0 ) ?
1898
-				floor($value['billseconds'] / 60) . ":" . sprintf("%02d", $value['billseconds'] % 60) : "00:00"  : $value['billseconds'];
1897
+				$duration = ($show_seconds == 'minutes') ? ($value['billseconds'] > 0) ?
1898
+				floor($value['billseconds'] / 60).":".sprintf("%02d", $value['billseconds'] % 60) : "00:00" : $value['billseconds'];
1899 1899
 				$customer_array[] = array(
1900 1900
 					$this->common->convert_GMT_to('', '', $value['callstart']),
1901 1901
 					$value['callerid'],
1902 1902
 					$value['callednum'],
1903 1903
 					filter_var($value['pattern'], FILTER_SANITIZE_NUMBER_INT),
1904 1904
 					$duration,
1905
-					$this->common->calculate_currency_manually($currency_info, $value['cost'],false),
1905
+					$this->common->calculate_currency_manually($currency_info, $value['cost'], false),
1906 1906
 					$value['disposition'],
1907 1907
 					$value['calltype']
1908 1908
 				);
1909 1909
 			}
1910
-			$duration = ($show_seconds == 'minutes') ? ($count_all['billseconds'] > 0 ) ?
1911
-			floor($count_all['billseconds'] / 60) . ":" . sprintf("%02d", $count_all['billseconds'] % 60) : "00:00"  : $count_all['billseconds'];
1910
+			$duration = ($show_seconds == 'minutes') ? ($count_all['billseconds'] > 0) ?
1911
+			floor($count_all['billseconds'] / 60).":".sprintf("%02d", $count_all['billseconds'] % 60) : "00:00" : $count_all['billseconds'];
1912 1912
 			$customer_array[] = array("Grand Total",
1913 1913
 				"",
1914 1914
 				"",
1915 1915
 				"",
1916 1916
 				$duration,
1917
-				$this->common->calculate_currency_manually($currency_info, $count_all['total_cost'],false,true),
1917
+				$this->common->calculate_currency_manually($currency_info, $count_all['total_cost'], false, true),
1918 1918
 				"",
1919 1919
 				""
1920 1920
 			);
1921 1921
 		}
1922 1922
 		$this->load->helper('csv');
1923
-		array_to_csv($customer_array, 'Provider_CDR_' . date("Y-m-d") . '.csv');
1923
+		array_to_csv($customer_array, 'Provider_CDR_'.date("Y-m-d").'.csv');
1924 1924
 	}
1925
-	function user_speeddial(){
1925
+	function user_speeddial() {
1926 1926
 		$data['page_title'] = "Speed Dial";
1927 1927
 		$accountinfo = $this->session->userdata('accountinfo');
1928 1928
 		$where = array('id' => $accountinfo['id'], "reseller_id" => $accountinfo['reseller_id']);
1929 1929
 		$account = $this->db_model->getSelect("*", "accounts", $where);
1930 1930
 	if ($account->num_rows() > 0) {
1931
-	$account_data = (array) $account->first_row();
1931
+	$account_data = (array)$account->first_row();
1932 1932
 	$speeddial_res = $this->db->get_where("speed_dial", array("accountid" => $accountinfo['id']));
1933 1933
 	$speeddial_info = array();
1934 1934
 		if ($speeddial_res->num_rows() > 0) {
@@ -1939,14 +1939,14 @@  discard block
 block discarded – undo
1939 1939
 		}
1940 1940
 		$data['speeddial'] = $speeddial_info;
1941 1941
 	$this->load->view('view_user_speeddial', $data);
1942
-	} else{
1942
+	} else {
1943 1943
 	 redirect(base_url.'user/user/');
1944 1944
 	}
1945 1945
 	  }
1946 1946
       
1947
-	  function user_speeddial_save(){
1948
-		  $add_array= $this->input->post();
1949
-		  $accountinfo=$this->session->userdata('accountinfo');
1947
+	  function user_speeddial_save() {
1948
+		  $add_array = $this->input->post();
1949
+		  $accountinfo = $this->session->userdata('accountinfo');
1950 1950
 		  $where = array("accountid" => $accountinfo['id']);
1951 1951
 	  $this->db->select('count(id) as count');
1952 1952
 	  $this->db->where($where);
@@ -1964,8 +1964,8 @@  discard block
 block discarded – undo
1964 1964
 	  }
1965 1965
 	}
1966 1966
 	function user_speeddial_remove() {
1967
-	$accountinfo=$this->session->userdata('accountinfo');
1968
-	$add_array=$this->input->post();
1967
+	$accountinfo = $this->session->userdata('accountinfo');
1968
+	$add_array = $this->input->post();
1969 1969
 		$updateinfo = array('number' => '');
1970 1970
 		$this->db->where('speed_num', $add_array['number']);
1971 1971
 		$this->db->where('accountid', $accountinfo['id']);
Please login to merge, or discard this patch.
web_interface/astpp/application/modules/dashboard/controllers/dashboard.php 2 patches
Spacing   +139 added lines, -139 removed lines patch added patch discarded remove patch
@@ -38,70 +38,70 @@  discard block
 block discarded – undo
38 38
 	function index() 
39 39
 	{
40 40
 		if ($this->session->userdata('user_login') == FALSE) 
41
-			redirect(base_url() . 'login/login');
41
+			redirect(base_url().'login/login');
42 42
 			$data['page_title'] = 'Dashboard';
43 43
 		if ($this->session->userdata('logintype') == 0) 
44 44
 	{
45 45
 			$this->load->view('view_user_dashboard', $data);
46 46
 		} else {
47
-		$gmtoffset=$this->common->get_timezone_offset();	    
47
+		$gmtoffset = $this->common->get_timezone_offset();	    
48 48
 			$this->load->view('view_dashboard', $data);
49 49
 		}
50 50
 	}
51
-	function user_recent_payments(){
51
+	function user_recent_payments() {
52 52
 	  $this->customerReport_recent_payments();
53 53
 	}     
54 54
 	function customerReport_recent_payments() 
55 55
 	{
56
-	$accountinfo=$this->session->userdata('accountinfo');
57
-	$currency=$this->common->get_field_name('currency','currency',array("id"=>$accountinfo['currency_id']));
56
+	$accountinfo = $this->session->userdata('accountinfo');
57
+	$currency = $this->common->get_field_name('currency', 'currency', array("id"=>$accountinfo['currency_id']));
58 58
 		$json_data = array();
59
-	$i=1;
59
+	$i = 1;
60 60
 	$result = $this->dashboard_model->get_recent_recharge();
61
-	$gmtoffset=$this->common->get_timezone_offset();
62
-		if($result->num_rows() > 0)
61
+	$gmtoffset = $this->common->get_timezone_offset();
62
+		if ($result->num_rows() > 0)
63 63
 	{
64
-		 $account_arr = $this->common->get_array('id,number,first_name,last_name', 'accounts','');
65
-		 $json_data[0]['accountid']='Accounts';
66
-		 $json_data[0]['credit']='Amount('.$currency.")";
67
-		 $json_data[0]['payment_date']='Date';
68
-		 foreach($result->result_array() as $key=>$data){
69
-			  $current_timestamp=strtotime($data['payment_date']);
70
-			  $modified_date=$current_timestamp+$gmtoffset;
71
-		  		  $data['accountid'] = ($data['accountid'] != '' && isset($account_arr[$data['accountid']])) ? $account_arr[$data['accountid']] :"Anonymous";
72
-			  $json_data[$i]['accountid']=$data['accountid'];
73
-			  $json_data[$i]['credit']=$this->common_model->calculate_currency($data['credit'],'','',true,false);
74
-			  $json_data[$i]['payment_date']=date('Y-m-d H:i:s',strtotime($data['payment_date'])+$gmtoffset);
64
+		 $account_arr = $this->common->get_array('id,number,first_name,last_name', 'accounts', '');
65
+		 $json_data[0]['accountid'] = 'Accounts';
66
+		 $json_data[0]['credit'] = 'Amount('.$currency.")";
67
+		 $json_data[0]['payment_date'] = 'Date';
68
+		 foreach ($result->result_array() as $key=>$data) {
69
+			  $current_timestamp = strtotime($data['payment_date']);
70
+			  $modified_date = $current_timestamp + $gmtoffset;
71
+		  		  $data['accountid'] = ($data['accountid'] != '' && isset($account_arr[$data['accountid']])) ? $account_arr[$data['accountid']] : "Anonymous";
72
+			  $json_data[$i]['accountid'] = $data['accountid'];
73
+			  $json_data[$i]['credit'] = $this->common_model->calculate_currency($data['credit'], '', '', true, false);
74
+			  $json_data[$i]['payment_date'] = date('Y-m-d H:i:s', strtotime($data['payment_date']) + $gmtoffset);
75 75
 			  $i++;
76 76
 		  	}
77 77
 		  }
78 78
 		 echo json_encode($json_data); 
79 79
 	}
80
-	function  user_call_statistics_with_profit(){
80
+	function  user_call_statistics_with_profit() {
81 81
 	  $this->customerReport_call_statistics_with_profit();
82 82
 	 }
83 83
 	function customerReport_call_statistics_with_profit() {
84
-		$post=$this->input->post();
85
-		$year=isset($post['year']) && $post['year'] >0 ? $post['year']:date("Y");
86
-		$month=isset($post['month'])&& $post['month'] >0 ? $post['month']:date("m");
84
+		$post = $this->input->post();
85
+		$year = isset($post['year']) && $post['year'] > 0 ? $post['year'] : date("Y");
86
+		$month = isset($post['month']) && $post['month'] > 0 ? $post['month'] : date("m");
87 87
 		$json_data = array();
88
-		$start_date=date($year.'-'.$month.'-01');
89
-		$end_day= $year==date("Y") && $month ==date("m") ? date("d") :cal_days_in_month(CAL_GREGORIAN, $month, $year);
90
-		$gmtoffset=$this->common->get_timezone_offset();
91
-		$end_date=date($year."-".$month."-".$end_day.' H:i:s');
92
-		$end_date=date('Y-m-d',strtotime($end_date)+$gmtoffset);
93
-		$current_date=(int)date("d");
94
-		$count=0;
95
-		$i=0;
88
+		$start_date = date($year.'-'.$month.'-01');
89
+		$end_day = $year == date("Y") && $month == date("m") ? date("d") : cal_days_in_month(CAL_GREGORIAN, $month, $year);
90
+		$gmtoffset = $this->common->get_timezone_offset();
91
+		$end_date = date($year."-".$month."-".$end_day.' H:i:s');
92
+		$end_date = date('Y-m-d', strtotime($end_date) + $gmtoffset);
93
+		$current_date = (int)date("d");
94
+		$count = 0;
95
+		$i = 0;
96 96
 		$begin = new DateTime($start_date);
97 97
 		$end = new DateTime($end_date);
98
-		$end=$end->modify('+1 day');
98
+		$end = $end->modify('+1 day');
99 99
 		$daterange = new DatePeriod($begin, new DateInterval('P1D'), $end);
100
-		$records_date=array();
101
-		$accountinfo=$this->session->userdata('accountinfo');
102
-		$parent_id= ($accountinfo['type'] == 1) ? $accountinfo['id'] : 0;
103
-		$customerresult = $this->dashboard_model->get_call_statistics('cdrs',$parent_id,$start_date,$end_date);
104
-		$resellerresult = $this->dashboard_model->get_call_statistics('reseller_cdrs',$parent_id,$start_date,$end_date);
100
+		$records_date = array();
101
+		$accountinfo = $this->session->userdata('accountinfo');
102
+		$parent_id = ($accountinfo['type'] == 1) ? $accountinfo['id'] : 0;
103
+		$customerresult = $this->dashboard_model->get_call_statistics('cdrs', $parent_id, $start_date, $end_date);
104
+		$resellerresult = $this->dashboard_model->get_call_statistics('reseller_cdrs', $parent_id, $start_date, $end_date);
105 105
 		$acc_arr = array();
106 106
 /*Date: 08-Mar-2017
107 107
 Reason: Improvement of Dashboard Performance*/
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
 		  $acc_arr[$data['day']] = $data;
133 133
 		  $customer_total_result['sum'] += $data['sum'];
134 134
 		  $customer_total_result['answered'] += $data['answered'];
135
-		  if($data['mcd'] > $mcd){
135
+		  if ($data['mcd'] > $mcd) {
136 136
 			  $mcd = $data['mcd'];
137 137
 		  }
138 138
 		  $customer_total_result['mcd'] = $mcd;
@@ -143,22 +143,22 @@  discard block
 block discarded – undo
143 143
 		  $customer_total_result['cost'] += $data['cost'];
144 144
 		  $customer_total_result['completed'] += $data['completed'];
145 145
 		}
146
-	foreach($resellerresult->result_array() as $data){
147
-	  $reseller_arr[$data['day']]=$data;
148
-	  if(isset($acc_arr[$data['day']])){
149
-		$acc_arr[$data['day']]['sum']= $data['sum']+$acc_arr[$data['day']]['sum'];
150
-		$acc_arr[$data['day']]['answered']= $data['answered']+$acc_arr[$data['day']]['answered'];
151
-		$acc_arr[$data['day']]['failed']= $data['failed']+$acc_arr[$data['day']]['failed'];
152
-		$acc_arr[$data['day']]['profit']= $data['profit']+$acc_arr[$data['day']]['profit'];
153
-			$acc_arr[$data['day']]['completed']= $data['completed']+$acc_arr[$data['day']]['completed'];
154
-			$acc_arr[$data['day']]['duration'] = $data['duration']+$acc_arr[$data['day']]['duration'];
155
-			$acc_arr[$data['day']]['mcd'] =$data['mcd'] > $acc_arr[$data['day']]['mcd'] ? $data['mcd']: $acc_arr[$data['day']]['mcd'];
156
-	  }else{
157
-		$acc_arr[$data['day']]=$data;
146
+	foreach ($resellerresult->result_array() as $data) {
147
+	  $reseller_arr[$data['day']] = $data;
148
+	  if (isset($acc_arr[$data['day']])) {
149
+		$acc_arr[$data['day']]['sum'] = $data['sum'] + $acc_arr[$data['day']]['sum'];
150
+		$acc_arr[$data['day']]['answered'] = $data['answered'] + $acc_arr[$data['day']]['answered'];
151
+		$acc_arr[$data['day']]['failed'] = $data['failed'] + $acc_arr[$data['day']]['failed'];
152
+		$acc_arr[$data['day']]['profit'] = $data['profit'] + $acc_arr[$data['day']]['profit'];
153
+			$acc_arr[$data['day']]['completed'] = $data['completed'] + $acc_arr[$data['day']]['completed'];
154
+			$acc_arr[$data['day']]['duration'] = $data['duration'] + $acc_arr[$data['day']]['duration'];
155
+			$acc_arr[$data['day']]['mcd'] = $data['mcd'] > $acc_arr[$data['day']]['mcd'] ? $data['mcd'] : $acc_arr[$data['day']]['mcd'];
156
+	  } else {
157
+		$acc_arr[$data['day']] = $data;
158 158
 	  }
159 159
 		$reseller_total_result['sum'] += $acc_arr[$data['day']]['sum'];
160 160
 		$reseller_total_result['answered'] += $acc_arr[$data['day']]['answered'];
161
-		if($data['mcd'] > $res_mcd){
161
+		if ($data['mcd'] > $res_mcd) {
162 162
 		  $res_mcd = $data['mcd'];
163 163
 		}
164 164
 		$reseller_total_result['mcd'] = $res_mcd;
@@ -167,130 +167,130 @@  discard block
 block discarded – undo
167 167
 		$reseller_total_result['profit'] += $acc_arr[$data['day']]['profit'];
168 168
 		$reseller_total_result['completed'] += $acc_arr[$data['day']]['completed'];
169 169
 	}
170
-	if(!empty($acc_arr)){
171
-		foreach($daterange as $date){
172
-		$json_data['date'][]=$date->format("d");
173
-		$day = (int) $date->format("d");
174
-		if(isset($acc_arr[$day])){
175
-				  $asr= ($acc_arr[$day]['sum'] > 0 ) ? (round(($acc_arr[$day]['completed'] / $acc_arr[$day]['sum']) * 100,2)) : 0;
176
-				  $acd= ($acc_arr[$day]['completed'] > 0 ) ? round($acc_arr[$day]['duration'] / $acc_arr[$day]['completed'],2) : 0;
177
-		  $json_data['total'][]=  array((string)$acc_arr[$day]['day'],(int) $acc_arr[$day]['sum']);
178
-		  $json_data['answered'][]=  array((string)$acc_arr[$day]['day'],(int) $acc_arr[$day]['answered']);
179
-		  $json_data['failed'][]=  array((string)$acc_arr[$day]['day'],(int) $acc_arr[$day]['failed']);
180
-		  $json_data['profit'][]=  array((string)$acc_arr[$day]['day'],(float)  str_replace(",", "", $this->common_model->calculate_currency($acc_arr[$day]['profit'])));
181
-				  $json_data['acd'][]=array((string)$acc_arr[$day]['day'],(float)$acd);
182
-				  $json_data['mcd'][]=array((string)$acc_arr[$day]['day'],(float)$acc_arr[$day]['mcd']);
183
-				  $json_data['asr'][]=array((string)$acc_arr[$day]['day'],(float)$asr);
184
-		}else{
185
-		  $json_data['total'][]=  array($date->format("d"), 0);
186
-		  $json_data['answered'][]=  array($date->format("d"), 0);
187
-		  $json_data['failed'][]=  array($date->format("d"), 0);
188
-		  $json_data['profit'][]=  array($date->format("d"), 0);
189
-				  $json_data['acd'][]=array($date->format("d"), 0);
190
-				  $json_data['mcd'][]=array($date->format("d"), 0);
191
-				  $json_data['asr'][]=array($date->format("d"),0);
170
+	if ( ! empty($acc_arr)) {
171
+		foreach ($daterange as $date) {
172
+		$json_data['date'][] = $date->format("d");
173
+		$day = (int)$date->format("d");
174
+		if (isset($acc_arr[$day])) {
175
+				  $asr = ($acc_arr[$day]['sum'] > 0) ? (round(($acc_arr[$day]['completed'] / $acc_arr[$day]['sum']) * 100, 2)) : 0;
176
+				  $acd = ($acc_arr[$day]['completed'] > 0) ? round($acc_arr[$day]['duration'] / $acc_arr[$day]['completed'], 2) : 0;
177
+		  $json_data['total'][] = array((string)$acc_arr[$day]['day'], (int)$acc_arr[$day]['sum']);
178
+		  $json_data['answered'][] = array((string)$acc_arr[$day]['day'], (int)$acc_arr[$day]['answered']);
179
+		  $json_data['failed'][] = array((string)$acc_arr[$day]['day'], (int)$acc_arr[$day]['failed']);
180
+		  $json_data['profit'][] = array((string)$acc_arr[$day]['day'], (float)str_replace(",", "", $this->common_model->calculate_currency($acc_arr[$day]['profit'])));
181
+				  $json_data['acd'][] = array((string)$acc_arr[$day]['day'], (float)$acd);
182
+				  $json_data['mcd'][] = array((string)$acc_arr[$day]['day'], (float)$acc_arr[$day]['mcd']);
183
+				  $json_data['asr'][] = array((string)$acc_arr[$day]['day'], (float)$asr);
184
+		} else {
185
+		  $json_data['total'][] = array($date->format("d"), 0);
186
+		  $json_data['answered'][] = array($date->format("d"), 0);
187
+		  $json_data['failed'][] = array($date->format("d"), 0);
188
+		  $json_data['profit'][] = array($date->format("d"), 0);
189
+				  $json_data['acd'][] = array($date->format("d"), 0);
190
+				  $json_data['mcd'][] = array($date->format("d"), 0);
191
+				  $json_data['asr'][] = array($date->format("d"), 0);
192 192
 		}
193 193
 		
194 194
 		}
195 195
 	}
196
-	else{
197
-	foreach($daterange as $date){
198
-		$json_data['date'][]=$date->format("d");
199
-		$day = (int) $date->format("d");
200
-		$json_data['total'][]=  array($date->format("d"), 0);
201
-		$json_data['answered'][]=  array($date->format("d"), 0);
202
-		$json_data['failed'][]=  array($date->format("d"), 0);
203
-		$json_data['profit'][]=  array($date->format("d"), 0);
204
-		$json_data['acd'][]=array($date->format("d"), 0);
205
-		$json_data['mcd'][]=array($date->format("d"), 0);
206
-		$json_data['asr'][]=array($date->format("d"), 0);
196
+	else {
197
+	foreach ($daterange as $date) {
198
+		$json_data['date'][] = $date->format("d");
199
+		$day = (int)$date->format("d");
200
+		$json_data['total'][] = array($date->format("d"), 0);
201
+		$json_data['answered'][] = array($date->format("d"), 0);
202
+		$json_data['failed'][] = array($date->format("d"), 0);
203
+		$json_data['profit'][] = array($date->format("d"), 0);
204
+		$json_data['acd'][] = array($date->format("d"), 0);
205
+		$json_data['mcd'][] = array($date->format("d"), 0);
206
+		$json_data['asr'][] = array($date->format("d"), 0);
207 207
 	}
208 208
 	}
209 209
 		
210
-		$json_data['total_count']['sum']=$reseller_total_result['sum']+$customer_total_result['sum'];
211
-		$json_data['total_count']['debit']=$this->common_model->to_calculate_currency($reseller_total_result['debit']+$customer_total_result['debit'],'','',true,true);
212
-		$json_data['total_count']['cost']=$this->common_model->to_calculate_currency($reseller_total_result['cost']+$customer_total_result['cost'],'','',true,true);
213
-		$json_data['total_count']['profit']=$this->common_model->to_calculate_currency($reseller_total_result['profit']+$customer_total_result['profit'],'','',true,true);
214
-		$json_data['total_count']['completed']=$reseller_total_result['completed']+$customer_total_result['completed'];
215
-		$json_data['total_count']['duration']=$reseller_total_result['duration']+$customer_total_result['duration'];
216
-		$json_data['total_count']['acd']=$json_data['total_count']['completed'] > 0 ? round($json_data['total_count']['duration']/$json_data['total_count']['completed'],2):0;
217
-		$json_data['total_count']['mcd']=($customer_total_result['mcd'] > 0 || $reseller_total_result['mcd'] > 0 ) ? ($customer_total_result['mcd'] > $reseller_total_result['mcd'] ? $customer_total_result['mcd']:$reseller_total_result['mcd']) : 0;
218
-		$json_data['total_count']['asr']=($json_data['total_count']['sum'] > 0 ) ? (round(($json_data['total_count']['completed'] / $json_data['total_count']['sum']) * 100,2)) : 0;
219
-		$json_data['total_count']['asr']=$this->common_model->format_currency($json_data['total_count']['asr']);
210
+		$json_data['total_count']['sum'] = $reseller_total_result['sum'] + $customer_total_result['sum'];
211
+		$json_data['total_count']['debit'] = $this->common_model->to_calculate_currency($reseller_total_result['debit'] + $customer_total_result['debit'], '', '', true, true);
212
+		$json_data['total_count']['cost'] = $this->common_model->to_calculate_currency($reseller_total_result['cost'] + $customer_total_result['cost'], '', '', true, true);
213
+		$json_data['total_count']['profit'] = $this->common_model->to_calculate_currency($reseller_total_result['profit'] + $customer_total_result['profit'], '', '', true, true);
214
+		$json_data['total_count']['completed'] = $reseller_total_result['completed'] + $customer_total_result['completed'];
215
+		$json_data['total_count']['duration'] = $reseller_total_result['duration'] + $customer_total_result['duration'];
216
+		$json_data['total_count']['acd'] = $json_data['total_count']['completed'] > 0 ? round($json_data['total_count']['duration'] / $json_data['total_count']['completed'], 2) : 0;
217
+		$json_data['total_count']['mcd'] = ($customer_total_result['mcd'] > 0 || $reseller_total_result['mcd'] > 0) ? ($customer_total_result['mcd'] > $reseller_total_result['mcd'] ? $customer_total_result['mcd'] : $reseller_total_result['mcd']) : 0;
218
+		$json_data['total_count']['asr'] = ($json_data['total_count']['sum'] > 0) ? (round(($json_data['total_count']['completed'] / $json_data['total_count']['sum']) * 100, 2)) : 0;
219
+		$json_data['total_count']['asr'] = $this->common_model->format_currency($json_data['total_count']['asr']);
220 220
 		echo json_encode($json_data);
221 221
 }
222 222
 
223
-	 function user_maximum_callminutes(){
223
+	 function user_maximum_callminutes() {
224 224
 	  $this->customerReport_maximum_callminutes();
225 225
 	}
226 226
 	 function customerReport_maximum_callminutes()
227 227
 	 {
228
-		$post=$this->input->post();
229
-		$year=isset($post['year']) && $post['year'] >0 ? $post['year']:date("Y");
230
-		$month=isset($post['month'])&& $post['month'] >0 ? $post['month']:date("m");
231
-	$start_date=date($year.'-'.$month.'-01');
232
-		$end_day= $year==date("Y") && $month ==date("m") ? date("d") :cal_days_in_month(CAL_GREGORIAN, $month, $year);
233
-	$gmtoffset=$this->common->get_timezone_offset();
234
-	$end_date=date($year."-".$month."-".$end_day.' H:i:s');
235
-	$end_date=date('Y-m-d',strtotime($end_date)+$gmtoffset);
228
+		$post = $this->input->post();
229
+		$year = isset($post['year']) && $post['year'] > 0 ? $post['year'] : date("Y");
230
+		$month = isset($post['month']) && $post['month'] > 0 ? $post['month'] : date("m");
231
+	$start_date = date($year.'-'.$month.'-01');
232
+		$end_day = $year == date("Y") && $month == date("m") ? date("d") : cal_days_in_month(CAL_GREGORIAN, $month, $year);
233
+	$gmtoffset = $this->common->get_timezone_offset();
234
+	$end_date = date($year."-".$month."-".$end_day.' H:i:s');
235
+	$end_date = date('Y-m-d', strtotime($end_date) + $gmtoffset);
236 236
 	 	$json_data = array();
237
- 	$result = $this->dashboard_model->get_customer_maximum_callminutes($start_date,$end_date);
238
-	$i=0;
239
-	$accountinfo=$this->session->userdata('accountinfo');
240
-	$reseller_id=$accountinfo['type']== -1 ? 0 : $accountinfo['id'];
241
-	if($this->session->userdata('userlevel_logintype')!= 0 && $this->session->userdata('userlevel_logintype')!= 3){
242
-	  $account_arr = $this->common->get_array('id,number,first_name,last_name', 'accounts',array('reseller_id'=>$reseller_id));
243
-	} else{
244
-	 $account_arr = $this->common->get_array('id,number,first_name,last_name', 'accounts',array('id'=>$reseller_id));
237
+ 	$result = $this->dashboard_model->get_customer_maximum_callminutes($start_date, $end_date);
238
+	$i = 0;
239
+	$accountinfo = $this->session->userdata('accountinfo');
240
+	$reseller_id = $accountinfo['type'] == -1 ? 0 : $accountinfo['id'];
241
+	if ($this->session->userdata('userlevel_logintype') != 0 && $this->session->userdata('userlevel_logintype') != 3) {
242
+	  $account_arr = $this->common->get_array('id,number,first_name,last_name', 'accounts', array('reseller_id'=>$reseller_id));
243
+	} else {
244
+	 $account_arr = $this->common->get_array('id,number,first_name,last_name', 'accounts', array('id'=>$reseller_id));
245 245
 	}
246
-		if($result->num_rows() > 0 )
246
+		if ($result->num_rows() > 0)
247 247
 	{	
248
-		   foreach ($result->result_array() as $data){
249
-			$data['accountid'] = ($data['accountid'] != '' && isset($account_arr[$data['accountid']])) ? $account_arr[$data['accountid']] :"Anonymous";
250
-			$json_data[$i][]= $data['accountid'];
251
-			$json_data[$i][]= round($data['billseconds']/60,0);
248
+		   foreach ($result->result_array() as $data) {
249
+			$data['accountid'] = ($data['accountid'] != '' && isset($account_arr[$data['accountid']])) ? $account_arr[$data['accountid']] : "Anonymous";
250
+			$json_data[$i][] = $data['accountid'];
251
+			$json_data[$i][] = round($data['billseconds'] / 60, 0);
252 252
 			$i++;
253 253
 		   } 
254
-		}else{
254
+		} else {
255 255
 	  $json_data[] = array();
256 256
 	  	}
257 257
 	 	echo json_encode($json_data);
258 258
 	 }
259 259
 
260
-	 function user_maximum_callcount(){
260
+	 function user_maximum_callcount() {
261 261
 	   $this->customerReport_maximum_callcount();
262 262
 	 }
263 263
 	 function customerReport_maximum_callcount()
264 264
 	 {
265
-	 	$post=$this->input->post();
266
-		$year=isset($post['year']) && $post['year'] >0 ? $post['year']:date("Y");
267
-		$month=isset($post['month'])&& $post['month'] >0 ? $post['month']:date("m");
268
-	$start_date=date($year.'-'.$month.'-01');
269
-		$end_day= $year==date("Y") && $month ==date("m") ? date("d") :cal_days_in_month(CAL_GREGORIAN, $month, $year);
270
-	$gmtoffset=$this->common->get_timezone_offset();
271
-	$end_date=date($year."-".$month."-".$end_day.' H:i:s');
272
-	$end_date=date('Y-m-d',strtotime($end_date)+$gmtoffset);
265
+	 	$post = $this->input->post();
266
+		$year = isset($post['year']) && $post['year'] > 0 ? $post['year'] : date("Y");
267
+		$month = isset($post['month']) && $post['month'] > 0 ? $post['month'] : date("m");
268
+	$start_date = date($year.'-'.$month.'-01');
269
+		$end_day = $year == date("Y") && $month == date("m") ? date("d") : cal_days_in_month(CAL_GREGORIAN, $month, $year);
270
+	$gmtoffset = $this->common->get_timezone_offset();
271
+	$end_date = date($year."-".$month."-".$end_day.' H:i:s');
272
+	$end_date = date('Y-m-d', strtotime($end_date) + $gmtoffset);
273 273
 	 	$json_data = array();
274
-	$result = $this->dashboard_model->get_customer_maximum_callcount($start_date,$end_date);
275
-	$accountinfo=$this->session->userdata('accountinfo');
276
-	$reseller_id=$accountinfo['type']== -1 ? 0 : $accountinfo['id'];
277
-	if($this->session->userdata('userlevel_logintype')!= 0 && $this->session->userdata('userlevel_logintype')!= 3){
278
-	  $account_arr = $this->common->get_array('id,number,first_name,last_name', 'accounts',array('reseller_id'=>$reseller_id));
279
-	} else{
280
-	 $account_arr = $this->common->get_array('id,number,first_name,last_name', 'accounts',array('id'=>$reseller_id));
274
+	$result = $this->dashboard_model->get_customer_maximum_callcount($start_date, $end_date);
275
+	$accountinfo = $this->session->userdata('accountinfo');
276
+	$reseller_id = $accountinfo['type'] == -1 ? 0 : $accountinfo['id'];
277
+	if ($this->session->userdata('userlevel_logintype') != 0 && $this->session->userdata('userlevel_logintype') != 3) {
278
+	  $account_arr = $this->common->get_array('id,number,first_name,last_name', 'accounts', array('reseller_id'=>$reseller_id));
279
+	} else {
280
+	 $account_arr = $this->common->get_array('id,number,first_name,last_name', 'accounts', array('id'=>$reseller_id));
281 281
 	}
282
-	$i=0;
283
-		if($result->num_rows() > 0 )
282
+	$i = 0;
283
+		if ($result->num_rows() > 0)
284 284
 	{
285 285
 		foreach ($result->result_array() as $data) 
286 286
 		{
287
-				$data['accountid'] = ($data['accountid'] != '' && isset($account_arr[$data['accountid']])) ? $account_arr[$data['accountid']] :"Anonymous";
288
-				$json_data[$i][]= $data['accountid'];
289
-				$json_data[$i][]= (int)$data['call_count'];
287
+				$data['accountid'] = ($data['accountid'] != '' && isset($account_arr[$data['accountid']])) ? $account_arr[$data['accountid']] : "Anonymous";
288
+				$json_data[$i][] = $data['accountid'];
289
+				$json_data[$i][] = (int)$data['call_count'];
290 290
 				$i++;
291 291
 			}
292 292
     	    
293
-		}else{
293
+		} else {
294 294
 				$json_data[] = array();
295 295
 	 		 }
296 296
 	echo json_encode($json_data);
Please login to merge, or discard this patch.
Braces   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -37,8 +37,9 @@  discard block
 block discarded – undo
37 37
 
38 38
 	function index() 
39 39
 	{
40
-		if ($this->session->userdata('user_login') == FALSE) 
41
-			redirect(base_url() . 'login/login');
40
+		if ($this->session->userdata('user_login') == FALSE) {
41
+					redirect(base_url() . 'login/login');
42
+		}
42 43
 			$data['page_title'] = 'Dashboard';
43 44
 		if ($this->session->userdata('logintype') == 0) 
44 45
 	{
@@ -153,7 +154,7 @@  discard block
 block discarded – undo
153 154
 			$acc_arr[$data['day']]['completed']= $data['completed']+$acc_arr[$data['day']]['completed'];
154 155
 			$acc_arr[$data['day']]['duration'] = $data['duration']+$acc_arr[$data['day']]['duration'];
155 156
 			$acc_arr[$data['day']]['mcd'] =$data['mcd'] > $acc_arr[$data['day']]['mcd'] ? $data['mcd']: $acc_arr[$data['day']]['mcd'];
156
-	  }else{
157
+	  } else{
157 158
 		$acc_arr[$data['day']]=$data;
158 159
 	  }
159 160
 		$reseller_total_result['sum'] += $acc_arr[$data['day']]['sum'];
@@ -181,7 +182,7 @@  discard block
 block discarded – undo
181 182
 				  $json_data['acd'][]=array((string)$acc_arr[$day]['day'],(float)$acd);
182 183
 				  $json_data['mcd'][]=array((string)$acc_arr[$day]['day'],(float)$acc_arr[$day]['mcd']);
183 184
 				  $json_data['asr'][]=array((string)$acc_arr[$day]['day'],(float)$asr);
184
-		}else{
185
+		} else{
185 186
 		  $json_data['total'][]=  array($date->format("d"), 0);
186 187
 		  $json_data['answered'][]=  array($date->format("d"), 0);
187 188
 		  $json_data['failed'][]=  array($date->format("d"), 0);
@@ -192,8 +193,7 @@  discard block
 block discarded – undo
192 193
 		}
193 194
 		
194 195
 		}
195
-	}
196
-	else{
196
+	} else{
197 197
 	foreach($daterange as $date){
198 198
 		$json_data['date'][]=$date->format("d");
199 199
 		$day = (int) $date->format("d");
@@ -251,7 +251,7 @@  discard block
 block discarded – undo
251 251
 			$json_data[$i][]= round($data['billseconds']/60,0);
252 252
 			$i++;
253 253
 		   } 
254
-		}else{
254
+		} else{
255 255
 	  $json_data[] = array();
256 256
 	  	}
257 257
 	 	echo json_encode($json_data);
@@ -290,7 +290,7 @@  discard block
 block discarded – undo
290 290
 				$i++;
291 291
 			}
292 292
     	    
293
-		}else{
293
+		} else{
294 294
 				$json_data[] = array();
295 295
 	 		 }
296 296
 	echo json_encode($json_data);
Please login to merge, or discard this patch.