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