X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;ds=sidebyside;f=httemplate%2Fbrowse%2Fpart_pkg.cgi;h=e226ce13e9560b853e04ae51c2d35a41bacb737d;hb=bf4223e554e0eb72f45f82392442780e8af4e0f9;hp=78cb77d269c00c447b163c3d1aa4f5173825d645;hpb=d8c81a25cb29cf0ca5d7cdeb8160f79d4fbb0bc6;p=freeside.git
diff --git a/httemplate/browse/part_pkg.cgi b/httemplate/browse/part_pkg.cgi
index 78cb77d26..e226ce13e 100755
--- a/httemplate/browse/part_pkg.cgi
+++ b/httemplate/browse/part_pkg.cgi
@@ -1,60 +1,115 @@
<% include( 'elements/browse.html',
- 'title' => 'Package Definitions',
- 'html_init' => $html_init,
- 'name' => 'package definitions',
- 'disableable' => 1,
- 'disabled_statuspos' => 3,
- 'agent_virt' => 1,
- 'agent_null_right' => 'Edit global package definitions',
- 'agent_pos' => 4,
- 'query' => { 'select' => $select,
- 'table' => 'part_pkg',
- 'hashref' => {},
- 'order_by' => "ORDER BY $orderby",
- },
- 'count_query' => $count_query,
- 'header' => \@header,
- 'fields' => \@fields,
- 'links' => \@links,
- 'align' => $align,
+ 'title' => 'Package Definitions',
+ 'html_init' => $html_init,
+ 'html_posttotal' => $html_posttotal,
+ 'name' => 'package definitions',
+ 'disableable' => 1,
+ 'disabled_statuspos' => 4,
+ 'agent_virt' => 1,
+ 'agent_null_right' => [ $edit, $edit_global ],
+ 'agent_null_right_link' => $edit_global,
+ 'agent_pos' => 6,
+ 'query' => { 'select' => $select,
+ 'table' => 'part_pkg',
+ 'hashref' => \%hash,
+ 'extra_sql' => $extra_sql,
+ 'order_by' => "ORDER BY $orderby"
+ },
+ 'count_query' => $count_query,
+ 'header' => \@header,
+ 'fields' => \@fields,
+ 'links' => \@links,
+ 'align' => $align,
)
%>
<%init>
+my $curuser = $FS::CurrentUser::CurrentUser;
+
+my $edit = 'Edit package definitions';
+my $edit_global = 'Edit global package definitions';
+my $acl_edit = $curuser->access_right($edit);
+my $acl_edit_global = $curuser->access_right($edit_global);
+my $acl_config = $curuser->access_right('Configuration'); #to edit services
+ #and agent types
+
die "access denied"
- unless $FS::CurrentUser::CurrentUser->access_right('Edit package definitions')
- || $FS::CurrentUser::CurrentUser->access_right('Edit global package definitions');
+ unless $acl_edit || $acl_edit_global;
+
+my $conf = new FS::Conf;
+my $taxclasses = $conf->exists('enable_taxclasses');
+my $money_char = $conf->config('money_char') || '$';
my $select = '*';
my $orderby = 'pkgpart';
-if ( $cgi->param('active') ) {
+my %hash = ();
+my $extra_count = '';
+if ( $cgi->param('active') ) {
$orderby = 'num_active DESC';
}
- $select = "
- *,
+my @where = ();
- ( 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,
+#if ( $cgi->param('activeONLY') ) {
+# push @where, ' WHERE num_active > 0 '; #XXX doesn't affect count...
+#}
- ( 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,
+if ( $cgi->param('recurring') ) {
+ $hash{'freq'} = { op=>'!=', value=>'0' };
+ $extra_count = " freq != '0' ";
+}
- ( SELECT COUNT(*) FROM cust_pkg WHERE cust_pkg.pkgpart = part_pkg.pkgpart
- AND cancel IS NOT NULL AND cancel != 0
- ) AS num_cancelled
+my $classnum = '';
+if ( $cgi->param('classnum') =~ /^(\d+)$/ ) {
+ $classnum = $1;
+ push @where, $classnum ? "classnum = $classnum"
+ : "classnum IS NULL";
+}
+$cgi->delete('classnum');
+
+if ( $cgi->param('missing_recur_fee') ) {
+ push @where, "0 = ( SELECT COUNT(*) FROM part_pkg_option
+ WHERE optionname = 'recur_fee'
+ AND part_pkg_option.pkgpart = part_pkg.pkgpart
+ AND CAST ( optionvalue AS NUMERIC ) > 0
+ )";
+}
- ";
+push @where, FS::part_pkg->curuser_pkgs_sql
+ unless $acl_edit_global;
-#}
+my $extra_sql = scalar(@where)
+ ? ( scalar(keys %hash) ? ' AND ' : ' WHERE ' ).
+ join( 'AND ', @where)
+ : '';
-my $conf = new FS::Conf;
-my $taxclasses = $conf->exists('enable_taxclasses');
+my $agentnums = join(',', $curuser->agentnums);
+my $count_cust_pkg = "
+ SELECT COUNT(*) FROM cust_pkg LEFT JOIN cust_main USING ( custnum )
+ WHERE cust_pkg.pkgpart = part_pkg.pkgpart
+ AND cust_main.agentnum IN ($agentnums)
+";
+
+$select = "
+
+ *,
+
+ ( $count_cust_pkg
+ AND ( cancel IS NULL OR cancel = 0 )
+ AND ( susp IS NULL OR susp = 0 )
+ ) AS num_active,
+
+ ( $count_cust_pkg
+ AND ( cancel IS NULL OR cancel = 0 )
+ AND susp IS NOT NULL AND susp != 0
+ ) AS num_suspended,
+
+ ( $count_cust_pkg
+ AND cancel IS NOT NULL AND cancel != 0
+ ) AS num_cancelled
+
+";
my $html_init;
#unless ( $cgi->param('active') ) {
@@ -62,19 +117,59 @@ my $html_init;
One or more service definitions are grouped together into a package
definition and given pricing information. Customers purchase packages
rather than purchase services directly.
+