[freeside-commits] freeside/httemplate/search inventory_class.html, 1.1, 1.2 inventory_item.html, 1.1, 1.2

Ivan,,, ivan at wavetail.420.am
Wed Mar 8 04:14:06 PST 2006


Update of /home/cvs/cvsroot/freeside/httemplate/search
In directory wavetail:/tmp/cvs-serv11473/httemplate/search

Modified Files:
	inventory_class.html inventory_item.html 
Log Message:
 Add an option to the web interface to batch upload new entries to the
inventory_item table.

Index: inventory_item.html
===================================================================
RCS file: /home/cvs/cvsroot/freeside/httemplate/search/inventory_item.html,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- inventory_item.html	8 Mar 2006 10:05:00 -0000	1.1
+++ inventory_item.html	8 Mar 2006 12:14:04 -0000	1.2
@@ -1,15 +1,31 @@
 <%
 
 my $classnum = $cgi->param('classnum');
-$classnum =~ /^(\d+)$/ or eidiot "illegal agentnum $agentnum";
+$classnum =~ /^(\d+)$/ or eidiot "illegal classnum $classnum";
 $classnum = $1;
-my $inventory_class = qsearchs('inventory_class', { 'classnum' => $classnum } );
+
+my $inventory_class = qsearchs( {
+  'table'     => 'inventory_class',
+  'hashref'   => { 'classnum' => $classnum },
+} );
+
+my $title = $inventory_class->classname. ' Inventory';
+
+#little false laziness with SQL fragments in inventory_class.pm
+my $extra_sql = '';
+if ( $cgi->param('avail') ) {
+  $extra_sql = 'AND ( svcnum IS NULL OR svcnum = 0 )';
+  $title .= ' - Available';
+} elsif ( $cgi->param('used') ) {
+  $extra_sql = 'AND svcnum IS NOT NULL AND svcnum > 0';
+  $title .= ' - In use';
+}
 
 my $count_query =
-  "SELECT COUNT(*) FROM inventory_class WHERE classnum = $classnum";
+  "SELECT COUNT(*) FROM inventory_item WHERE classnum = $classnum $extra_sql";
 
 %><%= include( 'elements/search.html',
-                 'title'       => $inventory_class->classname. ' Inventory',
+                 'title'       => $title,
 
                  #less lame to use Lingua:: something to pluralize
                  'name'        => $inventory_class->classname. 's',
@@ -17,6 +33,7 @@
                  'query'       => {
                                     'table'   => 'inventory_item',
                                     'hashref' => { 'classnum' => $classnum },
+                                    'extra_sql' => $extra_sql,
                                   },
 
                  'count_query' => $count_query,

Index: inventory_class.html
===================================================================
RCS file: /home/cvs/cvsroot/freeside/httemplate/search/inventory_class.html,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- inventory_class.html	8 Mar 2006 10:05:00 -0000	1.1
+++ inventory_class.html	8 Mar 2006 12:14:04 -0000	1.2
@@ -5,11 +5,18 @@
   'num_used'  => 'In use', #'Used', #'Allocated',
   'num_total' => 'Total',
 ;
-my %inv_action_link = (
-  'num_avail' => 'eventually'
+
+my %link = (
+  'num_avail' => ';avail=1',
+  'num_used'  => ';avail=1',
+  'num_total' => '',
 );
-my %inv_action_label = (
-  'num_avail' => 'upload_batch'
+
+my %inv_action_link = (
+  'num_avail' => [ 'upload batch',
+                   $p.'misc/inventory_item-import.html?classnum=',
+                   'classnum'
+                 ],
 );
 
 my $link = [ "${p}edit/inventory_class.html?", 'classnum' ];
@@ -29,20 +36,44 @@
                                           #my $inventory_class = shift;
                                           my $i_c = shift;
 
+                                          my $link =
+                                            $p. 'search/inventory_item.html?'.
+                                            'classnum='. $i_c->classnum;
+
+                                          my %actioncol = ();
+                                          foreach ( keys %inv_action_link ) {
+                                            my($label, $baseurl, $method) =
+                                              @{ $inv_action_link{$_} };
+                                            my $url = $baseurl. $i_c->$method();
+                                            $actioncol{$_} =
+                                              '<FONT SIZE="-1">'.
+                                              '('.
+                                              '<A HREF="'.$url.'">'.
+                                              $label.
+                                              '</A>'.
+                                              ')'.
+                                              '</FONT>';
+                                          }
+
+                                          my %num = map { 
+                                            $_ => $i_c->$_();
+                                          } keys %labels;
+
                                           [ map {
                                                   [
                                                     {
-                                                      'data'  => '<B>'. $i_c->$_(). '</B>',
+                                                      'data'  => '<B>'. $num{$_}. '</B>',
                                                       'align' => 'right',
                                                     },
                                                     {
                                                       'data'  => $labels{$_},
                                                       'align' => 'left',
-                                                    },
-                                                    { 'data'  => ( exists($inv_action_link{$_})
-                                                                   ? '<FONT SIZE="-1">(<A HREF="'. $inv_action_link{$_}. '">'. $inv_action_label{$_}. '</A>)</FONT>'
-                                                                   : ''
+                                                      'link'  => ( $num{$_}
+                                                                     ? $link.$link{$_}
+                                                                     : ''
                                                                  ),
+                                                    },
+                                                    { 'data'  => $actioncol{$_},
                                                       'align'  => 'left',
                                                     },
                                                   ]



More information about the freeside-commits mailing list