exact-match rate regions, #20851
authorMark Wells <mark@freeside.biz>
Fri, 22 Feb 2013 16:27:20 +0000 (08:27 -0800)
committerMark Wells <mark@freeside.biz>
Fri, 22 Feb 2013 16:27:20 +0000 (08:27 -0800)
FS/FS/Schema.pm
FS/FS/rate.pm
FS/FS/rate_region.pm
httemplate/browse/rate_region.html
httemplate/edit/rate_region.cgi

index 6c7453d..774dcd2 100644 (file)
@@ -3056,6 +3056,7 @@ sub tables_hashref {
       'columns' => [
         'regionnum',   'serial',      '', '', '', '', 
         'regionname',  'varchar',     '', $char_d, '', '', 
+        'exact_match', 'char',    'NULL',  1, '', '',
       ],
       'primary_key' => 'regionnum',
       'unique'      => [],
index a2511cf..49ac938 100644 (file)
@@ -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;
 
index f4a0ab1..d42fdb4 100644 (file)
@@ -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;
 
index b958894..b0ce467 100644 (file)
@@ -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 ? ' <I>(exact match only)</I>' : '');
+};
+
 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 );
index 367bbaf..a1c1bcb 100644 (file)
     </TD>
   </TR>
 
+  <& /elements/tr-checkbox.html,
+    label       => 'Exact match',
+    field       => 'exact_match',
+    cell_style  => 'font-weight: bold',
+    value       => 'Y',
+    curr_value  => $rate_region->exact_match
+  &>
+
 </TABLE>
 
 <BR>