X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Finventory_item.pm;h=39a0dff4b802f6c1fbfb9e4248f4aa4f9f449471;hb=b79a8cb932946c849328a3c117c35821d9d21e66;hp=23bacf040d85f0e9738ad6246506fc1045803be0;hpb=6d2cd8e6fc566b4fccd0075156e3e1ddd59fa042;p=freeside.git diff --git a/FS/FS/inventory_item.pm b/FS/FS/inventory_item.pm index 23bacf040..39a0dff4b 100644 --- a/FS/FS/inventory_item.pm +++ b/FS/FS/inventory_item.pm @@ -3,10 +3,11 @@ package FS::inventory_item; use strict; use vars qw( @ISA ); use FS::Record qw( dbh qsearch qsearchs ); +use FS::cust_main_Mixin; use FS::inventory_class; use FS::cust_svc; -@ISA = qw(FS::Record); +@ISA = qw( FS::cust_main_Mixin FS::Record ); =head1 NAME @@ -105,6 +106,9 @@ sub check { my $error = $self->ut_numbern('itemnum') || $self->ut_foreign_key('classnum', 'inventory_class', 'classnum' ) + #|| $self->ut_foreign_keyn('agentnum', 'agent', 'agentnum' ) + || $self->ut_agentnum_acl('agentnum', ['Configuration', + 'Edit global inventory'] ) || $self->ut_text('item') || $self->ut_foreign_keyn('svcnum', 'cust_svc', 'svcnum' ) ; @@ -126,63 +130,38 @@ sub cust_svc { qsearchs( 'cust_svc', { 'svcnum' => $self->svcnum } ); } -=back - -=head1 CLASS METHODS - -=over 4 +=item agent -=item batch_import +Returns the associated agent for this event, if any, as an FS::agent object. =cut -sub batch_import { - my $param = shift; - - my $fh = $param->{filehandle}; - - my $imported = 0; - - local $SIG{HUP} = 'IGNORE'; - local $SIG{INT} = 'IGNORE'; - local $SIG{QUIT} = 'IGNORE'; - local $SIG{TERM} = 'IGNORE'; - local $SIG{TSTP} = 'IGNORE'; - local $SIG{PIPE} = 'IGNORE'; - - my $oldAutoCommit = $FS::UID::AutoCommit; - local $FS::UID::AutoCommit = 0; - my $dbh = dbh; - - my $line; - while ( defined($line=<$fh>) ) { - - chomp $line; +sub agent { + my $self = shift; + qsearchs('agent', { 'agentnum' => $self->agentnum } ); +} - my $inventory_item = new FS::inventory_item { - 'classnum' => $param->{'classnum'}, - 'item' => $line, - }; +=back - my $error = $inventory_item->insert; +=head1 SUBROUTINES - if ( $error ) { - $dbh->rollback if $oldAutoCommit; - return $error; +=over 4 - #or just skip? - #next; - } +=item process_batch_import - $imported++; - } +=cut - $dbh->commit or die $dbh->errstr if $oldAutoCommit; +sub process_batch_import { + my $job = shift; - #might want to disable this if we skip records for any reason... - return "Empty file!" unless $imported; + my $opt = { 'table' => 'inventory_item', + #'params' => [ 'itembatch', 'classnum', ], + 'params' => [ 'classnum', 'agentnum', ], + 'formats' => { 'default' => [ 'item' ] }, + 'default_csv' => 1, + }; - ''; + FS::Record::process_batch_import( $job, $opt, @_ ); }