agent virt inventory, RT#7010
authorivan <ivan>
Thu, 20 May 2010 22:48:42 +0000 (22:48 +0000)
committerivan <ivan>
Thu, 20 May 2010 22:48:42 +0000 (22:48 +0000)
FS/FS/AccessRight.pm
FS/FS/Schema.pm
FS/FS/inventory_item.pm
httemplate/browse/inventory_class.html
httemplate/elements/menu.html
httemplate/misc/inventory_item-import.html
httemplate/search/elements/search.html
httemplate/search/inventory_item.html

index 01b9b58..08d31d2 100644 (file)
@@ -284,6 +284,9 @@ tie my %rights, 'Tie::IxHash',
   
     'Edit billing events',
     { rightname=>'Edit global billing events', global=>1 },
+
+    'Edit inventory',
+    { rightname=>'Edit global inventory', global=>1 },
   
     { rightname=>'Dialup configuration' },
     { rightname=>'Dialup global configuration', global=>1 },
index 07e5b30..ab80a08 100644 (file)
@@ -2593,12 +2593,13 @@ sub tables_hashref {
       'columns' => [
         'itemnum',  'serial',      '',      '', '', '',
         'classnum', 'int',         '',      '', '', '',
+        'agentnum', 'int',     'NULL',      '', '', '',
         'item',     'varchar',     '', $char_d, '', '',
         'svcnum',   'int',     'NULL',      '', '', '',
       ],
       'primary_key' => 'itemnum',
       'unique' => [ [ 'classnum', 'item' ] ],
-      'index'  => [ [ 'classnum' ], [ 'svcnum' ] ],
+      'index'  => [ [ 'classnum' ], [ 'agentnum' ], [ 'svcnum' ] ],
     },
 
     'inventory_class' => {
index 3bba1cd..39a0dff 100644 (file)
@@ -106,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' )
   ;
@@ -127,6 +130,17 @@ sub cust_svc {
   qsearchs( 'cust_svc', { 'svcnum' => $self->svcnum } );
 }
 
+=item agent 
+
+Returns the associated agent for this event, if any, as an FS::agent object.
+
+=cut
+
+sub agent {
+  my $self = shift;
+  qsearchs('agent', { 'agentnum' => $self->agentnum } );
+}
+
 =back
 
 =head1 SUBROUTINES
@@ -142,7 +156,7 @@ sub process_batch_import {
 
   my $opt = { 'table'   => 'inventory_item',
               #'params'  => [ 'itembatch', 'classnum', ],
-              'params'  => [ 'classnum', ],
+              'params'  => [ 'classnum', 'agentnum', ],
               'formats' => { 'default' => [ 'item' ] },
               'default_csv' => 1,
             };
index 8ce131a..4ad72a2 100644 (file)
@@ -1,9 +1,7 @@
 <% include( 'elements/browse.html',
                  'title'       => 'Inventory Classes',
                  'name'        => 'inventory classes',
-                 'menubar'     => [ 'Add a new inventory class' =>
-                                      $p.'edit/inventory_class.html',
-                                  ],
+                 'menubar'     => $menubar,
                  'query'       => { 'table' => 'inventory_class', },
                  'count_query' => 'SELECT COUNT(*) FROM inventory_class',
                  'header'      => [ '#', 'Inventory class', 'Inventory' ],
 %>
 <%init>
 
+my $curuser = $FS::CurrentUser::CurrentUser;
+
 die "access denied"
-  unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
+  unless $curuser->access_right('Edit inventory')
+      || $curuser->access_right('Edit global inventory')
+      || $curuser->access_right('Configuration');
 
 tie my %labels, 'Tie::IxHash',
   'num_avail' => 'Available', #  <FONT SIZE="-1"><A HREF="eventually">(upload batch)</A></FONT>',
@@ -88,6 +90,14 @@ my %inv_action_link = (
                  ],
 );
 
-my $link = [ "${p}edit/inventory_class.html?", 'classnum' ];
+my $menubar = $curuser->access_right('Configuration')
+                ? [ 'Add a new inventory class' =>
+                      $p.'edit/inventory_class.html',
+                  ]
+                : [];
+
+my $link = $curuser->access_right('Configuration')
+             ? [ "${p}edit/inventory_class.html?", 'classnum' ]
+             : '';
 
 </%init>
index 8b4a068..fc5498f 100644 (file)
@@ -469,8 +469,11 @@ $config_misc{'Advertising sources'} = [ $fsurl.'browse/part_referral.html', 'Whe
 if ( $curuser->access_right('Configuration') ) {
   $config_misc{'Virtual fields'} = [ $fsurl.'browse/part_virtual_field.cgi', 'Locally defined fields', ];
   $config_misc{'Message catalog'} = [ $fsurl.'browse/msgcat.cgi', 'Change error messages and other customizable labels' ];
-  $config_misc{'Inventory classes and inventory'} = [ $fsurl.'browse/inventory_class.html', 'Setup inventory classes and stock inventory' ];
 }
+$config_misc{'Inventory classes and inventory'} = [ $fsurl.'browse/inventory_class.html', 'Setup inventory classes and stock inventory' ]
+  if $curuser->access_right('Edit inventory')
+  || $curuser->access_right('Edit global inventory')
+  || $curuser->access_right('Configuration');
 
 tie my %config_menu, 'Tie::IxHash';
 if ( $curuser->access_right('Configuration' ) ) {
index c7edac6..990c14f 100644 (file)
@@ -7,8 +7,8 @@ Import a file containing <% PL($inventory_class->classname) %>, one per line.
               'name'      => 'InventoryItemImportForm',
               'action'    => 'process/inventory_item-import.html',
               'num_files' => 1,
-              #'fields'    => [ 'format', 'itembatch', 'classnum', ],
-              'fields'    => [ 'format', 'classnum', ],
+              #'fields'    => [ 'format', 'itembatch', 'classnum', 'agentnum' ],
+              'fields'    => [ 'format', 'classnum', 'agentnum', ],
               'message'   => 'Inventory import successful',
               #XXX redirect via $itembatch?  or just back to class browse?
               #'url'       => $p."search/phone_avail.html?availbatch=$availbatch",
@@ -24,6 +24,8 @@ Import a file containing <% PL($inventory_class->classname) %>, one per line.
 
 %#  <INPUT TYPE="hidden" NAME="itembatch" VALUE="<% $itembatch %>">
 
+  <% include('/elements/tr-select-agent.html') %>
+
   <% include( '/elements/file-upload.html',
                 'field' => 'file',
                 'label' => 'Filename',
index 0dc4170..636885e 100644 (file)
@@ -121,6 +121,7 @@ Example:
     #handling agent virtualization
     'agent_virt'            => 1, # set true if this search should be
                                   # agent-virtualized
+    'agent_null'            => 1, # set true to view global records always
     'agent_null_right'      => 'Access Right', # optional right to view global
                                                # records
     'agent_null_right_link' => 'Access Right'  # optional right to link to
@@ -235,7 +236,9 @@ if ( $opt{'agent_virt'} ) {
                                        || $opt{'agent_null_right'}      );
 
   my $agentnums_sql = $curuser->agentnums_sql(
-                        'null_right' => $opt{'agent_null_right'}
+                        'null'       => $opt{'agent_null'},
+                        'null_right' => $opt{'agent_null_right'},
+                        'table'      => $opt{'query'}{'table'},
                       );
 
   $opt{'query'}{'extra_sql'} .=
index 55fef94..80810ca 100644 (file)
@@ -1,8 +1,11 @@
 <% include( 'elements/search.html',
                  'title'       => $title,
 
-                 #less lame to use Lingua:: something to pluralize
-                 'name'        => $inventory_class->classname. 's',
+                 'menubar'     => [ 'View inventory classes' =>
+                                      $p.'browse/inventory_class.html',
+                                  ],
+
+                 'name'        => PL($inventory_class->classname),
 
                  'query'       => {
                                     'table'   => 'inventory_item',
 
                  'count_query' => $count_query,
 
+                 'agent_virt' => 1,
+                 'agent_null' => 1,
+                 'agent_pos'  => 2,
+
                  'header'      => [
                    '#',
                    $inventory_class->classname,
 %>
 <%init>
 
+my $curuser = $FS::CurrentUser::CurrentUser;
+
 die "access denied"
-  unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
+  unless $curuser->access_right('Edit inventory')
+      || $curuser->access_right('Edit global inventory')
+      || $curuser->access_right('Configuration');
 
 my $classnum = $cgi->param('classnum');
 $classnum =~ /^(\d+)$/ or errorpage("illegal classnum $classnum");