agent virt inventory, RT#7010
authorivan <ivan>
Fri, 21 May 2010 00:09:40 +0000 (00:09 +0000)
committerivan <ivan>
Fri, 21 May 2010 00:09:40 +0000 (00:09 +0000)
FS/FS/inventory_class.pm
FS/FS/svc_Common.pm
httemplate/edit/elements/svc_Common.html
httemplate/search/inventory_item.html

index 508889b..3d7f049 100644 (file)
@@ -121,10 +121,16 @@ sub num_avail {
 sub num_sql {
   my( $self, $sql ) = @_;
   $sql = "AND $sql" if length($sql);
-  my $statement =
-    "SELECT COUNT(*) FROM inventory_item WHERE classnum = ? $sql";
-  my $sth = dbh->prepare($statement) or die dbh->errstr. " preparing $statement";
-  $sth->execute($self->classnum) or die $sth->errstr. " executing $statement";
+
+  my $agentnums_sql = $FS::CurrentUser::CurrentUser->agentnums_sql(
+    'null'  => 1,
+    'table' => 'inventory_item',
+  );
+
+  my $st = "SELECT COUNT(*) FROM inventory_item ".
+           " WHERE classnum = ? AND $agentnums_sql $sql";
+  my $sth = dbh->prepare($st)    or die  dbh->errstr. " preparing $st";
+  $sth->execute($self->classnum) or die $sth->errstr. " executing $st";
   $sth->fetchrow_arrayref->[0];
 }
 
index fd2745d..71290f4 100644 (file)
@@ -735,10 +735,17 @@ sub set_auto_inventory {
       $hash{'item'} = $self->getfield($field);
     }
 
+    my $agentnums_sql = $FS::CurrentUser::CurrentUser->agentnums_sql(
+      'null'  => 1,
+      'table' => 'inventory_item',
+    );
+
     my $inventory_item = qsearchs({
       'table'     => 'inventory_item',
       'hashref'   => \%hash,
-      'extra_sql' => 'LIMIT 1 FOR UPDATE',
+      'extra_sql' => "AND $agentnums_sql",
+      'order_by'  => 'ORDER BY ( agentnum IS NULL ) '. #agent inventory first
+                     ' LIMIT 1 FOR UPDATE',
     });
 
     unless ( $inventory_item ) {
index 36950b2..e74f442 100644 (file)
@@ -79,6 +79,8 @@
                      $f->{'table'}       = 'inventory_item';
                      $f->{'name_col'}    = 'item'; 
                      $f->{'value_col'}   = 'item'; 
+                     $f->{'agent_virt'}  = 1;
+                     $f->{'agent_null'}  = 1;
                      $f->{'hashref'}     = {
                                             'classnum'=>$columndef->columnvalue,
                                             #'svcnum'  => '',
index 80810ca..681e5db 100644 (file)
@@ -3,6 +3,9 @@
 
                  'menubar'     => [ 'View inventory classes' =>
                                       $p.'browse/inventory_class.html',
+                                    'Upload '. PL($inventory_class->classname)=>
+                                      $p.'misc/inventory_item-import.html?'.
+                                      "classnum=$classnum"
                                   ],
 
                  'name'        => PL($inventory_class->classname),