have the UI use full country names, and state names outside the US...
[freeside.git] / FS / FS / cdr_upstream_rate.pm
1 package FS::cdr_upstream_rate;
2
3 use strict;
4 use vars qw( @ISA );
5 use FS::Record qw( qsearch qsearchs );
6 use FS::rate_detail;
7
8 @ISA = qw(FS::Record);
9
10 =head1 NAME
11
12 FS::cdr_upstream_rate - Object methods for cdr_upstream_rate records
13
14 =head1 SYNOPSIS
15
16   use FS::cdr_upstream_rate;
17
18   $record = new FS::cdr_upstream_rate \%hash;
19   $record = new FS::cdr_upstream_rate { 'column' => 'value' };
20
21   $error = $record->insert;
22
23   $error = $new_record->replace($old_record);
24
25   $error = $record->delete;
26
27   $error = $record->check;
28
29 =head1 DESCRIPTION
30
31 An FS::cdr_upstream_rate object represents an upstream rate mapping to 
32 internal rate detail (see L<FS::rate_detail>).  FS::cdr_upstream_rate inherits
33 from FS::Record.  The following fields are currently supported:
34
35 =over 4
36
37 =item upstreamratenum - primary key
38
39 =item upstream_rateid - CDR upstream Rate ID (cdr.upstream_rateid - see L<FS::cdr>)
40
41 =item ratedetailnum - Rate detail - see L<FS::rate_detail>
42
43 =back
44
45 =head1 METHODS
46
47 =over 4
48
49 =item new HASHREF
50
51 Creates a new upstream rate mapping.  To add the upstream rate to the database,
52 see L<"insert">.
53
54 Note that this stores the hash reference, not a distinct copy of the hash it
55 points to.  You can ask the object for a copy with the I<hash> method.
56
57 =cut
58
59 # the new method can be inherited from FS::Record, if a table method is defined
60
61 sub table { 'cdr_upstream_rate'; }
62
63 =item insert
64
65 Adds this record to the database.  If there is an error, returns the error,
66 otherwise returns false.
67
68 =cut
69
70 # the insert method can be inherited from FS::Record
71
72 =item delete
73
74 Delete this record from the database.
75
76 =cut
77
78 # the delete method can be inherited from FS::Record
79
80 =item replace OLD_RECORD
81
82 Replaces the OLD_RECORD with this one in the database.  If there is an error,
83 returns the error, otherwise returns false.
84
85 =cut
86
87 # the replace method can be inherited from FS::Record
88
89 =item check
90
91 Checks all fields to make sure this is a valid upstream rate.  If there is
92 an error, returns the error, otherwise returns false.  Called by the insert
93 and replace methods.
94
95 =cut
96
97 # the check method should currently be supplied - FS::Record contains some
98 # data checking routines
99
100 sub check {
101   my $self = shift;
102
103   my $error = 
104     $self->ut_numbern('upstreamratenum')
105     #|| $self->ut_number('upstream_rateid')
106     || $self->ut_alpha('upstream_rateid')
107     #|| $self->ut_text('upstream_rateid')
108     || $self->ut_foreign_key('ratedetailnum', 'rate_detail', 'ratedetailnum' )
109   ;
110   return $error if $error;
111
112   $self->SUPER::check;
113 }
114
115 =item rate_detail
116
117 Returns the internal rate detail object for this upstream rate (see
118 L<FS::rate_detail>).
119
120 =cut
121
122 sub rate_detail {
123   my $self = shift;
124   qsearchs('rate_detail', { 'ratedetailnum' => $self->ratedetailnum } );
125 }
126
127 =back
128
129 =head1 BUGS
130
131 =head1 SEE ALSO
132
133 L<FS::Record>, schema.html from the base documentation.
134
135 =cut
136
137 1;
138