1 <STYLE TYPE="text/css">
14 .row0 { background-color: #eeeeee; }
15 .row1 { background-color: #ffffff; }
20 % if ( $curuser->access_right('Qualify service') ) {
21 <% $s++ ? ' | ' : '' %>
22 <& qual_link.html, $cust_main &>
25 % if ( $curuser->access_right('Order customer package') ) {
26 <% $s++ ? ' | ' : '' %>
27 <& /elements/order_pkg_link.html, 'cust_main'=>$cust_main &>
30 % if ( $curuser->access_right('One-time charge')
31 % && $conf->config('payby-default') ne 'HIDE'
33 <% $s++ ? ' | ' : '' %>
34 <& one_time_charge_link.html, $cust_main &>
37 % if ( $curuser->access_right('Bulk change customer packages') ) {
38 <% $s++ ? ' | ' : '' %>
39 <A HREF="<% $p %>edit/cust_pkg.cgi?<% $cust_main->custnum %>"><% mt('Bulk order and cancel packages') |h %></A> (<% mt('preserves services') |h %>)
46 <TD ALIGN="left" VALIGN="top">
50 <% mt('Current packages') |h %>
52 % if ( $cust_main->num_cancelled_pkgs ) {
53 % if ( $cgi->param('showcancelledpackages') eq '0' #see if it was set by me
54 % || ( $conf->exists('hidecancelledpackages')
55 % && ! $cgi->param('showcancelledpackages')
59 % my $prev = $cgi->param('showcancelledpackages');
60 % $cgi->param('showcancelledpackages', 1);
61 ( <a href="<% $cgi->self_url %>"><% mt('show') |h %>
62 % $cgi->param('showcancelledpackages', $prev);
64 % $cgi->param('showcancelledpackages', 0);
65 ( <a href="<% $cgi->self_url %>"><% mt('hide') |h %>
66 % $cgi->param('showcancelledpackages', 1);
69 <% mt('cancelled packages') |h %></a> )
71 % if ( $num_old_packages ) {
72 % $cgi->param('showoldpackages', 1);
73 ( <a href="<% $cgi->self_url %>"><% mt('show old packages') |h %></a> )
74 % } elsif ( $cgi->param('showoldpackages') ) {
75 % $cgi->param('showoldpackages', 0);
76 ( <a href="<% $cgi->self_url %>"><% mt('hide old packages') |h %></a> )
81 <A HREF="<%$p%>search/report_cust_pkg.html?custnum=<% $cust_main->custnum %>"><% mt('Package reports') |h %></A>
82 % if ( $curuser->access_right('Qualify service') ) {
83 | <A HREF="<%$p%>search/qual.cgi?custnum=<% $cust_main->custnum %>"><% mt('View Qualifications') |h %></A>
86 <% mt('Service reports:') |h %>
87 <A HREF="<%$p%>search/report_svc_acct.html?custnum=<% $cust_main->custnum %>"><% mt('accounts') |h %></A><BR>
88 <% mt('Usage reports:') |h %>
89 <A HREF="<%$p%>search/report_cdr.html?custnum=<% $cust_main->custnum %>"><% mt('CDRs') |h %></A>
95 % if ( $conf->exists('cust_pkg-group_by_location') and $show_location ) {
97 'cust_main' => $cust_main,
98 'packages' => $packages,
102 % # in this format, put all packages in one section
103 <& /elements/table-grid.html &>
104 <& packages/section.html,
105 'cust_main' => $cust_main,
106 'packages' => $packages,
107 'show_location' => $show_location,
114 % if ( $cgi->param('fragment') =~ /^cust_pkg(\d+)$/ ) {
116 // IE-specific hack. other browsers listen to #fragments
117 // is this even working? or is the #target redirection just working cause
118 // we set the URL params differently?
119 var el = document.getElementById( 'cust_pkg<% $1 %>' );
120 if ( el ) el.scrollIntoView(true);
126 my $cust_main = shift;
128 my $conf = new FS::Conf;
130 my $curuser = $FS::CurrentUser::CurrentUser;
132 my( $packages, $num_old_packages ) = get_packages($cust_main, $conf);
135 my $show_location = $conf->exists('cust_pkg-always_show_location')
136 || (grep $_->locationnum ne $cust_main->ship_locationnum, @$packages);
138 my $countrydefault = scalar($conf->config('countrydefault')) || 'US';
142 my $cust_main = shift or return undef;
146 if ( $cgi->param('showcancelledpackages') eq '0' #see if it was set by me
147 || ( $conf->exists('hidecancelledpackages')
148 && ! $cgi->param('showcancelledpackages') )
151 $method = 'ncancelled_pkgs';
153 $method = 'all_pkgs';
156 my $cust_pkg_fields =
157 join(', ', map { "cust_pkg.$_ AS $_" } fields('cust_pkg') );
159 my $part_pkg_fields =
160 join(', ', map { "part_pkg.$_ AS part_pkg_$_" } fields('part_pkg') );
163 join(', ', map "cust_pkg.$_", fields('cust_pkg') ). ', '.
164 join(', ', map "part_pkg.$_", fields('part_pkg') );
166 my $num_svcs = '( SELECT COUNT(*) FROM cust_svc '.
167 ' WHERE cust_svc.pkgnum = cust_pkg.pkgnum ) AS num_svcs';
169 my @packages = $cust_main->$method( {
170 'select' => "$cust_pkg_fields, $part_pkg_fields, $num_svcs",
171 'addl_from' => 'LEFT JOIN part_pkg USING ( pkgpart )',
173 my $num_old_packages = scalar(@packages);
175 foreach my $cust_pkg ( @packages ) {
176 my %hash = $cust_pkg->hash;
177 my %part_pkg = map { /^part_pkg_(.+)$/ or die; ( $1 => $hash{$_} ); }
178 grep { /^part_pkg_/ } keys %hash;
179 $cust_pkg->{'_pkgpart'} = new FS::part_pkg \%part_pkg;
182 unless ( $cgi->param('showoldpackages') ) {
183 my $years = $conf->config('cust_main-packages-years') || 2;
184 my $then = time - $years * 31556926; #60*60*24*365.2422 is close enough
186 my %hide = ( 'cancelled' => 'cancel',
187 'one-time charge' => 'setup',
191 grep { !exists($hide{$_->status}) or $_->get($hide{$_->status}) > $then
192 or $_->num_svcs #don't hide packages w/services
197 $num_old_packages -= scalar(@packages);
199 # don't include supplemental packages in this list; they'll be found from
200 # their main packages
201 @packages = grep !$_->main_pkgnum, @packages;
203 ( \@packages, $num_old_packages );