Yep digilab, you are right. We have made some test and the 1st leg billing works a little better. There is still a problem though. Let's say that the calling rate of one of your callback clients is 10¢/min, and let's assume that this client only has 5¢ left in his account. The callback daemon should not call him back, right? (not enough balance) Unfortunately, currently, it does call the customer back. So if the customer olds the line for 1 minute or less, you will end up with a negative balance of -5¢. I have track down this bug to the function ...
Code:
function rate_engine_calcultimeout (&$A2B, $credit, $K=0, $calling_party = ''){
...
$this -> ratecard_obj[$K]['timeout']=0;
/*
Comment from Abdoulaye Siby
This following "if" statement used to verify the minimum credit to call can be improved.
This mininum credit should be calculated based on the destination, and the minimum billing block.
*/
if ($credit < $A2B->agiconfig['min_credit_2call']) return "ERROR CT1"; //NO ENOUGH CREDIT TO CALL THIS NUMBER
...
}
... located in the file Class.RateEngine.php
As for the call duration of the call, it will have to might be fixed by take the 2 kinds of calculation : progressive rate
and flat rate
I believe that the following code in the rate_engine_calcultimeout() function in Class.RateEngine.php is responsible for bug we are trying to fix.
Code:
// 2 KIND OF CALCULATION : PROGRESSIVE RATE & FLAT RATE
// IF FLAT RATE
if (empty($chargea) || $chargea==0 || empty($timechargea) || $timechargea==0 ){
/*
Comment from Abdoulaye Siby
In all-callback or cid-callback mode, the number of minutes for
the call should be calculated according to the rate of both legs of the call.
*/
$num_min = $credit/$rateinitial;
/*
This should look like :
$num_min = $credit/($rateinitial + $first_leg_rate);
*/
if ($this -> debug_st) echo "num_min:$num_min ($credit/$rateinitial)\n";
$num_sec = intval($num_min * 60);
if ($this -> debug_st) echo "num_sec:$num_sec \n";
if ($billingblock > 0) {
$mod_sec = $num_sec % $billingblock;
$num_sec=$num_sec-$mod_sec;
}
$TIMEOUT = $num_sec;
// IF PROGRESSIVE RATE
}else{
...
}
I am trying to figure out a way to calculate $first_leg_rate without breaking the code. The main problem I am experiencing is that when you call either of the following functions, they will simply return 1 or 0 (true or false) for success or failure. They will, on the other hand, change the $RateEngine object accordingly. This makes it a bit difficult to reuse the same functions with other parameters without disturbing the smooth flow of a2billing.
Code:
function rate_engine_findrates (&$A2B, $phonenumber, $tariffgroupid) ...
function rate_engine_all_calcultimeout (&$A2B, $credit) ...
I am bit stuck. Any ideas?