1 <STYLE TYPE="text/css">
14 <!-- even/odd rows -->
16 .row0 { background-color: #eeeeee; }
17 .row1 { background-color: #ffffff; }
22 % if ( $curuser->access_right('Qualify service') ) {
23 <% $s++ ? ' | ' : '' %>
24 <& qual_link.html, $cust_main &>
27 % if ( $curuser->access_right('Order customer package') ) {
28 <% $s++ ? ' | ' : '' %>
29 <& /elements/order_pkg_link.html, 'cust_main'=>$cust_main &>
32 % if ( $curuser->access_right('One-time charge')
33 % && $conf->config('payby-default') ne 'HIDE'
35 <% $s++ ? ' | ' : '' %>
36 <& one_time_charge_link.html, $cust_main &>
39 % if ( $curuser->access_right('Bulk change customer packages') ) {
40 <% $s++ ? ' | ' : '' %>
41 <A HREF="<% $p %>edit/cust_pkg.cgi?<% $cust_main->custnum %>"><% mt('Bulk order and cancel packages') |h %></A> (<% mt('preserves services') |h %>)
48 <TD ALIGN="left" VALIGN="top">
52 <% mt('Current packages') |h %>
54 % if ( $cust_main->num_cancelled_pkgs ) {
55 % if ( $cgi->param('showcancelledpackages') eq '0' #see if it was set by me
56 % || ( $conf->exists('hidecancelledpackages')
57 % && ! $cgi->param('showcancelledpackages')
61 % my $prev = $cgi->param('showcancelledpackages');
62 % $cgi->param('showcancelledpackages', 1);
63 ( <a href="<% $cgi->self_url %>"><% mt('show') |h %>
64 % $cgi->param('showcancelledpackages', $prev);
66 % $cgi->param('showcancelledpackages', 0);
67 ( <a href="<% $cgi->self_url %>"><% mt('hide') |h %>
68 % $cgi->param('showcancelledpackages', 1);
71 <% mt('cancelled packages') |h %></a> )
73 % if ( $num_old_packages ) {
74 % $cgi->param('showoldpackages', 1);
75 ( <a href="<% $cgi->self_url %>"><% mt('show old packages') |h %></a> )
76 % } elsif ( $cgi->param('showoldpackages') ) {
77 % $cgi->param('showoldpackages', 0);
78 ( <a href="<% $cgi->self_url %>"><% mt('hide old packages') |h %></a> )
83 <A HREF="<%$p%>search/report_cust_pkg.html?custnum=<% $cust_main->custnum %>"><% mt('Package reports') |h %></A>
84 % if ( $curuser->access_right('Qualify service') ) {
85 | <A HREF="<%$p%>search/qual.cgi?custnum=<% $cust_main->custnum %>"><% mt('View Qualifications') |h %></A>
88 <% mt('Service reports:') |h %>
89 <A HREF="<%$p%>search/report_svc_acct.html?custnum=<% $cust_main->custnum %>"><% mt('accounts') |h %></A><BR>
90 <% mt('Usage reports:') |h %>
91 <A HREF="<%$p%>search/report_cdr.html?custnum=<% $cust_main->custnum %>"><% mt('CDRs') |h %></A>
97 % if ( $conf->exists('cust_pkg-group_by_location') and $show_location ) {
99 'cust_main' => $cust_main,
100 'packages' => $packages,
104 % # in this format, put all packages in one section
105 <& /elements/table-grid.html &>
106 <& packages/section.html,
107 'cust_main' => $cust_main,
108 'packages' => $packages,
109 'show_location' => $show_location,
116 % if ( $cgi->param('fragment') =~ /^cust_pkg(\d+)$/ ) {
118 // IE-specific hack. other browsers listen to #fragments
119 // is this even working? or is the #target redirection just working cause
120 // we set the URL params differently?
121 var el = document.getElementById( 'cust_pkg<% $1 %>' );
122 if ( el ) el.scrollIntoView(true);
128 my $cust_main = shift;
130 my $conf = new FS::Conf;
132 my $curuser = $FS::CurrentUser::CurrentUser;
134 my( $packages, $num_old_packages ) = get_packages($cust_main, $conf);
137 my $show_location = $conf->exists('cust_pkg-always_show_location')
138 || (grep $_->locationnum ne $cust_main->ship_locationnum, @$packages);
140 my $countrydefault = scalar($conf->config('countrydefault')) || 'US';
144 my $cust_main = shift or return undef;
148 if ( $cgi->param('showcancelledpackages') eq '0' #see if it was set by me
149 || ( $conf->exists('hidecancelledpackages')
150 && ! $cgi->param('showcancelledpackages') )
153 $method = 'ncancelled_pkgs';
155 $method = 'all_pkgs';
158 my $cust_pkg_fields =
159 join(', ', map { "cust_pkg.$_ AS $_" } fields('cust_pkg') );
161 my $part_pkg_fields =
162 join(', ', map { "part_pkg.$_ AS part_pkg_$_" } fields('part_pkg') );
165 join(', ', map "cust_pkg.$_", fields('cust_pkg') ). ', '.
166 join(', ', map "part_pkg.$_", fields('part_pkg') );
168 my $num_svcs = '( SELECT COUNT(*) FROM cust_svc '.
169 ' WHERE cust_svc.pkgnum = cust_pkg.pkgnum ) AS num_svcs';
171 my @packages = $cust_main->$method( {
172 'select' => "$cust_pkg_fields, $part_pkg_fields, $num_svcs",
173 'addl_from' => 'LEFT JOIN part_pkg USING ( pkgpart )',
175 my $num_old_packages = scalar(@packages);
177 foreach my $cust_pkg ( @packages ) {
178 my %hash = $cust_pkg->hash;
179 my %part_pkg = map { /^part_pkg_(.+)$/ or die; ( $1 => $hash{$_} ); }
180 grep { /^part_pkg_/ } keys %hash;
181 $cust_pkg->{'_pkgpart'} = new FS::part_pkg \%part_pkg;
184 unless ( $cgi->param('showoldpackages') ) {
185 my $years = $conf->config('cust_main-packages-years') || 2;
186 my $then = time - $years * 31556926; #60*60*24*365.2422 is close enough
188 my %hide = ( 'cancelled' => 'cancel',
189 'one-time charge' => 'setup',
193 grep { !exists($hide{$_->status}) or $_->get($hide{$_->status}) > $then
194 or $_->num_svcs #don't hide packages w/services
199 $num_old_packages -= scalar(@packages);
201 # don't include supplemental packages in this list; they'll be found from
202 # their main packages
203 @packages = grep !$_->main_pkgnum, @packages;
205 ( \@packages, $num_old_packages );