RT# 83450 - fixed rateplan export
[freeside.git] / FS / FS / rate_prefix.pm
1 package FS::rate_prefix;
2 use base qw(FS::Record);
3
4 use strict;
5 use FS::Record qw( dbh ); #qw( qsearch qsearchs dbh );
6 use FS::lata;
7
8 =head1 NAME
9
10 FS::rate_prefix - Object methods for rate_prefix records
11
12 =head1 SYNOPSIS
13
14   use FS::rate_prefix;
15
16   $record = new FS::rate_prefix \%hash;
17   $record = new FS::rate_prefix { 'column' => 'value' };
18
19   $error = $record->insert;
20
21   $error = $new_record->replace($old_record);
22
23   $error = $record->delete;
24
25   $error = $record->check;
26
27 =head1 DESCRIPTION
28
29 An FS::rate_prefix object represents an call rating prefix.  FS::rate_prefix
30 inherits from FS::Record.  The following fields are currently supported:
31
32 =over 4
33
34 =item prefixnum - primary key
35
36 =item regionnum - call ration region (see L<FS::rate_region>)
37
38 =item countrycode
39
40 =item npa
41
42 =item nxx
43
44 =back
45
46 =head1 METHODS
47
48 =over 4
49
50 =item new HASHREF
51
52 Creates a new prefix.  To add the prefix to the database, 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 { 'rate_prefix'; }
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 prefix.  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('prefixnum')
105     || $self->ut_foreign_key('regionnum', 'rate_region', 'regionnum' )
106     || $self->ut_number('countrycode')
107     || $self->ut_numbern('npa')
108     || $self->ut_numbern('nxx')
109     || $self->ut_foreign_keyn('latanum', 'lata', 'latanum')
110     || $self->ut_textn('state')
111     || $self->ut_textn('ocn')
112   ;
113   return $error if $error;
114
115   $self->SUPER::check;
116 }
117
118 =item rate_region
119
120 Returns the rate region (see L<FS::rate_region>) for this prefix.
121
122 =back
123
124 =head1 CLASS METHODS
125
126 =over 4
127
128 =item all_countrycodes
129
130 Returns a list of all countrycodes listed in rate_prefix
131
132 =cut
133
134 sub all_countrycodes { 
135   #my $class = shift;
136   my $sql =
137     "SELECT DISTINCT(countrycode) FROM rate_prefix ORDER BY countrycode";
138   my $sth = dbh->prepare($sql) or die  dbh->errstr;
139   $sth->execute                or die $sth->errstr;
140   map $_->[0], @{ $sth->fetchall_arrayref };
141 }
142
143 =back
144
145 =head1 BUGS
146
147 =head1 SEE ALSO
148
149 L<FS::rate_region>, L<FS::Record>, schema.html from the base documentation.
150
151 =cut
152
153 1;
154