1 package FS::inventory_item;
5 use FS::Record qw( dbh qsearch qsearchs );
6 use FS::inventory_class;
13 FS::inventory_item - Object methods for inventory_item records
17 use FS::inventory_item;
19 $record = new FS::inventory_item \%hash;
20 $record = new FS::inventory_item { 'column' => 'value' };
22 $error = $record->insert;
24 $error = $new_record->replace($old_record);
26 $error = $record->delete;
28 $error = $record->check;
32 An FS::inventory_item object represents a specific piece of (real or virtual)
33 inventory, such as a specific DID or serial number. FS::inventory_item
34 inherits from FS::Record. The following fields are currently supported:
38 =item itemnum - primary key
40 =item classnum - Inventory class (see L<FS::inventory_class>)
42 =item item - Item identifier (unique within its inventory class)
44 =item svcnum - Customer servcie (see L<FS::cust_svc>)
54 Creates a new item. To add the item to the database, see L<"insert">.
56 Note that this stores the hash reference, not a distinct copy of the hash it
57 points to. You can ask the object for a copy with the I<hash> method.
61 # the new method can be inherited from FS::Record, if a table method is defined
63 sub table { 'inventory_item'; }
67 Adds this record to the database. If there is an error, returns the error,
68 otherwise returns false.
72 # the insert method can be inherited from FS::Record
76 Delete this record from the database.
80 # the delete method can be inherited from FS::Record
82 =item replace OLD_RECORD
84 Replaces the OLD_RECORD with this one in the database. If there is an error,
85 returns the error, otherwise returns false.
89 # the replace method can be inherited from FS::Record
93 Checks all fields to make sure this is a valid item. If there is
94 an error, returns the error, otherwise returns false. Called by the insert
99 # the check method should currently be supplied - FS::Record contains some
100 # data checking routines
106 $self->ut_numbern('itemnum')
107 || $self->ut_foreign_key('classnum', 'inventory_class', 'classnum' )
108 || $self->ut_text('item')
109 || $self->ut_foreign_keyn('svcnum', 'cust_svc', 'svcnum' )
111 return $error if $error;
118 Returns the customer service associated with this inventory item, if the
119 item has been used (see L<FS::cust_svc>).
125 return '' unless $self->svcnum;
126 qsearchs( 'cust_svc', { 'svcnum' => $self->svcnum } );
142 my $fh = $param->{filehandle};
146 local $SIG{HUP} = 'IGNORE';
147 local $SIG{INT} = 'IGNORE';
148 local $SIG{QUIT} = 'IGNORE';
149 local $SIG{TERM} = 'IGNORE';
150 local $SIG{TSTP} = 'IGNORE';
151 local $SIG{PIPE} = 'IGNORE';
153 my $oldAutoCommit = $FS::UID::AutoCommit;
154 local $FS::UID::AutoCommit = 0;
158 while ( defined($line=<$fh>) ) {
162 my $inventory_item = new FS::inventory_item {
163 'classnum' => $param->{'classnum'},
167 my $error = $inventory_item->insert;
170 $dbh->rollback if $oldAutoCommit;
180 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
182 #might want to disable this if we skip records for any reason...
183 return "Empty file!" unless $imported;
193 maybe batch_import should be a regular method in FS::inventory_class
197 L<inventory_class>, L<cust_svc>, L<FS::Record>, schema.html from the base