summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorivan <ivan>2006-04-22 00:58:40 +0000
committerivan <ivan>2006-04-22 00:58:40 +0000
commit1a033848671cad2cbe7687b37fc718b3b2a68b83 (patch)
tree01fc1ca352726cdc5786e0ccaf78515e9326ba84
parent303cb4ce4b6ce634e108e3b7a0b43086a5e4f184 (diff)
start of package class web UI (add/edit package classes, package class selection in package def edit)
-rw-r--r--FS/FS/part_pkg.pm34
-rw-r--r--htetc/handler.pl1
-rw-r--r--httemplate/browse/elements/browse.html6
-rw-r--r--httemplate/browse/generic.cgi46
-rw-r--r--httemplate/browse/inventory_class.html (renamed from httemplate/search/inventory_class.html)2
-rwxr-xr-xhttemplate/browse/part_pkg.cgi373
-rw-r--r--httemplate/browse/pkg_class.html26
-rw-r--r--httemplate/browse/rate.cgi59
-rw-r--r--httemplate/edit/elements/edit.html6
-rw-r--r--httemplate/edit/inventory_class.html1
-rwxr-xr-xhttemplate/edit/part_pkg.cgi9
-rw-r--r--httemplate/edit/pkg_class.html10
-rw-r--r--httemplate/edit/process/elements/process.html6
-rw-r--r--httemplate/edit/process/inventory_class.html3
-rw-r--r--httemplate/edit/process/pkg_class.html5
-rw-r--r--httemplate/elements/select-agent.html32
-rw-r--r--httemplate/elements/select-pkg_class.html16
-rw-r--r--httemplate/elements/select-table.html45
-rw-r--r--httemplate/elements/tr-select-pkg_class.html29
-rw-r--r--httemplate/index.html4
-rwxr-xr-xhttemplate/search/cust_pkg.cgi8
-rw-r--r--httemplate/search/elements/search.html57
22 files changed, 505 insertions, 273 deletions
diff --git a/FS/FS/part_pkg.pm b/FS/FS/part_pkg.pm
index 30a97227e..05dc59913 100644
--- a/FS/FS/part_pkg.pm
+++ b/FS/FS/part_pkg.pm
@@ -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
diff --git a/htetc/handler.pl b/htetc/handler.pl
index 008b0b5f9..dcbe72733 100644
--- a/htetc/handler.pl
+++ b/htetc/handler.pl
@@ -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
index 000000000..6d146d356
--- /dev/null
+++ b/httemplate/browse/elements/browse.html
@@ -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
index 9ac0f2391..000000000
--- a/httemplate/browse/generic.cgi
+++ /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/search/inventory_class.html b/httemplate/browse/inventory_class.html
index 37735f3c9..6da3c9e3c 100644
--- a/httemplate/search/inventory_class.html
+++ b/httemplate/browse/inventory_class.html
@@ -21,7 +21,7 @@ my %inv_action_link = (
my $link = [ "${p}edit/inventory_class.html?", 'classnum' ];
-%><%= include( 'elements/search.html',
+%><%= include( 'elements/browse.html',
'title' => 'Inventory Classes',
'name' => 'inventory classes',
'menubar' => [ 'Add a new inventory class' =>
diff --git a/httemplate/browse/part_pkg.cgi b/httemplate/browse/part_pkg.cgi
index e6454639f..0afa54750 100755
--- a/httemplate/browse/part_pkg.cgi
+++ b/httemplate/browse/part_pkg.cgi
@@ -1,169 +1,236 @@
-<!-- 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
index 000000000..d4f8f02a9
--- /dev/null
+++ b/httemplate/browse/pkg_class.html
@@ -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 ],
+ )
+%>
diff --git a/httemplate/browse/rate.cgi b/httemplate/browse/rate.cgi
index 4718b7147..c4ae2f081 100644
--- a/httemplate/browse/rate.cgi
+++ b/httemplate/browse/rate.cgi
@@ -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 ],
+ )
+%>
diff --git a/httemplate/edit/elements/edit.html b/httemplate/edit/elements/edit.html
index ce6e2dbb1..5486b4b00 100644
--- a/httemplate/edit/elements/edit.html
+++ b/httemplate/edit/elements/edit.html
@@ -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",
);
}
diff --git a/httemplate/edit/inventory_class.html b/httemplate/edit/inventory_class.html
index 5dde2e595..8c5ae4770 100644
--- a/httemplate/edit/inventory_class.html
+++ b/httemplate/edit/inventory_class.html
@@ -5,5 +5,6 @@
'classnum' => 'Class number',
'classname' => 'Class name',
},
+ 'viewall_dir' => 'browse',
)
%>
diff --git a/httemplate/edit/part_pkg.cgi b/httemplate/edit/part_pkg.cgi
index 158c6e2ff..462d5161f 100755
--- a/httemplate/edit/part_pkg.cgi
+++ b/httemplate/edit/part_pkg.cgi
@@ -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
index 000000000..b077f6fa9
--- /dev/null
+++ b/httemplate/edit/pkg_class.html
@@ -0,0 +1,10 @@
+<%= include( 'elements/edit.html',
+ 'name' => 'Package Class',
+ 'table' => 'pkg_class',
+ 'labels' => {
+ 'classnum' => 'Class number',
+ 'classname' => 'Class name',
+ },
+ 'viewall_dir' => 'browse',
+ )
+%>
diff --git a/httemplate/edit/process/elements/process.html b/httemplate/edit/process/elements/process.html
index 52c876720..83ff6f728 100644
--- a/httemplate/edit/process/elements/process.html
+++ b/httemplate/edit/process/elements/process.html
@@ -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) = @_;
@@ -40,7 +41,10 @@
$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"
+ );
}
%>
diff --git a/httemplate/edit/process/inventory_class.html b/httemplate/edit/process/inventory_class.html
index e30e74e7b..ab9efef48 100644
--- a/httemplate/edit/process/inventory_class.html
+++ b/httemplate/edit/process/inventory_class.html
@@ -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
index 000000000..48e2b8009
--- /dev/null
+++ b/httemplate/edit/process/pkg_class.html
@@ -0,0 +1,5 @@
+<%= include( 'elements/process.html',
+ 'table' => 'pkg_class',
+ 'viewall_dir' => 'browse',
+ )
+%>
diff --git a/httemplate/elements/select-agent.html b/httemplate/elements/select-agent.html
index c2a5e4bde..aa480a54b 100644
--- a/httemplate/elements/select-agent.html
+++ b/httemplate/elements/select-agent.html
@@ -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
index 000000000..5486e0877
--- /dev/null
+++ b/httemplate/elements/select-pkg_class.html
@@ -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
index 000000000..10cc8b995
--- /dev/null
+++ b/httemplate/elements/select-table.html
@@ -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
index 000000000..de10885c8
--- /dev/null
+++ b/httemplate/elements/tr-select-pkg_class.html
@@ -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>
+
+<% } %>
diff --git a/httemplate/index.html b/httemplate/index.html
index a1c3caf39..6cd667d8a 100644
--- a/httemplate/index.html
+++ b/httemplate/index.html
@@ -186,7 +186,7 @@
- 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>
@@ -234,6 +234,8 @@
- 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>
diff --git a/httemplate/search/cust_pkg.cgi b/httemplate/search/cust_pkg.cgi
index 5da4d82fb..a2fb89c12 100755
--- a/httemplate/search/cust_pkg.cgi
+++ b/httemplate/search/cust_pkg.cgi
@@ -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',
diff --git a/httemplate/search/elements/search.html b/httemplate/search/elements/search.html
index 7f7243588..6cf574164 100644
--- a/httemplate/search/elements/search.html
+++ b/httemplate/search/elements/search.html
@@ -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' => {
@@ -39,6 +43,10 @@
# # (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' => [
@@ -286,7 +294,13 @@
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),
@@ -295,26 +309,38 @@
);
%>
<% 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>
@@ -471,6 +497,13 @@
</TABLE>
<% } %>
+ <%= defined($opt{'html_foot'})
+ ? ( ref($opt{'html_foot'})
+ ? &{$opt{'html_foot'}}()
+ : $opt{'html_foot'}
+ )
+ : ''
+ %>
<%= include( '/elements/footer.html' ) %>
<% } %>
<% } %>