diff --git a/freeswitch/fs/cdr.php b/freeswitch/fs/cdr.php
index 14cb7103b..152c8de65 100755
--- a/freeswitch/fs/cdr.php
+++ b/freeswitch/fs/cdr.php
@@ -20,7 +20,7 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see .
// ##############################################################################
-define ( 'ENVIRONMENT', 'production' );
+define ( 'ENVIRONMENT', 'development' );
if (defined ( 'ENVIRONMENT' )) {
switch (ENVIRONMENT) {
case 'development' :
@@ -70,10 +70,10 @@
// process_cdr($data,$db,$logger,$decimal_points);
if ($data ['variables'] ['calltype'] == "CALLINGCARD") {
if (isset ( $data ['variables'] ['originating_leg_uuid'] )) {
- process_cdr ( $data, $db, $logger, $decimal_points );
+ process_cdr ( $data, $db, $logger, $decimal_points,$config );
}
} else {
- process_cdr ( $data, $db, $logger, $decimal_points );
+ process_cdr ( $data, $db, $logger, $decimal_points,$config );
}
}
diff --git a/freeswitch/fs/lib/astpp.cdr.php b/freeswitch/fs/lib/astpp.cdr.php
index 850fc0954..26dac9b2f 100755
--- a/freeswitch/fs/lib/astpp.cdr.php
+++ b/freeswitch/fs/lib/astpp.cdr.php
@@ -22,7 +22,7 @@
// ##############################################################################
// Process CDR
-function process_cdr($data, $db, $logger, $decimal_points) {
+function process_cdr($data, $db, $logger, $decimal_points, $config) {
// $logger->log(print_r($data,true));//exit;
// Initializing variables
@@ -126,12 +126,12 @@ function process_cdr($data, $db, $logger, $decimal_points) {
// Update customer balance
if ($debit > 0 && $dataVariable ['calltype'] != "FREE") {
- update_balance ( $accountid, $debit, 0, $logger, $db );
+ update_balance ( $accountid, $debit, 0, $logger, $db, $config );
}
// Update parent or provider balance
if ($parent_cost > 0) {
- update_balance ( $termination_rate ['PROVIDER'], ($parent_cost * - 1), 3, $logger, $db );
+ update_balance ( $termination_rate ['PROVIDER'], ($parent_cost * - 1), 3, $logger, $db, $config );
}
// Resellers CDR entry
@@ -171,13 +171,13 @@ function process_cdr($data, $db, $logger, $decimal_points) {
$receiver_parentid = $receiver_carddata ['reseller_id'];
// For additional cdr entry of receiver
- 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 );
+ 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, $config );
$flag_parent = true;
$dataVariable ['uuid'] = $dataVariable ['uuid'] . $dataVariable ['calltype'] . "_" . $receiver_parentid;
// Insert parent reseller cdr
- insert_parent_data ( $dataVariable, $actual_calltype, $receiver_parentid, $origination_rate, $actual_duration, $provider_cost, $flag_parent, $logger, $db, $decimal_points );
+ insert_parent_data ( $dataVariable, $actual_calltype, $receiver_parentid, $origination_rate, $actual_duration, $provider_cost, $flag_parent, $logger, $db, $decimal_points, $config );
$logger->log ( "*********************** EXTRA ENTRY SECTION FOR BILLING END *************" );
}
// *****************************************************************************************
@@ -190,7 +190,7 @@ function process_cdr($data, $db, $logger, $decimal_points) {
* @param string $provider_cost
* @param boolean $flag_parent
*/
-function insert_parent_data($dataVariable, $actual_calltype, $parentid, $origination_rate, $actual_duration, $provider_cost, $flag_parent, $logger, $db, $decimal_points) {
+function insert_parent_data($dataVariable, $actual_calltype, $parentid, $origination_rate, $actual_duration, $provider_cost, $flag_parent, $logger, $db, $decimal_points, $config) {
while ( $parentid > 0 ) {
$logger->log ( "*************** IN PARENT DATA SECTION ********" );
$dataVariable ['calltype'] = $actual_calltype;
@@ -225,7 +225,7 @@ function insert_parent_data($dataVariable, $actual_calltype, $parentid, $origina
if (isset ( $dataVariable ['receiver_accid'] ) && $dataVariable ['receiver_accid'] != "" && $flag_parent == true) {
$logger->log ( "********* IN RESELLER FOR RECEIVER ENTRY START ******" );
$flag_parent = true;
- insert_extra_receiver_entry ( $dataVariable, $origination_rate, $termination_rate, $account_type, $actual_duration, $provider_cost, $parentid, $flag_parent, $accountid, $logger, $db, $decimal_points );
+ insert_extra_receiver_entry ( $dataVariable, $origination_rate, $termination_rate, $account_type, $actual_duration, $provider_cost, $parentid, $flag_parent, $accountid, $logger, $db, $decimal_points, $config );
$logger->log ( "********* IN RESELLER FOR RECEIVER ENTRY END ******" );
} else {
@@ -238,7 +238,7 @@ function insert_parent_data($dataVariable, $actual_calltype, $parentid, $origina
// Update reseller balance
if ($debit > 0 && $dataVariable ['calltype'] != "FREE") {
- update_balance ( $accountid, $debit, 0, $logger, $db );
+ update_balance ( $accountid, $debit, 0, $logger, $db, $config );
}
}
}
@@ -249,7 +249,7 @@ function insert_parent_data($dataVariable, $actual_calltype, $parentid, $origina
*
* @param boolean $flag_parent
*/
-function insert_extra_receiver_entry($dataVariable, $origination_rate, $termination_rate, $account_type, $actual_duration, $provider_cost, $parentid, $flag_parent, $accountid, $logger, $db, $decimal_points) {
+function insert_extra_receiver_entry($dataVariable, $origination_rate, $termination_rate, $account_type, $actual_duration, $provider_cost, $parentid, $flag_parent, $accountid, $logger, $db, $decimal_points, $config) {
$localVariable = $dataVariable;
$localVariable ['call_direction'] = "inbound";
$localVariable ['uuid'] = $localVariable ['uuid'] . $dataVariable ['calltype'] . "_" . $accountid;
@@ -285,8 +285,9 @@ function insert_extra_receiver_entry($dataVariable, $origination_rate, $terminat
$logger->log ( $query );
$db->run ( $query );
+ //if ($debit > 0 && ($dataVariable ['calltype'] != "FREE" && $dataVariable ['calltype'] != "LOCAL")) {
if ($debit > 0 && ($dataVariable ['calltype'] != "FREE" && $dataVariable ['calltype'] != "LOCAL")) {
- update_balance ( $accountid, $debit, 0, $logger, $db );
+ update_balance ( $accountid, $debit, 0, $logger, $db, $config );
}
return true;
}
@@ -333,9 +334,10 @@ function get_reseller_cdr_string($dataVariable, $accountid, $account_type, $actu
*
* @param integer $entity_id
*/
-function update_balance($user_id, $amount, $entity_id, $logger, $db) {
+function update_balance($user_id, $amount, $entity_id, $logger, $db, $config) {
/*If not realtime billing */
- if ($this->config ['realtime_billing'] == '1') {
+
+ if ($config ['realtime_billing'] == '1') {
$math_sign = ($entity_id == 0 || $entity_id == 1) ? '-' : '+';
$query = "UPDATE accounts SET balance=IF(posttoexternal=1,balance+" . $amount . ",balance-" . $amount . ") WHERE id=" . $user_id;
$logger->log ( "Balance update : " . $query );
@@ -414,13 +416,13 @@ function package_calculation($destination_number, $pricelist_id, $duration, $cal
$custom_destination = number_loop ( $destination_number, "patterns", $db );
$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";
-
+ $logger->log ( "Package query : " . $query );
$package_info = $db->run ( $query );
if ($package_info) {
$package_info = $package_info [0];
-
- if (($package_info ['applicable_for'] == "0" && $call_direction == "outbound") || ($package_info ['applicable_for'] == "1" && $call_direction == "inbound") || ($package_info ['applicable_for'] == "2")) {
-
+
+ if (($package_info ['applicable_for'] == "0" && $call_direction == "outbound") || ($package_info ['applicable_for'] == "1" && $call_direction == "inbound") || ($package_info ['applicable_for'] == "2")) {
+
$counter_info = get_counters ( $accountid, $package_info ['package_id'], $db, $logger );
if (! $counter_info) {
@@ -466,7 +468,7 @@ function get_accounts($parent_id, $logger, $db) {
// Get configuration
function load_configuration($logger) {
- $query = "SELECT name,value FROM system WHERE name='decimal_points' and group_title = 'global'";
+ $query = "SELECT name,value FROM system WHERE name IN ('decimal_points','realtime_billing') and group_title = 'global'";
$config = $db->run ( $query );
$logger->log ( "GET configuration : " . $query );
return $config [0];
diff --git a/freeswitch/fs/lib/astpp.functions.php b/freeswitch/fs/lib/astpp.functions.php
deleted file mode 100755
index 386c89777..000000000
--- a/freeswitch/fs/lib/astpp.functions.php
+++ /dev/null
@@ -1,143 +0,0 @@
-
-// ASTPP Version 3.0 and above
-// License https://www.gnu.org/licenses/agpl-3.0.html
-//
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU Affero General Public License as
-// published by the Free Software Foundation, either version 3 of the
-// License, or (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Affero General Public License for more details.
-//
-// You should have received a copy of the GNU Affero General Public License
-// along with this program. If not, see .
-// ##############################################################################
-
-// Parse user and rates array which we got in cdr xml
-function parse_rates_array($xml_rate, $constant_array, $logger) {
- $rates_array = array ();
-
- // decode string using urldecode
- $xml_rate = urldecode ( $xml_rate );
- $xml_rate_array = explode ( "||", $xml_rate );
-
- foreach ( $xml_rate_array as $rate_key => $rate_value ) {
- $rates_array = explode ( "|", $rate_value );
-
- $user_id_param = $rates_array [count ( $rates_array ) - 1];
- $user_id = (substr ( $user_id_param, 0, 3 ) == 'UID') ? substr ( $user_id_param, 3 ) : 0;
-
- foreach ( $rates_array as $key => $value ) {
- $rates_array_info [$user_id] [$constant_array [substr ( $value, 0, 3 )]] = substr ( $value, 3 );
- }
- }
- return $rates_array_info;
-}
-
-// Process package
-function process_package($xml_cdr, $user_id, $rates_array, $logger, $db) {
- $duration = $xml_cdr->variables->duration;
- $xml_cdr->variables->package_id = 0;
- $flag = false;
- if ($duration > 0 && $xml_cdr->variables->call_direction == 'outbound') {
- $destination_number = $xml_cdr->variables->effective_destination_number;
-
- $number_len = strlen ( $destination_number );
- $number_loop_str = '(';
- while ( $number_len > 0 ) {
- $number_loop_str .= " code='" . substr ( $destination_number, 0, $number_len ) . "' OR ";
- $number_len -= 1;
- }
- $number_loop_str .= " code='--')";
-
- $query = "SELECT A.id as package_id,code,includedseconds FROM tbl_package AS A ,tbl_package_codes AS B WHERE " . $number_loop_str . " AND B.package_id = A.id AND A.ratecard_id=" . $rates_array ['ratecard_id'] . " AND A.status=0 AND A.is_del=0 ORDER BY length(code) DESC";
- $logger->log ( "Package Query : " . $query );
- $res_package = $db->run ( $query );
-
- foreach ( $res_package as $res_package_key => $package_info ) {
- if (isset ( $package_info ['package_id'] )) {
- $query = "SELECT SUM(used_seconds) as used_seconds FROM tbl_package_usage WHERE code=" . $package_info ['code'] . " AND package_id=" . $package_info ['package_id'] . " AND user_id=" . $user_id;
- $logger->log ( "Package usage Query : " . $query );
- $res_pkg_usg = $db->run ( $query );
- $package_usage_info = $res_pkg_usg [0];
-
- $used_seconds = (isset ( $package_usage_info ['used_seconds'] )) ? $package_usage_info ['used_seconds'] : 0;
-
- $logger->log ( "Included seconds : " . $package_info ['includedseconds'] . ", Used seconds : " . $used_seconds );
- if ($package_info ['includedseconds'] > $used_seconds) {
- $remaining_seconds = $package_info ['includedseconds'] - ($duration + $used_seconds);
- if ($remaining_seconds > 0) {
- $dud_sec = $duration;
- $duration = 0;
- } else {
- $dud_sec = $duration - abs ( $remaining_seconds );
- $duration = abs ( $remaining_seconds );
- }
- $flag = true;
- $xml_cdr->variables->package_id = $package_info ['package_id'];
-
- $query = "INSERT INTO tbl_package_usage (package_id,user_id,code,used_seconds) VALUES (" . $package_info ['package_id'] . "," . $user_id . ",'" . $package_info ['code'] . "'," . $dud_sec . ") ON DUPLICATE KEY UPDATE used_seconds=used_seconds+" . $dud_sec;
- $logger->log ( "Package Usage Query : " . $query );
- $db->run ( $query );
-
- break;
- }
- }
- }
- }
- return array (
- $duration,
- $flag
- );
-}
-
-// Process user/vendor cdr
-function do_cdr_process($xml_cdr, $debit, $cost, $vendor_cost, $rates_array, $parent_id = 0, $parent_rates, $carrier_rates_array, $logger, $db) {
- $query_string = "'" . $xml_cdr->variables->uuid . "','" . $xml_cdr->variables->user_id . "','" . $xml_cdr->variables->entity_id . "','" . urldecode ( $xml_cdr->variables->effective_caller_id_name ) . "','" . $xml_cdr->variables->effective_caller_id_number . "','" . $xml_cdr->variables->effective_destination_number . "'," . $xml_cdr->variables->duration . ",'" . $xml_cdr->variables->carrier_id . "','" . $xml_cdr->callflow [0]->caller_profile->originatee->originatee_caller_profile->network_addr . "','" . $xml_cdr->variables->sip_contact_host . "','" . $xml_cdr->variables->hangup_cause . "','" . urldecode ( $xml_cdr->variables->start_stamp ) . "'," . $debit . "," . $cost . ",'" . $xml_cdr->variables->vendor_id . "'," . $vendor_cost . "," . $rates_array ['ratecard_id'] . "," . $xml_cdr->variables->package_id . ",'" . $rates_array ['code'] . "','" . $rates_array ['destination'] . "','" . $rates_array ['cost'] . "','" . $parent_id . "','" . @$parent_rates ['code'] . "','" . @$parent_rates ['destination'] . "','" . @$parent_rates ['cost'] . "','" . @$carrier_rates_array ['code'] . "','" . @$carrier_rates_array ['destination'] . "','" . @$carrier_rates_array ['cost'] . "','" . $xml_cdr->variables->call_direction . "','" . urldecode ( $xml_cdr->variables->profile_start_stamp ) . "','" . urldecode ( $xml_cdr->variables->answer_stamp ) . "','" . urldecode ( $xml_cdr->variables->bridge_stamp ) . "','" . urldecode ( $xml_cdr->variables->progress_stamp ) . "','" . urldecode ( $xml_cdr->variables->progress_media_stamp ) . "','" . urldecode ( $xml_cdr->variables->end_stamp ) . "'," . $xml_cdr->variables->billmsec . "," . $xml_cdr->variables->answermsec . "," . $xml_cdr->variables->waitmsec . "," . $xml_cdr->variables->progress_mediamsec . "," . $xml_cdr->variables->flow_billmsec;
-
- $query = "INSERT INTO tbl_cdrs (uniqueid,user_id,entity_id,callerid_name,callerid_number,dstnum,duration,carrier_id,carrierip,callerip,disposition,start_stamp,debit,cost,vendor_id,vendor_cost,ratecard_id,package_id,rate_code,rate_code_destination,rate_cost,parent_id,parent_code,parent_code_destination,parent_cost,carrier_code,carrier_code_destination ,carrier_cost,call_direction,profile_start_stamp,answer_stamp,bridge_stamp,progress_stamp,progress_media_stamp,end_stamp,billmsec,answermsec,waitmsec,progress_mediamsec,flow_billmsec) values ($query_string)";
-
- $logger->log ( "CDR Query : " . $query );
- $db->run ( $query );
-}
-
-// Process reseller cdr
-function do_reseller_cdr_process($xml_cdr, $debit, $cost, $rates_array, $parent_id = 0, $parent_rates, $logger, $db) {
- $query_string = "'" . $xml_cdr->variables->uuid . "','" . $xml_cdr->variables->user_id . "','" . urldecode ( $xml_cdr->variables->effective_caller_id_name ) . "','" . $xml_cdr->variables->effective_caller_id_number . "','" . $xml_cdr->variables->effective_destination_number . "'," . $xml_cdr->variables->duration . ",'" . $xml_cdr->variables->hangup_cause . "','" . urldecode ( $xml_cdr->variables->start_stamp ) . "'," . $debit . "," . $cost . "," . $rates_array ['ratecard_id'] . "," . $xml_cdr->variables->package_id . ",'" . $rates_array ['code'] . "','" . $rates_array ['destination'] . "','" . $rates_array ['cost'] . "','" . $parent_id . "','" . @$parent_rates ['code'] . "','" . @$parent_rates ['destination'] . "','" . @$parent_rates ['cost'] . "','" . $xml_cdr->variables->call_direction . "'";
-
- $query = "INSERT INTO tbl_cdrs_reseller (uniqueid,reseller_id,callerid_name,callerid_number,dstnum,duration,disposition,start_stamp,debit,cost,ratecard_id,package_id,rate_code,rate_code_destination,rate_cost,parent_id,parent_code,parent_code_destination,parent_cost,call_direction) values ($query_string)";
-
- $logger->log ( "CDR Query : " . $query );
- $db->run ( $query );
-}
-
-// Update user balance
-/**
- *
- * @param integer $entity_id
- */
-function update_balance($user_id, $amount, $entity_id, $logger, $db) {
- if ($amount > 0) {
- $math_sign = ($entity_id == 0 || $entity_id == 1) ? '-' : '+';
- $query = "UPDATE tbl_users SET credit=credit$math_sign" . $amount . " WHERE id=" . $user_id;
- $logger->log ( "Balance update : " . $query );
- $db->run ( $query );
- }
-}
-
-// Get user info
-function get_user_info($parent_id, $db) {
- $query = "SELECT * FROM tbl_users WHERE id=" . $parent_id;
- $res_user = $db->run ( $query );
- return $res_user [0];
-}
-
-?>