From 0597179a1c5d6e68896eb6387807eb9dc9cb2aa0 Mon Sep 17 00:00:00 2001 From: FusionPBX Date: Tue, 3 Sep 2019 08:53:11 -0600 Subject: [PATCH] Remove the 3rd party billing system A better way to integrate 3rd party billing is is to create own CDR import code to fit their needs. --- app/xml_cdr/v_xml_cdr_import.php | 176 +------------------------------ 1 file changed, 1 insertion(+), 175 deletions(-) diff --git a/app/xml_cdr/v_xml_cdr_import.php b/app/xml_cdr/v_xml_cdr_import.php index fafa431c66..0d614b4838 100644 --- a/app/xml_cdr/v_xml_cdr_import.php +++ b/app/xml_cdr/v_xml_cdr_import.php @@ -68,11 +68,7 @@ //set pdo attribute that enables exception handling $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); -//add rating functions if the billing is installed - if (file_exists($_SERVER["PROJECT_ROOT"]."/app/billing/app_config.php")){ - require_once "app/billing/resources/functions/rating.php"; - } - +//define accept_b_leg function function accept_b_leg($xml){ // if no filter set allow all for backward compatibility if(empty($_SESSION['cdr']['b_leg'])){ @@ -439,176 +435,6 @@ } } - //billing information - if (file_exists($_SERVER["PROJECT_ROOT"]."/app/billing/app_config.php")){ - $db2 = new database; - $lcr_currency = (strlen($_SESSION['billing']['currency']['text'])?$_SESSION['billing']['currency']['text']:'USD'); - $accountcode = (strlen(urldecode($xml->variables->accountcode)))?check_str(urldecode($xml->variables->accountcode)):$domain_name; - - switch(check_str(urldecode($xml->variables->call_direction))){ - case "outbound": - $destination_number = check_str(urldecode($xml->variables->lcr_query_digits)); - $destination_number_serie = number_series($destination_number); - $database->fields['carrier_name'] = check_str(urldecode($xml->variables->lcr_carrier)); - $sql_rate ="SELECT v_lcr.connect_increment, v_lcr.talk_increment, v_lcr.currency FROM v_lcr, v_carriers WHERE v_carriers.carrier_name = '".$xml->variables->lcr_carrier."' AND v_lcr.rate=".$xml->variables->lcr_rate." AND v_lcr.lcr_direction = '".check_str(urldecode($xml->variables->call_direction))."' AND digits IN ($destination_number_serie) AND v_lcr.carrier_uuid = v_carriers.carrier_uuid ORDER BY digits DESC, rate ASC limit 1"; - $sql_user_rate = "SELECT v_lcr.currency, connect_increment, talk_increment FROM v_lcr JOIN v_billings ON v_billings.type_value='$accountcode' WHERE v_lcr.carrier_uuid IS NULL AND v_lcr.lcr_direction = '".check_str(urldecode($xml->variables->call_direction))."' AND v_lcr.lcr_profile=v_billings.lcr_profile AND NOW() >= v_lcr.date_start AND NOW() < v_lcr.date_end AND digits IN ($destination_number_serie) ORDER BY digits DESC, rate ASC, date_start DESC LIMIT 1"; - if ($debug) { - echo "sql_rate: $sql_rate\n"; - echo "sql_user_rate: $sql_user_rate\n"; - } - - $db2->sql = $sql_rate; - $db2->result = $db2->execute(); - //print_r($db2->result); - $lcr_currency = (strlen($db2->result[0]['currency'])?check_str($db2->result[0]['currency']): - (strlen($_SESSION['billing']['currency']['text'])?$_SESSION['billing']['currency']['text']:'USD') - ); - $lcr_rate = (strlen($xml->variables->lcr_rate)?$xml->variables->lcr_rate:0); - $lcr_first_increment = (strlen($db2->result[0]['connect_increment'])?check_str($db2->result[0]['connect_increment']):60); - $lcr_second_increment = (strlen($db2->result[0]['talk_increment'])?check_str($db2->result[0]['talk_increment']):60); - unset($db2->sql); - unset($db2->result); - - $db2->sql = $sql_user_rate; - $db2->result = $db2->execute(); - $lcr_user_rate = (strlen($xml->variables->lcr_user_rate)?$xml->variables->lcr_user_rate:0.01); - $lcr_user_first_increment = (strlen($db2->result[0]['connect_increment'])?check_str($db2->result[0]['connect_increment']):60); - $lcr_user_second_increment = (strlen($db2->result[0]['talk_increment'])?check_str($db2->result[0]['talk_increment']):60); - $lcr_user_currency = (strlen($db2->result[0]['currency'])?check_str($db2->result[0]['currency']): - (strlen($_SESSION['billing']['currency']['text'])?$_SESSION['billing']['currency']['text']:'USD') - ); - - unset($db2->sql); - unset($db2->result); - break; - case "inbound": - $callee_number = check_str(urldecode($row->caller_profile->destination_number)); - $callee_number_serie = number_series($callee_number); - $sql_user_rate = "SELECT v_lcr.currency, v_lcr.rate, v_lcr.connect_increment, v_lcr.talk_increment FROM v_lcr JOIN v_billings ON v_billings.type_value='$accountcode' WHERE v_lcr.carrier_uuid IS NULL AND v_lcr.lcr_direction = '".check_str(urldecode($xml->variables->call_direction))."' AND v_lcr.lcr_profile=v_billings.lcr_profile AND NOW() >= v_lcr.date_start AND NOW() < v_lcr.date_end AND digits IN ($callee_number_serie) ORDER BY digits DESC, rate ASC, date_start DESC LIMIT 1"; - - if ($debug) { - echo "sql_user_rate: $sql_user_rate\n"; - } - - $db2->sql = $sql_user_rate; - $db2->result = $db2->execute(); - - // If selling rate is found, then we fill with data, otherwise rate will be 0 - $lcr_currency = (strlen($db2->result[0]['currency'])?check_str($db2->result[0]['currency']): - (strlen($_SESSION['billing']['currency']['text'])?$_SESSION['billing']['currency']['text']:'USD') - ); - $lcr_user_rate = (strlen($db2->result[0]['rate']))?($db2->result[0]['rate']):0; - $lcr_user_first_increment = (strlen($db2->result[0]['connect_increment']))?($db2->result[0]['connect_increment']):60; - $lcr_user_second_increment = (strlen($db2->result[0]['talk_increment']))?($db2->result[0]['talk_increment']):60; - $lcr_user_currency = (strlen($db2->result[0]['currency'])?check_str($db2->result[0]['currency']): - (strlen($_SESSION['billing']['currency']['text'])?$_SESSION['billing']['currency']['text']:'USD') - ); - - // Actually, there is no way to detect what carrier is the calling comming from using current information - $lcr_rate = 0; $lcr_first_increment = 0; $lcr_second_increment = 0; - unset($db2->sql); - unset($db2->result); - break; - case "local": - $destination_number = check_str(urldecode($xml->variables->lcr_query_digits)); - $destination_number_serie = number_series($destination_number); - $sql_user_rate = "SELECT v_lcr.currency, connect_increment, talk_increment FROM v_lcr JOIN v_billings ON v_billings.type_value='$accountcode' WHERE v_lcr.carrier_uuid IS NULL AND v_lcr.lcr_direction = '".check_str(urldecode($xml->variables->call_direction))."' AND v_lcr.lcr_profile=v_billings.lcr_profile AND NOW() >= v_lcr.date_start AND NOW() < v_lcr.date_end AND digits IN ($destination_number_serie) ORDER BY digits DESC, rate ASC, date_start DESC LIMIT 1"; - if ($debug) { - echo "sql_user_rate: $sql_user_rate\n"; - } - - $db2->sql = $sql_user_rate; - $db2->result = $db2->execute(); - - // If selling rate is found, then we fill with data, otherwise rate will be 0 - $lcr_currency = (strlen($db2->result[0]['currency'])?check_str($db2->result[0]['currency']): - (strlen($_SESSION['billing']['currency']['text'])?$_SESSION['billing']['currency']['text']:'USD') - ); - $lcr_user_rate = (strlen($db2->result[0]['rate']))?($$db2->result[0]['rate']):0; - $lcr_user_first_increment = (strlen($db2->result[0]['connect_increment']))?($db2->result[0]['connect_increment']):60; - $lcr_user_second_increment = (strlen($db2->result[0]['talk_increment']))?($db2->result[0]['talk_increment']):60; - $lcr_user_currency = (strlen($db2->result[0]['currency'])?check_str($db2->result[0]['currency']): - (strlen($_SESSION['billing']['currency']['text'])?$_SESSION['billing']['currency']['text']:'USD') - ); - - // Actually, internal calls have 0 cost - $lcr_rate = 0; $lcr_first_increment = 0; $lcr_second_increment = 0; - unset($db2->sql); - unset($db2->result); - break; - } - - // Please note that we save values using LCR currency, but we discount balance in billing currency - - $time = check_str(urldecode($xml->variables->billsec)); - $call_buy = call_cost($lcr_rate, $lcr_first_increment, $lcr_second_increment, $time); - $call_sell = call_cost($lcr_user_rate, $lcr_user_first_increment, $lcr_user_second_increment, $time); - // Costs/Sell call are in original LCR currency, they need to be converted - - $database->fields['call_buy'] = check_str($call_buy); - $database->fields['call_sell'] = check_str($call_sell); - - $db2->table = "v_xml_cdr"; - - $db2->sql = "SELECT currency FROM v_billings WHERE type_value='$accountcode' LIMIT 1"; - $db2->result = $db2->execute(); - - $actual_currency = (strlen($lcr_currency)? - $lcr_currency: - (strlen($_SESSION['billing']['currency']['text'])?$_SESSION['billing']['currency']['text']:'USD') - ); - $billing_currency = (strlen($db2->result[0]['currency'])?$db2->result[0]['currency']:$default_currency); - - if ($debug) { - echo "sql: " . $db2->sql . "\n"; - echo "c ".$database->fields['carrier_name']."\n"; - echo "t $time\n"; - echo "b r:$lcr_rate - $lcr_first_increment - $lcr_first_increment = $call_buy\n"; - echo "s r:$lcr_user_rate - $lcr_user_first_increment - $lcr_user_second_increment = $call_sell\n"; - echo "lcr currency $lcr_currency\n"; - echo "actual currency $actual_currency\n"; - echo "user currency $lcr_user_currency\n"; - echo "billing currency $billing_currency\n"; - } - - unset($database->sql); - unset($database->result); - - $sql_balance = "SELECT balance, old_balance FROM v_billings WHERE type_value='".check_str(urldecode($xml->variables->accountcode))."'"; - $db2->sql = $sql_balance; - $db2->result = $db2->execute(); - $balance = $db2->result[0]['balance']; - $old_balance = $db2->result[0]['old_balance']; - - if ($debug) { - echo "sql_balance: $sql_balance\n"; - echo "bal: $balance\n"; - echo "old bal: $old_balance\n"; - } - - // Lets convert rate from lcr_currency to billing_currency - $billing_call_sell = currency_convert($call_sell, $billing_currency, $lcr_user_currency); - - if ($debug) { - echo "bcs: $billing_call_sell $billing_currency\n"; - } - - // Remember that old_balance is using billing_currency - $updated_balance = (double)$old_balance - (double)$billing_call_sell; - unset($db2->sql); - unset($db2->result); - - $sql_update_balance = "UPDATE v_billings SET balance=$updated_balance, old_balance=$updated_balance WHERE type_value='".check_str(urldecode($xml->variables->accountcode))."'"; - if ($debug) { - echo "sql_update_balance: $sql_update_balance\n"; - } - $db2->sql = $sql_update_balance; - $db2->result = $db2->execute(); - unset($db2->sql); - unset($db2->result); - - } - //insert xml_cdr into the db if (strlen($start_stamp) > 0) { $database->add();