eliminate some false laziness in FS::Misc::send_email vs. msg_template/email.pm send_...
[freeside.git] / FS / FS / inventory_item.pm
index 7fa350f..9a58a64 100644 (file)
@@ -1,13 +1,7 @@
 package FS::inventory_item;
+use base qw( FS::cust_main_Mixin FS::Record );
 
 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::cust_main_Mixin FS::Record );
 
 =head1 NAME
 
@@ -106,8 +100,12 @@ 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' )
+    || $self->ut_alphan('svc_field')
   ;
   return $error if $error;
 
@@ -119,71 +117,31 @@ sub check {
 Returns the customer service associated with this inventory item, if the
 item has been used (see L<FS::cust_svc>).
 
-=cut
+=item agent 
 
-sub cust_svc {
-  my $self = shift;
-  return '' unless $self->svcnum;
-  qsearchs( 'cust_svc', { 'svcnum' => $self->svcnum } );
-}
+Returns the associated agent for this event, if any, as an FS::agent object.
 
 =back
 
-=head1 CLASS METHODS
+=head1 SUBROUTINES
 
 =over 4
 
-=item batch_import
+=item process_batch_import
 
 =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;
-
-    my $inventory_item = new FS::inventory_item {
-      'classnum' => $param->{'classnum'},
-      'item'     => $line,
-    };
-
-    my $error = $inventory_item->insert;
-
-    if ( $error ) {
-      $dbh->rollback if $oldAutoCommit;
-      return $error;
-
-      #or just skip?
-      #next;
-    }
-
-    $imported++;
-  }
-
-  $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, @_ );
 
 }
 
@@ -195,7 +153,7 @@ maybe batch_import should be a regular method in FS::inventory_class
 
 =head1 SEE ALSO
 
-L<inventory_class>, L<cust_svc>, L<FS::Record>, schema.html from the base
+L<FS::inventory_class>, L<FS::cust_svc>, L<FS::Record>, schema.html from the base
 documentation.
 
 =cut