mirror of
https://github.com/fusionpbx/fusionpbx.git
synced 2026-02-22 19:06:37 +00:00
fix odd billing currency error when using different currencies
This commit is contained in:
@@ -218,14 +218,15 @@
|
||||
//billing information
|
||||
if (file_exists($_SERVER['DOCUMENT_ROOT'].PROJECT_PATH."/app/billing/app_config.php")){
|
||||
$db2 = new database;
|
||||
$lcr_currency = 'USD';
|
||||
$destination_number = check_str(urldecode($row->caller_profile->destination_number));
|
||||
$destination_number_serie = number_series($destination_number);
|
||||
$lcr_currency = (strlen($_SESSION['billing']['currency']['text'])?$_SESSION['billing']['currency']['text']:'USD');
|
||||
|
||||
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 connect_increment, talk_increment FROM v_lcr WHERE carrier_uuid IS NULL AND v_lcr.lcr_direction = '".check_str(urldecode($xml->variables->call_direction))."' AND digits IN ($destination_number_serie) ORDER BY digits DESC, rate ASC limit 1";
|
||||
$sql_user_rate = "SELECT currency, connect_increment, talk_increment FROM v_lcr WHERE carrier_uuid IS NULL AND v_lcr.lcr_direction = '".check_str(urldecode($xml->variables->call_direction))."' AND digits IN ($destination_number_serie) ORDER BY digits DESC, rate ASC limit 1";
|
||||
if ($debug) {
|
||||
echo "sql_rate: $sql_rate\n";
|
||||
echo "sql_user_rate: $sql_user_rate\n";
|
||||
@@ -235,6 +236,9 @@
|
||||
$db2->result = $db2->execute();
|
||||
// print_r($db2->result);
|
||||
$lcr_currency = (strlen($db2->result[0]['currency'])?check_str($db2->result[0]['currency']):'USD');
|
||||
$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);
|
||||
@@ -246,12 +250,17 @@
|
||||
$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":
|
||||
$sql_user_rate = "SELECT v_lcr.rate, v_lcr.connect_increment, v_lcr.talk_increment, v_lcr.currency FROM v_lcr WHERE v_lcr.carrier_uuid IS NULL AND v_lcr.enabled='true' AND v_lcr.lcr_direction='inbound' AND v_lcr.digits IN (".number_series($n).") ORDER BY digits DESC, rate ASC, date_start DESC LIMIT 1";
|
||||
$caller_number = check_str(urldecode($row->caller_profile->caller_id_number));
|
||||
$caller_number_serie = number_series($caller_number);
|
||||
$sql_user_rate = "SELECT v_lcr.currency, v_lcr.rate, v_lcr.connect_increment, v_lcr.talk_increment, v_lcr.currency FROM v_lcr WHERE v_lcr.carrier_uuid IS NULL AND v_lcr.enabled='true' AND v_lcr.lcr_direction='inbound' AND v_lcr.digits IN (".$caller_number_serie.") ORDER BY digits DESC, rate ASC, date_start DESC LIMIT 1";
|
||||
if ($debug) {
|
||||
echo "sql_user_rate: $sql_user_rate\n";
|
||||
}
|
||||
@@ -260,10 +269,15 @@
|
||||
$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']):'USD');
|
||||
$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']))?strlen($db2->result[0]['rate']):0;
|
||||
$lcr_user_first_increment = (strlen($db2->result[0]['connect_increment']))?strlen($db2->result[0]['connect_increment']):60;
|
||||
$lcr_user_second_increment = (strlen($db2->result[0]['talk_increment']))?strlen($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;
|
||||
@@ -271,7 +285,9 @@
|
||||
unset($db2->result);
|
||||
break;
|
||||
case "local":
|
||||
$sql_user_rate = "SELECT v_lcr.rate, v_lcr.connect_increment, v_lcr.talk_increment, v_lcr.currency FROM v_lcr WHERE v_lcr.carrier_uuid IS NULL AND v_lcr.enabled='true' AND v_lcr.lcr_direction='local' AND v_lcr.digits IN (".number_series($n).") ORDER BY digits DESC, rate ASC, date_start DESC LIMIT 1";
|
||||
$destination_number = check_str(urldecode($xml->variables->lcr_query_digits));
|
||||
$destination_number_serie = number_series($destination_number);
|
||||
$sql_user_rate = "SELECT v_lcr.currency, v_lcr.rate, v_lcr.connect_increment, v_lcr.talk_increment, v_lcr.currency FROM v_lcr WHERE v_lcr.carrier_uuid IS NULL AND v_lcr.enabled='true' AND v_lcr.lcr_direction='local' AND v_lcr.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";
|
||||
}
|
||||
@@ -280,10 +296,16 @@
|
||||
$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']):'USD');
|
||||
$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']))?strlen($$db2->result[0]['rate']):0;
|
||||
$lcr_user_first_increment = (strlen($db2->result[0]['connect_increment']))?strlen($db2->result[0]['connect_increment']):60;
|
||||
$lcr_user_second_increment = (strlen($db2->result[0]['talk_increment']))?strlen($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;
|
||||
@@ -297,7 +319,7 @@
|
||||
$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 is in original LCR currency, needs to be converted
|
||||
// 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);
|
||||
@@ -320,9 +342,10 @@
|
||||
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 "lc $lcr_currency\n";
|
||||
echo "ac $actual_currency\n";
|
||||
echo "bc $billing_currency\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);
|
||||
@@ -341,7 +364,7 @@
|
||||
}
|
||||
|
||||
// Lets convert rate from lcr_currency to billing_currency
|
||||
$billing_call_sell = currency_convert($call_sell, $billing_currency, $actual_currency);
|
||||
$billing_call_sell = currency_convert($call_sell, $billing_currency, $lcr_user_currency);
|
||||
|
||||
if ($debug) {
|
||||
echo "bcs: $billing_call_sell $billing_currency\n";
|
||||
|
||||
Reference in New Issue
Block a user