Tuesday, October 27, 2015

Handling Austrian (and maybe German and Swiss) DID numbers with extensions at A2Billing

In Austria still using classic ISDN dialing rules. So, if your company have number 431234567, and your internal number is 101 you can dial 431234567101 from any phone and get to extension 101 without any crappy IVR's.
Causes several problems with dialing rules, but make life much more comfortable.
So, the problem is how to handle those DID's in A2Billing, cause this soft uses only exact matches.
Solution - use MySQL patterns in DID fields directly.

So, now DID in A2Billing will looks like
 431234567%
 yes with "%" sign at the end.
Also, for VoIP destination was made a quick modification, that allows to use variables in dialstring.
So, destination will be like
SIP/<YourSipUser>/%did%.
At %did% A2billing will automatically place original DID(extension)

Patch is below
diff -Naur AGI/a2billing.php agi-bin/a2billing.php
--- AGI/a2billing.php 2015-02-27 15:42:38.000000000 +0100
+++ agi-bin/a2billing.php 2015-10-27 13:17:49.000000000 +0100
@@ -643,7 +643,8 @@
             " aleg_carrier_initblock_offp, aleg_carrier_increment_offp, aleg_retail_initblock_offp, aleg_retail_increment_offp ".
             " FROM cc_did, cc_did_destination, cc_card ".
             " WHERE id_cc_did=cc_did.id AND cc_card.status=1 AND cc_card.id=id_cc_card AND cc_did_destination.activated=1 ".
-            " AND cc_did.activated=1 AND did='$mydnid' ".
+            //" AND cc_did.activated=1 AND did='$mydnid' ".
+            " AND cc_did.activated=1 AND '$mydnid' LIKE did ". // Added to Austrian DID handling
             " AND cc_did.startingdate<= CURRENT_TIMESTAMP AND (cc_did.expirationdate > CURRENT_TIMESTAMP OR cc_did.expirationdate IS NULL ".
             " AND cc_did_destination.validated=1";
         if ($A2B->config["database"]['dbtype'] != "postgres") {
diff -Naur AGI/lib/Class.A2Billing.php agi-bin/lib/Class.A2Billing.php
--- AGI/lib/Class.A2Billing.php 2015-02-27 15:42:38.000000000 +0100
+++ agi-bin/lib/Class.A2Billing.php 2015-10-27 11:26:36.000000000 +0100
@@ -1324,6 +1324,8 @@
                     $dialparams = str_replace("%timeout%", min($time2call * 1000, $max_long), $dialparams);
                     $dialparams = str_replace("%timeoutsec%", min($time2call, $max_long), $dialparams);
                     $dialstr = $inst_listdestination[4] . $dialparams;
+    // Added support for %did% variable
+    $dialstr = str_replace("%did%", $this->orig_ext, $dialstr);

                     $this->debug(DEBUG, $agi, __FILE__, __LINE__, "[A2Billing] DID call friend: Dialing '$dialstr' Friend.\n");