2 % if ( $curuser->access_right('Order customer package') ) {
3 <% $s++ ? ' | ' : '' %>
4 <% include('order_pkg_link.html', $cust_main) %>
7 % if ( $curuser->access_right('One-time charge')
8 % && $conf->config('payby-default') ne 'HIDE'
10 <% $s++ ? ' | ' : '' %>
11 <% include('one_time_charge_link.html', $cust_main) %>
14 % if ( $curuser->access_right('Bulk change customer packages') ) {
15 <% $s++ ? ' | ' : '' %>
16 <A HREF="<% $p %>edit/cust_pkg.cgi?<% $cust_main->custnum %>">Bulk order and cancel packages</A> (preserves services)
29 % if ( $cust_main->num_cancelled_pkgs ) {
30 % if ( $cgi->param('showcancelledpackages') eq '0' #see if it was set by me
31 % || ( $conf->exists('hidecancelledpackages')
32 % && ! $cgi->param('showcancelledpackages')
36 % my $prev = $cgi->param('showcancelledpackages');
37 % $cgi->param('showcancelledpackages', 1);
38 ( <a href="<% $cgi->self_url %>">show
39 % $cgi->param('showcancelledpackages', $prev);
41 % $cgi->param('showcancelledpackages', 0);
42 ( <a href="<% $cgi->self_url %>">hide
43 % $cgi->param('showcancelledpackages', 1);
46 cancelled packages</a> )
48 % if ( $num_old_packages ) {
49 % $cgi->param('showoldpackages', 1);
50 ( <a href="<% $cgi->self_url %>">show old packages</a> )
51 % } elsif ( $cgi->param('showoldpackages') ) {
52 % $cgi->param('showoldpackages', 0);
53 ( <a href="<% $cgi->self_url %>">hide old packages</a> )
58 <A HREF="<%$p%>search/report_cust_pkg.html?custnum=<% $cust_main->custnum %>">Package reports</A><BR>
60 <A HREF="<%$p%>search/report_svc_acct.html?custnum=<% $cust_main->custnum %>">accounts</A><BR>
62 <A HREF="<%$p%>search/report_cdr.html?custnum=<% $cust_main->custnum %>">CDRs</A>
68 % if ( $conf->exists('cust_pkg-group_by_location') and $show_location ) {
69 <% include('locations.html',
70 'cust_main' => $cust_main,
71 'packages' => $packages,
75 % # in this format, put all packages in one section
76 <% include('/elements/table-grid.html') %>
77 <% include('packages/section.html',
78 'packages' => $packages,
79 'show_location' => $show_location,
86 % if ( $cgi->param('fragment') =~ /^cust_pkg(\d+)$/ ) {
88 // IE-specific hack. other browsers listen to #fragments
89 // is this even working? or is the #target redirection just working cause
90 // we set the URL params differently?
91 var el = document.getElementById( 'cust_pkg<% $1 %>' );
92 if ( el ) el.scrollIntoView(true);
98 my $cust_main = shift;
100 my $conf = new FS::Conf;
102 my $curuser = $FS::CurrentUser::CurrentUser;
104 my( $packages, $num_old_packages ) = get_packages($cust_main, $conf);
107 my $show_location = $conf->exists('cust_pkg-always_show_location')
108 || (grep $_->locationnum, @$packages); # ? '1' : '0';
110 my $countrydefault = scalar($conf->config('countrydefault')) || 'US';
114 my $cust_main = shift or return undef;
118 if ( $cgi->param('showcancelledpackages') eq '0' #see if it was set by me
119 || ( $conf->exists('hidecancelledpackages')
120 && ! $cgi->param('showcancelledpackages') )
123 $method = 'ncancelled_pkgs';
125 $method = 'all_pkgs';
128 my $cust_pkg_fields =
129 join(', ', map { "cust_pkg.$_ AS $_" } fields('cust_pkg') );
131 my $part_pkg_fields =
132 join(', ', map { "part_pkg.$_ AS part_pkg_$_" } fields('part_pkg') );
135 join(', ', map "cust_pkg.$_", fields('cust_pkg') ). ', '.
136 join(', ', map "part_pkg.$_", fields('part_pkg') );
138 my $num_svcs = '( SELECT COUNT(*) FROM cust_svc '.
139 ' WHERE cust_svc.pkgnum = cust_pkg.pkgnum ) AS num_svcs';
141 my @packages = $cust_main->$method( {
142 'select' => "$cust_pkg_fields, $part_pkg_fields, $num_svcs",
143 'addl_from' => 'LEFT JOIN part_pkg USING ( pkgpart )',
145 my $num_old_packages = scalar(@packages);
147 foreach my $cust_pkg ( @packages ) {
148 my %hash = $cust_pkg->hash;
149 my %part_pkg = map { /^part_pkg_(.+)$/ or die; ( $1 => $hash{$_} ); }
150 grep { /^part_pkg_/ } keys %hash;
151 $cust_pkg->{'_pkgpart'} = new FS::part_pkg \%part_pkg;
154 unless ( $cgi->param('showoldpackages') ) {
155 my $years = $conf->config('cust_main-packages-years') || 2;
156 my $then = time - $years * 31556926; #60*60*24*365.2422 is close enough
158 my %hide = ( 'cancelled' => 'cancel',
159 'one-time charge' => 'setup',
163 grep { !exists($hide{$_->status}) or $_->get($hide{$_->status}) > $then
164 or $_->num_svcs #don't hide packages w/services
169 $num_old_packages -= scalar(@packages);
171 ( \@packages, $num_old_packages );