From c3b8e954dbf5ddd04930809edfb77fa106fccaee Mon Sep 17 00:00:00 2001 From: Mark Wells Date: Fri, 22 Feb 2013 08:27:20 -0800 Subject: exact-match rate regions, #20851 --- FS/FS/Schema.pm | 1 + FS/FS/rate.pm | 29 ++++++++++++++++++++--------- FS/FS/rate_region.pm | 6 +++++- 3 files changed, 26 insertions(+), 10 deletions(-) (limited to 'FS') diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm index 6c7453d1c..774dcd239 100644 --- a/FS/FS/Schema.pm +++ b/FS/FS/Schema.pm @@ -3056,6 +3056,7 @@ sub tables_hashref { 'columns' => [ 'regionnum', 'serial', '', '', '', '', 'regionname', 'varchar', '', $char_d, '', '', + 'exact_match', 'char', 'NULL', 1, '', '', ], 'primary_key' => 'regionnum', 'unique' => [], diff --git a/FS/FS/rate.pm b/FS/FS/rate.pm index a2511cf99..49ac938fd 100644 --- a/FS/FS/rate.pm +++ b/FS/FS/rate.pm @@ -308,17 +308,28 @@ sub dest_detail { #find a rate prefix, first look at most specific, then fewer digits, # finally trying the country code only my $rate_prefix = ''; - for my $len ( reverse(1..10) ) { - $rate_prefix = qsearchs('rate_prefix', { + $rate_prefix = qsearchs({ + 'table' => 'rate_prefix', + 'addl_from' => ' JOIN rate_region USING (regionnum)', + 'hashref' => { + 'countrycode' => $countrycode, + 'npa' => $phonenum, + }, + 'extra_sql' => ' AND exact_match = \'Y\'' + }); + if (!$rate_prefix) { + for my $len ( reverse(1..10) ) { + $rate_prefix = qsearchs('rate_prefix', { + 'countrycode' => $countrycode, + #'npa' => { op=> 'LIKE', value=> substr($number, 0, $len) } + 'npa' => substr($phonenum, 0, $len), + } ) and last; + } + $rate_prefix ||= qsearchs('rate_prefix', { 'countrycode' => $countrycode, - #'npa' => { op=> 'LIKE', value=> substr($number, 0, $len) } - 'npa' => substr($phonenum, 0, $len), - } ) and last; + 'npa' => '', + }); } - $rate_prefix ||= qsearchs('rate_prefix', { - 'countrycode' => $countrycode, - 'npa' => '', - }); return '' unless $rate_prefix; diff --git a/FS/FS/rate_region.pm b/FS/FS/rate_region.pm index f4a0ab196..d42fdb41e 100644 --- a/FS/FS/rate_region.pm +++ b/FS/FS/rate_region.pm @@ -36,7 +36,10 @@ inherits from FS::Record. The following fields are currently supported: =item regionnum - primary key -=item regionname +=item regionname - name of the region + +=item exact_match - 'Y' if "prefixes" in this region really represent +complete phone numbers. Null if they represent prefixes (the usual case). =back @@ -233,6 +236,7 @@ sub check { my $error = $self->ut_numbern('regionnum') || $self->ut_text('regionname') + || $self->ut_flag('exact_match') ; return $error if $error; -- cgit v1.2.1 From 21c3ee38fc44a1ff55f1dc1755ab13ffde82de16 Mon Sep 17 00:00:00 2001 From: Mark Wells Date: Sun, 24 Feb 2013 20:42:03 -0800 Subject: protocol fixes, #20836 --- FS/FS/part_export/huawei_hlr.pm | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'FS') diff --git a/FS/FS/part_export/huawei_hlr.pm b/FS/FS/part_export/huawei_hlr.pm index fb3b6790a..5a6a98352 100644 --- a/FS/FS/part_export/huawei_hlr.pm +++ b/FS/FS/part_export/huawei_hlr.pm @@ -18,6 +18,7 @@ tie my %options, 'Tie::IxHash', 'pwd' => { label=>'Operator password' }, 'tplid' => { label=>'Template number' }, 'hlrsn' => { label=>'HLR serial number' }, + 'timeout' => { label=>'Timeout (seconds)', default => 120 }, 'debug' => { label=>'Enable debugging', type=>'checkbox' }, ; @@ -36,13 +37,13 @@ sub _export_insert { my( $self, $svc_phone ) = (shift, shift); # svc_phone::check should ensure phonenum and sim_imsi are numeric my @command = ( - 'ADD TPLSUB', IMSI => '"'.$svc_phone->sim_imsi.'"', ISDN => '"'.$svc_phone->phonenum.'"', TPLID => $self->option('tplid'), ); unshift @command, 'HLRSN', $self->option('hlrsn') if $self->option('hlrsn'); + unshift @command, 'ADD TPLSUB'; my $err_or_queue = $self->queue_command($svc_phone->svcnum, @command); ref($err_or_queue) ? '' : $err_or_queue; } @@ -107,7 +108,7 @@ sub _export_delete { my( $self, $svc_phone ) = (shift, shift); my @command = ( 'RMV SUB', - IMSI => '"'.$svc_phone->sim_imsi.'"', + #IMSI => '"'.$svc_phone->sim_imsi.'"', ISDN => '"'.$svc_phone->phonenum.'"', ); my $err_or_queue = $self->queue_command($svc_phone->svcnum, @command); @@ -179,15 +180,16 @@ sub command { $string .= shift(@param) . '=' . shift(@param); $string .= ',' if @param; } - $string .= "\n"; + $string .= "\n;"; my @result; eval { # timeout local $SIG{ALRM} = sub { die "timeout\n" }; - alarm ($self->option('timeout') || 30); + alarm ($self->option('timeout') || 120); warn "Sending to server:\n$string\n\n" if $DEBUG; $socket->print($string); warn "Received:\n"; my $line; + local $/ = "\r\n"; do { $line = $socket->getline(); warn $line if $DEBUG; @@ -203,11 +205,10 @@ sub command { return { error => $@ }; } else { #+++ HLR9820