@@ -31,7 +31,7 @@ |
||
31 | 31 | if ($xml == "") |
32 | 32 | xml_not_found(); |
33 | 33 | echo $xml; |
34 | -}else { |
|
34 | +} else { |
|
35 | 35 | xml_not_found(); |
36 | 36 | } |
37 | 37 | $logger->log("*************************** Directory Ends **********************************"); |
@@ -28,10 +28,11 @@ |
||
28 | 28 | |
29 | 29 | if (isset($_REQUEST['user']) && isset($_REQUEST['domain'])) { |
30 | 30 | $xml = load_directory($logger, $db); |
31 | - if ($xml == "") |
|
32 | - xml_not_found(); |
|
31 | + if ($xml == "") { |
|
32 | + xml_not_found(); |
|
33 | + } |
|
33 | 34 | echo $xml; |
34 | -}else { |
|
35 | +} else { |
|
35 | 36 | xml_not_found(); |
36 | 37 | } |
37 | 38 | $logger->log("*************************** Directory Ends **********************************"); |
@@ -208,7 +208,7 @@ |
||
208 | 208 | <?php |
209 | 209 | if($account_data['logo'] != ''){ |
210 | 210 | $logo=$account_data['file']; |
211 | - }else{ |
|
211 | + } else{ |
|
212 | 212 | $logo=$account_data['logo']; |
213 | 213 | } |
214 | 214 | if($logo != ''){ |
@@ -198,13 +198,13 @@ |
||
198 | 198 | </div> |
199 | 199 | </div> |
200 | 200 | <?php |
201 | - if($account_data['logo'] != ''){ |
|
202 | - $logo=$account_data['file']; |
|
203 | - }else{ |
|
204 | - $logo=$account_data['logo']; |
|
201 | + if ($account_data['logo'] != '') { |
|
202 | + $logo = $account_data['file']; |
|
203 | + } else { |
|
204 | + $logo = $account_data['logo']; |
|
205 | 205 | } |
206 | - if($logo != ''){ |
|
207 | - $file_name= base_url()."upload/$logo"; |
|
206 | + if ($logo != '') { |
|
207 | + $file_name = base_url()."upload/$logo"; |
|
208 | 208 | ?> |
209 | 209 | |
210 | 210 | <div class='col-md-12 no-padding'> |
@@ -20,8 +20,9 @@ |
||
20 | 20 | # You should have received a copy of the GNU Affero General Public License |
21 | 21 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
22 | 22 | ############################################################################### |
23 | -if (!defined('BASEPATH')) |
|
23 | +if (!defined('BASEPATH')) { |
|
24 | 24 | exit('No direct script access allowed'); |
25 | +} |
|
25 | 26 | |
26 | 27 | class Refill_coupon_form { |
27 | 28 | function __construct($library_name = '') { |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | # You should have received a copy of the GNU Affero General Public License |
21 | 21 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
22 | 22 | ############################################################################### |
23 | -if (!defined('BASEPATH')) |
|
23 | +if ( ! defined('BASEPATH')) |
|
24 | 24 | exit('No direct script access allowed'); |
25 | 25 | |
26 | 26 | class Permission { |
@@ -30,31 +30,31 @@ discard block |
||
30 | 30 | $this->CI->load->library('session'); |
31 | 31 | } |
32 | 32 | |
33 | - function get_module_access($user_type){ |
|
33 | + function get_module_access($user_type) { |
|
34 | 34 | $where = array("userlevelid"=>$user_type); |
35 | - $modules_arr = $this->CI->db_model->getSelect("module_permissions","userlevels",$where); |
|
36 | - if($modules_arr->num_rows > 0){ |
|
35 | + $modules_arr = $this->CI->db_model->getSelect("module_permissions", "userlevels", $where); |
|
36 | + if ($modules_arr->num_rows > 0) { |
|
37 | 37 | $modules_arr = $modules_arr->result_array(); |
38 | 38 | $modules_arr = $modules_arr[0]['module_permissions']; |
39 | 39 | |
40 | - $menu_arr = $this->CI->db_model->select("*","menu_modules","id IN ($modules_arr)","priority","asc","","",""); |
|
40 | + $menu_arr = $this->CI->db_model->select("*", "menu_modules", "id IN ($modules_arr)", "priority", "asc", "", "", ""); |
|
41 | 41 | $menu_list = array(); |
42 | 42 | $permited_modules = array(); |
43 | 43 | $modules_seq_arr = array(); |
44 | - $modules_seq_arr = explode(",",$modules_arr); |
|
45 | - $label_arr=array(); |
|
46 | - foreach($menu_arr->result_array() as $menu_key =>$menu_value){ |
|
47 | - if(!isset($label_arr[$menu_value['menu_label']]) && $menu_value['menu_label'] != 'Configuration'){ |
|
48 | - $label_arr[$menu_value['menu_label']]=$menu_value['menu_label']; |
|
49 | - $menu_value["menu_image"] = ($menu_value["menu_image"] == "")?"Home.png":$menu_value["menu_image"]; |
|
44 | + $modules_seq_arr = explode(",", $modules_arr); |
|
45 | + $label_arr = array(); |
|
46 | + foreach ($menu_arr->result_array() as $menu_key =>$menu_value) { |
|
47 | + if ( ! isset($label_arr[$menu_value['menu_label']]) && $menu_value['menu_label'] != 'Configuration') { |
|
48 | + $label_arr[$menu_value['menu_label']] = $menu_value['menu_label']; |
|
49 | + $menu_value["menu_image"] = ($menu_value["menu_image"] == "") ? "Home.png" : $menu_value["menu_image"]; |
|
50 | 50 | $menu_list[$menu_value["menu_title"]][$menu_value["menu_subtitle"]][] = array("menu_label" =>trim($menu_value["menu_label"]), |
51 | - "module_url"=>trim($menu_value["module_url"]),"module"=>trim($menu_value["module_name"]), |
|
51 | + "module_url"=>trim($menu_value["module_url"]), "module"=>trim($menu_value["module_name"]), |
|
52 | 52 | "menu_image"=>trim($menu_value["menu_image"])); |
53 | 53 | } |
54 | 54 | $permited_modules[] = trim($menu_value["module_name"]); |
55 | 55 | } |
56 | - $this->CI->session->set_userdata('permited_modules',serialize($permited_modules)); |
|
57 | - $this->CI->session->set_userdata('menuinfo',serialize($menu_list)); |
|
56 | + $this->CI->session->set_userdata('permited_modules', serialize($permited_modules)); |
|
57 | + $this->CI->session->set_userdata('menuinfo', serialize($menu_list)); |
|
58 | 58 | return true; |
59 | 59 | } |
60 | 60 | } |
@@ -20,8 +20,9 @@ |
||
20 | 20 | # You should have received a copy of the GNU Affero General Public License |
21 | 21 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
22 | 22 | ############################################################################### |
23 | -if (!defined('BASEPATH')) |
|
23 | +if (!defined('BASEPATH')) { |
|
24 | 24 | exit('No direct script access allowed'); |
25 | +} |
|
25 | 26 | |
26 | 27 | class Refill_coupon_form { |
27 | 28 | function __construct($library_name = '') { |
@@ -21,13 +21,13 @@ discard block |
||
21 | 21 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
22 | 22 | ############################################################################### |
23 | 23 | |
24 | -if (!defined('BASEPATH')) |
|
24 | +if ( ! defined('BASEPATH')) |
|
25 | 25 | exit('No direct script access allowed'); |
26 | 26 | |
27 | 27 | /** |
28 | 28 | * Dynamically build forms for display |
29 | 29 | */ |
30 | -class Locale{ |
|
30 | +class Locale { |
|
31 | 31 | |
32 | 32 | function __construct($library_name = '') { |
33 | 33 | |
@@ -38,23 +38,23 @@ discard block |
||
38 | 38 | $this->CI->load->driver('cache'); |
39 | 39 | $this->set_lang(); |
40 | 40 | } |
41 | - function set_lang($lang=FALSE){ |
|
41 | + function set_lang($lang = FALSE) { |
|
42 | 42 | |
43 | - $current_locale=$this->CI->session->userdata('user_language'); |
|
44 | - if(empty($current_locale)){ |
|
45 | - $current_locale= 'en_US'; |
|
43 | + $current_locale = $this->CI->session->userdata('user_language'); |
|
44 | + if (empty($current_locale)) { |
|
45 | + $current_locale = 'en_US'; |
|
46 | 46 | } |
47 | 47 | putenv("LANG=$current_locale"); |
48 | 48 | setlocale(LC_ALL, $current_locale.".UTF-8"); |
49 | - setlocale(LC_MESSAGES,$current_locale); |
|
49 | + setlocale(LC_MESSAGES, $current_locale); |
|
50 | 50 | setlocale(LC_TIME, $current_locale); |
51 | - setlocale(LC_CTYPE,$current_locale); |
|
52 | - $domain='messages'; |
|
53 | - $uri_segment=''; |
|
51 | + setlocale(LC_CTYPE, $current_locale); |
|
52 | + $domain = 'messages'; |
|
53 | + $uri_segment = ''; |
|
54 | 54 | $uri_segment = $this->CI->uri->segments; |
55 | - if(isset($uri_segment[1])){ |
|
55 | + if (isset($uri_segment[1])) { |
|
56 | 56 | $filename = getcwd().'/application/modules/user/language/'.$lang.'/LC_MESSAGES/messages.mo'; |
57 | - bindtextdomain(WEBSITE_DOMAIN,getcwd().'/application/modules/'.$uri_segment[1].'/language/'); |
|
57 | + bindtextdomain(WEBSITE_DOMAIN, getcwd().'/application/modules/'.$uri_segment[1].'/language/'); |
|
58 | 58 | } |
59 | 59 | bind_textdomain_codeset(WEBSITE_DOMAIN, 'UTF-8'); |
60 | 60 | textdomain(WEBSITE_DOMAIN); |
@@ -25,8 +25,9 @@ |
||
25 | 25 | function __construct() |
26 | 26 | { |
27 | 27 | parent::__construct(); |
28 | - if(!defined( 'CRON' ) ) |
|
29 | - exit(); |
|
28 | + if(!defined( 'CRON' ) ) { |
|
29 | + exit(); |
|
30 | + } |
|
30 | 31 | $this->load->model("db_model"); |
31 | 32 | $this->load->library("astpp/common"); |
32 | 33 | } |
@@ -25,21 +25,21 @@ |
||
25 | 25 | function __construct() |
26 | 26 | { |
27 | 27 | parent::__construct(); |
28 | - if(!defined( 'CRON' ) ) |
|
28 | + if ( ! defined('CRON')) |
|
29 | 29 | exit(); |
30 | 30 | $this->load->model("db_model"); |
31 | 31 | $this->load->library("astpp/email_lib"); |
32 | 32 | } |
33 | - function broadcast_email(){ |
|
33 | + function broadcast_email() { |
|
34 | 34 | |
35 | 35 | $where = array("status"=>"1"); |
36 | 36 | $query = $this->db_model->getSelect("*", "mail_details", $where); |
37 | - if($query->num_rows >0){ |
|
37 | + if ($query->num_rows > 0) { |
|
38 | 38 | $account_data = $query->result_array(); |
39 | - foreach($account_data as $data_key =>$account_value){ |
|
40 | - $account_value['history_id']=$account_value['id']; |
|
39 | + foreach ($account_data as $data_key =>$account_value) { |
|
40 | + $account_value['history_id'] = $account_value['id']; |
|
41 | 41 | unset($account_value['id']); |
42 | - $this->email_lib->send_email('',$account_value,'',$account_value['attachment'],1,0,1); |
|
42 | + $this->email_lib->send_email('', $account_value, '', $account_value['attachment'], 1, 0, 1); |
|
43 | 43 | } |
44 | 44 | } |
45 | 45 | } |
@@ -25,8 +25,9 @@ |
||
25 | 25 | function __construct() |
26 | 26 | { |
27 | 27 | parent::__construct(); |
28 | - if(!defined( 'CRON' ) ) |
|
29 | - exit(); |
|
28 | + if(!defined( 'CRON' ) ) { |
|
29 | + exit(); |
|
30 | + } |
|
30 | 31 | $this->load->model("db_model"); |
31 | 32 | $this->load->library("astpp/common"); |
32 | 33 | } |
@@ -25,19 +25,19 @@ |
||
25 | 25 | function __construct() |
26 | 26 | { |
27 | 27 | parent::__construct(); |
28 | - if(!defined( 'CRON' ) ) |
|
28 | + if ( ! defined('CRON')) |
|
29 | 29 | exit(); |
30 | 30 | $this->load->model("db_model"); |
31 | 31 | $this->load->library("astpp/common"); |
32 | 32 | } |
33 | - function low_creditlimit(){ |
|
34 | - $where = array("posttoexternal"=>1,"deleted" => "0","status"=>"0"); |
|
33 | + function low_creditlimit() { |
|
34 | + $where = array("posttoexternal"=>1, "deleted" => "0", "status"=>"0"); |
|
35 | 35 | $query = $this->db_model->getSelect("*", "accounts", $where); |
36 | - if($query->num_rows >0){ |
|
36 | + if ($query->num_rows > 0) { |
|
37 | 37 | $account_data = $query->result_array(); |
38 | - foreach($account_data as $data_key =>$account_value){ |
|
39 | - if(($account_value["balance"]) >= $account_value["credit_limit"]){ |
|
40 | - $this->common->mail_to_users("email_low_balance",$account_value); |
|
38 | + foreach ($account_data as $data_key =>$account_value) { |
|
39 | + if (($account_value["balance"]) >= $account_value["credit_limit"]) { |
|
40 | + $this->common->mail_to_users("email_low_balance", $account_value); |
|
41 | 41 | } |
42 | 42 | } |
43 | 43 | } |
@@ -20,8 +20,9 @@ |
||
20 | 20 | # You should have received a copy of the GNU Affero General Public License |
21 | 21 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
22 | 22 | ############################################################################### |
23 | -if (!defined('BASEPATH')) |
|
23 | +if (!defined('BASEPATH')) { |
|
24 | 24 | exit('No direct script access allowed'); |
25 | +} |
|
25 | 26 | |
26 | 27 | class Refill_coupon_form { |
27 | 28 | function __construct($library_name = '') { |
@@ -1,6 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if (!defined('BASEPATH')) |
|
3 | +if ( ! defined('BASEPATH')) |
|
4 | 4 | exit('No direct script access allowed'); |
5 | 5 | |
6 | 6 | /* |
@@ -256,6 +256,7 @@ |
||
256 | 256 | //Insert callee cdr entry for DID calls |
257 | 257 | /** |
258 | 258 | * @param boolean $flag_parent |
259 | + * @param string $provider_cost |
|
259 | 260 | */ |
260 | 261 | function insert_extra_receiver_entry($dataVariable,$origination_rate,$termination_rate,$account_type,$actual_duration,$provider_cost,$parentid,$flag_parent,$accountid,$logger,$db,$decimal_points) |
261 | 262 | { |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | if ($dataVariable['billsec'] == 0 && $dataVariable['hangup_cause'] == 'NORMAL_CLEARING') |
48 | 48 | { |
49 | 49 | $hangup_cause = isset($dataVariable['last_bridge_hangup_cause'])?$dataVariable['last_bridge_hangup_cause']:$dataVariable['hangup_cause']; |
50 | - }else{ |
|
50 | + } else{ |
|
51 | 51 | $hangup_cause = $dataVariable['hangup_cause']; |
52 | 52 | } |
53 | 53 | |
@@ -86,10 +86,12 @@ discard block |
||
86 | 86 | $actual_calltype = $dataVariable['calltype']; |
87 | 87 | |
88 | 88 | //Normalize origination and termination rates array |
89 | - if(isset($dataVariable['origination_rates'])) |
|
90 | - $origination_rate = normalize_origination_rate($dataVariable['origination_rates']); |
|
91 | - if(isset($dataVariable['termination_rates'])) |
|
92 | - $termination_rate = normalize_rate($dataVariable['termination_rates']); |
|
89 | + if(isset($dataVariable['origination_rates'])) { |
|
90 | + $origination_rate = normalize_origination_rate($dataVariable['origination_rates']); |
|
91 | + } |
|
92 | + if(isset($dataVariable['termination_rates'])) { |
|
93 | + $termination_rate = normalize_rate($dataVariable['termination_rates']); |
|
94 | + } |
|
93 | 95 | |
94 | 96 | //If receiver account id found then explicitly set call direction and call type |
95 | 97 | if(isset($dataVariable['receiver_accid'])) |
@@ -441,11 +443,12 @@ discard block |
||
441 | 443 | $query_counter = "SELECT id,seconds FROM counters WHERE accountid = ".$accountid." AND package_id = ".$package_id." AND status=1 LIMIT 1"; |
442 | 444 | $counter = $db->run($query_counter); |
443 | 445 | $logger->log("GET Counters : " . $query_counter); |
444 | - if($counter) |
|
445 | - return $counter[0]; |
|
446 | - else |
|
447 | - return ""; |
|
448 | -} |
|
446 | + if($counter) { |
|
447 | + return $counter[0]; |
|
448 | + } else { |
|
449 | + return ""; |
|
450 | + } |
|
451 | + } |
|
449 | 452 | |
450 | 453 | //Get user info |
451 | 454 | function get_accounts($parent_id,$logger, $db) { |
@@ -159,16 +159,16 @@ discard block |
||
159 | 159 | $dataVariable['call_direction'] = "inbound"; |
160 | 160 | $dataVariable['calltype'] = "DID"; |
161 | 161 | |
162 | - //Override variables if call for DID PSTN |
|
163 | - if(isset($dataVariable['caller_did_account_id'])) |
|
164 | - { |
|
165 | - $dataVariable['receiver_accid'] = $dataVariable['caller_did_account_id']; |
|
166 | - $dataVariable['call_direction'] = "outbound"; |
|
167 | - $dataVariable['calltype'] = "STANDARD"; |
|
168 | - $dataVariable['effective_destination_number']=$dataVariable['sip_to_user']; |
|
169 | - unset($termination_rate); |
|
170 | - unset($provider_cost); |
|
171 | - } |
|
162 | + //Override variables if call for DID PSTN |
|
163 | + if(isset($dataVariable['caller_did_account_id'])) |
|
164 | + { |
|
165 | + $dataVariable['receiver_accid'] = $dataVariable['caller_did_account_id']; |
|
166 | + $dataVariable['call_direction'] = "outbound"; |
|
167 | + $dataVariable['calltype'] = "STANDARD"; |
|
168 | + $dataVariable['effective_destination_number']=$dataVariable['sip_to_user']; |
|
169 | + unset($termination_rate); |
|
170 | + unset($provider_cost); |
|
171 | + } |
|
172 | 172 | |
173 | 173 | |
174 | 174 | |
@@ -316,7 +316,7 @@ discard block |
||
316 | 316 | //Generate CDR string for insert query for reseller |
317 | 317 | function get_reseller_cdr_string($dataVariable,$accountid,$account_type,$actual_duration,$termination_rate,$origination_rate,$provider_cost,$parentid,$debit,$cost) |
318 | 318 | { |
319 | - $dataVariable['calltype'] = ($dataVariable['calltype'] == 'DID-LOCAL' || $dataVariable['calltype'] == 'SIP-DID' || $dataVariable['calltype'] == 'OTHER')?"DID":$dataVariable['calltype']; |
|
319 | + $dataVariable['calltype'] = ($dataVariable['calltype'] == 'DID-LOCAL' || $dataVariable['calltype'] == 'SIP-DID' || $dataVariable['calltype'] == 'OTHER')?"DID":$dataVariable['calltype']; |
|
320 | 320 | $callerIdNumber = isset($dataVariable['effective_caller_id_number']) && !empty($dataVariable['effective_caller_id_number'])? $dataVariable['effective_caller_id_number'] :$dataVariable['caller_id']; |
321 | 321 | |
322 | 322 | return $cdr_string = "'".($dataVariable['uuid'])."','".$accountid."','".(urldecode($callerIdNumber))."','".($dataVariable['effective_destination_number'])."','".$actual_duration."','".($dataVariable['hangup_cause'])."','".convert_to_gmt(urldecode($dataVariable['callstart']))."','".$debit."','".$cost."','".$origination_rate[$accountid]['RATEGROUP']."','".$dataVariable['package_id']."','".($origination_rate[$accountid]['CODE'])."',".(($origination_rate[$accountid]['DESTINATION']) ? "'".$origination_rate[$accountid]['DESTINATION']."'" : "'".''."'").",".(($origination_rate[$accountid]['COST']) ? "'".$origination_rate[$accountid]['COST']."'" : "'".'0'."'").",'".$parentid."',".(($origination_rate[$parentid]['CODE'] ) ? "'".$origination_rate[$parentid]['CODE']."'" : "'".'0'."'").",".(($origination_rate[$parentid]['DESTINATION']) ? "'".$origination_rate[$parentid]['DESTINATION']."'" : "'".''."'").",".(($origination_rate[$parentid]['COST']) ? "'".$origination_rate[$parentid]['COST']."'" : '0').",".(($dataVariable['call_direction']) ? "'".$dataVariable['call_direction']."'" : "'internal'").",'".($dataVariable['calltype'])."'"; |
@@ -327,27 +327,27 @@ discard block |
||
327 | 327 | * @param integer $entity_id |
328 | 328 | */ |
329 | 329 | function update_balance($user_id, $amount, $entity_id, $logger, $db) { |
330 | - $math_sign = ($entity_id == 0 || $entity_id == 1) ? '-' : '+'; |
|
331 | - $query = "UPDATE accounts SET balance=balance-" . $amount . " WHERE id=" . $user_id; |
|
332 | - $logger->log("Balance update : " . $query); |
|
333 | - $db->run($query); |
|
330 | + $math_sign = ($entity_id == 0 || $entity_id == 1) ? '-' : '+'; |
|
331 | + $query = "UPDATE accounts SET balance=balance-" . $amount . " WHERE id=" . $user_id; |
|
332 | + $logger->log("Balance update : " . $query); |
|
333 | + $db->run($query); |
|
334 | 334 | } |
335 | 335 | |
336 | 336 | //Normalize rate string which we are getting from dialplan |
337 | 337 | function normalize_rate($dataVariable) |
338 | 338 | { |
339 | 339 | $rates = urldecode($dataVariable); |
340 | - $data = explode("|", $rates); |
|
340 | + $data = explode("|", $rates); |
|
341 | 341 | |
342 | 342 | $newarray = array(); |
343 | - foreach ($data as $key => $value) |
|
344 | - { |
|
345 | - $data1 = explode(":", $value); |
|
346 | - foreach ($data1 as $newkey => $newvalue) |
|
347 | - { |
|
348 | - $newarray[$data1[0]] = $data1[$newkey]; |
|
349 | - } |
|
350 | - } |
|
343 | + foreach ($data as $key => $value) |
|
344 | + { |
|
345 | + $data1 = explode(":", $value); |
|
346 | + foreach ($data1 as $newkey => $newvalue) |
|
347 | + { |
|
348 | + $newarray[$data1[0]] = $data1[$newkey]; |
|
349 | + } |
|
350 | + } |
|
351 | 351 | return $newarray; |
352 | 352 | } |
353 | 353 |
@@ -46,15 +46,15 @@ discard block |
||
46 | 46 | |
47 | 47 | if ($dataVariable['billsec'] == 0 && $dataVariable['hangup_cause'] == 'NORMAL_CLEARING') |
48 | 48 | { |
49 | - $hangup_cause = isset($dataVariable['last_bridge_hangup_cause'])?$dataVariable['last_bridge_hangup_cause']:$dataVariable['hangup_cause']; |
|
50 | - }else{ |
|
49 | + $hangup_cause = isset($dataVariable['last_bridge_hangup_cause']) ? $dataVariable['last_bridge_hangup_cause'] : $dataVariable['hangup_cause']; |
|
50 | + } else { |
|
51 | 51 | $hangup_cause = $dataVariable['hangup_cause']; |
52 | 52 | } |
53 | 53 | |
54 | 54 | if ($dataVariable['error_cdr'] == '1') |
55 | 55 | { |
56 | 56 | //Get actual hangup cause |
57 | - $hangup_cause= (isset($dataVariable['error_cdr'])) ? $dataVariable['last_bridge_hangup_cause'] : (isset($dataVariable['last_bridge_hangup_cause'])?$dataVariable['last_bridge_hangup_cause']:$dataVariable['hangup_cause']); |
|
57 | + $hangup_cause = (isset($dataVariable['error_cdr'])) ? $dataVariable['last_bridge_hangup_cause'] : (isset($dataVariable['last_bridge_hangup_cause']) ? $dataVariable['last_bridge_hangup_cause'] : $dataVariable['hangup_cause']); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | /*#### PATCH FOR ONE WAY AUDIO ####*/ |
@@ -65,14 +65,14 @@ discard block |
||
65 | 65 | /*#### ************* END *************####*/ |
66 | 66 | |
67 | 67 | //Don't thing this will be useful anytime. Need to remove it after testing. |
68 | - if($hangup_cause == "NONE") |
|
68 | + if ($hangup_cause == "NONE") |
|
69 | 69 | { |
70 | 70 | $hangup_cause = $dataVariable['current_application_data']; |
71 | 71 | } |
72 | 72 | |
73 | 73 | $dataVariable['hangup_cause'] = $hangup_cause; |
74 | 74 | |
75 | - if ( ($dataVariable['hangup_cause'] != 'NORMAL_CLEARING') && ($dataVariable['hangup_cause'] != 'ALLOTTED_TIMEOUT')) { |
|
75 | + if (($dataVariable['hangup_cause'] != 'NORMAL_CLEARING') && ($dataVariable['hangup_cause'] != 'ALLOTTED_TIMEOUT')) { |
|
76 | 76 | $dataVariable['billsec'] = 0; |
77 | 77 | } |
78 | 78 | |
@@ -86,13 +86,13 @@ discard block |
||
86 | 86 | $actual_calltype = $dataVariable['calltype']; |
87 | 87 | |
88 | 88 | //Normalize origination and termination rates array |
89 | - if(isset($dataVariable['origination_rates'])) |
|
89 | + if (isset($dataVariable['origination_rates'])) |
|
90 | 90 | $origination_rate = normalize_origination_rate($dataVariable['origination_rates']); |
91 | - if(isset($dataVariable['termination_rates'])) |
|
91 | + if (isset($dataVariable['termination_rates'])) |
|
92 | 92 | $termination_rate = normalize_rate($dataVariable['termination_rates']); |
93 | 93 | |
94 | 94 | //If receiver account id found then explicitly set call direction and call type |
95 | - if(isset($dataVariable['receiver_accid'])) |
|
95 | + if (isset($dataVariable['receiver_accid'])) |
|
96 | 96 | { |
97 | 97 | $dataVariable['call_direction'] = "outbound"; |
98 | 98 | $dataVariable['calltype'] = "STANDARD"; |
@@ -101,23 +101,23 @@ discard block |
||
101 | 101 | //Check if cusotmer have any package seconds left to use |
102 | 102 | if ($actual_duration > 0) |
103 | 103 | { |
104 | - $package_array = package_calculation( $dataVariable['effective_destination_number'],$origination_rate[$accountid]['RATEGROUP'],$actual_duration,$dataVariable['call_direction'],$accountid,$db,$logger); |
|
105 | - if(!empty($package_array)) |
|
104 | + $package_array = package_calculation($dataVariable['effective_destination_number'], $origination_rate[$accountid]['RATEGROUP'], $actual_duration, $dataVariable['call_direction'], $accountid, $db, $logger); |
|
105 | + if ( ! empty($package_array)) |
|
106 | 106 | { |
107 | 107 | $dataVariable['calltype'] = "FREE"; |
108 | - $dataVariable['package_id']= $package_array['package_id']; |
|
108 | + $dataVariable['package_id'] = $package_array['package_id']; |
|
109 | 109 | } |
110 | 110 | } |
111 | 111 | |
112 | 112 | //Calculate debit of customer call |
113 | - $debit = calc_cost($dataVariable,$origination_rate[$accountid],$logger,$decimal_points); |
|
113 | + $debit = calc_cost($dataVariable, $origination_rate[$accountid], $logger, $decimal_points); |
|
114 | 114 | |
115 | 115 | //Calculate cost for customer call for provider |
116 | - $provider_cost = calc_cost($dataVariable,$termination_rate,$logger,$decimal_points); |
|
116 | + $provider_cost = calc_cost($dataVariable, $termination_rate, $logger, $decimal_points); |
|
117 | 117 | |
118 | 118 | //Calculate parent cost if customer have any parent |
119 | - $parent_cost = ($parentid > 0) ? calc_cost($dataVariable,$origination_rate[$parentid],$logger,$decimal_points) : $provider_cost; |
|
120 | - $logger->log("Debit :".$debit ." Cost : ".$cost ." Provider Cost : ".$parent_cost); |
|
119 | + $parent_cost = ($parentid > 0) ? calc_cost($dataVariable, $origination_rate[$parentid], $logger, $decimal_points) : $provider_cost; |
|
120 | + $logger->log("Debit :".$debit." Cost : ".$cost." Provider Cost : ".$parent_cost); |
|
121 | 121 | |
122 | 122 | //Initialize final cost variable to use for billing |
123 | 123 | $cost = ($parent_cost > 0) ? $parent_cost : $provider_cost; |
@@ -125,33 +125,33 @@ discard block |
||
125 | 125 | //Outbound call entry for all type of calls |
126 | 126 | $logger->log("*********************** OUTBOUND CALL ENTRY START *************"); |
127 | 127 | |
128 | - $cdr_string = get_cdr_string($dataVariable,$accountid,$account_type,$actual_duration,$termination_rate,$origination_rate,$provider_cost,$parentid,$debit,$cost,$logger); |
|
128 | + $cdr_string = get_cdr_string($dataVariable, $accountid, $account_type, $actual_duration, $termination_rate, $origination_rate, $provider_cost, $parentid, $debit, $cost, $logger); |
|
129 | 129 | |
130 | 130 | $query = "INSERT INTO cdrs (uniqueid,accountid,type,callerid,callednum,billseconds,trunk_id,trunkip,callerip,disposition,callstart,debit,cost,provider_id,pricelist_id,package_id,pattern,notes,rate_cost,reseller_id,reseller_code,reseller_code_destination,reseller_cost,provider_code,provider_code_destination,provider_cost,provider_call_cost,call_direction,calltype,profile_start_stamp,answer_stamp,bridge_stamp,progress_stamp,progress_media_stamp,end_stamp,billmsec,answermsec,waitmsec,progress_mediamsec,flow_billmsec) values ($cdr_string)"; |
131 | 131 | $logger->log($query); |
132 | 132 | $db->run($query); |
133 | 133 | |
134 | 134 | //Update customer balance |
135 | - if($debit > 0 && $dataVariable['calltype'] != "FREE") |
|
135 | + if ($debit > 0 && $dataVariable['calltype'] != "FREE") |
|
136 | 136 | { |
137 | 137 | update_balance($accountid, $debit, 0, $logger, $db); |
138 | 138 | } |
139 | 139 | |
140 | 140 | //Update parent or provider balance |
141 | - if($parent_cost > 0){ |
|
141 | + if ($parent_cost > 0) { |
|
142 | 142 | update_balance($termination_rate['PROVIDER'], ($parent_cost * -1), 3, $logger, $db); |
143 | 143 | } |
144 | 144 | |
145 | 145 | //Resellers CDR entry |
146 | 146 | $flag_parent = false; |
147 | - insert_parent_data($dataVariable,$actual_calltype,$parentid,$origination_rate,$actual_duration,$provider_cost,$flag_parent,$logger,$db,$decimal_points); |
|
147 | + insert_parent_data($dataVariable, $actual_calltype, $parentid, $origination_rate, $actual_duration, $provider_cost, $flag_parent, $logger, $db, $decimal_points); |
|
148 | 148 | |
149 | 149 | $logger->log("*********************** OUTBOUND CALL ENTRY END *************"); |
150 | 150 | |
151 | 151 | |
152 | 152 | //************ ADDING EXTRA ENTRY For local/DID Inbound call **************************** |
153 | - $receiver_parentid=0; |
|
154 | - if(isset($dataVariable['receiver_accid']) && $dataVariable['receiver_accid'] != "") |
|
153 | + $receiver_parentid = 0; |
|
154 | + if (isset($dataVariable['receiver_accid']) && $dataVariable['receiver_accid'] != "") |
|
155 | 155 | { |
156 | 156 | $logger->log("*********************** EXTRA ENTRY SECTION FOR BILLING START *************"); |
157 | 157 | |
@@ -160,12 +160,12 @@ discard block |
||
160 | 160 | $dataVariable['calltype'] = "DID"; |
161 | 161 | |
162 | 162 | //Override variables if call for DID PSTN |
163 | - if(isset($dataVariable['caller_did_account_id'])) |
|
163 | + if (isset($dataVariable['caller_did_account_id'])) |
|
164 | 164 | { |
165 | 165 | $dataVariable['receiver_accid'] = $dataVariable['caller_did_account_id']; |
166 | 166 | $dataVariable['call_direction'] = "outbound"; |
167 | 167 | $dataVariable['calltype'] = "STANDARD"; |
168 | - $dataVariable['effective_destination_number']=$dataVariable['sip_to_user']; |
|
168 | + $dataVariable['effective_destination_number'] = $dataVariable['sip_to_user']; |
|
169 | 169 | unset($termination_rate); |
170 | 170 | unset($provider_cost); |
171 | 171 | } |
@@ -173,17 +173,17 @@ discard block |
||
173 | 173 | |
174 | 174 | |
175 | 175 | //Get call receiver account information |
176 | - $receiver_carddata = get_accounts($dataVariable['receiver_accid'],$logger,$db); |
|
176 | + $receiver_carddata = get_accounts($dataVariable['receiver_accid'], $logger, $db); |
|
177 | 177 | $receiver_parentid = $receiver_carddata['reseller_id']; |
178 | 178 | |
179 | 179 | //For additional cdr entry of receiver |
180 | - insert_extra_receiver_entry($dataVariable,$origination_rate,$termination_rate,$account_type,$actual_duration,$provider_cost,$receiver_parentid,$flag_parent,$dataVariable['receiver_accid'],$logger,$db,$decimal_points); |
|
180 | + insert_extra_receiver_entry($dataVariable, $origination_rate, $termination_rate, $account_type, $actual_duration, $provider_cost, $receiver_parentid, $flag_parent, $dataVariable['receiver_accid'], $logger, $db, $decimal_points); |
|
181 | 181 | |
182 | 182 | $flag_parent = true; |
183 | 183 | $dataVariable['uuid'] = $dataVariable['uuid'].$dataVariable['calltype']."_".$receiver_parentid; |
184 | 184 | |
185 | 185 | //Insert parent reseller cdr |
186 | - insert_parent_data($dataVariable,$actual_calltype,$receiver_parentid,$origination_rate,$actual_duration,$provider_cost,$flag_parent,$logger,$db,$decimal_points); |
|
186 | + insert_parent_data($dataVariable, $actual_calltype, $receiver_parentid, $origination_rate, $actual_duration, $provider_cost, $flag_parent, $logger, $db, $decimal_points); |
|
187 | 187 | $logger->log("*********************** EXTRA ENTRY SECTION FOR BILLING END *************"); |
188 | 188 | } |
189 | 189 | //***************************************************************************************** |
@@ -195,16 +195,16 @@ discard block |
||
195 | 195 | * @param string $provider_cost |
196 | 196 | * @param boolean $flag_parent |
197 | 197 | */ |
198 | -function insert_parent_data($dataVariable,$actual_calltype,$parentid,$origination_rate,$actual_duration,$provider_cost,$flag_parent,$logger,$db,$decimal_points) |
|
198 | +function insert_parent_data($dataVariable, $actual_calltype, $parentid, $origination_rate, $actual_duration, $provider_cost, $flag_parent, $logger, $db, $decimal_points) |
|
199 | 199 | { |
200 | - while($parentid > 0 ) |
|
200 | + while ($parentid > 0) |
|
201 | 201 | { |
202 | 202 | $logger->log("*************** IN PARENT DATA SECTION ********"); |
203 | 203 | $dataVariable['calltype'] = $actual_calltype; |
204 | - $carddata = get_accounts($parentid,$logger,$db); |
|
204 | + $carddata = get_accounts($parentid, $logger, $db); |
|
205 | 205 | $accountid = $carddata['id']; |
206 | 206 | |
207 | - $debit = calc_cost($dataVariable,$origination_rate[$accountid],$logger,$decimal_points); |
|
207 | + $debit = calc_cost($dataVariable, $origination_rate[$accountid], $logger, $decimal_points); |
|
208 | 208 | |
209 | 209 | //If receiver account id found then explicitly set call direction and call type |
210 | 210 | /*if(isset($dataVariable['receiver_accid'])) |
@@ -214,31 +214,31 @@ discard block |
||
214 | 214 | }*/ |
215 | 215 | |
216 | 216 | //Check if reseller have any package seconds left to use |
217 | - if ($actual_duration > 0) { |
|
218 | - $package_array = package_calculation( $dataVariable['effective_destination_number'],$origination_rate[$accountid]['RATEGROUP'],$actual_duration,$dataVariable['call_direction'],$accountid,$db,$logger); |
|
219 | - if(!empty($package_array)) |
|
217 | + if ($actual_duration > 0) { |
|
218 | + $package_array = package_calculation($dataVariable['effective_destination_number'], $origination_rate[$accountid]['RATEGROUP'], $actual_duration, $dataVariable['call_direction'], $accountid, $db, $logger); |
|
219 | + if ( ! empty($package_array)) |
|
220 | 220 | { |
221 | 221 | $dataVariable['calltype'] = "FREE"; |
222 | - $dataVariable['package_id']= $package_array['package_id']; |
|
222 | + $dataVariable['package_id'] = $package_array['package_id']; |
|
223 | 223 | } |
224 | 224 | } |
225 | 225 | |
226 | 226 | //Get parent id for cost calculation |
227 | 227 | $parentid = $carddata['reseller_id']; |
228 | - $parent_cost = ($parentid > 0) ? calc_cost($dataVariable,$origination_rate[$parentid],$logger,$decimal_points) : $provider_cost; |
|
228 | + $parent_cost = ($parentid > 0) ? calc_cost($dataVariable, $origination_rate[$parentid], $logger, $decimal_points) : $provider_cost; |
|
229 | 229 | $cost = ($parent_cost > 0) ? $parent_cost : $provider_cost; |
230 | 230 | |
231 | - if(isset($dataVariable['receiver_accid']) && $dataVariable['receiver_accid'] != "" && $flag_parent == true) |
|
231 | + if (isset($dataVariable['receiver_accid']) && $dataVariable['receiver_accid'] != "" && $flag_parent == true) |
|
232 | 232 | { |
233 | 233 | $logger->log("********* IN RESELLER FOR RECEIVER ENTRY START ******"); |
234 | 234 | $flag_parent = true; |
235 | - insert_extra_receiver_entry($dataVariable,$origination_rate,$termination_rate,$account_type,$actual_duration,$provider_cost,$parentid,$flag_parent,$accountid,$logger,$db,$decimal_points); |
|
235 | + insert_extra_receiver_entry($dataVariable, $origination_rate, $termination_rate, $account_type, $actual_duration, $provider_cost, $parentid, $flag_parent, $accountid, $logger, $db, $decimal_points); |
|
236 | 236 | $logger->log("********* IN RESELLER FOR RECEIVER ENTRY END ******"); |
237 | 237 | return true; |
238 | 238 | |
239 | - } else{ |
|
239 | + } else { |
|
240 | 240 | |
241 | - $cdr_string = get_reseller_cdr_string($dataVariable,$accountid,$account_type,$actual_duration,$termination_rate,$origination_rate,$provider_cost,$parentid,$debit,$cost); |
|
241 | + $cdr_string = get_reseller_cdr_string($dataVariable, $accountid, $account_type, $actual_duration, $termination_rate, $origination_rate, $provider_cost, $parentid, $debit, $cost); |
|
242 | 242 | |
243 | 243 | $query = "INSERT INTO reseller_cdrs (uniqueid,accountid,callerid,callednum,billseconds,disposition,callstart,debit,cost,pricelist_id,package_id,pattern,notes,rate_cost, |
244 | 244 | reseller_id,reseller_code,reseller_code_destination,reseller_cost,call_direction,calltype) values ($cdr_string)"; |
@@ -259,38 +259,38 @@ discard block |
||
259 | 259 | /** |
260 | 260 | * @param boolean $flag_parent |
261 | 261 | */ |
262 | -function insert_extra_receiver_entry($dataVariable,$origination_rate,$termination_rate,$account_type,$actual_duration,$provider_cost,$parentid,$flag_parent,$accountid,$logger,$db,$decimal_points) |
|
262 | +function insert_extra_receiver_entry($dataVariable, $origination_rate, $termination_rate, $account_type, $actual_duration, $provider_cost, $parentid, $flag_parent, $accountid, $logger, $db, $decimal_points) |
|
263 | 263 | { |
264 | 264 | $localVariable = $dataVariable; |
265 | 265 | $localVariable['call_direction'] = "inbound"; |
266 | 266 | $localVariable['uuid'] = $localVariable['uuid'].$dataVariable['calltype']."_".$accountid; |
267 | 267 | |
268 | - if($dataVariable['calltype'] == "LOCAL") |
|
268 | + if ($dataVariable['calltype'] == "LOCAL") |
|
269 | 269 | { |
270 | 270 | $origination_rate[$accountid]['CODE'] = $dataVariable['effective_destination_number']; |
271 | 271 | $origination_rate[$accountid]['DESTINATION'] = $dataVariable['calltype']; |
272 | - if($flag_parent == false){ |
|
273 | - $cdr_string = get_cdr_string($localVariable,$accountid,$account_type,$actual_duration,$termination_rate,$origination_rate,$provider_cost,$parentid,0,0,$logger); |
|
274 | - } else{ |
|
275 | - $cdr_string = get_reseller_cdr_string($dataVariable,$accountid,$account_type,$actual_duration,$termination_rate,$origination_rate,$provider_cost,$parentid,$debit,$cost); |
|
272 | + if ($flag_parent == false) { |
|
273 | + $cdr_string = get_cdr_string($localVariable, $accountid, $account_type, $actual_duration, $termination_rate, $origination_rate, $provider_cost, $parentid, 0, 0, $logger); |
|
274 | + } else { |
|
275 | + $cdr_string = get_reseller_cdr_string($dataVariable, $accountid, $account_type, $actual_duration, $termination_rate, $origination_rate, $provider_cost, $parentid, $debit, $cost); |
|
276 | 276 | } |
277 | - } else{ |
|
277 | + } else { |
|
278 | 278 | |
279 | 279 | $origination_rate_did = normalize_origination_rate($dataVariable['origination_rates_did']); |
280 | - $debit = calc_cost($dataVariable,$origination_rate_did[$accountid],$logger,$decimal_points); |
|
280 | + $debit = calc_cost($dataVariable, $origination_rate_did[$accountid], $logger, $decimal_points); |
|
281 | 281 | |
282 | - if($flag_parent == false){ |
|
282 | + if ($flag_parent == false) { |
|
283 | 283 | |
284 | - $cdr_string = get_cdr_string($localVariable,$accountid,$account_type,$actual_duration,$termination_rate,$origination_rate_did,$provider_cost,$parentid,$debit,0,$logger); |
|
285 | - } else{ |
|
286 | - $cdr_string = get_reseller_cdr_string($dataVariable,$accountid,$account_type,$actual_duration,$termination_rate,$origination_rate,$provider_cost,$parentid,$debit,$cost); |
|
284 | + $cdr_string = get_cdr_string($localVariable, $accountid, $account_type, $actual_duration, $termination_rate, $origination_rate_did, $provider_cost, $parentid, $debit, 0, $logger); |
|
285 | + } else { |
|
286 | + $cdr_string = get_reseller_cdr_string($dataVariable, $accountid, $account_type, $actual_duration, $termination_rate, $origination_rate, $provider_cost, $parentid, $debit, $cost); |
|
287 | 287 | } |
288 | 288 | } |
289 | 289 | |
290 | - if($flag_parent == false) |
|
290 | + if ($flag_parent == false) |
|
291 | 291 | { |
292 | 292 | $query = "INSERT INTO cdrs(uniqueid,accountid,type,callerid,callednum,billseconds,trunk_id,trunkip,callerip,disposition,callstart,debit,cost,provider_id,pricelist_id,package_id,pattern,notes,rate_cost,reseller_id,reseller_code,reseller_code_destination,reseller_cost,provider_code,provider_code_destination,provider_cost,provider_call_cost,call_direction,calltype,profile_start_stamp,answer_stamp,bridge_stamp,progress_stamp,progress_media_stamp,end_stamp,billmsec,answermsec,waitmsec,progress_mediamsec,flow_billmsec) values ($cdr_string)"; |
293 | - } else{ |
|
293 | + } else { |
|
294 | 294 | $query = "INSERT INTO reseller_cdrs (uniqueid,accountid,callerid,callednum,billseconds,disposition,callstart,debit,cost,pricelist_id,package_id,pattern,notes,rate_cost, |
295 | 295 | reseller_id,reseller_code,reseller_code_destination,reseller_cost,call_direction,calltype) values ($cdr_string)"; |
296 | 296 | } |
@@ -306,20 +306,20 @@ discard block |
||
306 | 306 | } |
307 | 307 | |
308 | 308 | //Generate CDR string for insert query for customer. |
309 | -function get_cdr_string($dataVariable,$accountid,$account_type,$actual_duration,$termination_rate,$origination_rate,$provider_cost,$parentid,$debit,$cost,$logger) |
|
309 | +function get_cdr_string($dataVariable, $accountid, $account_type, $actual_duration, $termination_rate, $origination_rate, $provider_cost, $parentid, $debit, $cost, $logger) |
|
310 | 310 | { |
311 | - $dataVariable['calltype'] = ($dataVariable['calltype'] == 'DID-LOCAL' || $dataVariable['calltype'] == 'SIP-DID' || $dataVariable['calltype'] == 'OTHER')?"DID":$dataVariable['calltype']; |
|
312 | - $callerIdNumber = isset($dataVariable['effective_caller_id_number']) && !empty($dataVariable['effective_caller_id_number'])? $dataVariable['effective_caller_id_number'] :$dataVariable['caller_id']; |
|
313 | - return $cdr_string = "'".($dataVariable['uuid'])."','".$accountid."','".$account_type."','".(urldecode($callerIdNumber))."','".($dataVariable['effective_destination_number'])."','".$actual_duration."',".(($termination_rate['TRUNK']) ? $termination_rate['TRUNK'] : '0').",".(($dataVariable['sip_via_host']) ? "'".$dataVariable['sip_via_host']."'" : '').",".(($dataVariable['sip_contact_host']) ? "'".$dataVariable['sip_contact_host']."'" : '').",'".($dataVariable['hangup_cause'])."','".urldecode($dataVariable['callstart'])."','".$debit."','".$cost."',".(($termination_rate['PROVIDER']) ? $termination_rate['PROVIDER'] : '0').",'".$origination_rate[$accountid]['RATEGROUP']."','".$dataVariable['package_id']."','".($origination_rate[$accountid]['CODE'])."',".(($origination_rate[$accountid]['DESTINATION']) ? "'".htmlentities($origination_rate[$accountid]['DESTINATION'],ENT_COMPAT, 'UTF-8')."'" : "'".''."'").",".(($origination_rate[$accountid]['COST']) ? "'".$origination_rate[$accountid]['COST']."'" : "'".'0'."'").",'".$parentid."',".(($origination_rate[$parentid]['CODE'] ) ? "'".$origination_rate[$parentid]['CODE']."'" : "'".'0'."'").",".(($origination_rate[$parentid]['DESTINATION']) ? "'".$origination_rate[$parentid]['DESTINATION']."'" : "'".''."'").",".(($origination_rate[$parentid]['COST']) ? "'".$origination_rate[$parentid]['COST']."'" : '0').",".(($termination_rate['CODE']) ? "'".$termination_rate['CODE']."'" : "'".''."'" ).",".(($termination_rate['DESTINATION']) ? "'".$termination_rate['DESTINATION']."'" : "'".''."'").",".(($termination_rate['COST']) ? "'".$termination_rate['COST']."'" : '0').",'".$provider_cost."',".(($dataVariable['call_direction']) ? "'".$dataVariable['call_direction']."'" : "'internal'").",'".($dataVariable['calltype'])."','".convert_to_gmt(urldecode($dataVariable['profile_start_stamp']))."','".convert_to_gmt(urldecode($dataVariable['answer_stamp']))."','".convert_to_gmt(urldecode($dataVariable['bridge_stamp']))."','".convert_to_gmt(urldecode(@$dataVariable['progress_stamp']))."','".convert_to_gmt(urldecode(@$dataVariable['progress_media_stamp']))."','".convert_to_gmt(urldecode($dataVariable['end_stamp']))."',".$dataVariable['billmsec'].",'".$dataVariable['answermsec']."','".$dataVariable['waitmsec']."','".$dataVariable['progress_mediamsec']."','".$dataVariable['flow_billmsec']."'"; |
|
311 | + $dataVariable['calltype'] = ($dataVariable['calltype'] == 'DID-LOCAL' || $dataVariable['calltype'] == 'SIP-DID' || $dataVariable['calltype'] == 'OTHER') ? "DID" : $dataVariable['calltype']; |
|
312 | + $callerIdNumber = isset($dataVariable['effective_caller_id_number']) && ! empty($dataVariable['effective_caller_id_number']) ? $dataVariable['effective_caller_id_number'] : $dataVariable['caller_id']; |
|
313 | + return $cdr_string = "'".($dataVariable['uuid'])."','".$accountid."','".$account_type."','".(urldecode($callerIdNumber))."','".($dataVariable['effective_destination_number'])."','".$actual_duration."',".(($termination_rate['TRUNK']) ? $termination_rate['TRUNK'] : '0').",".(($dataVariable['sip_via_host']) ? "'".$dataVariable['sip_via_host']."'" : '').",".(($dataVariable['sip_contact_host']) ? "'".$dataVariable['sip_contact_host']."'" : '').",'".($dataVariable['hangup_cause'])."','".urldecode($dataVariable['callstart'])."','".$debit."','".$cost."',".(($termination_rate['PROVIDER']) ? $termination_rate['PROVIDER'] : '0').",'".$origination_rate[$accountid]['RATEGROUP']."','".$dataVariable['package_id']."','".($origination_rate[$accountid]['CODE'])."',".(($origination_rate[$accountid]['DESTINATION']) ? "'".htmlentities($origination_rate[$accountid]['DESTINATION'], ENT_COMPAT, 'UTF-8')."'" : "'".''."'").",".(($origination_rate[$accountid]['COST']) ? "'".$origination_rate[$accountid]['COST']."'" : "'".'0'."'").",'".$parentid."',".(($origination_rate[$parentid]['CODE']) ? "'".$origination_rate[$parentid]['CODE']."'" : "'".'0'."'").",".(($origination_rate[$parentid]['DESTINATION']) ? "'".$origination_rate[$parentid]['DESTINATION']."'" : "'".''."'").",".(($origination_rate[$parentid]['COST']) ? "'".$origination_rate[$parentid]['COST']."'" : '0').",".(($termination_rate['CODE']) ? "'".$termination_rate['CODE']."'" : "'".''."'").",".(($termination_rate['DESTINATION']) ? "'".$termination_rate['DESTINATION']."'" : "'".''."'").",".(($termination_rate['COST']) ? "'".$termination_rate['COST']."'" : '0').",'".$provider_cost."',".(($dataVariable['call_direction']) ? "'".$dataVariable['call_direction']."'" : "'internal'").",'".($dataVariable['calltype'])."','".convert_to_gmt(urldecode($dataVariable['profile_start_stamp']))."','".convert_to_gmt(urldecode($dataVariable['answer_stamp']))."','".convert_to_gmt(urldecode($dataVariable['bridge_stamp']))."','".convert_to_gmt(urldecode(@$dataVariable['progress_stamp']))."','".convert_to_gmt(urldecode(@$dataVariable['progress_media_stamp']))."','".convert_to_gmt(urldecode($dataVariable['end_stamp']))."',".$dataVariable['billmsec'].",'".$dataVariable['answermsec']."','".$dataVariable['waitmsec']."','".$dataVariable['progress_mediamsec']."','".$dataVariable['flow_billmsec']."'"; |
|
314 | 314 | } |
315 | 315 | |
316 | 316 | //Generate CDR string for insert query for reseller |
317 | -function get_reseller_cdr_string($dataVariable,$accountid,$account_type,$actual_duration,$termination_rate,$origination_rate,$provider_cost,$parentid,$debit,$cost) |
|
317 | +function get_reseller_cdr_string($dataVariable, $accountid, $account_type, $actual_duration, $termination_rate, $origination_rate, $provider_cost, $parentid, $debit, $cost) |
|
318 | 318 | { |
319 | - $dataVariable['calltype'] = ($dataVariable['calltype'] == 'DID-LOCAL' || $dataVariable['calltype'] == 'SIP-DID' || $dataVariable['calltype'] == 'OTHER')?"DID":$dataVariable['calltype']; |
|
320 | - $callerIdNumber = isset($dataVariable['effective_caller_id_number']) && !empty($dataVariable['effective_caller_id_number'])? $dataVariable['effective_caller_id_number'] :$dataVariable['caller_id']; |
|
319 | + $dataVariable['calltype'] = ($dataVariable['calltype'] == 'DID-LOCAL' || $dataVariable['calltype'] == 'SIP-DID' || $dataVariable['calltype'] == 'OTHER') ? "DID" : $dataVariable['calltype']; |
|
320 | + $callerIdNumber = isset($dataVariable['effective_caller_id_number']) && ! empty($dataVariable['effective_caller_id_number']) ? $dataVariable['effective_caller_id_number'] : $dataVariable['caller_id']; |
|
321 | 321 | |
322 | - return $cdr_string = "'".($dataVariable['uuid'])."','".$accountid."','".(urldecode($callerIdNumber))."','".($dataVariable['effective_destination_number'])."','".$actual_duration."','".($dataVariable['hangup_cause'])."','".convert_to_gmt(urldecode($dataVariable['callstart']))."','".$debit."','".$cost."','".$origination_rate[$accountid]['RATEGROUP']."','".$dataVariable['package_id']."','".($origination_rate[$accountid]['CODE'])."',".(($origination_rate[$accountid]['DESTINATION']) ? "'".$origination_rate[$accountid]['DESTINATION']."'" : "'".''."'").",".(($origination_rate[$accountid]['COST']) ? "'".$origination_rate[$accountid]['COST']."'" : "'".'0'."'").",'".$parentid."',".(($origination_rate[$parentid]['CODE'] ) ? "'".$origination_rate[$parentid]['CODE']."'" : "'".'0'."'").",".(($origination_rate[$parentid]['DESTINATION']) ? "'".$origination_rate[$parentid]['DESTINATION']."'" : "'".''."'").",".(($origination_rate[$parentid]['COST']) ? "'".$origination_rate[$parentid]['COST']."'" : '0').",".(($dataVariable['call_direction']) ? "'".$dataVariable['call_direction']."'" : "'internal'").",'".($dataVariable['calltype'])."'"; |
|
322 | + return $cdr_string = "'".($dataVariable['uuid'])."','".$accountid."','".(urldecode($callerIdNumber))."','".($dataVariable['effective_destination_number'])."','".$actual_duration."','".($dataVariable['hangup_cause'])."','".convert_to_gmt(urldecode($dataVariable['callstart']))."','".$debit."','".$cost."','".$origination_rate[$accountid]['RATEGROUP']."','".$dataVariable['package_id']."','".($origination_rate[$accountid]['CODE'])."',".(($origination_rate[$accountid]['DESTINATION']) ? "'".$origination_rate[$accountid]['DESTINATION']."'" : "'".''."'").",".(($origination_rate[$accountid]['COST']) ? "'".$origination_rate[$accountid]['COST']."'" : "'".'0'."'").",'".$parentid."',".(($origination_rate[$parentid]['CODE']) ? "'".$origination_rate[$parentid]['CODE']."'" : "'".'0'."'").",".(($origination_rate[$parentid]['DESTINATION']) ? "'".$origination_rate[$parentid]['DESTINATION']."'" : "'".''."'").",".(($origination_rate[$parentid]['COST']) ? "'".$origination_rate[$parentid]['COST']."'" : '0').",".(($dataVariable['call_direction']) ? "'".$dataVariable['call_direction']."'" : "'internal'").",'".($dataVariable['calltype'])."'"; |
|
323 | 323 | } |
324 | 324 | |
325 | 325 | //Update user balance |
@@ -328,8 +328,8 @@ discard block |
||
328 | 328 | */ |
329 | 329 | function update_balance($user_id, $amount, $entity_id, $logger, $db) { |
330 | 330 | $math_sign = ($entity_id == 0 || $entity_id == 1) ? '-' : '+'; |
331 | - $query = "UPDATE accounts SET balance=balance-" . $amount . " WHERE id=" . $user_id; |
|
332 | - $logger->log("Balance update : " . $query); |
|
331 | + $query = "UPDATE accounts SET balance=balance-".$amount." WHERE id=".$user_id; |
|
332 | + $logger->log("Balance update : ".$query); |
|
333 | 333 | $db->run($query); |
334 | 334 | } |
335 | 335 | |
@@ -388,46 +388,46 @@ discard block |
||
388 | 388 | |
389 | 389 | if ($billseconds > 0) |
390 | 390 | { |
391 | - $call_cost += (ceil($billseconds/$rates['INC'])*$rates['INC'])*($rates['COST']/60); |
|
391 | + $call_cost += (ceil($billseconds / $rates['INC']) * $rates['INC']) * ($rates['COST'] / 60); |
|
392 | 392 | } |
393 | 393 | } |
394 | - $call_cost = number_format($call_cost,$decimal_points); |
|
394 | + $call_cost = number_format($call_cost, $decimal_points); |
|
395 | 395 | $logger->log("Return cost ".$call_cost); |
396 | 396 | return $call_cost; |
397 | 397 | } |
398 | 398 | |
399 | 399 | // get intial package information |
400 | -function package_calculation($destination_number,$pricelist_id,$duration,$call_direction,$accountid,$db,$logger) |
|
400 | +function package_calculation($destination_number, $pricelist_id, $duration, $call_direction, $accountid, $db, $logger) |
|
401 | 401 | { |
402 | 402 | $package_array = array(); |
403 | - $custom_destination = number_loop($destination_number,"patterns",$db); |
|
403 | + $custom_destination = number_loop($destination_number, "patterns", $db); |
|
404 | 404 | |
405 | 405 | $query = "SELECT * FROM packages as P inner join package_patterns as PKGPTR on P.id = PKGPTR.package_id WHERE ".$custom_destination." AND status = 0 AND pricelist_id = ".$pricelist_id." ORDER BY LENGTH(PKGPTR.patterns) DESC LIMIT 1"; |
406 | 406 | |
407 | 407 | $package_info = $db->run($query); |
408 | - if($package_info){ |
|
408 | + if ($package_info) { |
|
409 | 409 | $package_info = $package_info[0]; |
410 | 410 | |
411 | - if( ($package_info['applicable_for'] == "0" && $call_direction == "outbound") || ($package_info['applicable_for'] == "1" && $call_direction == "inbound") || ($package_info['applicable_for'] == "2") ) { |
|
411 | + if (($package_info['applicable_for'] == "0" && $call_direction == "outbound") || ($package_info['applicable_for'] == "1" && $call_direction == "inbound") || ($package_info['applicable_for'] == "2")) { |
|
412 | 412 | |
413 | - $counter_info = get_counters($accountid,$package_info['package_id'],$db,$logger); |
|
413 | + $counter_info = get_counters($accountid, $package_info['package_id'], $db, $logger); |
|
414 | 414 | |
415 | - if(!$counter_info) { |
|
415 | + if ( ! $counter_info) { |
|
416 | 416 | $Insert_Query = "INSERT INTO counters (package_id,accountid) VALUES (".$package_info['package_id'].",".$accountid.")"; |
417 | - $logger->log("Insert Counters : " . $Insert_query); |
|
417 | + $logger->log("Insert Counters : ".$Insert_query); |
|
418 | 418 | $db->run($Insert_Query); |
419 | - $counter_info = get_counters($accountid,$package_info['package_id'],$db,$logger); |
|
419 | + $counter_info = get_counters($accountid, $package_info['package_id'], $db, $logger); |
|
420 | 420 | |
421 | 421 | } |
422 | 422 | //print_r($counter_info); |
423 | - if ( $package_info['includedseconds'] > ($counter_info['seconds'] )) { |
|
423 | + if ($package_info['includedseconds'] > ($counter_info['seconds'])) { |
|
424 | 424 | $availableseconds = $package_info['includedseconds'] - $counter_info['seconds']; |
425 | 425 | $freeseconds = ($availableseconds >= $duration) ? $duration : $availableseconds; |
426 | 426 | $duration = ($availableseconds >= $duration) ? $duration : $availableseconds; |
427 | - $update_query = "UPDATE counters SET seconds = ".($counter_info['seconds'] + $freeseconds ). " WHERE id = ". $counter_info['id']; |
|
428 | - $logger->log("Update Counters : " . $update_query); |
|
427 | + $update_query = "UPDATE counters SET seconds = ".($counter_info['seconds'] + $freeseconds)." WHERE id = ".$counter_info['id']; |
|
428 | + $logger->log("Update Counters : ".$update_query); |
|
429 | 429 | $db->run($update_query); |
430 | - $package_array['package_id']= $package_info['package_id']; |
|
430 | + $package_array['package_id'] = $package_info['package_id']; |
|
431 | 431 | $package_array['calltype'] = "FREE"; |
432 | 432 | } |
433 | 433 | } |
@@ -436,21 +436,21 @@ discard block |
||
436 | 436 | } |
437 | 437 | |
438 | 438 | // Getting used package minutes in counter table |
439 | -function get_counters($accountid,$package_id,$db,$logger) |
|
439 | +function get_counters($accountid, $package_id, $db, $logger) |
|
440 | 440 | { |
441 | 441 | $query_counter = "SELECT id,seconds FROM counters WHERE accountid = ".$accountid." AND package_id = ".$package_id." AND status=1 LIMIT 1"; |
442 | 442 | $counter = $db->run($query_counter); |
443 | - $logger->log("GET Counters : " . $query_counter); |
|
444 | - if($counter) |
|
443 | + $logger->log("GET Counters : ".$query_counter); |
|
444 | + if ($counter) |
|
445 | 445 | return $counter[0]; |
446 | 446 | else |
447 | 447 | return ""; |
448 | 448 | } |
449 | 449 | |
450 | 450 | //Get user info |
451 | -function get_accounts($parent_id,$logger, $db) { |
|
452 | - $query = "SELECT * FROM accounts WHERE id=" . $parent_id; |
|
453 | - $logger->log("GET configuration : " . $query); |
|
451 | +function get_accounts($parent_id, $logger, $db) { |
|
452 | + $query = "SELECT * FROM accounts WHERE id=".$parent_id; |
|
453 | + $logger->log("GET configuration : ".$query); |
|
454 | 454 | $res_user = $db->run($query); |
455 | 455 | return $res_user[0]; |
456 | 456 | } |
@@ -460,7 +460,7 @@ discard block |
||
460 | 460 | { |
461 | 461 | $query = "SELECT name,value FROM system WHERE name='decimal_points' and group_title = 'global'"; |
462 | 462 | $config = $db->run($query); |
463 | - $logger->log("GET configuration : " . $query); |
|
463 | + $logger->log("GET configuration : ".$query); |
|
464 | 464 | return $config[0]; |
465 | 465 | } |
466 | 466 | |
@@ -468,16 +468,16 @@ discard block |
||
468 | 468 | /** |
469 | 469 | * @param string $field |
470 | 470 | */ |
471 | -function number_loop($destination,$field,$db) |
|
471 | +function number_loop($destination, $field, $db) |
|
472 | 472 | { |
473 | - $max_len_prefix = strlen($destination); |
|
473 | + $max_len_prefix = strlen($destination); |
|
474 | 474 | $number_prefix = '('; |
475 | - while ($max_len_prefix > 0) |
|
475 | + while ($max_len_prefix > 0) |
|
476 | 476 | { |
477 | - $number_prefix .= "$field='^".substr($destination,0,$max_len_prefix).".*' OR "; |
|
477 | + $number_prefix .= "$field='^".substr($destination, 0, $max_len_prefix).".*' OR "; |
|
478 | 478 | $max_len_prefix--; |
479 | 479 | } |
480 | - $number_prefix .= "$field='^defaultprefix.*')";//echo $number_prefix;exit; |
|
480 | + $number_prefix .= "$field='^defaultprefix.*')"; //echo $number_prefix;exit; |
|
481 | 481 | return $number_prefix; |
482 | 482 | } |
483 | 483 | |
@@ -487,6 +487,6 @@ discard block |
||
487 | 487 | */ |
488 | 488 | function convert_to_gmt($date) |
489 | 489 | { |
490 | - return gmdate('Y-m-d H:i:s', strtotime($date) ); |
|
490 | + return gmdate('Y-m-d H:i:s', strtotime($date)); |
|
491 | 491 | } |
492 | 492 | ?> |
@@ -115,6 +115,10 @@ |
||
115 | 115 | $this->process_invoice($account_value, $start_date, $end_date); |
116 | 116 | } |
117 | 117 | |
118 | + /** |
|
119 | + * @param string $start_date |
|
120 | + * @param string $end_date |
|
121 | + */ |
|
118 | 122 | function process_invoice($accountdata, $start_date, $end_date) { |
119 | 123 | //Get Invoice configuration using single query instead of multiple queries. |
120 | 124 | $invoice_conf = array(); |
@@ -24,264 +24,264 @@ |
||
24 | 24 | |
25 | 25 | class GenerateInvoice extends MX_Controller { |
26 | 26 | |
27 | - public static $global_config; |
|
27 | + public static $global_config; |
|
28 | 28 | |
29 | - function __construct() { |
|
30 | - parent::__construct(); |
|
31 | - $this->load->model("db_model"); |
|
32 | - $this->load->library("astpp/common"); |
|
33 | - $this->load->library('html2pdf'); |
|
34 | - ini_set("memory_limit", "2048M"); |
|
35 | - ini_set("max_execution_time", "259200"); |
|
36 | - $this->get_system_config(); |
|
37 | - } |
|
29 | + function __construct() { |
|
30 | + parent::__construct(); |
|
31 | + $this->load->model("db_model"); |
|
32 | + $this->load->library("astpp/common"); |
|
33 | + $this->load->library('html2pdf'); |
|
34 | + ini_set("memory_limit", "2048M"); |
|
35 | + ini_set("max_execution_time", "259200"); |
|
36 | + $this->get_system_config(); |
|
37 | + } |
|
38 | 38 | |
39 | - function get_system_config() { |
|
40 | - $query = $this->db->get("system"); |
|
41 | - $config = array(); |
|
42 | - $result = $query->result_array(); |
|
43 | - foreach ($result as $row) { |
|
44 | - $config[$row['name']] = $row['value']; |
|
45 | - } |
|
46 | - self::$global_config['system_config'] = $config; |
|
47 | - } |
|
39 | + function get_system_config() { |
|
40 | + $query = $this->db->get("system"); |
|
41 | + $config = array(); |
|
42 | + $result = $query->result_array(); |
|
43 | + foreach ($result as $row) { |
|
44 | + $config[$row['name']] = $row['value']; |
|
45 | + } |
|
46 | + self::$global_config['system_config'] = $config; |
|
47 | + } |
|
48 | 48 | |
49 | - function getInvoiceData() { |
|
50 | - $where = array("posttoexternal" => 1, "deleted" => "0", "status" => "0"); |
|
51 | - $query = $this->db_model->getSelect("*", "accounts", $where); |
|
52 | - if ($query->num_rows > 0) { |
|
53 | - $account_data = $query->result_array(); |
|
54 | - foreach ($account_data as $data_key => $account_value) { |
|
55 | - $end_date = gmdate("Y-m-d")." 23:59:59"; |
|
56 | - $account_value['sweep_id'] = (int)$account_value['sweep_id']; |
|
57 | - switch ($account_value['sweep_id']) { |
|
58 | - case 0: |
|
59 | - $start_date = $this->validate_invoice_date($account_value); |
|
60 | - if (strtotime($start_date) >= strtotime(gmdate("Y-m-d H:i:s"))) { |
|
61 | - $start_date = gmdate("Y-m-d H:i:s"); |
|
62 | - } |
|
63 | - $end_date = gmdate("Y-m-d 23:59:59", strtotime($start_date." + 1 days")); |
|
64 | - $this->Generate_Daily_invoice($account_value, $start_date, $end_date); |
|
65 | - break; |
|
66 | - case 2: |
|
67 | - if (date("d") == $account_value['invoice_day']) { |
|
68 | - $start_date = $this->validate_invoice_date($account_value); |
|
69 | - if (strtotime($start_date) >= strtotime(gmdate("Y-m-d H:i:s"))) { |
|
70 | - $start_date = gmdate("Y-m-d H:i:s"); |
|
71 | - } |
|
72 | - $end_date = gmdate("Y-m-d 23:59:59", strtotime($start_date." + 1 month")); |
|
73 | - $this->Generate_Monthly_invoice($account_value, $start_date, $end_date); |
|
74 | - } |
|
75 | - break; |
|
76 | - } |
|
77 | - } |
|
78 | - $screen_path = getcwd()."/cron"; |
|
79 | - $screen_filename = "Email_Broadcast_".strtotime('now'); |
|
80 | - $command = "cd ".$screen_path." && /usr/bin/screen -d -m -S $screen_filename php cron.php BroadcastEmail"; |
|
81 | - exec($command); |
|
82 | - } |
|
83 | - } |
|
49 | + function getInvoiceData() { |
|
50 | + $where = array("posttoexternal" => 1, "deleted" => "0", "status" => "0"); |
|
51 | + $query = $this->db_model->getSelect("*", "accounts", $where); |
|
52 | + if ($query->num_rows > 0) { |
|
53 | + $account_data = $query->result_array(); |
|
54 | + foreach ($account_data as $data_key => $account_value) { |
|
55 | + $end_date = gmdate("Y-m-d")." 23:59:59"; |
|
56 | + $account_value['sweep_id'] = (int)$account_value['sweep_id']; |
|
57 | + switch ($account_value['sweep_id']) { |
|
58 | + case 0: |
|
59 | + $start_date = $this->validate_invoice_date($account_value); |
|
60 | + if (strtotime($start_date) >= strtotime(gmdate("Y-m-d H:i:s"))) { |
|
61 | + $start_date = gmdate("Y-m-d H:i:s"); |
|
62 | + } |
|
63 | + $end_date = gmdate("Y-m-d 23:59:59", strtotime($start_date." + 1 days")); |
|
64 | + $this->Generate_Daily_invoice($account_value, $start_date, $end_date); |
|
65 | + break; |
|
66 | + case 2: |
|
67 | + if (date("d") == $account_value['invoice_day']) { |
|
68 | + $start_date = $this->validate_invoice_date($account_value); |
|
69 | + if (strtotime($start_date) >= strtotime(gmdate("Y-m-d H:i:s"))) { |
|
70 | + $start_date = gmdate("Y-m-d H:i:s"); |
|
71 | + } |
|
72 | + $end_date = gmdate("Y-m-d 23:59:59", strtotime($start_date." + 1 month")); |
|
73 | + $this->Generate_Monthly_invoice($account_value, $start_date, $end_date); |
|
74 | + } |
|
75 | + break; |
|
76 | + } |
|
77 | + } |
|
78 | + $screen_path = getcwd()."/cron"; |
|
79 | + $screen_filename = "Email_Broadcast_".strtotime('now'); |
|
80 | + $command = "cd ".$screen_path." && /usr/bin/screen -d -m -S $screen_filename php cron.php BroadcastEmail"; |
|
81 | + exec($command); |
|
82 | + } |
|
83 | + } |
|
84 | 84 | |
85 | - function validate_invoice_date($account_value) { |
|
86 | - $last_invoice_date = $this->common->get_invoice_date("to_date", $account_value["id"], $account_value['reseller_id'], "to_date"); |
|
87 | - $last_invoice_date = ($last_invoice_date) ? $last_invoice_date : $account_value['creation']; |
|
88 | - $last_invoice_date = gmdate("Y-m-d H:i:s", strtotime("+1 Second", strtotime($last_invoice_date))); |
|
89 | - return $last_invoice_date; |
|
90 | - } |
|
85 | + function validate_invoice_date($account_value) { |
|
86 | + $last_invoice_date = $this->common->get_invoice_date("to_date", $account_value["id"], $account_value['reseller_id'], "to_date"); |
|
87 | + $last_invoice_date = ($last_invoice_date) ? $last_invoice_date : $account_value['creation']; |
|
88 | + $last_invoice_date = gmdate("Y-m-d H:i:s", strtotime("+1 Second", strtotime($last_invoice_date))); |
|
89 | + return $last_invoice_date; |
|
90 | + } |
|
91 | 91 | |
92 | - /** |
|
93 | - * @param string $start_date |
|
94 | - * @param string $end_date |
|
95 | - */ |
|
96 | - function Generate_Daily_invoice($account_value, $start_date, $end_date) { |
|
97 | - // echo "INVOICE SCRIPT-------start date :".$start_date."-------end date....".$end_date; |
|
92 | + /** |
|
93 | + * @param string $start_date |
|
94 | + * @param string $end_date |
|
95 | + */ |
|
96 | + function Generate_Daily_invoice($account_value, $start_date, $end_date) { |
|
97 | + // echo "INVOICE SCRIPT-------start date :".$start_date."-------end date....".$end_date; |
|
98 | 98 | |
99 | - require_once('updateBalance.php'); |
|
100 | - $updateBalance = new updateBalance(); |
|
101 | - $updateBalance->process_subscriptions($account_value, $start_date, $end_date, TRUE); |
|
102 | - $updateBalance->process_DID_charges($account_value, $start_date, $end_date, TRUE); |
|
103 | - $this->process_invoice($account_value, $start_date, $end_date); |
|
104 | - } |
|
99 | + require_once('updateBalance.php'); |
|
100 | + $updateBalance = new updateBalance(); |
|
101 | + $updateBalance->process_subscriptions($account_value, $start_date, $end_date, TRUE); |
|
102 | + $updateBalance->process_DID_charges($account_value, $start_date, $end_date, TRUE); |
|
103 | + $this->process_invoice($account_value, $start_date, $end_date); |
|
104 | + } |
|
105 | 105 | |
106 | - /** |
|
107 | - * @param string $start_date |
|
108 | - * @param string $end_date |
|
109 | - */ |
|
110 | - function Generate_Monthly_invoice($account_value, $start_date, $end_date) { |
|
111 | - require_once('updateBalance.php'); |
|
112 | - $updateBalance = new updateBalance(); |
|
113 | - $updateBalance->process_subscriptions($account_value, $start_date, $end_date, TRUE); |
|
114 | - $updateBalance->process_DID_charges($account_value, $start_date, $end_date, TRUE); |
|
115 | - $this->process_invoice($account_value, $start_date, $end_date); |
|
116 | - } |
|
106 | + /** |
|
107 | + * @param string $start_date |
|
108 | + * @param string $end_date |
|
109 | + */ |
|
110 | + function Generate_Monthly_invoice($account_value, $start_date, $end_date) { |
|
111 | + require_once('updateBalance.php'); |
|
112 | + $updateBalance = new updateBalance(); |
|
113 | + $updateBalance->process_subscriptions($account_value, $start_date, $end_date, TRUE); |
|
114 | + $updateBalance->process_DID_charges($account_value, $start_date, $end_date, TRUE); |
|
115 | + $this->process_invoice($account_value, $start_date, $end_date); |
|
116 | + } |
|
117 | 117 | |
118 | - function process_invoice($accountdata, $start_date, $end_date) { |
|
119 | - //Get Invoice configuration using single query instead of multiple queries. |
|
120 | - $invoice_conf = array(); |
|
121 | - $reseller_id = ($accountdata['reseller_id'] == 0) ? 1 : $accountdata['reseller_id']; |
|
122 | - $where = "accountid IN ('".$reseller_id."','1')"; |
|
123 | - $this->db->select('*'); |
|
124 | - $this->db->where($where); |
|
125 | - $this->db->order_by('accountid', 'desc'); |
|
126 | - $this->db->limit(1); |
|
127 | - $invoice_conf = $this->db->get('invoice_conf'); |
|
128 | - $invoice_conf = (array)$invoice_conf->first_row(); |
|
129 | - /*******************************************************/ |
|
130 | - $last_invoice_ID = $this->common->get_invoice_date("invoiceid", "", $accountdata['reseller_id']); |
|
131 | - if ($last_invoice_ID && $last_invoice_ID > 0) { |
|
132 | - $last_invoice_ID = ($last_invoice_ID + 1); |
|
133 | - } else { |
|
134 | - $last_invoice_ID = $invoice_conf['invoice_start_from']; |
|
135 | - } |
|
136 | - $last_invoice_ID = str_pad($last_invoice_ID, (strlen($last_invoice_ID) + 4), '0', STR_PAD_LEFT); |
|
137 | - $invoice_sub_total = $this->count_invoice_data($accountdata, $start_date, $end_date); |
|
138 | - if ($invoice_sub_total > 0) { |
|
139 | - $invoiceid = $this->create_invoice($accountdata, $start_date, $end_date, $last_invoice_ID, $invoice_conf['invoice_prefix'], $invoice_conf); |
|
140 | - $this->update_cdrs_data($accountdata['id'], $invoiceid, $start_date, $end_date); |
|
141 | - $sort_order = $this->common_model->apply_invoice_taxes($invoiceid, $accountdata, $start_date); |
|
142 | - $invoice_total = $this->set_invoice_total($invoiceid, $accountdata['id']); |
|
143 | - $this->download_invoice($invoiceid, $accountdata, $invoice_conf); |
|
144 | - } else { |
|
145 | - $invoiceid = $this->create_invoice($accountdata, $start_date, $end_date, $last_invoice_ID, $invoice_conf['invoice_prefix'], $invoice_conf); |
|
146 | - $sort_order = $this->common_model->apply_invoice_taxes($invoiceid, $accountdata, $start_date); |
|
147 | - $invoice_total = $this->set_invoice_total($invoiceid, $accountdata['id']); |
|
148 | - } |
|
149 | - } |
|
118 | + function process_invoice($accountdata, $start_date, $end_date) { |
|
119 | + //Get Invoice configuration using single query instead of multiple queries. |
|
120 | + $invoice_conf = array(); |
|
121 | + $reseller_id = ($accountdata['reseller_id'] == 0) ? 1 : $accountdata['reseller_id']; |
|
122 | + $where = "accountid IN ('".$reseller_id."','1')"; |
|
123 | + $this->db->select('*'); |
|
124 | + $this->db->where($where); |
|
125 | + $this->db->order_by('accountid', 'desc'); |
|
126 | + $this->db->limit(1); |
|
127 | + $invoice_conf = $this->db->get('invoice_conf'); |
|
128 | + $invoice_conf = (array)$invoice_conf->first_row(); |
|
129 | + /*******************************************************/ |
|
130 | + $last_invoice_ID = $this->common->get_invoice_date("invoiceid", "", $accountdata['reseller_id']); |
|
131 | + if ($last_invoice_ID && $last_invoice_ID > 0) { |
|
132 | + $last_invoice_ID = ($last_invoice_ID + 1); |
|
133 | + } else { |
|
134 | + $last_invoice_ID = $invoice_conf['invoice_start_from']; |
|
135 | + } |
|
136 | + $last_invoice_ID = str_pad($last_invoice_ID, (strlen($last_invoice_ID) + 4), '0', STR_PAD_LEFT); |
|
137 | + $invoice_sub_total = $this->count_invoice_data($accountdata, $start_date, $end_date); |
|
138 | + if ($invoice_sub_total > 0) { |
|
139 | + $invoiceid = $this->create_invoice($accountdata, $start_date, $end_date, $last_invoice_ID, $invoice_conf['invoice_prefix'], $invoice_conf); |
|
140 | + $this->update_cdrs_data($accountdata['id'], $invoiceid, $start_date, $end_date); |
|
141 | + $sort_order = $this->common_model->apply_invoice_taxes($invoiceid, $accountdata, $start_date); |
|
142 | + $invoice_total = $this->set_invoice_total($invoiceid, $accountdata['id']); |
|
143 | + $this->download_invoice($invoiceid, $accountdata, $invoice_conf); |
|
144 | + } else { |
|
145 | + $invoiceid = $this->create_invoice($accountdata, $start_date, $end_date, $last_invoice_ID, $invoice_conf['invoice_prefix'], $invoice_conf); |
|
146 | + $sort_order = $this->common_model->apply_invoice_taxes($invoiceid, $accountdata, $start_date); |
|
147 | + $invoice_total = $this->set_invoice_total($invoiceid, $accountdata['id']); |
|
148 | + } |
|
149 | + } |
|
150 | 150 | |
151 | - function count_invoice_data($account, $start_date = "", $end_date = "") { |
|
152 | - $cdr_query = ""; |
|
153 | - $inv_data_query = ""; |
|
154 | - $cdr_query = "select calltype,sum(debit) as debit from cdrs where accountid = ".$account['id']; |
|
155 | - $cdr_query .= " AND callstart >='".$start_date."' AND callstart <= '".$end_date."' AND invoiceid=0 group by calltype"; |
|
151 | + function count_invoice_data($account, $start_date = "", $end_date = "") { |
|
152 | + $cdr_query = ""; |
|
153 | + $inv_data_query = ""; |
|
154 | + $cdr_query = "select calltype,sum(debit) as debit from cdrs where accountid = ".$account['id']; |
|
155 | + $cdr_query .= " AND callstart >='".$start_date."' AND callstart <= '".$end_date."' AND invoiceid=0 group by calltype"; |
|
156 | 156 | //echo $cdr_query; |
157 | - $cdr_data = $this->db->query($cdr_query); |
|
158 | - if ($cdr_data->num_rows > 0) { |
|
159 | - $cdr_data = $cdr_data->result_array(); |
|
160 | - //echo '<pre>'; print_r($cdr_data); exit; |
|
161 | - foreach ($cdr_data as $cdrvalue) { |
|
162 | - $cdrvalue['debit'] = round($cdrvalue['debit'], self::$global_config['system_config']['decimalpoints']); |
|
163 | - $tempArr = array("accountid" => $account['id'], "reseller_id" => $account['reseller_id'], "item_id" => "0", |
|
164 | - "description" => $cdrvalue['calltype']." CALLS for the period (".$start_date." to ".$end_date, "debit" => $cdrvalue['debit'], "item_type" => $cdrvalue['calltype'], "created_date" => $end_date); |
|
165 | - $this->db->insert("invoice_details", $tempArr); |
|
166 | - } |
|
167 | - } |
|
168 | - $inv_data_query = "select count(id) as count,sum(debit) as debit,sum(credit) as credit from invoice_details where accountid=".$account['id']." AND created_date >='".$start_date."' AND created_date <= '".$end_date."' AND invoiceid=0 AND item_type != 'FREECALL'"; |
|
157 | + $cdr_data = $this->db->query($cdr_query); |
|
158 | + if ($cdr_data->num_rows > 0) { |
|
159 | + $cdr_data = $cdr_data->result_array(); |
|
160 | + //echo '<pre>'; print_r($cdr_data); exit; |
|
161 | + foreach ($cdr_data as $cdrvalue) { |
|
162 | + $cdrvalue['debit'] = round($cdrvalue['debit'], self::$global_config['system_config']['decimalpoints']); |
|
163 | + $tempArr = array("accountid" => $account['id'], "reseller_id" => $account['reseller_id'], "item_id" => "0", |
|
164 | + "description" => $cdrvalue['calltype']." CALLS for the period (".$start_date." to ".$end_date, "debit" => $cdrvalue['debit'], "item_type" => $cdrvalue['calltype'], "created_date" => $end_date); |
|
165 | + $this->db->insert("invoice_details", $tempArr); |
|
166 | + } |
|
167 | + } |
|
168 | + $inv_data_query = "select count(id) as count,sum(debit) as debit,sum(credit) as credit from invoice_details where accountid=".$account['id']." AND created_date >='".$start_date."' AND created_date <= '".$end_date."' AND invoiceid=0 AND item_type != 'FREECALL'"; |
|
169 | 169 | //echo $inv_data_query; |
170 | - $invoice_data = $this->db->query($inv_data_query); |
|
171 | - if ($invoice_data->num_rows > 0) { |
|
172 | - $invoice_data = $invoice_data->result_array(); |
|
173 | - foreach ($invoice_data as $data_value) { |
|
174 | - if ($data_value['count'] > 0) { |
|
175 | - $sub_total = ($data_value['debit'] - $data_value['credit']); |
|
176 | - $sub_total = round($sub_total, self::$global_config['system_config']['decimalpoints']); |
|
177 | - return $sub_total; |
|
178 | - } |
|
179 | - } |
|
180 | - } |
|
181 | - return "0"; |
|
182 | - } |
|
170 | + $invoice_data = $this->db->query($inv_data_query); |
|
171 | + if ($invoice_data->num_rows > 0) { |
|
172 | + $invoice_data = $invoice_data->result_array(); |
|
173 | + foreach ($invoice_data as $data_value) { |
|
174 | + if ($data_value['count'] > 0) { |
|
175 | + $sub_total = ($data_value['debit'] - $data_value['credit']); |
|
176 | + $sub_total = round($sub_total, self::$global_config['system_config']['decimalpoints']); |
|
177 | + return $sub_total; |
|
178 | + } |
|
179 | + } |
|
180 | + } |
|
181 | + return "0"; |
|
182 | + } |
|
183 | 183 | |
184 | - //Change Order of arguements |
|
185 | - function update_cdrs_data($accountid, $invoiceid, $start_date = "", $end_date = "") { |
|
186 | - $inv_data_query = "update invoice_details SET invoiceid = '".$invoiceid."' where accountid=".$accountid; |
|
187 | - $inv_data_query .= " AND created_date >='".$start_date."' AND created_date <= '".$end_date."' AND invoiceid=0 AND item_type !='PAYMENT'"; |
|
188 | - $this->db->query($inv_data_query); |
|
189 | - return true; |
|
190 | - } |
|
184 | + //Change Order of arguements |
|
185 | + function update_cdrs_data($accountid, $invoiceid, $start_date = "", $end_date = "") { |
|
186 | + $inv_data_query = "update invoice_details SET invoiceid = '".$invoiceid."' where accountid=".$accountid; |
|
187 | + $inv_data_query .= " AND created_date >='".$start_date."' AND created_date <= '".$end_date."' AND invoiceid=0 AND item_type !='PAYMENT'"; |
|
188 | + $this->db->query($inv_data_query); |
|
189 | + return true; |
|
190 | + } |
|
191 | 191 | |
192 | - /** |
|
193 | - * @param string $last_invoice_ID |
|
194 | - */ |
|
195 | - function create_invoice($account, $from_date, $to_date, $last_invoice_ID, $INVprefix, $invoiceconf) { |
|
196 | - //$due_date = gmdate("Y-m-d H:i:s",strtotime($to_date." +".$invoiceconf['interval']." days")); |
|
197 | - if ($invoiceconf['interval'] > 0) { |
|
198 | - $due_date = gmdate("Y-m-d H:i:s", strtotime(gmdate("Y-m-d H:i:s")." +".$invoiceconf['interval']." days")); |
|
199 | - } else { |
|
200 | - $due_date = gmdate("Y-m-d H:i:s", strtotime(gmdate("Y-m-d H:i:s")." +7 days")); |
|
201 | - } |
|
202 | - // echo "due daye-------".$due_date.'----------'.$to_date.'------------> Invoice interval'.$invoiceconf['interval']; |
|
203 | - $balance = ($account['credit_limit'] - $account['balance']); |
|
204 | - $automatic_flag = self::$global_config['system_config']['automatic_invoice']; |
|
192 | + /** |
|
193 | + * @param string $last_invoice_ID |
|
194 | + */ |
|
195 | + function create_invoice($account, $from_date, $to_date, $last_invoice_ID, $INVprefix, $invoiceconf) { |
|
196 | + //$due_date = gmdate("Y-m-d H:i:s",strtotime($to_date." +".$invoiceconf['interval']." days")); |
|
197 | + if ($invoiceconf['interval'] > 0) { |
|
198 | + $due_date = gmdate("Y-m-d H:i:s", strtotime(gmdate("Y-m-d H:i:s")." +".$invoiceconf['interval']." days")); |
|
199 | + } else { |
|
200 | + $due_date = gmdate("Y-m-d H:i:s", strtotime(gmdate("Y-m-d H:i:s")." +7 days")); |
|
201 | + } |
|
202 | + // echo "due daye-------".$due_date.'----------'.$to_date.'------------> Invoice interval'.$invoiceconf['interval']; |
|
203 | + $balance = ($account['credit_limit'] - $account['balance']); |
|
204 | + $automatic_flag = self::$global_config['system_config']['automatic_invoice']; |
|
205 | 205 | if ($automatic_flag == 1) { |
206 | - $invoice_data = array("accountid" => $account['id'], "invoice_prefix" => $INVprefix, "invoiceid" => $last_invoice_ID, "reseller_id" => |
|
207 | - $account['reseller_id'], "invoice_date" => gmdate("Y-m-d H:i:s"), "from_date" => $from_date, "to_date" => $to_date, "due_date" => $due_date, "status" => 1, "amount" => "0.00", "balance" => $balance); |
|
206 | + $invoice_data = array("accountid" => $account['id'], "invoice_prefix" => $INVprefix, "invoiceid" => $last_invoice_ID, "reseller_id" => |
|
207 | + $account['reseller_id'], "invoice_date" => gmdate("Y-m-d H:i:s"), "from_date" => $from_date, "to_date" => $to_date, "due_date" => $due_date, "status" => 1, "amount" => "0.00", "balance" => $balance); |
|
208 | 208 | } else { |
209 | - $invoice_data = array("accountid" => $account['id'], "invoice_prefix" => $INVprefix, "invoiceid" => $last_invoice_ID, "reseller_id" => |
|
210 | - $account['reseller_id'], "invoice_date" => gmdate("Y-m-d H:i:s"), "from_date" => $from_date, "to_date" => $to_date, "due_date" => $due_date, "status" => 1, "amount" => "0.00", "balance" => $balance, "confirm" => 1); |
|
209 | + $invoice_data = array("accountid" => $account['id'], "invoice_prefix" => $INVprefix, "invoiceid" => $last_invoice_ID, "reseller_id" => |
|
210 | + $account['reseller_id'], "invoice_date" => gmdate("Y-m-d H:i:s"), "from_date" => $from_date, "to_date" => $to_date, "due_date" => $due_date, "status" => 1, "amount" => "0.00", "balance" => $balance, "confirm" => 1); |
|
211 | 211 | } |
212 | - // echo "<pre>"; print_r($invoice_data); exit; |
|
213 | - $this->db->insert("invoices", $invoice_data); |
|
214 | - $invoiceid = $this->db->insert_id(); |
|
212 | + // echo "<pre>"; print_r($invoice_data); exit; |
|
213 | + $this->db->insert("invoices", $invoice_data); |
|
214 | + $invoiceid = $this->db->insert_id(); |
|
215 | 215 | if ($automatic_flag == 0) { |
216 | - $this->download_invoice($invoiceid, $account, $invoiceconf); |
|
216 | + $this->download_invoice($invoiceid, $account, $invoiceconf); |
|
217 | + } |
|
218 | + return $invoiceid; |
|
217 | 219 | } |
218 | - return $invoiceid; |
|
219 | - } |
|
220 | 220 | |
221 | - function set_invoice_total($invoiceid, $accountid) { |
|
222 | - $query = $this->db_model->getSelect("SUM(debit) as total", "invoice_details", array("invoiceid" => $invoiceid, "item_type <>" => "FREECALL")); |
|
223 | - $query = $query->result_array(); |
|
224 | - $sub_total = $query["0"]["total"]; |
|
225 | - $updateArr = array("amount" => $sub_total); |
|
226 | - $this->db->where(array("id" => $invoiceid)); |
|
227 | - $this->db->update("invoices", $updateArr); |
|
221 | + function set_invoice_total($invoiceid, $accountid) { |
|
222 | + $query = $this->db_model->getSelect("SUM(debit) as total", "invoice_details", array("invoiceid" => $invoiceid, "item_type <>" => "FREECALL")); |
|
223 | + $query = $query->result_array(); |
|
224 | + $sub_total = $query["0"]["total"]; |
|
225 | + $updateArr = array("amount" => $sub_total); |
|
226 | + $this->db->where(array("id" => $invoiceid)); |
|
227 | + $this->db->update("invoices", $updateArr); |
|
228 | 228 | |
229 | - $updateArr = array("balance" => "0.00"); |
|
230 | - $this->db->where(array("id" => $accountid)); |
|
231 | - $this->db->update("accounts", $updateArr); |
|
229 | + $updateArr = array("balance" => "0.00"); |
|
230 | + $this->db->where(array("id" => $accountid)); |
|
231 | + $this->db->update("accounts", $updateArr); |
|
232 | 232 | |
233 | - return true; |
|
234 | - } |
|
233 | + return true; |
|
234 | + } |
|
235 | 235 | |
236 | - function download_invoice($invoiceid, $accountdata, $invoice_conf) { |
|
237 | - $invoicedata = $this->db_model->getSelect("*", "invoices", array("id" => $invoiceid)); |
|
238 | - $invoicedata = $invoicedata->result_array(); |
|
239 | - $invoicedata = $invoicedata[0]; |
|
240 | - $FilePath = FCPATH."invoices/".$accountdata["id"].'/'.$invoicedata['invoice_prefix']."".$invoicedata['invoiceid']."_invoice.pdf"; |
|
241 | - $Filenm = $invoicedata['invoice_prefix']."_".$invoicedata['invoiceid']."_invoice.pdf"; |
|
242 | - $this->common->get_invoice_template($invoicedata, $accountdata, false); |
|
243 | - if ($invoice_conf['invoice_notification']) { |
|
244 | - $this->send_email_notification($FilePath, $Filenm, $accountdata, $invoice_conf, $invoicedata); |
|
245 | - } |
|
246 | - } |
|
236 | + function download_invoice($invoiceid, $accountdata, $invoice_conf) { |
|
237 | + $invoicedata = $this->db_model->getSelect("*", "invoices", array("id" => $invoiceid)); |
|
238 | + $invoicedata = $invoicedata->result_array(); |
|
239 | + $invoicedata = $invoicedata[0]; |
|
240 | + $FilePath = FCPATH."invoices/".$accountdata["id"].'/'.$invoicedata['invoice_prefix']."".$invoicedata['invoiceid']."_invoice.pdf"; |
|
241 | + $Filenm = $invoicedata['invoice_prefix']."_".$invoicedata['invoiceid']."_invoice.pdf"; |
|
242 | + $this->common->get_invoice_template($invoicedata, $accountdata, false); |
|
243 | + if ($invoice_conf['invoice_notification']) { |
|
244 | + $this->send_email_notification($FilePath, $Filenm, $accountdata, $invoice_conf, $invoicedata); |
|
245 | + } |
|
246 | + } |
|
247 | 247 | |
248 | - /** |
|
249 | - * @param string $FilePath |
|
250 | - * @param string $Filenm |
|
251 | - */ |
|
252 | - function send_email_notification($FilePath, $Filenm, $AccountData, $invoice_conf, $invData) { |
|
253 | - $TemplateData = array(); |
|
254 | - $where = array('name' => 'email_new_invoice'); |
|
255 | - $EmailTemplate = $this->db_model->getSelect("*", "default_templates", $where); |
|
256 | - foreach ($EmailTemplate->result_array() as $TemplateVal) { |
|
257 | - $TemplateData = $TemplateVal; |
|
258 | - $TemplateData['subject'] = str_replace('#NAME#', $AccountData['first_name']." ".$AccountData['last_name'], $TemplateData['subject']); |
|
259 | - $TemplateData['subject'] = str_replace('#INVOICE_NUMBER#', $invData['invoice_prefix'].$invData['invoiceid'], $TemplateData['subject']); |
|
260 | - $TemplateData['template'] = str_replace('#NAME#', $AccountData['first_name']." ".$AccountData['last_name'], $TemplateData['template']); |
|
261 | - $TemplateData['template'] = str_replace('#INVOICE_NUMBER#', $invData['invoice_prefix'].$invData['invoiceid'], $TemplateData['template']); |
|
262 | - $TemplateData['template'] = str_replace('#AMOUNT#', $invData['amount'], $TemplateData['template']); |
|
248 | + /** |
|
249 | + * @param string $FilePath |
|
250 | + * @param string $Filenm |
|
251 | + */ |
|
252 | + function send_email_notification($FilePath, $Filenm, $AccountData, $invoice_conf, $invData) { |
|
253 | + $TemplateData = array(); |
|
254 | + $where = array('name' => 'email_new_invoice'); |
|
255 | + $EmailTemplate = $this->db_model->getSelect("*", "default_templates", $where); |
|
256 | + foreach ($EmailTemplate->result_array() as $TemplateVal) { |
|
257 | + $TemplateData = $TemplateVal; |
|
258 | + $TemplateData['subject'] = str_replace('#NAME#', $AccountData['first_name']." ".$AccountData['last_name'], $TemplateData['subject']); |
|
259 | + $TemplateData['subject'] = str_replace('#INVOICE_NUMBER#', $invData['invoice_prefix'].$invData['invoiceid'], $TemplateData['subject']); |
|
260 | + $TemplateData['template'] = str_replace('#NAME#', $AccountData['first_name']." ".$AccountData['last_name'], $TemplateData['template']); |
|
261 | + $TemplateData['template'] = str_replace('#INVOICE_NUMBER#', $invData['invoice_prefix'].$invData['invoiceid'], $TemplateData['template']); |
|
262 | + $TemplateData['template'] = str_replace('#AMOUNT#', $invData['amount'], $TemplateData['template']); |
|
263 | 263 | |
264 | - $TemplateData['template'] = str_replace("#COMPANY_EMAIL#", $invoice_conf['emailaddress'], $TemplateData['template']); |
|
265 | - $TemplateData['template'] = str_replace("#COMPANY_NAME#", $invoice_conf['company_name'], $TemplateData['template']); |
|
266 | - $TemplateData['template'] = str_replace("#COMPANY_WEBSITE#", $invoice_conf['website'], $TemplateData['template']); |
|
267 | - $TemplateData['template'] = str_replace("#INVOICE_DATE#", $invData['invoice_date'], $TemplateData['template']); |
|
268 | - $TemplateData['template'] = str_replace("#DUE_DATE#", $invData['due_date'], $TemplateData['template']); |
|
269 | - } |
|
270 | - $dir_path = getcwd()."/attachments/"; |
|
271 | - $path = $dir_path.$Filenm; |
|
272 | - $command = "cp ".$FilePath." ".$path; |
|
273 | - exec($command); |
|
274 | - $email_array = array('accountid' => $AccountData['id'], |
|
275 | - 'subject' => $TemplateData['subject'], |
|
276 | - 'body' => $TemplateData['template'], |
|
277 | - 'from' => $invoice_conf['emailaddress'], |
|
278 | - 'to' => $AccountData['email'], |
|
279 | - 'status' => "1", |
|
280 | - 'attachment' => $Filenm, |
|
281 | - 'template' => ''); |
|
282 | - //echo "<pre>"; print_r($TemplateData); exit; |
|
283 | - $this->db->insert("mail_details", $email_array); |
|
284 | - } |
|
264 | + $TemplateData['template'] = str_replace("#COMPANY_EMAIL#", $invoice_conf['emailaddress'], $TemplateData['template']); |
|
265 | + $TemplateData['template'] = str_replace("#COMPANY_NAME#", $invoice_conf['company_name'], $TemplateData['template']); |
|
266 | + $TemplateData['template'] = str_replace("#COMPANY_WEBSITE#", $invoice_conf['website'], $TemplateData['template']); |
|
267 | + $TemplateData['template'] = str_replace("#INVOICE_DATE#", $invData['invoice_date'], $TemplateData['template']); |
|
268 | + $TemplateData['template'] = str_replace("#DUE_DATE#", $invData['due_date'], $TemplateData['template']); |
|
269 | + } |
|
270 | + $dir_path = getcwd()."/attachments/"; |
|
271 | + $path = $dir_path.$Filenm; |
|
272 | + $command = "cp ".$FilePath." ".$path; |
|
273 | + exec($command); |
|
274 | + $email_array = array('accountid' => $AccountData['id'], |
|
275 | + 'subject' => $TemplateData['subject'], |
|
276 | + 'body' => $TemplateData['template'], |
|
277 | + 'from' => $invoice_conf['emailaddress'], |
|
278 | + 'to' => $AccountData['email'], |
|
279 | + 'status' => "1", |
|
280 | + 'attachment' => $Filenm, |
|
281 | + 'template' => ''); |
|
282 | + //echo "<pre>"; print_r($TemplateData); exit; |
|
283 | + $this->db->insert("mail_details", $email_array); |
|
284 | + } |
|
285 | 285 | |
286 | 286 | } |
287 | 287 |