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

Code to allow National calls without country code
http://forum.asterisk2billing.org/viewtopic.php?f=14&t=4837
Page 1 of 1

Author:  mazhar996 [ Thu Feb 05, 2009 6:00 pm ]
Post subject:  Code to allow National calls without country code

Dear All,
I wanted to change the code in Class.A2Billing.php , so that national calls could be made without country code. since the provider requires all calls in international format i.e. including country code, so i thought to modify the apply_rules following way.


Code:
   /*
    * Function apply_rules to the phonenumber : Remove internation prefix
    */
   function apply_rules ($phonenumber) {

      if (is_array($this->agiconfig['international_prefixes']) && (count($this->agiconfig['international_prefixes'])>0)) {
         foreach ($this->agiconfig['international_prefixes'] as $testprefix) {
            if (substr($phonenumber,0,strlen($testprefix))==$testprefix) {
               $this->myprefix = $testprefix;
               return substr($phonenumber,strlen($testprefix));
            }

            /*
             * Following code allows callers to dial Germany numbers without countrycode
             */
            elseif ((substr($phonenumber,0,1)=="0") && (substr($phonenumber,0,2)!="00")) {
               $phonenumber = substr($phonenumber,1);
               return "49".$phonenumber;
            }
         }
      }

      $this->myprefix='';
      return $phonenumber;
   }


i thought that the code within the elseif block would be executed only if both conditions are true.
Now I don’t know why this logic is not working.
if no number is dialed by the user after calling the access number,
the funtion returns 49
I do not know why is it returning 49 where in case no number is dialed the elseif statement is not met and code inside the elseif block should never be executed.

with best regards
mazhar

Author:  jerdguez [ Thu Feb 05, 2009 8:37 pm ]
Post subject: 

mazhar996:


Quote:
I wanted to change the code in Class.A2Billing.php , so that national calls could be made without country code. since the provider requires all calls in international format


This can be done with RATECARD configuration. No need to change a2billing code.

Author:  mazhar996 [ Fri Feb 06, 2009 7:51 am ]
Post subject: 

how can it be done using ratecard?
i do not see any such option. please advise.

Added after 3 minutes:

there is an option to remove international prefixes, but no option to remove leading zingle zero and add country code for national calls.

but anyhow, would be great if someone can comment on the php code behaviour i have mentioned.

Author:  jroper [ Fri Feb 06, 2009 4:21 pm ]
Post subject: 

It is usually fairly easy to identify a national call compared to an international call.

International calls will start with either a 00 or a 011. National calls will not.

Therefore anything that starts with something other than a 00 or a 011 must be a national call.

Therefore you can either manipulate the number into international format before passing it into A2Billing using the asterisk dial plan, or you can set up rate tables and trunks that either add digits if it is a national call, or remove the 00 or 011 if it is an international call before sending it on to the carrier.

I cannot comment on your php code, as I am no expert on it, however modifying the code does take you out of the development loop.


Joe

Author:  manugmedia [ Sat Feb 07, 2009 6:48 pm ]
Post subject: 

Joe,
Say when calling UK mobile 079********* What about creating a trunk that will remove prefix 0 and add 0044 then create a rate card say named local UK, Dial prefix 07 and add the rate card to the call plan. When a customer dails 079******, the trunk will strip 0 and add 0044 passing 004479*******. I remember i did this and it worked.

Author:  tompken [ Mon Feb 09, 2009 1:30 pm ]
Post subject: 

manugmedia wrote:
Joe,
Say when calling UK mobile 079********* What about creating a trunk that will remove prefix 0 and add 0044 then create a rate card say named local UK, Dial prefix 07 and add the rate card to the call plan. When a customer dails 079******, the trunk will strip 0 and add 0044 passing 004479*******. I remember i did this and it worked.


The only disadvantage to this solution is that it requires yet another ratesheet in the system. For example - for the UK we already have 3 rate sets: normal, 0800, 0800 + PAL.

That said, this is the way I solved it, and it seems to be working fine:

Code:
function apply_rules ($phonenumber) {

                if (is_array($this->agiconfig['international_prefixes']) && (count($this->agiconfig['international_prefixes'])>0)) {
                        foreach ($this->agiconfig['international_prefixes'] as $testprefix) {
                                if (substr($phonenumber,0,strlen($testprefix))==$testprefix) {
                                        $this->myprefix = $testprefix;
                                        return substr($phonenumber,strlen($testprefix));
                                }
                        }
                }

                if ((substr($phonenumber, 0, 1) == '0') && (substr($phonenumber, 1, 1) != '0'))
                        return '44' . substr($phonenumber, 1);

                $this->myprefix='';
                return $phonenumber;
        }


Please note: this assumes that all the international calls have to be prefixed with a 00, so be sure to edit your a2billing.conf accordingly.

Author:  mazhar996 [ Tue Feb 10, 2009 11:44 pm ]
Post subject: 

thanks tompken your code works exactly the way i needed although i still don't undestand what was wrong with my code but no matter, main thing is that it is fixed.

regards

Author:  manugmedia [ Sat Feb 14, 2009 4:33 pm ]
Post subject: 

tompken wrote:
Quote:
function apply_rules ($phonenumber) {

if (is_array($this->agiconfig['international_prefixes']) && (count($this->agiconfig['international_prefixes'])>0)) {
foreach ($this->agiconfig['international_prefixes'] as $testprefix) {
if (substr($phonenumber,0,strlen($testprefix))==$testprefix) {
$this->myprefix = $testprefix;
return substr($phonenumber,strlen($testprefix));
}
}
}

if ((substr($phonenumber, 0, 1) == '0') && (substr($phonenumber, 1, 1) != '0'))
return '44' . substr($phonenumber, 1);

$this->myprefix='';
return $phonenumber;
}

Am trying to use the code line 1325 Class:A2billing.php i have created a rate for 07 number but i get "the number is not available prompt" then "the number is currenly busy prompt".
What am i doing wrong or not doing for the code to work. Attached is my asterisk CLI output.
Thanks for your help

Attachments:
CLI.txt [5 KiB]
Downloaded 698 times

Author:  mazhar996 [ Tue Feb 17, 2009 1:23 am ]
Post subject: 

manugmedia,
from the trace it seems that your provider rejected the call. Apparent reason seem to be Invalid Number:
you said that you have added the rate for code 07 but outgoing number to your provider is 0307961652954, so looks like you have a prefix 030 for this provider. Do your calls work when you dial international country code? e.g. what happens if you dial 447961652954 instead of 07961652954?

Author:  manugmedia [ Tue Feb 17, 2009 10:40 am ]
Post subject: 

Thanks mazhar996 for your reply.
mazhar996 Wrote
Quote:
so looks like you have a prefix 030 for this provider

Yes i have prefix 03, the trunk is configured to strip the leading 00 and add 03.
Quote:
Do your calls work when you dial international country code? e.g. what happens if you dial 447961652954 instead of 07961652954

Yes they do and i have another trunk that passes the dialed number as it is but when i dial the number its returning AGI dial options
Quote:
(SIP/Free-Call/07961652954|60|gL(360000:61000:30000)

it works if i dial 4477961652954. Am confused, seems like the if statement in Class:A2B.php is not being executed.

:evil:
Thanks so much for your help in advance
God Bless

Author:  tompken [ Tue Feb 17, 2009 1:37 pm ]
Post subject: 

mazhar996 wrote:
thanks tompken your code works exactly the way i needed although i still don't undestand what was wrong with my code but no matter, main thing is that it is fixed.

regards


Pleased to hear that.

I wonder if it would be possible to add this feature to a2b properly. Are the devs interested in community submissions at all?

I also have another feature working - Payphone Access Levy for UK payphones - which I think other people might be interested in.

Author:  mazhar996 [ Mon Feb 23, 2009 10:09 pm ]
Post subject: 

Dear manugmedia, sorry for the delayed response, i was out of city and could not check my emails.

Anyhow the code works 100% , the only reason that its not working for you could be that you don't have it at right place. please recheck the method and compare the code provided by tompken.

br
mazhar

Author:  manugmedia [ Mon Feb 23, 2009 11:04 pm ]
Post subject: 

mazhar996,
Thank you for your continued concern to help with the issue.
Just to confirm, i have the file in the right place. I have added the code in the following 3 directories,
1. /var/www/html/users/lib/Class.A2Billing.php
2. /var/lib/asterisk/agi-bin/libs_a2billing/Class.A2Billing.php and
3. /var/www/html/A2Billing_UI/lib/Class.A2Billing.php

Class.A2Billing.php reads between line 1322 and 1341
Quote:
/*
* Function apply_rules to the phonenumber : Remove internation prefix
*/
function apply_rules ($phonenumber) {

if (is_array($this->agiconfig['international_prefixes']) && (count($this->agiconfig['international_prefixes'])>0)) {
foreach ($this->agiconfig['international_prefixes'] as $testprefix) {
if (substr($phonenumber,0,strlen($testprefix))==$testprefix) {
$this->myprefix = $testprefix;
return substr($phonenumber,strlen($testprefix));
}
}
}

if ((substr($phonenumber, 0, 1) == '0') && (substr($phonenumber, 1, 1) != '0'))
return '44' . substr($phonenumber, 1);

$this->myprefix='';
return $phonenumber;
}

Is this correct or i have done something wrong?

Thank you for your help.
God Bless

Author:  mazhar996 [ Tue Feb 24, 2009 9:08 am ]
Post subject: 

manugmedia, you are very welcome.
and you have the code at the right place. in-fact you need it only in var/lib/asterisk/agi-bin/libs_a2billing/Class.A2Billing.php

now this is very strange because with me its working and i didn't nothing else than adding the if statement

if ((substr($phonenumber, 0, 1) == '0') && (substr($phonenumber, 1, 1) != '0'))
return '49'. substr($phonenumber, 1);

the only difference between yours and mine is the country code.

perhaps tompken or stavros can help.

may be a reload will help, not sure though.

Author:  parjeen [ Thu Aug 01, 2013 5:03 pm ]
Post subject:  Re: Code to allow National calls without country code

Dear TOpken And Mazhar

Thank you for this precious code.

However I know that this post is too old but I am still finding it helpful if I can get some help from people in this forum to get this working on my system.

So far I have copied and pasted Topkens Modified cod in this file: /var/lib/asterisk/agi-bin/libs_a2billing/Class.A2Billing.php but unfortunately it doesn't work.

I would gratefully appreciate that if someone can help me get this working because I am struggling with this at the moment and I need this crucial feature in my A2Billing system now.

Thank you for helping

Regards
Parjeen.

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