enable CardFortress in test database, #71513
[freeside.git] / FS / FS / inventory_item.pm
1 package FS::inventory_item;
2 use base qw( FS::cust_main_Mixin FS::Record );
3
4 use strict;
5
6 =head1 NAME
7
8 FS::inventory_item - Object methods for inventory_item records
9
10 =head1 SYNOPSIS
11
12   use FS::inventory_item;
13
14   $record = new FS::inventory_item \%hash;
15   $record = new FS::inventory_item { 'column' => 'value' };
16
17   $error = $record->insert;
18
19   $error = $new_record->replace($old_record);
20
21   $error = $record->delete;
22
23   $error = $record->check;
24
25 =head1 DESCRIPTION
26
27 An FS::inventory_item object represents a specific piece of (real or virtual)
28 inventory, such as a specific DID or serial number.  FS::inventory_item
29 inherits from FS::Record.  The following fields are currently supported:
30
31 =over 4
32
33 =item itemnum - primary key
34
35 =item classnum - Inventory class (see L<FS::inventory_class>)
36
37 =item item - Item identifier (unique within its inventory class)
38
39 =item svcnum - Customer servcie (see L<FS::cust_svc>)
40
41 =back
42
43 =head1 METHODS
44
45 =over 4
46
47 =item new HASHREF
48
49 Creates a new item.  To add the item to the database, see L<"insert">.
50
51 Note that this stores the hash reference, not a distinct copy of the hash it
52 points to.  You can ask the object for a copy with the I<hash> method.
53
54 =cut
55
56 # the new method can be inherited from FS::Record, if a table method is defined
57
58 sub table { 'inventory_item'; }
59
60 =item insert
61
62 Adds this record to the database.  If there is an error, returns the error,
63 otherwise returns false.
64
65 =cut
66
67 # the insert method can be inherited from FS::Record
68
69 =item delete
70
71 Delete this record from the database.
72
73 =cut
74
75 # the delete method can be inherited from FS::Record
76
77 =item replace OLD_RECORD
78
79 Replaces the OLD_RECORD with this one in the database.  If there is an error,
80 returns the error, otherwise returns false.
81
82 =cut
83
84 # the replace method can be inherited from FS::Record
85
86 =item check
87
88 Checks all fields to make sure this is a valid item.  If there is
89 an error, returns the error, otherwise returns false.  Called by the insert
90 and replace methods.
91
92 =cut
93
94 # the check method should currently be supplied - FS::Record contains some
95 # data checking routines
96
97 sub check {
98   my $self = shift;
99
100   my $error = 
101     $self->ut_numbern('itemnum')
102     || $self->ut_foreign_key('classnum', 'inventory_class', 'classnum' )
103     #|| $self->ut_foreign_keyn('agentnum', 'agent', 'agentnum' )
104     || $self->ut_agentnum_acl('agentnum', ['Configuration',
105                                            'Edit global inventory'] )
106     || $self->ut_text('item')
107     || $self->ut_foreign_keyn('svcnum', 'cust_svc', 'svcnum' )
108     || $self->ut_alphan('svc_field')
109   ;
110   return $error if $error;
111
112   $self->SUPER::check;
113 }
114
115 =item cust_svc
116
117 Returns the customer service associated with this inventory item, if the
118 item has been used (see L<FS::cust_svc>).
119
120 =item agent 
121
122 Returns the associated agent for this event, if any, as an FS::agent object.
123
124 =back
125
126 =head1 SUBROUTINES
127
128 =over 4
129
130 =item process_batch_import
131
132 =cut
133
134 sub process_batch_import {
135   my $job = shift;
136
137   my $opt = { 'table'   => 'inventory_item',
138               #'params'  => [ 'itembatch', 'classnum', ],
139               'params'  => [ 'classnum', 'agentnum', ],
140               'formats' => { 'default' => [ 'item' ] },
141               'default_csv' => 1,
142             };
143
144   FS::Record::process_batch_import( $job, $opt, @_ );
145
146 }
147
148 =back
149
150 =head1 BUGS
151
152 maybe batch_import should be a regular method in FS::inventory_class
153
154 =head1 SEE ALSO
155
156 L<inventory_class>, L<cust_svc>, L<FS::Record>, schema.html from the base
157 documentation.
158
159 =cut
160
161 1;
162