Support A2Billing :

provided by Star2Billing S.L.

Support A2Billing :
It is currently Sun Dec 09, 2018 8:15 pm
Predictive Dialer


All times are UTC




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: A2billing with LRN routing
PostPosted: Thu May 01, 2014 5:56 am 
Offline

Joined: Tue Apr 22, 2014 3:54 pm
Posts: 4
Is anyone out there working on adding LRN routing to the A2Billing Rate Engine? I have modified the Class.RateEngine.php file to do LRN routing. My solution was to create two call plans, one for intrastate and one for interstate. The interstate and intrastate must have sequential IDs with the interstate route having and ID of +1 of the intrastate plan. The customer is setup with the intrastate plan. The modification to the Rate Engine does an LRN dip and checks the calls LRN and JURISDICTION. The Rate Engine will return rates based on the LRN value. If the JUSRISDICTION is "INTERSTATE" the the call plan ID is incremented by 1 before the database lookup. A real solution would probably expand the Rate Table to include both interstate and intrastate pricing. My solution doubles the number of entries in the rate table. I would also think a real solution would provide some short term caching of the LRN information.

I am not a PHP programmer and know very little about the structure of A2Billing. It would be nice if someone could integrate this code into the A2Billing master and provide a more robust solution:).

--- Class.RateEngine.php 2014-04-23 18:31:08.000000000 -0400
+++ Class.RateEngine.php.new 2014-04-25 15:11:21.965342552 -0400
@@ -115,25 +115,56 @@
if (strlen($A2B->dnid) >= 1) $mydnid = $A2B->dnid;
if (strlen($A2B->CallerID) >= 1) $mycallerid = $A2B->CallerID;

+ // Check BulkVS LRN for NANPA numbers
+ // NANPA Pattern 1NXXNXXXXXX
+ $nanpa_pattern = '/^1[2-9][0-9][0-9][2-9][0-9][0-9][0-9][0-9][0-9][0-9]$/';
+ $API_Key = "Your API Key";
+ $tariffgroupid2 = $tariffgroupid;
+ $phonenumber2 = $phonenumber;
+ if (preg_match($nanpa_pattern, $phonenumber)) {
+ if ($A2B->dnid == "") $ani=$A2B->CallerID;
+ else $ani = "1" . $A2B->config["callback"]['callerid'];
+ $command="wget -qO- 'http://lrn.bulkcnam.com/?id=" . $API_Key . "&did=" . $phonenumber . "&ani=" . $ani . "&format=xml'";
+ exec($command, $LRN);
+ $xml = simplexml_load_string($LRN[0]);
+ if (preg_match($nanpa_pattern,$xml->LRN)) {
+ $phonenumber2 = $xml->LRN;
+ if ($xml->JURISDICTION == "INTERSTATE") {
+ $tariffgroupid2 = $tariffgroupid + 1;
+ }
+ }
+ if ($this->webui) {
+ $A2B->debug(DEBUG, $agi, __FILE__, __LINE__, "[rate-engine: LRN=$xml->LRN]");
+ $A2B->debug(DEBUG, $agi, __FILE__, __LINE__, "[rate-engine: OCN=$xml->OCN]");
+ $A2B->debug(DEBUG, $agi, __FILE__, __LINE__, "[rate-engine: LATA=$xml->LATA]");
+ $A2B->debug(DEBUG, $agi, __FILE__, __LINE__, "[rate-engine: CITY=$xml->CITY]");
+ $A2B->debug(DEBUG, $agi, __FILE__, __LINE__, "[rate-engine: RC=$xml->RC]");
+ $A2B->debug(DEBUG, $agi, __FILE__, __LINE__, "[rate-engine: STATE=$xml->STATE]");
+ $A2B->debug(DEBUG, $agi, __FILE__, __LINE__, "[rate-engine: JURISDICTION=$xml->JURISDICTION]");
+ $A2B->debug(DEBUG, $agi, __FILE__, __LINE__, "[rate-engine: LOCAL=$xml->LOCAL]");
+ $A2B->debug(DEBUG, $agi, __FILE__, __LINE__, "[rate-engine: LEC=$xml->LEC]");
+ }
+ }
+
if ($this->webui) $A2B->debug(DEBUG, $agi, __FILE__, __LINE__, "[CC_asterisk_rate-engine - CALLERID : " . $A2B->CallerID . "]", 0);

- $DNID_SUB_QUERY = "AND 0 = (SELECT COUNT(dnidprefix) FROM cc_tariffgroup_plan RIGHT JOIN cc_tariffplan ON cc_tariffgroup_plan.idtariffplan = cc_tariffplan.id WHERE dnidprefix = SUBSTRING('$mydnid', 1, length(dnidprefix)) AND idtariffgroup = $tariffgroupid) ";
+ $DNID_SUB_QUERY = "AND 0 = (SELECT COUNT(dnidprefix) FROM cc_tariffgroup_plan RIGHT JOIN cc_tariffplan ON cc_tariffgroup_plan.idtariffplan = cc_tariffplan.id WHERE dnidprefix = SUBSTRING('$mydnid', 1, length(dnidprefix)) AND idtariffgroup = $tariffgroupid2) ";

- $CID_SUB_QUERY = "AND 0 = (SELECT count(calleridprefix) FROM cc_tariffgroup_plan RIGHT JOIN cc_tariffplan ON cc_tariffgroup_plan.idtariffplan = cc_tariffplan.id WHERE calleridprefix = SUBSTRING('$mycallerid', 1, length(calleridprefix)) AND idtariffgroup = $tariffgroupid)";
+ $CID_SUB_QUERY = "AND 0 = (SELECT count(calleridprefix) FROM cc_tariffgroup_plan RIGHT JOIN cc_tariffplan ON cc_tariffgroup_plan.idtariffplan = cc_tariffplan.id WHERE calleridprefix = SUBSTRING('$mycallerid', 1, length(calleridprefix)) AND idtariffgroup = $tariffgroupid2)";

// $prefixclause to allow good DB servers to use an index rather than sequential scan
// justification at viewtopic.php?p=9620#9620
- $max_len_prefix = min(strlen($phonenumber), 15); // don't match more than 15 digits (the most I have on my side is 8 digit prefixes)
+ $max_len_prefix = min(strlen($phonenumber2), 15); // don't match more than 15 digits (the most I have on my side is 8 digit prefixes)
$prefixclause = '(';
while ($max_len_prefix > 0) {
- $prefixclause .= "dialprefix='" . substr($phonenumber, 0, $max_len_prefix) . "' OR ";
+ $prefixclause .= "dialprefix='" . substr($phonenumber2, 0, $max_len_prefix) . "' OR ";
$max_len_prefix--;
}
$prefixclause .= "dialprefix='defaultprefix')";

// match Asterisk/POSIX regex prefixes, rewrite the Asterisk '_XZN.' characters to
// POSIX equivalents, and test each of them against the dialed number
- $prefixclause .= " OR (dialprefix LIKE '&_%' ESCAPE '&' AND '$phonenumber' ";
+ $prefixclause .= " OR (dialprefix LIKE '&_%' ESCAPE '&' AND '$phonenumber2' ";
$prefixclause .= "REGEXP REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(CONCAT('^', dialprefix, '$'), ";
$prefixclause .= "'X', '[0-9]'), 'Z', '[1-9]'), 'N', '[2-9]'), '.', '.+'), '_', ''))";

@@ -160,11 +191,11 @@
LEFT JOIN cc_trunk AS rt_trunk ON cc_ratecard.id_trunk = rt_trunk.id_trunk
LEFT JOIN cc_trunk AS tp_trunk ON cc_tariffplan.id_trunk = tp_trunk.id_trunk

- WHERE cc_tariffgroup.id = $tariffgroupid AND ($prefixclause)
+ WHERE cc_tariffgroup.id = $tariffgroupid2 AND ($prefixclause)
AND startingdate <= CURRENT_TIMESTAMP AND (expirationdate > CURRENT_TIMESTAMP OR expirationdate IS NULL)
AND startdate <= CURRENT_TIMESTAMP AND (stopdate > CURRENT_TIMESTAMP OR stopdate IS NULL)
$sql_clause_days
- AND idtariffgroup = '$tariffgroupid'
+ AND idtariffgroup = '$tariffgroupid2'
AND (dnidprefix = SUBSTRING('$mydnid', 1, length(dnidprefix)) OR (dnidprefix = 'all' $DNID_SUB_QUERY))
AND (calleridprefix = SUBSTRING('$mycallerid', 1, length(calleridprefix)) OR (calleridprefix = 'all' $CID_SUB_QUERY))
ORDER BY LENGTH(dialprefix) DESC";


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 
Hosted Voice Broadcast


All times are UTC


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group