1 package FS::rate_detail;
5 use FS::Record qw( qsearch qsearchs );
10 @ISA = qw(FS::Record);
14 FS::rate_detail - Object methods for rate_detail records
20 $record = new FS::rate_detail \%hash;
21 $record = new FS::rate_detail { 'column' => 'value' };
23 $error = $record->insert;
25 $error = $new_record->replace($old_record);
27 $error = $record->delete;
29 $error = $record->check;
33 An FS::rate_detail object represents an call plan rate. FS::rate_detail
34 inherits from FS::Record. The following fields are currently supported:
38 =item ratedetailnum - primary key
40 =item ratenum - rate plan (see L<FS::rate>)
42 =item orig_regionnum - call origination region
44 =item dest_regionnum - call destination region
46 =item min_included - included minutes
48 =item min_charge - charge per minute
50 =item sec_granularity - granularity in seconds, i.e. 6 or 60; 0 for per-call
52 =item classnum - usage class (see L<FS::usage_class>) if any for this rate
62 Creates a new call plan rate. To add the call plan rate to the database, see
65 Note that this stores the hash reference, not a distinct copy of the hash it
66 points to. You can ask the object for a copy with the I<hash> method.
70 # the new method can be inherited from FS::Record, if a table method is defined
72 sub table { 'rate_detail'; }
76 Adds this record to the database. If there is an error, returns the error,
77 otherwise returns false.
81 # the insert method can be inherited from FS::Record
85 Delete this record from the database.
89 # the delete method can be inherited from FS::Record
91 =item replace OLD_RECORD
93 Replaces the OLD_RECORD with this one in the database. If there is an error,
94 returns the error, otherwise returns false.
98 # the replace method can be inherited from FS::Record
102 Checks all fields to make sure this is a valid call plan rate. If there is
103 an error, returns the error, otherwise returns false. Called by the insert
108 # the check method should currently be supplied - FS::Record contains some
109 # data checking routines
115 $self->ut_numbern('ratedetailnum')
116 || $self->ut_foreign_key('ratenum', 'rate', 'ratenum')
117 || $self->ut_foreign_keyn('orig_regionnum', 'rate_region', 'regionnum' )
118 || $self->ut_foreign_key('dest_regionnum', 'rate_region', 'regionnum' )
119 || $self->ut_number('min_included')
121 #|| $self->ut_money('min_charge')
122 #good enough for now...
123 || $self->ut_float('min_charge')
125 || $self->ut_number('sec_granularity')
127 || $self->ut_foreign_keyn('classnum', 'usage_class', 'classnum' )
129 return $error if $error;
136 Returns the parent call plan (see L<FS::rate>) associated with this call plan
143 qsearchs('rate', { 'ratenum' => $self->ratenum } );
148 Returns the origination region (see L<FS::rate_region>) associated with this
155 qsearchs('rate_region', { 'regionnum' => $self->orig_regionnum } );
160 Returns the destination region (see L<FS::rate_region>) associated with this
167 qsearchs('rate_region', { 'regionnum' => $self->dest_regionnum } );
170 =item dest_regionname
172 Returns the name of the destination region (see L<FS::rate_region>) associated
173 with this call plan rate.
177 sub dest_regionname {
179 $self->dest_region->regionname;
182 =item dest_regionname
184 Returns a short list of the prefixes for the destination region
185 (see L<FS::rate_region>) associated with this call plan rate.
189 sub dest_prefixes_short {
191 $self->dest_region->prefixes_short;
196 Returns the name of the usage class (see L<FS::usage_class>) associated with
203 my $usage_class = qsearchs('usage_class', { classnum => $self->classnum });
204 $usage_class ? $usage_class->classname : '';
216 Returns an (ordered) hash of granularity => name pairs
220 tie my %granularities, 'Tie::IxHash',
223 '30' => '30 second', # '1/2 minute',
239 L<FS::rate>, L<FS::rate_region>, L<FS::Record>,
240 schema.html from the base documentation.