start of package class web UI (add/edit package classes, package class selection...
authorivan <ivan>
Sat, 22 Apr 2006 00:58:40 +0000 (00:58 +0000)
committerivan <ivan>
Sat, 22 Apr 2006 00:58:40 +0000 (00:58 +0000)
23 files changed:
FS/FS/part_pkg.pm
htetc/handler.pl
httemplate/browse/elements/browse.html [new file with mode: 0644]
httemplate/browse/generic.cgi [deleted file]
httemplate/browse/inventory_class.html [new file with mode: 0644]
httemplate/browse/part_pkg.cgi
httemplate/browse/pkg_class.html [new file with mode: 0644]
httemplate/browse/rate.cgi
httemplate/edit/elements/edit.html
httemplate/edit/inventory_class.html
httemplate/edit/part_pkg.cgi
httemplate/edit/pkg_class.html [new file with mode: 0644]
httemplate/edit/process/elements/process.html
httemplate/edit/process/inventory_class.html
httemplate/edit/process/pkg_class.html [new file with mode: 0644]
httemplate/elements/select-agent.html
httemplate/elements/select-pkg_class.html [new file with mode: 0644]
httemplate/elements/select-table.html [new file with mode: 0644]
httemplate/elements/tr-select-pkg_class.html [new file with mode: 0644]
httemplate/index.html
httemplate/search/cust_pkg.cgi
httemplate/search/elements/search.html
httemplate/search/inventory_class.html [deleted file]

index 30a9722..05dc599 100644 (file)
@@ -12,6 +12,7 @@ use FS::cust_pkg;
 use FS::agent_type;
 use FS::type_pkgs;
 use FS::part_pkg_option;
+use FS::pkg_class;
 
 @ISA = qw( FS::Record ); # FS::option_Common ); # this can use option_Common
                                                 # when all the plandata bs is
@@ -58,6 +59,8 @@ inherits from FS::Record.  The following fields are currently supported:
 
 =item comment - Text name of this package definition (non-customer-viewable)
 
+=item classnum - Optional package class (see L<FS::pkg_class>)
+
 =item promo_code - Promotional code
 
 =item setup - Setup fee expression (deprecated)
@@ -455,6 +458,37 @@ sub check {
   '';
 }
 
+=item pkg_class
+
+Returns the package class, as an FS::pkg_class object, or the empty string
+if there is no package class.
+
+=cut
+
+sub pkg_class {
+  my $self = shift;
+  if ( $self->classnum ) {
+    qsearchs('pkg_class', { 'classnum' => $self->classnum } );
+  } else {
+    return '';
+  }
+}
+
+=item classname 
+
+Returns the package class name, or the empty string if there is no package
+class.
+
+=cut
+
+sub classname {
+  my $self = shift;
+  my $pkg_class = $self->pkg_class;
+  $pkg_class
+    ? $pkg_class->classname
+    : '';
+}
+
 =item pkg_svc
 
 Returns all FS::pkg_svc objects (see L<FS::pkg_svc>) for this package
index 008b0b5..dcbe727 100644 (file)
@@ -176,6 +176,7 @@ sub handler
       use FS::cdr;
       use FS::inventory_class;
       use FS::inventory_item;
+      use FS::pkg_class;
 
       if ( %%%RT_ENABLED%%% ) {
         eval '
diff --git a/httemplate/browse/elements/browse.html b/httemplate/browse/elements/browse.html
new file mode 100644 (file)
index 0000000..6d146d3
--- /dev/null
@@ -0,0 +1,6 @@
+<%= include( '/search/elements/search.html',
+               @_,
+               'disable_download'  => 1,
+               'disable_nonefound' => 1,
+           )
+%>
diff --git a/httemplate/browse/generic.cgi b/httemplate/browse/generic.cgi
deleted file mode 100644 (file)
index 9ac0f23..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-<%
-
-use FS::Record qw(qsearch dbdef);
-use DBIx::DBSchema;
-use DBIx::DBSchema::Table;
-
-my $error;
-my $p2 = popurl(2);
-my ($table) = $cgi->keywords;
-my $dbdef = dbdef or die "Cannot fetch dbdef!";
-my $dbdef_table = $dbdef->table($table) or die "Cannot fetch schema for $table";
-
-my $pkey = $dbdef_table->primary_key or die "Cannot fetch pkey for $table";
-print header("Browse $table", menubar('Main Menu'   => $p));
-
-my @rec = qsearch($table, {});
-my @col = $dbdef_table->columns;
-
-if ($cgi->param('error')) { %>
-   <FONT SIZE="+1" COLOR="#ff0000">Error: <%=$cgi->param('error')%></FONT>
-   <BR><BR>
-<% } 
-%>
-<A HREF="<%=$p2%>edit/<%=$table%>.cgi"><I>Add a new <%=$table%></I></A><BR><BR>
-
-<%=table()%>
-<TH>
-<% foreach (grep { $_ ne $pkey } @col) {
-  %><TD><%=$_%></TD>
-  <% } %>
-</TH>
-<% foreach $rec (sort {$a->getfield($pkey) cmp $b->getfield($pkey) } @rec) { 
-  %>
-  <TR>
-    <TD>
-      <A HREF="<%=$p2%>edit/<%=$table%>.cgi?<%=$rec->getfield($pkey)%>">
-      <%=$rec->getfield($pkey)%></A> </TD> <%
-  foreach $col (grep { $_ ne $pkey } @col)  { %>
-    <TD><%=$rec->getfield($col)%></TD> <% } %>
-  </A>
-  </TR>
-<% } %>
-</TABLE>
-</BODY>
-</HTML>
-
diff --git a/httemplate/browse/inventory_class.html b/httemplate/browse/inventory_class.html
new file mode 100644 (file)
index 0000000..6da3c9e
--- /dev/null
@@ -0,0 +1,89 @@
+<%
+
+tie my %labels, 'Tie::IxHash',
+  'num_avail' => 'Available', #  <FONT SIZE="-1"><A HREF="eventually">(upload batch)</A></FONT>',
+  'num_used'  => 'In use', #'Used', #'Allocated',
+  'num_total' => 'Total',
+;
+
+my %link = (
+  'num_avail' => ';avail=1',
+  'num_used'  => ';avail=1',
+  'num_total' => '',
+);
+
+my %inv_action_link = (
+  'num_avail' => [ 'upload batch',
+                   $p.'misc/inventory_item-import.html?classnum=',
+                   'classnum'
+                 ],
+);
+
+my $link = [ "${p}edit/inventory_class.html?", 'classnum' ];
+
+%><%= include( 'elements/browse.html',
+                 'title'       => 'Inventory Classes',
+                 'name'        => 'inventory classes',
+                 'menubar'     => [ 'Add a new inventory class' =>
+                                      $p.'edit/inventory_class.html',
+                                  ],
+                 'query'       => { 'table' => 'inventory_class', },
+                 'count_query' => 'SELECT COUNT(*) FROM inventory_class',
+                 'header'      => [ '#', 'Inventory class', 'Inventory' ],
+                 'fields'      => [ 'classnum',
+                                    'classname',
+                                    sub {
+                                          #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>'. $num{$_}. '</B>',
+                                                      'align' => 'right',
+                                                    },
+                                                    {
+                                                      'data'  => $labels{$_},
+                                                      'align' => 'left',
+                                                      'link'  => ( $num{$_}
+                                                                     ? $link.$link{$_}
+                                                                     : ''
+                                                                 ),
+                                                    },
+                                                    { 'data'  => $actioncol{$_},
+                                                      'align'  => 'left',
+                                                    },
+                                                  ]
+                                                } keys %labels
+                                          ];
+                                        },
+                                  ],
+                 'links'       => [ $link,
+                                    $link,
+                                    '',
+                                  ],
+             )
+%>
index e645463..0afa547 100755 (executable)
-<!-- mason kludge -->
 <%
 
-my %search;
-if ( $cgi->param('showdisabled') ) {
-  %search = ();
-} else {
+my %search = ();
+my $search = '';
+unless ( $cgi->param('showdisabled') ) {
   %search = ( 'disabled' => '' );
+  $search = "( disabled = '' OR disabled IS NULL )";
 }
 
-my @part_pkg = qsearch('part_pkg', \%search );
-my $total = scalar(@part_pkg);
-
-my $sortby;
-my %num_active_cust_pkg = ();
-my( $suspended_sth, $canceled_sth ) = ( '', '' );
+my $select = '*';
+my $orderby = 'pkgpart';
 if ( $cgi->param('active') ) {
-  my $active_sth = dbh->prepare(
-    'SELECT COUNT(*) FROM cust_pkg WHERE pkgpart = ?'.
-    ' AND ( cancel IS NULL OR cancel = 0 )'.
-    ' AND ( susp IS NULL OR susp = 0 )'
-  ) or die dbh->errstr;
-  foreach my $part_pkg ( @part_pkg ) {
-    $active_sth->execute($part_pkg->pkgpart) or die $active_sth->errstr;
-    $num_active_cust_pkg{$part_pkg->pkgpart} =
-      $active_sth->fetchrow_arrayref->[0];
-  }
-  $sortby = sub {
-    $num_active_cust_pkg{$b->pkgpart} <=> $num_active_cust_pkg{$a->pkgpart};
-  };
-
-  $suspended_sth = dbh->prepare(
-    'SELECT COUNT(*) FROM cust_pkg WHERE pkgpart = ?'.
-    ' AND ( cancel IS NULL OR cancel = 0 )'.
-    ' AND susp IS NOT NULL AND susp != 0'
-  ) or die dbh->errstr;
-
-  $canceled_sth = dbh->prepare(
-    'SELECT COUNT(*) FROM cust_pkg WHERE pkgpart = ?'.
-    ' AND cancel IS NOT NULL AND cancel != 0'
-  ) or die dbh->errstr;
 
-} else {
-  $sortby = sub { $a->pkgpart <=> $b->pkgpart; };
+  $orderby = 'num_active';
+
+  $select = "
+
+    *,
+
+    ( SELECT COUNT(*) FROM cust_pkg WHERE cust_pkg.pkgpart = part_pkg.pkgpart
+       AND ( cancel IS NULL OR cancel = 0 )
+       AND ( susp IS NULL OR susp = 0 )
+    ) AS num_active,
+
+    ( SELECT COUNT(*) FROM cust_pkg WHERE cust_pkg.pkgpart = part_pkg.pkgpart
+        AND ( cancel IS NULL OR cancel = 0 )
+        AND susp IS NOT NULL AND susp != 0
+    ) AS num_suspended,
+
+    ( SELECT COUNT(*) FROM cust_pkg WHERE cust_pkg.pkgpart = part_pkg.pkgpart
+        AND cancel IS NOT NULL AND cancel != 0
+    ) AS num_cancelled
+
+  ";
+
 }
 
 my $conf = new FS::Conf;
 my $taxclasses = $conf->exists('enable_taxclasses');
 
-%>
-<%= include("/elements/header.html","Package Definition Listing",menubar( 'Main Menu' => $p )) %>
-<% unless ( $cgi->param('active') ) { %>
-  One or more service definitions are grouped together into a package 
-  definition and given pricing information.  Customers purchase packages
-  rather than purchase services directly.<BR><BR>
-  <A HREF="<%= $p %>edit/part_pkg.cgi"><I>Add a new package definition</I></A>
-  <BR><BR>
-<% } %>
-
-<%= $total %> package definitions
-<% if ( $cgi->param('showdisabled') ) { $cgi->param('showdisabled', 0); %>
-  ( <a href="<%= $cgi->self_url %>">hide disabled packages</a> )
-<% } else { $cgi->param('showdisabled', 1); %>
-  ( <a href="<%= $cgi->self_url %>">show disabled packages</a> )
-<% } %>
-
-<% my $colspan = $cgi->param('showdisabled') ? 2 : 3; %>
-
-<%= &table() %>
-      <TR>
-        <TH COLSPAN=<%= $colspan %>>Package</TH>
-        <TH>Comment</TH>
-<% if ( $cgi->param('active') ) { %>
-        <TH><FONT SIZE=-1>Customer<BR>packages</FONT></TH>
-<% } %>
-        <TH><FONT SIZE=-1>Freq.</FONT></TH>
-<% if ( $taxclasses ) { %>
-       <TH><FONT SIZE=-1>Taxclass</FONT></TH>
-<% } %>
-        <TH><FONT SIZE=-1>Plan</FONT></TH>
-        <TH><FONT SIZE=-1>Data</FONT></TH>
-        <TH>Service</TH>
-        <TH><FONT SIZE=-1>Quan.</FONT></TH>
-<% if ( dbdef->table('pkg_svc')->column('primary_svc') ) { %>
-        <TH><FONT SIZE=-1>Primary</FONT></TH>
-<% } %>
-
-      </TR>
+my $html_init;
+unless ( $cgi->param('active') ) {
+  $html_init = qq!
+    One or more service definitions are grouped together into a package 
+    definition and given pricing information.  Customers purchase packages
+    rather than purchase services directly.<BR><BR>
+    <A HREF="${p}edit/part_pkg.cgi"><I>Add a new package definition</I></A>
+    <BR><BR>
+  !;
+}
 
-<%
-foreach my $part_pkg ( sort $sortby @part_pkg ) {
-  my @pkg_svc = $part_pkg->pkg_svc;
-  my($rowspan)=scalar(@pkg_svc);
-  my $plandata;
-  if ( $part_pkg->plan ) {
-    $plandata = $part_pkg->plandata;
-    $plandata =~ s/^(\w+)=/$1&nbsp;/mg;
-    $plandata =~ s/\n/<BR>/g;
-  } else {
-    $part_pkg->plan('(legacy)');
-    $plandata = "Setup&nbsp;". $part_pkg->setup.
-                "<BR>Recur&nbsp;". $part_pkg->recur;
-  }
-%>
-      <TR>
-        <TD ROWSPAN=<%= $rowspan %>><A HREF="<%=$p%>edit/part_pkg.cgi?<%= $part_pkg->pkgpart %>"><%= $part_pkg->pkgpart %></A></TD>
-
-<% unless ( $cgi->param('showdisabled') ) { %>
-        <TD ROWSPAN=<%= $rowspan %>>
-   <% if ( $part_pkg->disabled ) { %>
-          DISABLED
-   <% } %>
-        </TD>
-<% } %>
-
-        <TD ROWSPAN=<%= $rowspan %>><A HREF="<%=$p%>edit/part_pkg.cgi?<%= $part_pkg->pkgpart %>"><%= $part_pkg->pkg %></A></TD>
-        <TD ROWSPAN=<%= $rowspan %>><%= $part_pkg->comment %></TD>
-
-<% if ( $cgi->param('active') ) { %>
-        <TD ROWSPAN=<%= $rowspan %>>
-          <FONT COLOR="#00CC00"><B><%= $num_active_cust_pkg{$part_pkg->pkgpart} %></B></FONT>&nbsp;<A HREF="<%=$p%>search/cust_pkg.cgi?magic=active;pkgpart=<%= $part_pkg->pkgpart %>">active</A><BR>
-
-   <% $suspended_sth->execute( $part_pkg->pkgpart )
-        or die $suspended_sth->errstr;
-      my $num_suspended = $suspended_sth->fetchrow_arrayref->[0];
-   %>
-          <FONT COLOR="#FF9900"><B><%= $num_suspended %></B></FONT>&nbsp;<A HREF="<%=$p%>search/cust_pkg.cgi?magic=suspended;pkgpart=<%= $part_pkg->pkgpart %>">suspended</A><BR>
-
-   <% $canceled_sth->execute( $part_pkg->pkgpart )
-        or die $canceled_sth->errstr;
-      my $num_canceled = $canceled_sth->fetchrow_arrayref->[0];
-   %>
-          <FONT COLOR="#FF0000"><B><%= $num_canceled %></B></FONT>&nbsp;<A HREF="<%=$p%>search/cust_pkg.cgi?magic=canceled;pkgpart=<%= $part_pkg->pkgpart %>">canceled</A>
-        </TD>
-<% } %>
-
-        <TD ROWSPAN=<%= $rowspan %>><%= $part_pkg->freq_pretty %></TD>
-
-<% if ( $taxclasses ) { %>
-       <TD ROWSPAN=<%= $rowspan %>><%= $part_pkg->taxclass || '&nbsp;' %></TD>
-<% } %>
-
-        <TD ROWSPAN=<%= $rowspan %>><%= $part_pkg->plan %></TD>
-        <TD ROWSPAN=<%= $rowspan %>><%= $plandata %></TD>
+my $posttotal;
+if ( $cgi->param('showdisabled') ) {
+  $cgi->param('showdisabled', 0);
+  $posttotal = '( <a href="'. $cgi->self_url. '">hide disabled packages</a> )';
+} else {
+  $cgi->param('showdisabled', 1);
+  $posttotal = '( <a href="'. $cgi->self_url. '">show disabled packages</a> )';
+}
 
-<%
-  my($n)="";
-  foreach my $pkg_svc ( @pkg_svc ) {
-    my($svcpart)=$pkg_svc->getfield('svcpart');
-    my($part_svc) = qsearchs('part_svc',{'svcpart'=> $svcpart });
-    print $n,qq!<TD><A HREF="${p}edit/part_svc.cgi?$svcpart">!,
-          $part_svc->getfield('svc'),"</A></TD><TD>",
-          $pkg_svc->getfield('quantity'),"</TD>";
-    if ( dbdef->table('pkg_svc')->column('primary_svc') ) {
-      print '<TD>';
-      print 'PRIMARY' if $pkg_svc->primary_svc =~ /^Y/i;
-      print '</TD>';
-    }
-    print "</TR>\n";
-    $n="<TR>";
-  }
-%>
+# ------
+
+my $link = [ $p.'edit/part_pkg.cgi?', 'pkgpart' ];
+
+my @header = ( '#', 'Package', 'Comment' );
+my @fields = ( 'pkgpart', 'pkg', 'comment' );
+my $align = 'rll';
+my @links = ( $link, $link, '' );
+my @style = ( '', '', '' );
+
+unless ( $cgi->param('showdisabled') ) { #its been reversed already
+  push @header, 'Status';
+  push @fields, sub { shift->disabled
+                        ? '<FONT COLOR="#FF0000">DISABLED</FONT>'
+                        : '<FONT COLOR="#00CC00">Active</FONT>'
+                    };
+  push @links, '';
+  $align .= 'c';
+  push @style, 'b';
+}
+
+unless ( 0 ) { #already showing only one class or something?
+  push @header, 'Class';
+  push @fields, sub { shift->classname || '(none)'; };
+  $align .= 'l';
+}
+
+if ( $cgi->param('active') ) {
+  push @header, 'Customer<BR>packages';
+  my %col = (
+    'active'      => '00CC00',
+    'suspended'   => 'FF9900',
+    'cancelled'   => 'FF0000',
+  );
+  my $cust_pkg_link = $p. 'search/cust_pkg.cgi?pkgpart=';
+  push @fields, sub { my $part_pkg = shift;
+                      [
+                        map {
+                              [
+                                {
+                                 'data'  => '<B><FONT COLOR="#'. $col{$_}. '">'.
+                                            $part_pkg->get("num_$_").
+                                            '</FONT></B>',
+                                 'align' => 'right',
+                                },
+                                {
+                                 'data'  => $_,
+                                 'align' => 'left',
+                                 'link'  => ( $part_pkg->get("num_$_")
+                                                ? $cust_pkg_link.
+                                                  $part_pkg->pkgpart.
+                                                  ";magic=$_"
+                                                : ''
+                                            ),
+                                },
+                              ],
+                            } (qw( active suspended cancelled ))
+                      ]; };
+  $align .= 'r';
+}
 
-      </TR>
-<% } %>
+push @header, 'Frequency';
+push @fields, sub { shift->freq_pretty; };
+$align .= 'l';
 
-    </TABLE>
-  </BODY>
-</HTML>
+if ( $taxclasses ) {
+  push @header, 'Taxclass';
+  push @fields, sub { shift->taxclass() || '&nbsp;'; };
+  $align .= 'l';
+}
+
+push @header, 'Plan',
+              'Data',
+              'Services';
+              #'Service', 'Quan', 'Primary';
+
+push @fields, sub { shift->plan || '(legacy)' }, 
+
+              sub {
+                    my $part_pkg = shift;
+                    if ( $part_pkg->plan ) {
+
+                      [ map { 
+                              /^(\w+)=(.*)$/; #or something;
+                              [
+                                { 'data'  => $1,
+                                  'align' => 'right',
+                                },
+                                { 'data'  => $2,
+                                  'align' => 'left',
+                                },
+                              ];
+                            }
+                        split(/\n/, $part_pkg->plandata)
+                      ];
+
+                    } else {
+
+                      [ map { [
+                                { 'data'  => uc($_),
+                                  'align' => 'right',
+                                },
+                                {
+                                  'data'  => $part_pkg->$_(),
+                                  'align' => 'left',
+                                },
+                              ];
+                            }
+                        (qw(setup recur))
+                      ];
+
+                    }
+
+                  },
+
+              sub {
+                    my $part_pkg = shift;
+
+                    [ map  {
+                             my $pkg_svc = $_;
+                             my $part_svc = $pkg_svc->part_svc;
+                             my $svc = $part_svc->svc;
+                             if ( $pkg_svc->primary_svc =~ /^Y/i ) {
+                               $svc = "<B>$svc (PRIMARY)</B>";
+                             }
+                             $svc =~ s/ +/&nbsp;/g;
+
+                             [
+                               {
+                                 'data'  => '<B>'. $pkg_svc->quantity. '</B>',
+                                 'align' => 'right'
+                               },
+                               {
+                                 'data'  => $svc,
+                                 'align' => 'left',
+                                 'link'  => $p. 'edit/part_svc.cgi?'.
+                                            $part_svc->svcpart,
+                               },
+                             ];
+                           }
+                      sort {     $b->primary_svc =~ /^Y/i
+                             <=> $a->primary_svc =~ /^Y/i
+                           }
+                           $part_pkg->pkg_svc
+
+                    ];
+
+                  };
+
+$align .= 'lrl'; #rr';
+
+# --------
+
+my $count_query = 'SELECT COUNT(*) FROM part_pkg';
+$count_query .= " WHERE $search"
+  if $search;
+
+%><%= include( 'elements/browse.html',
+                 'title'          => 'Package Definitions',
+                 'menubar'        => [ 'Main Menu' => $p ],
+                 'html_init'      => $html_init,
+                 'html_posttotal' => $posttotal,
+                 'name'           => 'package definitions',
+                 'query'          => { 'select'    => $select,
+                                       'table'     => 'part_pkg',
+                                       'hashref'   => \%search,
+                                       'extra_sql' => "ORDER BY $orderby",
+                                     },
+                 'count_query'    => $count_query,
+                 'header'         => \@header,
+                 'fields'         => \@fields,
+                 'links'          => \@links,
+                 'align'          => $align,
+                 'style'          => \@style,
+             )
+%>
diff --git a/httemplate/browse/pkg_class.html b/httemplate/browse/pkg_class.html
new file mode 100644 (file)
index 0000000..d4f8f02
--- /dev/null
@@ -0,0 +1,26 @@
+<%
+
+my $html_init = 
+  'Package classes define groups of packages, for reporting and '.
+  'convenience purposes.<BR><BR>'.
+  qq!<A HREF="${p}edit/pkg_class.html"><I>Add a package class</I></A><BR><BR>!;
+
+my $count_query = 'SELECT COUNT(*) FROM pkg_class';
+
+my $link = [ $p.'edit/pkg_class.html?', 'classnum' ];
+
+%><%= include( 'elements/browse.html',
+                 'title'       => 'Package classes',
+                 'menubar'     => [ 'Main menu' => $p, ],
+                 'html_init'   => $html_init,
+                 'name'        => 'package classes',
+                 'query'       => { 'table'     => 'pkg_class',
+                                    'hashref'   => {},
+                                    'extra_sql' => 'ORDER BY classnum',
+                                  },
+                 'count_query' => $count_query,
+                 'header'      => [ '#', 'Class', ],
+                 'fields'      => [ 'classnum', 'classname' ],
+                 'links'       => [ $link, $link ],
+             )
+%>
index 4718b71..c4ae2f0 100644 (file)
@@ -1,34 +1,33 @@
-<!-- mason kludge -->
-<%= include("/elements/header.html","Rate plan listing", menubar( 'Main Menu' => "$p#sysadmin" )) %>
-Rate plans, regions and prefixes for VoIP and call billing.<BR><BR>
-<A HREF="<%=$p%>edit/rate.cgi"><I>Add a rate plan</I></A>
-| <A HREF="<%=$p%>edit/rate_region.cgi"><I>Add a region</I></A>
-<BR><BR>
-<SCRIPT>
-function rate_areyousure(href) {
-  if (confirm("Are you sure you want to delete this rate plan?") == true)
-    window.location.href = href;
-}
-</SCRIPT>
+<%
 
-<%= table() %>
-  <TR>
-    <TH COLSPAN=2>Rate plan</TH>
-  </TR>
+my $html_init = 
+  'Rate plans, regions and prefixes for VoIP and call billing.<BR><BR>'.
+  qq!<A HREF="${p}edit/rate.cgi"><I>Add a rate plan</I></A>!.
+  qq! | <A HREF="${p}edit/rate_region.cgi"><I>Add a region</I></A>!.
+  '<BR><BR>
+   <SCRIPT>
+   function rate_areyousure(href) {
+    if (confirm("Are you sure you want to delete this rate plan?") == true)
+      window.location.href = href;
+   }
+   </SCRIPT>';
 
-<% foreach my $rate ( sort { 
-     $a->getfield('ratenum') <=> $b->getfield('ratenum')
-   } qsearch('rate',{}) ) {
-%>
-  <TR>
-    <TD><A HREF="<%= $p %>edit/rate.cgi?<%= $rate->ratenum %>"><%= $rate->ratenum %></A></TD>
-    <TD><A HREF="<%= $p %>edit/rate.cgi?<%= $rate->ratenum %>"><%= $rate->ratename %></A></TD>
-  </TR>
-
-<% } %>
+my $count_query = 'SELECT COUNT(*) FROM rate';
 
-</TABLE>
-</BODY>
-</HTML>
+my $link = [ $p.'edit/rate.cgi?', 'ratenum' ];
 
+%><%= include( 'elements/browse.html',
+                 'title'       => 'Rate plans',
+                 'menubar'     => [ 'Main menu' => $p, ],
+                 'html_init'   => $html_init,
+                 'name'        => 'rate plans',
+                 'query'       => { 'table'     => 'rate',
+                                    'hashref'   => {},
+                                    'extra_sql' => 'ORDER BY ratenum',
+                                  },
+                 'count_query' => $count_query,
+                 'header'      => [ '#', 'Rate plan', ],
+                 'fields'      => [ 'ratenum', 'ratename' ],
+                 'links'       => [ $link, $link ],
+             )
+%>
index ce6e2db..5486b4b 100644 (file)
@@ -15,6 +15,8 @@
   #             ]
   #
   # 'menubar'     => '', #menubar arrayref
+  #
+  # 'viewall_dir' => '', #'search' or 'browse', defaults to 'search'
 
   my(%opt) = @_;
 
@@ -55,7 +57,9 @@
   } else {
     @menubar = (
       'Main menu' => $p, #eventually get rid of this when the ACL/UI update is done
-      "View all $opt{'name'}s" => "${p}search/$table.html", #eventually use Lingua::bs to pluralize
+      #eventually use Lingua::bs to pluralize
+      "View all $opt{'name'}s" => $p. ( $opt{'viewall_dir'} || 'search' ).
+                                  "/$table.html",
     );
   }
 
index 5dde2e5..8c5ae47 100644 (file)
@@ -5,5 +5,6 @@
                                'classnum'  => 'Class number',
                                'classname' => 'Class name',
                              },
+                 'viewall_dir' => 'browse',
            )
 %>
index 158c6e2..462d516 100755 (executable)
@@ -84,6 +84,7 @@ Package information
       <INPUT TYPE="text" NAME="comment" SIZE=32 VALUE="<%=$part_pkg->comment%>">
     </TD>
   </TR>
+  <%= include( '/elements/tr-select-pkg_class.html', $part_pkg->classnum ) %>
   <TR>
     <TD ALIGN="right">Promotional code</TD>
     <TD>
@@ -146,8 +147,8 @@ $thead .= '<TH BGCOLOR="#dcdcdc">Service</TH></TR>';
 
 %>
 
-<%= itable('', 4, 1) %><TR><TD VALIGN="top">
 <BR><BR>Services included
+<%= itable('', 4, 1) %><TR><TD VALIGN="top">
 <%= $thead %>
 
 <%
@@ -194,14 +195,14 @@ foreach my $part_svc ( @part_svc ) {
     </TD>
   </TR>
 
-  <% $count++;
-     foreach ( 1 .. $columns-1 ) {
+  <% foreach ( 1 .. $columns-1 ) {
        if ( $count == int( $_ * scalar(@part_svc) / $columns ) ) { 
   %>
          </TABLE></TD><TD VALIGN="top"><%= $thead %>
 
   <%   }
      }
+     $count++;
   %>
 
 <% } %>
@@ -224,7 +225,7 @@ my %plandata = map { /^(\w+)=(.*)$/; ( $1 => $2 ); }
 
 tie my %options, 'Tie::IxHash', map { $_=>$plans{$_}->{'name'} } keys %plans;
 
-my @form_select = ();
+my @form_select = ('classnum');
 if ( $conf->exists('enable_taxclasses') ) {
   push @form_select, 'taxclass';
 } else {
diff --git a/httemplate/edit/pkg_class.html b/httemplate/edit/pkg_class.html
new file mode 100644 (file)
index 0000000..b077f6f
--- /dev/null
@@ -0,0 +1,10 @@
+<%= include( 'elements/edit.html',
+                 'name'   => 'Package Class',
+                 'table'  => 'pkg_class',
+                 'labels' => { 
+                               'classnum'  => 'Class number',
+                               'classname' => 'Class name',
+                             },
+                 'viewall_dir' => 'browse',
+           )
+%>
index 52c8767..83ff6f7 100644 (file)
@@ -5,6 +5,7 @@
   # 'table' => 
   # #? 'primary_key' => #required when the dbdef doesn't know...???
   # #? 'fields' => []
+  # 'viewall_dir' => '', #'search' or 'browse', defaults to 'search'
 
   my(%opt) = @_;
 
     $cgi->param('error', $error);
     print $cgi->redirect(popurl(2). "$table.html?". $cgi->query_string );
   } else { 
-    print $cgi->redirect(popurl(3). "search/$table.html");
+    print $cgi->redirect( popurl(3).
+                          ( $opt{'viewall_dir'} || 'search' ).
+                          "/$table.html"
+                        );
   }
 
 %>
index e30e74e..ab9efef 100644 (file)
@@ -1,4 +1,5 @@
 <%= include( 'elements/process.html',
-               'table' => 'inventory_class',
+               'table'       => 'inventory_class',
+               'viewall_dir' => 'browse',
            )
 %>
diff --git a/httemplate/edit/process/pkg_class.html b/httemplate/edit/process/pkg_class.html
new file mode 100644 (file)
index 0000000..48e2b80
--- /dev/null
@@ -0,0 +1,5 @@
+<%= include( 'elements/process.html',
+               'table'       => 'pkg_class',
+               'viewall_dir' => 'browse',
+           )
+%>
index c2a5e4b..aa480a5 100644 (file)
@@ -1,24 +1,16 @@
 <%
   my( $agentnum, %opt ) = @_;
 
-  my @agents;
-  if ( $opt{'agents'} ) {
-    @agents = @{ $opt{'agents'} };
-  } else {
-    @agents = qsearch( 'agent', { disabled=>'' } );
-  }
-
+  my %select_opt = ();
+  $select_opt{'records'} = $opt{'agents'}
+    if $opt{'agents'};
+
+%><%= include( '/elements/select-table.html',
+                 'table'       => 'agent',
+                 'name_col'    => 'agent',
+                 'value'       => $agentnum,
+                 'empty_label' => 'all',
+                 'hashref'     => { 'disabled' => '' },
+                 %select_opt,
+             )
 %>
-
-<SELECT NAME="agentnum">
-
-  <OPTION VALUE="">all</OPTION>
-
-  <% foreach my $agent ( sort { $a->agent cmp $b->agent } @agents ) { %>
-
-    <OPTION VALUE="<%= $agent->agentnum %>"<%= $agentnum == $agent->agentnum ? ' SELECTED' : '' %>><%= $agent->agent %>
-
-  <% } %>
-
-</SELECT>
-
diff --git a/httemplate/elements/select-pkg_class.html b/httemplate/elements/select-pkg_class.html
new file mode 100644 (file)
index 0000000..5486e08
--- /dev/null
@@ -0,0 +1,16 @@
+<%
+  my( $classnum, %opt ) = @_;
+
+  my %select_opt = ();
+  $select_opt{'records'} = $opt{'pkg_class'}
+    if $opt{'pkg_class'};
+
+%><%= include( '/elements/select-table.html',
+                 'table'       => 'pkg_class',
+                 'name_col'    => 'classname',
+                 'value'       => $classnum,
+                 'empty_label' => '(none)',
+                 #'hashref'     => { 'disabled' => '' },
+                 #%select_opt,
+             )
+%>
diff --git a/httemplate/elements/select-table.html b/httemplate/elements/select-table.html
new file mode 100644 (file)
index 0000000..10cc8b9
--- /dev/null
@@ -0,0 +1,45 @@
+<%
+
+  ##required
+  # 'table'    => 'table_name',
+  # 'name_col' => 'name_column',
+  #
+  ##strongly recommended (you want your forms to be "sticky" on errors, right?)
+  # 'value'    => 'current_value',
+  #
+  ##opt
+  # 'empty_label' => '', #better specify it though, the default might change
+  # 'hashref'     => {},
+  # 'records'     => \@records, #instead of hashref
+
+  my( %opt ) = @_;
+
+  my $key = dbdef->table($opt{'table'})->primary_key; #? $opt{'primary_key'} ||
+
+  my $name_col = $opt{'name_col'};
+
+  my @records = ();
+  if ( $opt{'records'} ) {
+    @records = @{ $opt{'records'} };
+  } else {
+    @records = qsearch( $opt{'table'}, ( $opt{'hashref'} || {} ) );
+  }
+
+%>
+
+<SELECT NAME="<%= $key %>">
+
+  <OPTION VALUE=""><%= $opt{'empty_label'} || 'all' %></OPTION>
+
+  <% foreach my $record ( sort { $a->$name_col() cmp $b->$name_col() }
+                               @records
+                        )
+     {
+  %>
+
+    <OPTION VALUE="<%= $record->$key() %>"<%= $opt{'value'} == $record->$key() ? ' SELECTED' : '' %>><%= $record->$name_col() %>
+
+  <% } %>
+
+</SELECT>
+
diff --git a/httemplate/elements/tr-select-pkg_class.html b/httemplate/elements/tr-select-pkg_class.html
new file mode 100644 (file)
index 0000000..de10885
--- /dev/null
@@ -0,0 +1,29 @@
+<%
+  my( $classnum, %opt ) = @_;
+
+  my @pkg_class;
+  if ( $opt{'pkg_class'} ) {
+    @pkg_class = @{ $opt{'pkg_class'} };
+  } else {
+    @pkg_class = qsearch( 'pkg_class', {} ); # { disabled=>'' } );
+  }
+
+%>
+
+<% if ( scalar(@pkg_class) == 0 ) { %>
+
+  <INPUT TYPE="hidden" NAME="classnum" VALUE="">
+
+<% } else { %>
+
+  <TR>
+    <TD ALIGN="right"><%= $opt{'label'} || 'Package class' %></TD>
+    <TD>
+      <%= include( '/elements/select-pkg_class.html', $classnum,
+                     'pkg_class' => \@pkg_class,
+                 )
+      %>
+    </TD>
+  </TR>
+
+<% } %>
index a1c3caf..6cd667d 100644 (file)
             - One or more services are grouped together into a package and
               given pricing information.  Customers purchase packages, not
               services.
-          <LI><A HREF="browse/pkg_class.cgi">View/Edit package classes</A>
+          <LI><A HREF="browse/pkg_class.html">View/Edit package classes</A>
             - Package classes define groups of packages, for reporting and
               convenience purposes.
         </ul>
          - Locally defined fields
          <LI><A HREF="browse/msgcat.cgi">View/Edit message catalog</A>
          - Change error messages and other customizable labels.
+         <LI><A HREF="browse/inventory_class.html">View/Edit inventory classes and inventory</A>
+         - Setup inventory classes and stock inventory.
        </ul>
         <BR>
       </TD></TR>
index 5da4d82..a2fb89c 100755 (executable)
@@ -19,8 +19,10 @@ if ( $cgi->param('magic') && $cgi->param('magic') eq 'bill' ) {
 
   my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi);
   push @where,
-    "bill >= $beginning ",
-    "bill <= $ending",
+    #"bill >= $beginning ",
+    #"bill <= $ending",
+    "CASE WHEN bill IS NULL THEN 0 ELSE bill END >= $beginning ",
+    "CASE WHEN bill IS NULL THEN 0 ELSE bill END <= $ending",
     '( cancel IS NULL OR cancel = 0 )';
 
 } else {
@@ -141,7 +143,7 @@ sub time_or_blank {
                   'name'        => 'packages',
                   'query'       => $sql_query,
                   'count_query' => $count_query,
-                  'redirect'    => $link,
+                  #'redirect'    => $link,
                   'header'      => [ '#',
                                      'Package',
                                      'Status',
index 7f72435..6cf5741 100644 (file)
@@ -8,8 +8,12 @@
   # 'name'        => 'items', #name for the records returned
   #
   # # some HTML callbacks...
-  # 'menubar'     => '', #menubar arrayref
-  # 'html_init'   => '', #after the header/menubar and before the pager
+  # 'menubar'          => '', #menubar arrayref
+  # 'html_init'        => '', #after the header/menubar and before the pager
+  # 'html_foot'        => '', #at the bottom
+  # 'html_posttotal'   => '', #at the bottom
+  #                           # (these three can be strings or coderefs)
+  # 
   #
   # #literal SQL query string or qsearch hashref, required
   # 'query'       => {
   # # (if not specified the database column names will be used)
   # 'header'      => [ '#', 'Item' ],
   #
+  # 'disable_download' => '', # set true to hide the CSV/Excel download links
+  # 'disable_nonefound' => '', # set true to disable the "No matching Xs found"
+  #                            # message
+  #
   # #listref - each item is a literal column name (or method) or coderef
   # #if not specified all columns will be shown
   # 'fields'      => [
                  include( '/elements/menubar.html', @menubar )
              )
   %>
-  <%= defined($opt{'html_init'}) ? $opt{'html_init'} : '' %>
+  <%= defined($opt{'html_init'}) 
+        ? ( ref($opt{'html_init'})
+              ? &{$opt{'html_init'}}()
+              : $opt{'html_init'}
+          )
+        : ''
+  %>
   <% my $pager = include ( '/elements/pager.html',
                              'offset'     => $offset,
                              'num_rows'   => scalar(@$rows),
                          );
   %>
   <% unless ( $total ) { %>
-    No matching <%= $opt{'name'} %> found.<BR>
+    <% unless ( $opt{'disable_nonefound'} ) { %>
+      No matching <%= $opt{'name'} %> found.<BR>
+    <% } %>
   <% } else { %>
   
     <TABLE>
       <TR>
         <TD VALIGN="bottom">
-          <%= $total %> total <%= $opt{'name'} %><BR>
+          <%= $total %> total <%= $opt{'name'} %>
+          <%= defined($opt{'html_posttotal'}) 
+                ? ( ref($opt{'html_posttotal'})
+                      ? &{$opt{'html_posttotal'}}()
+                      : $opt{'html_posttotal'}
+                  )
+                : ''
+          %>
+          <BR>
           <% if ( $opt{'count_addl'} ) { %>
             <% my $n=0; foreach my $count ( @{$opt{'count_addl'}} ) { %>
               <%= sprintf( $count, $count_arrayref->[++$n] ) %><BR>
             <% } %>
           <% } %>
         </TD>
-        <TD ALIGN="right">
-          <% $cgi->param('_type', "$xlsname.xls" ); %>
-          Download full results<BR>
-          as <A HREF="<%= $cgi->self_url %>">Excel spreadsheet</A><BR>
-          <% $cgi->param('_type', 'csv'); %>
-          as <A HREF="<%= $cgi->self_url %>">CSV file</A>
-        </TD>
+        <% unless ( $opt{'disable_download'} ) { %>
+          <TD ALIGN="right">
+            <% $cgi->param('_type', "$xlsname.xls" ); %>
+            Download full results<BR>
+            as <A HREF="<%= $cgi->self_url %>">Excel spreadsheet</A><BR>
+            <% $cgi->param('_type', 'csv'); %>
+            as <A HREF="<%= $cgi->self_url %>">CSV file</A>
+          </TD>
+        <% } %>
       </TR>
       <TR>
         <TD COLSPAN=2>
       </TABLE>
   
   <% } %>
+  <%= defined($opt{'html_foot'}) 
+        ? ( ref($opt{'html_foot'})
+              ? &{$opt{'html_foot'}}()
+              : $opt{'html_foot'}
+          )
+        : ''
+  %>
   <%= include( '/elements/footer.html' ) %>
   <% } %>
 <% } %>
diff --git a/httemplate/search/inventory_class.html b/httemplate/search/inventory_class.html
deleted file mode 100644 (file)
index 37735f3..0000000
+++ /dev/null
@@ -1,89 +0,0 @@
-<%
-
-tie my %labels, 'Tie::IxHash',
-  'num_avail' => 'Available', #  <FONT SIZE="-1"><A HREF="eventually">(upload batch)</A></FONT>',
-  'num_used'  => 'In use', #'Used', #'Allocated',
-  'num_total' => 'Total',
-;
-
-my %link = (
-  'num_avail' => ';avail=1',
-  'num_used'  => ';avail=1',
-  'num_total' => '',
-);
-
-my %inv_action_link = (
-  'num_avail' => [ 'upload batch',
-                   $p.'misc/inventory_item-import.html?classnum=',
-                   'classnum'
-                 ],
-);
-
-my $link = [ "${p}edit/inventory_class.html?", 'classnum' ];
-
-%><%= include( 'elements/search.html',
-                 'title'       => 'Inventory Classes',
-                 'name'        => 'inventory classes',
-                 'menubar'     => [ 'Add a new inventory class' =>
-                                      $p.'edit/inventory_class.html',
-                                  ],
-                 'query'       => { 'table' => 'inventory_class', },
-                 'count_query' => 'SELECT COUNT(*) FROM inventory_class',
-                 'header'      => [ '#', 'Inventory class', 'Inventory' ],
-                 'fields'      => [ 'classnum',
-                                    'classname',
-                                    sub {
-                                          #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>'. $num{$_}. '</B>',
-                                                      'align' => 'right',
-                                                    },
-                                                    {
-                                                      'data'  => $labels{$_},
-                                                      'align' => 'left',
-                                                      'link'  => ( $num{$_}
-                                                                     ? $link.$link{$_}
-                                                                     : ''
-                                                                 ),
-                                                    },
-                                                    { 'data'  => $actioncol{$_},
-                                                      'align'  => 'left',
-                                                    },
-                                                  ]
-                                                } keys %labels
-                                          ];
-                                        },
-                                  ],
-                 'links'       => [ $link,
-                                    $link,
-                                    '',
-                                  ],
-             )
-%>