asterisk2billing.org
http://forum.asterisk2billing.org/

RateEngine Bug + Fix
http://forum.asterisk2billing.org/viewtopic.php?f=18&t=4028
Page 1 of 1

Author:  alosmart [ Thu Jul 24, 2008 2:47 am ]
Post subject:  Bug in min_duration_2bill + fix

Hi All,

I noticed that when a call is less than initialblock it is still billed at the billingblock rate :
for example,
Initialblock = 60
billingblock = 120

call duration = 32

this call should be billed as Initialblock = 60 , but now with the curent code it is billed at 120 = 2 minutes.

The problem is in Class.RateEngine.php file in this section:
inside the function rate_engine_calculcost(....
Code:
// 2 KIND OF CALCULATION : PROGRESSIVE RATE & FLAT RATE
// IF FLAT RATE
if (empty($chargea) || $chargea==0 || empty($timechargea) || $timechargea==0 ){
         
if ($billingblock>0) {   //  <<------- This is where the error is
$mod_sec = $callduration % $billingblock; 
if ($mod_sec>0) $callduration += ($billingblock - $mod_sec);
}
$cost -= ($callduration/60) * $rateinitial;



To fix it you only need to change this line
Code:
if ($billingblock>0) {
to
Code:
if (($callduration > $initblock) && ($billingblock > 0)) {


By adding this line you make sure that you do not add any increment to the calls that have durations less then or equal to initialblock.


same thing applies to
Code:
// CALCULATION BUYRATE COST
$buyratecallduration = $callduration;
      
$buyratecost =0;
if ($buyratecallduration<$buyrateinitblock) $buyratecallduration=$buyrateinitblock;
if ($buyrateincrement > 0) {   // <---------------ERROR in here
$mod_sec = $buyratecallduration % $buyrateincrement;
if ($mod_sec>0) $buyratecallduration += ($buyrateincrement - $mod_sec);
}
      
$buyratecost -= ($buyratecallduration/60) * $buyrate;


to fix it
change this
Code:
if ($buyrateincrement > 0) {

to
Code:
if (($buyratecallduration>$buyrateinitblock) && ($buyrateincrement > 0) {

this
Thank you,

Added after 1 hours 51 minutes:

Hi,

Today I have been looking at the code of ClassRateEngine.php and debugging.

I found that if you have this case:
min_duration_2bill = 10 ( or any other number > 0 )
( if there was a problem or the call is less then 10 seconds I don't want to bill the client)

BUT I want to know how much it is costing me, and when i generate a report in order to compare my buycost with my provider's bill, I want them to match.

After fixing the bug, you will have a much more accurate Profit estimate
- assuming the rest of the code that I havn't checked yet is good ;)

The curent code does not bill the client and sets the buycost to zero.

I prefer to keep my buycost as it is and not zero, this way I know how much it is costing me to keep that min_duration_2bill > 0

Look for this code

Code:
$buycost = 0;
if ($doibill==0 || $sessiontime < $A2B->agiconfig['min_duration_2bill'])  $cost = 0;      
  else{
   $cost = $this -> lastcost;
   $buycost = abs($this -> lastbuycost);
}


and change the first line to
Code:
$buycost = abs($this -> lastbuycost);



thanks,

Author:  jmartin [ Sun Nov 02, 2008 9:25 am ]
Post subject: 

Good Information, I currently have minimum duration and billing increment all set to zero. I wanted to change them to 6 seconds to save some money. Can someone please explain to me fully how they're related and exactly what they're supposed to do?

Is it a problem now that they're set to 0 on the buyers side and sellers side. Thanks.

Page 1 of 1 All times are UTC
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/