X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Frate.pm;h=d30517051ba28b6cc94c84ed3e707c97d37bc73e;hb=9313346347265c5a1ad3e1da8f2fcbb965a9d6cd;hp=88e93b6f161e554b6da82c68a6044b731a4287b8;hpb=1bea3acc9951c272bd9f5f872d3262c9380e067f;p=freeside.git diff --git a/FS/FS/rate.pm b/FS/FS/rate.pm index 88e93b6f1..d30517051 100644 --- a/FS/FS/rate.pm +++ b/FS/FS/rate.pm @@ -3,7 +3,6 @@ package FS::rate; use strict; use vars qw( @ISA $DEBUG ); use FS::Record qw( qsearch qsearchs dbh fields ); -#use FS::agent; #causes a weird dep loop in freeside-cdrrated, only needed for v3-style manual FK-checking, so, probably not bother use FS::rate_detail; @ISA = qw(FS::Record); @@ -48,6 +47,16 @@ Rate name Optional agent (see L) for agent-virtualized rates. +=item default_detailnum + +Optional rate detail to apply when a call doesn't match any region in the +rate plan. If this is not set, the call will either be left unrated (though +it may still be processed under a different pricing addon package), or be +marked as 'skipped', or throw a fatal error, depending on the setting of +the 'ignore_unrateable' package option. + +=item + =back =head1 METHODS @@ -270,6 +279,7 @@ sub check { $self->ut_numbern('ratenum') || $self->ut_text('ratename') #|| $self->ut_foreign_keyn('agentnum', 'agent', 'agentnum') + || $self->ut_numbern('default_detailnum') ; return $error if $error; @@ -279,8 +289,8 @@ sub check { =item dest_detail REGIONNUM | RATE_REGION_OBJECTD | HASHREF Returns the rate detail (see L) for this rate to the -specificed destination, or the empty string if no rate can be found for -the given destination. +specificed destination. If no rate can be found, returns the default +rate if there is one, and an empty string otherwise. Destination can be specified as an FS::rate_detail object or regionnum (see L), or as a hashref containing the following keys: @@ -338,7 +348,7 @@ sub dest_detail { }); } - return '' unless $rate_prefix; + return $self->default_detail unless $rate_prefix; $regionnum = $rate_prefix->regionnum; @@ -381,8 +391,8 @@ sub dest_detail { foreach (@details) { return $_ if $_->ratetimenum eq ''; } - # found nothing - return; + # if still nothing, return the global default rate for this plan + return $self->default_detail; } =item rate_detail @@ -396,9 +406,31 @@ 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 +=item default_detail + +Returns the default rate detail, if there is one. + +=cut + +sub default_detail { + my $self = shift; + $self->default_detailnum ? + FS::rate_detail->by_key($self->default_detailnum) : '' +} + =head1 SUBROUTINES =over 4