X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Frate.pm;h=b2d121c228365fe1076dbbb826f2346190ebf45f;hb=cff1496af12df71e2fd35775cb72d8e8bf2560f8;hp=02d8250ebbdc79a777132c2fcbd76c553645e270;hpb=0fb307c305e4bc2c9c27dc25a3308beae3a4d33c;p=freeside.git diff --git a/FS/FS/rate.pm b/FS/FS/rate.pm index 02d8250eb..b2d121c22 100644 --- a/FS/FS/rate.pm +++ b/FS/FS/rate.pm @@ -35,10 +35,18 @@ FS::Record. The following fields are currently supported: =over 4 -=item ratenum - primary key +=item ratenum + +primary key =item ratename +Rate name + +=item agentnum + +Optional agent (see L) for agent-virtualized rates. + =back =head1 METHODS @@ -254,15 +262,13 @@ and replace methods. =cut -# the check method should currently be supplied - FS::Record contains some -# data checking routines - sub check { my $self = shift; my $error = $self->ut_numbern('ratenum') || $self->ut_text('ratename') + #|| $self->ut_foreign_keyn('agentnum', 'agent', 'agentnum') ; return $error if $error; @@ -308,17 +314,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; @@ -378,6 +395,16 @@ sub rate_detail { qsearch( 'rate_detail', { 'ratenum' => $self->ratenum } ); } +=item agent + +=cut + +sub agent { + my $self = shift; + eval "use FS::agent"; + die $@ if $@; + qsearchs( 'agent', { 'agentnum' => $self->agentnum } ); +} =back @@ -387,7 +414,7 @@ sub rate_detail { =item process -Experimental job-queue processor for web interface adds/edits +Job-queue processor for web interface adds/edits =cut