From 1c6dc4c05037cd0ccba39785fa0616e0c08f54ee Mon Sep 17 00:00:00 2001 From: luis daniel lucio quiroz Date: Wed, 25 Jun 2014 23:58:47 +0000 Subject: [PATCH] multi-currency support to xml_cdr --- app/xml_cdr/v_xml_cdr_import.php | 18 +++--------------- app/xml_cdr/xml_cdr.php | 32 +++++++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 16 deletions(-) diff --git a/app/xml_cdr/v_xml_cdr_import.php b/app/xml_cdr/v_xml_cdr_import.php index cd6a41ca8b..6efb78242e 100644 --- a/app/xml_cdr/v_xml_cdr_import.php +++ b/app/xml_cdr/v_xml_cdr_import.php @@ -57,22 +57,10 @@ //set pdo attribute that enables exception handling $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); -// some maths for costs -function call_cost($rate, $i1, $i2, $t){ - $c = (double)0.0; - if ($t > 0){ - $c = (double)$i1 * (double)$rate / (double)60.0; - - if ($t > $i1){ - $t -= $i1; - $times = intval($t/$i2) + (($t % $i2)?1:0); - $c += (double)$times * (double)$i2 * (double)$rate / (double)60.0; - } - } - - return $c; -} + if (file_exists($_SERVER['DOCUMENT_ROOT'].PROJECT_PATH."/app/billings/app_config.php")){ + require_once "app/billings/functions.php"; + } //define the process_xml_cdr function function process_xml_cdr($db, $leg, $xml_string) { //set global variable diff --git a/app/xml_cdr/xml_cdr.php b/app/xml_cdr/xml_cdr.php index 57351b4251..6f1219edf7 100644 --- a/app/xml_cdr/xml_cdr.php +++ b/app/xml_cdr/xml_cdr.php @@ -310,7 +310,19 @@ else { echo " \n"; } echo "\n"; + if (file_exists($_SERVER['DOCUMENT_ROOT'].PROJECT_PATH."/app/billings/app_config.php")){ + require_once "app/billings/functions.php"; + require_once "resources/classes/database.php"; + $database = new database; + $database->table = "v_billings"; + $tv = (strlen($_GET["accountcode"])?$_GET["accountcode"]:$_SESSION[domain_name]); + $database->sql = "SELECT currency from v_billings WHERE type_value='$tv'"; + $database->result = $database->execute(); + $currency = (strlen($database->result[0]['currency'])?$database->result[0]['currency']:'USD'); + unset($database->sql); + unset($database->result); + } if ($result_count > 0) { foreach($result as $row) { $tmp_year = date("Y", strtotime($row['start_stamp'])); @@ -435,7 +447,25 @@ else { echo " ".gmdate("G:i:s", $seconds)."\n"; if (file_exists($_SERVER['DOCUMENT_ROOT'].PROJECT_PATH."/app/billings/app_config.php")){ - echo " ".$row['call_sell']."\n"; + + $price = $row['call_sell']; + $lcr_direction = (strlen($row['direction'])?$row['direction']:"outbound"); + + $n = $row['destination_number']; + + if ($lcr_direction == "inbound"){ + $n = $row['caller_id_number']; + } + $database->table = "v_lcr"; + $database->sql = "SELECT currency FROM v_lcr WHERE v_lcr.carrier_uuid= '' AND v_lcr.lcr_direction='$lcr_direction' AND v_lcr.digits IN (".number_series($n).") ORDER BY digits DESC, rate ASC, date_start DESC LIMIT 1"; + $database->result = $database->execute(); + //print "
"; print_r($database->result); print "[".$database->result[0]['currency']."]"; print "
"; + + $billed_currency = ((is_string($database->result[0]['currency']) && strlen($database->result[0]['currency']))?$database->result[0]['currency']:'USD'); //billed currency + unset($database->sql); + unset($database->result); + $price = currency_convert($price, $currency, $billed_currency); + echo " ".number_format($price,6)." $billed_currency\n"; } if (permission_exists("xml_cdr_pdd")) { echo " ".number_format($row['pdd_ms']/1000,2)."s\n";