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 <& order_pkg_link.html, $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 %>)
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 'packages' => $packages,
89 'show_location' => $show_location,
96 % if ( $cgi->param('fragment') =~ /^cust_pkg(\d+)$/ ) {
98 // IE-specific hack. other browsers listen to #fragments
99 // is this even working? or is the #target redirection just working cause
100 // we set the URL params differently?
101 var el = document.getElementById( 'cust_pkg<% $1 %>' );
102 if ( el ) el.scrollIntoView(true);
108 my $cust_main = shift;
110 my $conf = new FS::Conf;
112 my $curuser = $FS::CurrentUser::CurrentUser;
114 my( $packages, $num_old_packages ) = get_packages($cust_main, $conf);
117 my $show_location = $conf->exists('cust_pkg-always_show_location')
118 || (grep $_->locationnum, @$packages); # ? '1' : '0';
120 my $countrydefault = scalar($conf->config('countrydefault')) || 'US';
124 my $cust_main = shift or return undef;
128 if ( $cgi->param('showcancelledpackages') eq '0' #see if it was set by me
129 || ( $conf->exists('hidecancelledpackages')
130 && ! $cgi->param('showcancelledpackages') )
133 $method = 'ncancelled_pkgs';
135 $method = 'all_pkgs';
138 my $cust_pkg_fields =
139 join(', ', map { "cust_pkg.$_ AS $_" } fields('cust_pkg') );
141 my $part_pkg_fields =
142 join(', ', map { "part_pkg.$_ AS part_pkg_$_" } fields('part_pkg') );
145 join(', ', map "cust_pkg.$_", fields('cust_pkg') ). ', '.
146 join(', ', map "part_pkg.$_", fields('part_pkg') );
148 my $num_svcs = '( SELECT COUNT(*) FROM cust_svc '.
149 ' WHERE cust_svc.pkgnum = cust_pkg.pkgnum ) AS num_svcs';
151 my @packages = $cust_main->$method( {
152 'select' => "$cust_pkg_fields, $part_pkg_fields, $num_svcs",
153 'addl_from' => 'LEFT JOIN part_pkg USING ( pkgpart )',
155 my $num_old_packages = scalar(@packages);
157 foreach my $cust_pkg ( @packages ) {
158 my %hash = $cust_pkg->hash;
159 my %part_pkg = map { /^part_pkg_(.+)$/ or die; ( $1 => $hash{$_} ); }
160 grep { /^part_pkg_/ } keys %hash;
161 $cust_pkg->{'_pkgpart'} = new FS::part_pkg \%part_pkg;
164 unless ( $cgi->param('showoldpackages') ) {
165 my $years = $conf->config('cust_main-packages-years') || 2;
166 my $then = time - $years * 31556926; #60*60*24*365.2422 is close enough
168 my %hide = ( 'cancelled' => 'cancel',
169 'one-time charge' => 'setup',
173 grep { !exists($hide{$_->status}) or $_->get($hide{$_->status}) > $then
174 or $_->num_svcs #don't hide packages w/services
179 $num_old_packages -= scalar(@packages);
181 ( \@packages, $num_old_packages );