3 % if ( $curuser->access_right('Qualify service') ) {
4 <% $s++ ? ' | ' : '' %>
5 <& qual_link.html, $cust_main &>
8 % if ( $curuser->access_right('Order customer package') ) {
9 <% $s++ ? ' | ' : '' %>
10 <& /elements/order_pkg_link.html, 'cust_main'=>$cust_main &>
13 % if ( $curuser->access_right('One-time charge')
14 % && $conf->config('payby-default') ne 'HIDE'
16 <% $s++ ? ' | ' : '' %>
17 <& one_time_charge_link.html, $cust_main &>
20 % if ( $curuser->access_right('Bulk change customer packages') ) {
21 <% $s++ ? ' | ' : '' %>
22 <A HREF="<% $p %>edit/cust_pkg.cgi?<% $cust_main->custnum %>"><% mt('Bulk order and cancel packages') |h %></A> (<% mt('preserves services') |h %>)
29 <TD ALIGN="left" VALIGN="top">
33 <% mt('Current packages') |h %>
35 % if ( $cust_main->num_cancelled_pkgs ) {
36 % if ( $cgi->param('showcancelledpackages') eq '0' #see if it was set by me
37 % || ( $conf->exists('hidecancelledpackages')
38 % && ! $cgi->param('showcancelledpackages')
42 % my $prev = $cgi->param('showcancelledpackages');
43 % $cgi->param('showcancelledpackages', 1);
44 ( <a href="<% $cgi->self_url %>"><% mt('show') |h %>
45 % $cgi->param('showcancelledpackages', $prev);
47 % $cgi->param('showcancelledpackages', 0);
48 ( <a href="<% $cgi->self_url %>"><% mt('hide') |h %>
49 % $cgi->param('showcancelledpackages', 1);
52 <% mt('cancelled packages') |h %></a> )
54 % if ( $num_old_packages ) {
55 % $cgi->param('showoldpackages', 1);
56 ( <a href="<% $cgi->self_url %>"><% mt('show old packages') |h %></a> )
57 % } elsif ( $cgi->param('showoldpackages') ) {
58 % $cgi->param('showoldpackages', 0);
59 ( <a href="<% $cgi->self_url %>"><% mt('hide old packages') |h %></a> )
64 <A HREF="<%$p%>search/report_cust_pkg.html?custnum=<% $cust_main->custnum %>"><% mt('Package reports') |h %></A>
65 % if ( $curuser->access_right('Qualify service') ) {
66 | <A HREF="<%$p%>search/qual.cgi?custnum=<% $cust_main->custnum %>"><% mt('View Qualifications') |h %></A>
69 <% mt('Service reports:') |h %>
70 <A HREF="<%$p%>search/report_svc_acct.html?custnum=<% $cust_main->custnum %>"><% mt('accounts') |h %></A><BR>
71 <% mt('Usage reports:') |h %>
72 <A HREF="<%$p%>search/report_cdr.html?custnum=<% $cust_main->custnum %>"><% mt('CDRs') |h %></A>
78 % if ( $conf->exists('cust_pkg-group_by_location') and $show_location ) {
80 'cust_main' => $cust_main,
81 'packages' => $packages,
85 % # in this format, put all packages in one section
86 <& /elements/table-grid.html &>
87 <& packages/section.html,
88 'cust_main' => $cust_main,
89 'packages' => $packages,
90 'show_location' => $show_location,
97 % if ( $cgi->param('fragment') =~ /^cust_pkg(\d+)$/ ) {
99 // IE-specific hack. other browsers listen to #fragments
100 // is this even working? or is the #target redirection just working cause
101 // we set the URL params differently?
102 var el = document.getElementById( 'cust_pkg<% $1 %>' );
103 if ( el ) el.scrollIntoView(true);
109 my $cust_main = shift;
111 my $conf = new FS::Conf;
113 my $curuser = $FS::CurrentUser::CurrentUser;
115 my( $packages, $num_old_packages ) = get_packages($cust_main, $conf);
118 my $show_location = $conf->exists('cust_pkg-always_show_location')
119 || (grep $_->locationnum, @$packages); # ? '1' : '0';
121 my $countrydefault = scalar($conf->config('countrydefault')) || 'US';
125 my $cust_main = shift or return undef;
129 if ( $cgi->param('showcancelledpackages') eq '0' #see if it was set by me
130 || ( $conf->exists('hidecancelledpackages')
131 && ! $cgi->param('showcancelledpackages') )
134 $method = 'ncancelled_pkgs';
136 $method = 'all_pkgs';
139 my $cust_pkg_fields =
140 join(', ', map { "cust_pkg.$_ AS $_" } fields('cust_pkg') );
142 my $part_pkg_fields =
143 join(', ', map { "part_pkg.$_ AS part_pkg_$_" } fields('part_pkg') );
146 join(', ', map "cust_pkg.$_", fields('cust_pkg') ). ', '.
147 join(', ', map "part_pkg.$_", fields('part_pkg') );
149 my $num_svcs = '( SELECT COUNT(*) FROM cust_svc '.
150 ' WHERE cust_svc.pkgnum = cust_pkg.pkgnum ) AS num_svcs';
152 my @packages = $cust_main->$method( {
153 'select' => "$cust_pkg_fields, $part_pkg_fields, $num_svcs",
154 'addl_from' => 'LEFT JOIN part_pkg USING ( pkgpart )',
156 my $num_old_packages = scalar(@packages);
158 foreach my $cust_pkg ( @packages ) {
159 my %hash = $cust_pkg->hash;
160 my %part_pkg = map { /^part_pkg_(.+)$/ or die; ( $1 => $hash{$_} ); }
161 grep { /^part_pkg_/ } keys %hash;
162 $cust_pkg->{'_pkgpart'} = new FS::part_pkg \%part_pkg;
165 unless ( $cgi->param('showoldpackages') ) {
166 my $years = $conf->config('cust_main-packages-years') || 2;
167 my $then = time - $years * 31556926; #60*60*24*365.2422 is close enough
169 my %hide = ( 'cancelled' => 'cancel',
170 'one-time charge' => 'setup',
174 grep { !exists($hide{$_->status}) or $_->get($hide{$_->status}) > $then
175 or $_->num_svcs #don't hide packages w/services
180 $num_old_packages -= scalar(@packages);
182 ( \@packages, $num_old_packages );