POD cleanups
[freeside.git] / FS / FS / rate_detail.pm
1 package FS::rate_detail;
2
3 use strict;
4 use vars qw( @ISA );
5 use FS::Record qw( qsearch qsearchs );
6 use FS::rate;
7 use FS::rate_region;
8 use Tie::IxHash;
9
10 @ISA = qw(FS::Record);
11
12 =head1 NAME
13
14 FS::rate_detail - Object methods for rate_detail records
15
16 =head1 SYNOPSIS
17
18   use FS::rate_detail;
19
20   $record = new FS::rate_detail \%hash;
21   $record = new FS::rate_detail { 'column' => 'value' };
22
23   $error = $record->insert;
24
25   $error = $new_record->replace($old_record);
26
27   $error = $record->delete;
28
29   $error = $record->check;
30
31 =head1 DESCRIPTION
32
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:
35
36 =over 4
37
38 =item ratedetailnum - primary key
39
40 =item ratenum - rate plan (see L<FS::rate>)
41
42 =item orig_regionnum - call origination region
43
44 =item dest_regionnum - call destination region
45
46 =item min_included - included minutes
47
48 =item min_charge - charge per minute
49
50 =item sec_granularity - granularity in seconds, i.e. 6 or 60; 0 for per-call
51
52 =item classnum - usage class (see L<FS::usage_class>) if any for this rate
53
54 =back
55
56 =head1 METHODS
57
58 =over 4
59
60 =item new HASHREF
61
62 Creates a new call plan rate.  To add the call plan rate to the database, see
63 L<"insert">.
64
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.
67
68 =cut
69
70 # the new method can be inherited from FS::Record, if a table method is defined
71
72 sub table { 'rate_detail'; }
73
74 =item insert
75
76 Adds this record to the database.  If there is an error, returns the error,
77 otherwise returns false.
78
79 =cut
80
81 # the insert method can be inherited from FS::Record
82
83 =item delete
84
85 Delete this record from the database.
86
87 =cut
88
89 # the delete method can be inherited from FS::Record
90
91 =item replace OLD_RECORD
92
93 Replaces the OLD_RECORD with this one in the database.  If there is an error,
94 returns the error, otherwise returns false.
95
96 =cut
97
98 # the replace method can be inherited from FS::Record
99
100 =item check
101
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
104 and replace methods.
105
106 =cut
107
108 # the check method should currently be supplied - FS::Record contains some
109 # data checking routines
110
111 sub check {
112   my $self = shift;
113
114   my $error = 
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')
120
121     #|| $self->ut_money('min_charge')
122     #good enough for now...
123     || $self->ut_float('min_charge')
124
125     || $self->ut_number('sec_granularity')
126
127     || $self->ut_foreign_keyn('classnum', 'usage_class', 'classnum' )
128   ;
129   return $error if $error;
130
131   $self->SUPER::check;
132 }
133
134 =item rate 
135
136 Returns the parent call plan (see L<FS::rate>) associated with this call plan
137 rate.
138
139 =cut
140
141 sub rate {
142   my $self = shift;
143   qsearchs('rate', { 'ratenum' => $self->ratenum } );
144 }
145
146 =item orig_region 
147
148 Returns the origination region (see L<FS::rate_region>) associated with this
149 call plan rate.
150
151 =cut
152
153 sub orig_region {
154   my $self = shift;
155   qsearchs('rate_region', { 'regionnum' => $self->orig_regionnum } );
156 }
157
158 =item dest_region 
159
160 Returns the destination region (see L<FS::rate_region>) associated with this
161 call plan rate.
162
163 =cut
164
165 sub dest_region {
166   my $self = shift;
167   qsearchs('rate_region', { 'regionnum' => $self->dest_regionnum } );
168 }
169
170 =item dest_regionname
171
172 Returns the name of the destination region (see L<FS::rate_region>) associated
173 with this call plan rate.
174
175 =cut
176
177 sub dest_regionname {
178   my $self = shift;
179   $self->dest_region->regionname;
180 }
181
182 =item dest_regionname
183
184 Returns a short list of the prefixes for the destination region
185 (see L<FS::rate_region>) associated with this call plan rate.
186
187 =cut
188
189 sub dest_prefixes_short {
190   my $self = shift;
191   $self->dest_region->prefixes_short;
192 }
193
194 =item classname
195
196 Returns the name of the usage class (see L<FS::usage_class>) associated with
197 this call plan rate.
198
199 =cut
200
201 sub classname {
202   my $self = shift;
203   my $usage_class = qsearchs('usage_class', { classnum => $self->classnum });
204   $usage_class ? $usage_class->classname : '';
205 }
206
207
208 =back
209
210 =head1 SUBROUTINES
211
212 =over 4
213
214 =item granularities
215
216   Returns an (ordered) hash of granularity => name pairs
217
218 =cut
219
220 tie my %granularities, 'Tie::IxHash',
221   '1', => '1 second',
222   '6'  => '6 second',
223   '30' => '30 second', # '1/2 minute',
224   '60' => 'minute',
225   '0'  => 'call',
226 ;
227
228 sub granularities {
229   %granularities;
230 }
231
232
233 =back
234
235 =head1 BUGS
236
237 =head1 SEE ALSO
238
239 L<FS::rate>, L<FS::rate_region>, L<FS::Record>,
240 schema.html from the base documentation.
241
242 =cut
243
244 1;
245