svc_hardware: better error messages for bad hw_addr when not validating as a MAC...
[freeside.git] / FS / FS / rate_tier.pm
1 package FS::rate_tier;
2 use base qw( FS::o2m_Common FS::Record );
3
4 use strict;
5 use FS::Record qw( qsearch qsearchs );
6 use FS::rate_tier_detail;
7
8 =head1 NAME
9
10 FS::rate_tier - Object methods for rate_tier records
11
12 =head1 SYNOPSIS
13
14   use FS::rate_tier;
15
16   $record = new FS::rate_tier \%hash;
17   $record = new FS::rate_tier { '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_tier object represents a set of rate tiers.  FS::rate_tier inherits
30  from FS::Record.  The following fields are currently supported:
31
32 =over 4
33
34 =item tiernum
35
36 primary key
37
38 =item tiername
39
40 tiername
41
42
43 =back
44
45 =head1 METHODS
46
47 =over 4
48
49 =item new HASHREF
50
51 Creates a new record.  To add the record to the database, see L<"insert">.
52
53 Note that this stores the hash reference, not a distinct copy of the hash it
54 points to.  You can ask the object for a copy with the I<hash> method.
55
56 =cut
57
58 # the new method can be inherited from FS::Record, if a table method is defined
59
60 sub table { 'rate_tier'; }
61
62 =item insert
63
64 Adds this record to the database.  If there is an error, returns the error,
65 otherwise returns false.
66
67 =cut
68
69 # the insert method can be inherited from FS::Record
70
71 =item delete
72
73 Delete this record from the database.
74
75 =cut
76
77 # the delete method can be inherited from FS::Record
78
79 =item replace OLD_RECORD
80
81 Replaces the OLD_RECORD with this one in the database.  If there is an error,
82 returns the error, otherwise returns false.
83
84 =cut
85
86 # the replace method can be inherited from FS::Record
87
88 =item check
89
90 Checks all fields to make sure this is a valid record.  If there is
91 an error, returns the error, otherwise returns false.  Called by the insert
92 and replace methods.
93
94 =cut
95
96 # the check method should currently be supplied - FS::Record contains some
97 # data checking routines
98
99 sub check {
100   my $self = shift;
101
102   my $error = 
103     $self->ut_numbern('tiernum')
104     || $self->ut_text('tiername')
105   ;
106   return $error if $error;
107
108   $self->SUPER::check;
109 }
110
111 =item rate_tier_detail QUANTITY
112
113 =cut
114
115 sub rate_tier_detail {
116   my $self = shift;
117
118   if ( defined($_[0]) && length($_[0]) ) {
119
120     my $quantity = shift;
121     $quantity = int( $quantity + 0.00001 );
122
123     qsearchs({
124       'table'    => 'rate_tier_detail',
125       'hashref'  => { 'tiernum'  => $self->tiernum,
126                       'min_quan' => { op=>'<=', value=>$quantity },
127                     },
128       'order_by' => 'ORDER BY min_charge ASC LIMIT 1',
129     });
130
131   } else {
132
133     qsearch({
134       'table'    => 'rate_tier_detail',
135       'hashref'  => { 'tiernum' => $self->tiernum, },
136       'order_by' => 'ORDER BY min_quan ASC',
137     });
138
139   }
140
141 }
142
143 =back
144
145 =head1 BUGS
146
147 =head1 SEE ALSO
148
149 L<FS::Record>, schema.html from the base documentation.
150
151 =cut
152
153 1;
154