<% 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,
+ 'name' => 'package definitions',
+ 'disableable' => 1,
+ 'disabled_statuspos' => 3,
+ 'agent_virt' => 1,
+ 'agent_null_right' => [ $edit, $edit_global ],
+ 'agent_null_right_link' => $edit_global,
+ 'agent_pos' => 5,
+ 'query' => { 'select' => $select,
+ 'table' => 'part_pkg',
+ 'hashref' => {},
+ '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
+
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') ) {
-
$orderby = 'num_active DESC';
}
- $select = "
- *,
+my $extra_sql = '';
+
+#false laziness w/elements/select-part_pkg.html
+my $agentnums = join(',', $curuser->agentnums);
+
+unless ( $acl_edit_global ) {
+ $extra_sql .= "
+ WHERE (
+ agentnum IS NOT NULL OR 0 < (
+ SELECT COUNT(*)
+ FROM type_pkgs
+ LEFT JOIN agent_type USING ( typenum )
+ LEFT JOIN agent AS typeagent USING ( typenum )
+ WHERE type_pkgs.pkgpart = part_pkg.pkgpart
+ AND typeagent.agentnum IN ($agentnums)
+ )
+ )
+ ";
+}
+#eofalse
- ( 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,
+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(*) 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 = "
- ( SELECT COUNT(*) FROM cust_pkg WHERE cust_pkg.pkgpart = part_pkg.pkgpart
- AND cancel IS NOT NULL AND cancel != 0
- ) AS num_cancelled
+ *,
- ";
+ ( $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,
-my $conf = new FS::Conf;
-my $taxclasses = $conf->exists('enable_taxclasses');
+ ( $count_cust_pkg
+ AND cancel IS NOT NULL AND cancel != 0
+ ) AS num_cancelled
+
+";
my $html_init;
#unless ( $cgi->param('active') ) {
$align .= 'l';
}
+tie my %plans, 'Tie::IxHash', %{ FS::part_pkg::plan_info() };
+
+tie my %plan_labels, 'Tie::IxHash',
+ map { $_ => ( $plans{$_}->{'shortname'} || $plans{$_}->{'name'} ) }
+ keys %plans;
+
+push @header, 'Pricing';
+$align .= 'r'; #?
+push @fields, sub {
+ my $part_pkg = shift;
+ (my $plan = $plan_labels{$part_pkg->plan} ) =~ s/ / /g;
+ my $is_recur = ( $part_pkg->freq ne '0' );
+
+ [
+ [
+ { data =>$plan,
+ align=>'center',
+ colspan=>2,
+ },
+ ],
+ [
+ { data =>$money_char.
+ sprintf('%.2f', $part_pkg->option('setup_fee') ),
+ align=>'right'
+ },
+ { data => ( $is_recur ? ' setup' : ' one-time' ),
+ align=>'left',
+ },
+ ],
+ [
+ { data=>( $is_recur
+ ? $money_char.sprintf('%.2f ', $part_pkg->option('recur_fee') )
+ : $part_pkg->freq_pretty
+ ),
+ align=> ( $is_recur ? 'right' : 'center' ),
+ colspan=> ( $is_recur ? 1 : 2 ),
+ },
+ ( $is_recur
+ ? { data => ( $is_recur ? $part_pkg->freq_pretty : '' ),
+ align=>'left',
+ }
+ : ()
+ ),
+ ],
+ ( map {
+ my $dst_pkg = $_->dst_pkg;
+ [
+ { data => 'Add-on: '.$dst_pkg->pkg_comment,
+ align=>'center', #?
+ colspan=>2,
+ }
+ ]
+ }
+ $part_pkg->bill_part_pkg_link
+ ),
+ ];
+
+# $plan_labels{$part_pkg->plan}.'<BR>'.
+# $money_char.sprintf('%.2f setup<BR>', $part_pkg->option('setup_fee') ).
+# ( $part_pkg->freq ne '0'
+# ? $money_char.sprintf('%.2f ', $part_pkg->option('recur_fee') )
+# : ''
+# ).
+# $part_pkg->freq_pretty; #.'<BR>'
+};
+
#if ( $cgi->param('active') ) {
push @header, 'Customer<BR>packages';
my %col = (
$align .= 'r';
#}
-push @header, 'Frequency';
-push @fields, sub { shift->freq_pretty; };
-$align .= 'l';
-
if ( $taxclasses ) {
push @header, 'Taxclass';
push @fields, sub { shift->taxclass() || ' '; };
$align .= 'l';
}
-push @header, 'Plan',
- 'Data',
+push @header, 'Plan options',
'Services';
#'Service', 'Quan', 'Primary';
-push @fields, sub { shift->plan || '(legacy)' },
-
+push @fields,
sub {
my $part_pkg = shift;
if ( $part_pkg->plan ) {
+ my %options = $part_pkg->options;
+
[ map {
- /^(\w+)=(.*)$/; #or something;
[
- { 'data' => $1,
+ { 'data' => $_,
'align' => 'right',
},
- { 'data' => $part_pkg->format($1,$2),
+ { 'data' => $part_pkg->format($_,$options{$_}),
'align' => 'left',
},
];
}
- split(/\n/, $part_pkg->plandata)
+ grep { $options{$_} =~ /\S/ }
+ grep { $_ !~ /^(setup|recur)_fee$/ }
+ keys %options
];
} else {
sub {
my $part_pkg = shift;
- [ map {
+ [
+ (map {
my $pkg_svc = $_;
my $part_svc = $pkg_svc->part_svc;
my $svc = $part_svc->svc;
{
'data' => $svc,
'align' => 'left',
- 'link' => $p. 'edit/part_svc.cgi?'.
- $part_svc->svcpart,
+ 'link' => ( $acl_config
+ ? $p. 'edit/part_svc.cgi?'.
+ $part_svc->svcpart
+ : ''
+ ),
},
];
}
sort { $b->primary_svc =~ /^Y/i
<=> $a->primary_svc =~ /^Y/i
}
- $part_pkg->pkg_svc
-
+ $part_pkg->pkg_svc('disable_linked'=>1)
+ ),
+ ( map {
+ my $dst_pkg = $_->dst_pkg;
+ [
+ { data => 'Add-on: '.$dst_pkg->pkg_comment,
+ align=>'center', #?
+ colspan=>2,
+ }
+ ]
+ }
+ $part_pkg->svc_part_pkg_link
+ )
];
};
# --------
-my $count_query = 'SELECT COUNT(*) FROM part_pkg WHERE '.
- $FS::CurrentUser::CurrentUser->agentnums_sql(
- 'null_right' => 'Edit global package definitions',
- );
+my $count_query = "SELECT COUNT(*) FROM part_pkg $extra_sql";
</%init>