From c3b8e954dbf5ddd04930809edfb77fa106fccaee Mon Sep 17 00:00:00 2001 From: Mark Wells Date: Fri, 22 Feb 2013 08:27:20 -0800 Subject: [PATCH] exact-match rate regions, #20851 --- FS/FS/Schema.pm | 1 + FS/FS/rate.pm | 29 ++++++++++++++++++++--------- FS/FS/rate_region.pm | 6 +++++- httemplate/browse/rate_region.html | 8 +++++++- httemplate/edit/rate_region.cgi | 8 ++++++++ 5 files changed, 41 insertions(+), 11 deletions(-) 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; diff --git a/httemplate/browse/rate_region.html b/httemplate/browse/rate_region.html index b958894cb..b0ce467c0 100644 --- a/httemplate/browse/rate_region.html +++ b/httemplate/browse/rate_region.html @@ -62,8 +62,14 @@ tie my %granularity, 'Tie::IxHash', FS::rate_detail::granularities(); die "access denied" unless $FS::CurrentUser::CurrentUser->access_right('Configuration'); +my $sub_prefixes = sub { + my $region = shift; + $region->prefixes . + ($region->exact_match ? ' (exact match only)' : ''); +}; + my @header = ( '#', 'Region', 'Country code', 'Prefixes' ); -my @fields = ( 'regionnum', 'regionname', 'ccode', 'prefixes' ); +my @fields = ( 'regionnum', 'regionname', 'ccode', $sub_prefixes ); my @links = ( ($link) x 4 ); my @align = ( 'right', 'left', 'right', 'left' ); my @xls_format = ( ({ locked=>1, bg_color=>22 }) x 4 ); diff --git a/httemplate/edit/rate_region.cgi b/httemplate/edit/rate_region.cgi index 367bbafb6..a1c1bcb7d 100644 --- a/httemplate/edit/rate_region.cgi +++ b/httemplate/edit/rate_region.cgi @@ -33,6 +33,14 @@ + <& /elements/tr-checkbox.html, + label => 'Exact match', + field => 'exact_match', + cell_style => 'font-weight: bold', + value => 'Y', + curr_value => $rate_region->exact_match + &> +
-- 2.11.0