From 276c1e6f4efb7ba5568bee9189298bc1a757d34d Mon Sep 17 00:00:00 2001 From: ivan Date: Fri, 21 May 2010 00:09:40 +0000 Subject: [PATCH] agent virt inventory, RT#7010 --- FS/FS/inventory_class.pm | 14 ++++++++++---- FS/FS/svc_Common.pm | 9 ++++++++- httemplate/edit/elements/svc_Common.html | 2 ++ httemplate/search/inventory_item.html | 3 +++ 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/FS/FS/inventory_class.pm b/FS/FS/inventory_class.pm index 508889bca..3d7f0499d 100644 --- a/FS/FS/inventory_class.pm +++ b/FS/FS/inventory_class.pm @@ -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]; } diff --git a/FS/FS/svc_Common.pm b/FS/FS/svc_Common.pm index fd2745dac..71290f441 100644 --- a/FS/FS/svc_Common.pm +++ b/FS/FS/svc_Common.pm @@ -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 ) { diff --git a/httemplate/edit/elements/svc_Common.html b/httemplate/edit/elements/svc_Common.html index 36950b2c9..e74f44276 100644 --- a/httemplate/edit/elements/svc_Common.html +++ b/httemplate/edit/elements/svc_Common.html @@ -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' => '', diff --git a/httemplate/search/inventory_item.html b/httemplate/search/inventory_item.html index 80810caf9..681e5dbac 100644 --- a/httemplate/search/inventory_item.html +++ b/httemplate/search/inventory_item.html @@ -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), -- 2.11.0