I have discovered that up till now, my customers have actually been charged for the 300 free seconds in package offer. Very dangerous bug in the Class.RateEngine.php
Around line 814, cost of call is calculated :
Code:
$cost -= ($callduration/60) * $rateinitial;
So if a customer has $1 balance with a 300 free seconds package offer and dials a destination costing 0.14USD/min ( 60 seconds billing increment), his $callduration calculated by Class.RateEngine.php will be 420 seconds ( 7 minutes ).
So his $cost will be - 3.15 USD. Now when his balance is updated at the end of the call, he will end up with a balance of -2.15USD.
This is wrong.
We need to subtract the 300 free seconds from $callduration before calculating the cost of the call. So i added the following if statement to do that.
Code:
if ($this -> freetimetocall_used <= $callduration)
{
$callduration = $callduration - $this->freetimetocall_used;
}
$cost -= ($callduration/60) * $rateinitial;
Below are logs i captured showing the above scenario :
a2billing.php,1: file:Class.RateEngine.php - line:1274 - uniqueid:1344958630.134 - DIAL SIP/###/##########|60|HL(420000:60000:00000)
a2billing.php,1: file:Class.RateEngine.php - line:1157 - uniqueid:1344958630.134 - [TRUNK STATUS UPDATE : UPDATE cc_trunk SET inuse=inuse-1 WHERE id_trunk='8']
a2billing.php,1: file:Class.RateEngine.php - line:1422 - uniqueid:1344958630.134 - -> dialstatus : ANSWER, answered time is 420
a2billing.php,1:
a2billing.php,1: file:Class.RateEngine.php - line:1426 - uniqueid:1344958630.134 - [USEDRATECARD=0]
a2billing.php,1: file:Class.RateEngine.php - line:959 - uniqueid:1344958630.134 - :[sessiontime:420 - id_cc_package_offer:2 - package2apply:Array]
a2billing.php,1:
a2billing.php,1:
a2billing.php,1: file:Class.RateEngine.php - line:736 - uniqueid:1344958630.134 - [CC_RATE_ENGINE_CALCULCOST: K=0 - CALLDURATION:420 - freetimetocall_used=300 - freetimetocall_left=300]
a2billing.php,1: file:Class.RateEngine.php - line:814 - uniqueid:1344958630.134 - [TEMP - CC_RATE_ENGINE_CALCULCOST: 1. COST: -3.15]:[ (420/60) * 0.45 ]
a2billing.php,1: file:Class.RateEngine.php - line:899 - uniqueid:1344958630.134 - [CC_RATE_ENGINE_CALCULCOST: K=0 - BUYCOST:-0.63 - SELLING COST:-3.15]
a2billing.php,1: file:Class.RateEngine.php - line:1000 - uniqueid:1344958630.134 - :[ID_CARD_PACKAGE_OFFER CREATED : 1259]:['620', '2', '300']
a2billing.php,1:
a2billing.php,1:
a2billing.php,1:
a2billing.php,1:
a2billing.php,1: file:Class.RateEngine.php - line:1042 - uniqueid:1344958630.134 - [CC_RATE_ENGINE_UPDATESYSTEM: usedratecard K=0 - (sessiontime=420 :: dialstatus=ANSWER :: buycost=0.63 :: cost=-3.15 : signe_cc_call=+: signe=-)]
a2billing.php,1: file:Class.RateEngine.php - line:1107 - uniqueid:1344958630.134 - [CC_asterisk_stop : SQL: DONE : result=1]
a2billing.php,1: file:Class.RateEngine.php - line:1108 - uniqueid:1344958630.134 - [CC_asterisk_stop : SQL: INSERT INTO cc_call (uniqueid, sessionid, card_id, nasipaddress, starttime, sessiontime, real_sessiontime, calledstation, terminatecauseid, stoptime, sessionbill, id_tariffgroup, id_tariffplan, id_ratecard, id_trunk, src, sipiax, buycost, id_card_package_offer, dnid, destination) VALUES ('1344958630.134', 'SIP/didforsale_Config1B-00000086', '620', '', SUBDATE(CURRENT_TIMESTAMP, INTERVAL 420 SECOND) , '420', '420', '##########', 1, now() , '+3.15', '1', '44', '1448122', '8', '##########', '0', '0.63', '1259', '##########', '#####')]
a2billing.php,1: file:Class.RateEngine.php - line:1132 - uniqueid:1344958630.134 - [CC_asterisk_stop 1.2: SQL: UPDATE cc_card SET credit= credit-3.15 , lastuse=now(), firstusedate=now(), nbused=nbused+1 WHERE username='7635008738']
a2billing.php,1: file:Class.RateEngine.php - line:1137 - uniqueid:1344958630.134 - UPDATE cc_trunk SET secondusedreal = secondusedreal + 420 WHERE id_trunk='8'
a2billing.php,1: file:Class.RateEngine.php - line:1141 - uniqueid:1344958630.134 - UPDATE cc_tariffplan SET secondusedreal = secondusedreal + 420 WHERE id='44'
a2billing.php,1: file:a2billing.php - line:588 - uniqueid:1344958630.134 - [a2billing account stop]
a2billing.php,1: file:a2billing.php - line:193 - uniqueid:1344958630.134 - [CHANNEL STATUS : 6 = Line is up]
a2billing.php,1: [CREDIT : -2.15][CREDIT MIN_CREDIT_2CALL : 0]
a2billing.php,1: file:a2billing.php - line:396 - uniqueid:2344958630.134 - TARIFF ID -> 1
-- Playing 'prepaid-no-enough-credit-stop' (escape_digits=#) (sample_offset 0)
a2billing.php,1: file:a2billing.php - line:403 - uniqueid:2344958630.134 - [STOP STREAM FILE prepaid-no-enough-credit-stop]
a2billing.php,1: file:a2billing.php - line:427 - uniqueid:2344958630.134 - [SET MAIL REMINDER - NOT ENOUGH CREDIT]
-- <SIP/######>AGI Script a2billing.php completed, returning 4
== Spawn extension (call-a2billing, #######, 3) exited non-zero on 'SIP/#####