1 <STYLE TYPE="text/css">
15 border: 1px solid black;
21 background-color: #ffffaa;
23 .row0 { background-color: #eeeeee; }
24 .row1 { background-color: #ffffff; }
29 % if ( $curuser->access_right('Qualify service') ) {
30 <% $s++ ? ' | ' : '' %>
31 <& qual_link.html, $cust_main &>
34 % if ( $curuser->access_right('Order customer package') ) {
35 <% $s++ ? ' | ' : '' %>
36 <& /elements/order_pkg_link.html, 'cust_main'=>$cust_main &>
39 % if ( $curuser->access_right('One-time charge')
40 % && $conf->config('payby-default') ne 'HIDE'
42 <% $s++ ? ' | ' : '' %>
43 <& one_time_charge_link.html, $cust_main &>
46 % if ( $curuser->access_right('Bulk change customer packages') ) {
47 <% $s++ ? ' | ' : '' %>
48 <A HREF="<% $p %>edit/cust_pkg.cgi?<% $cust_main->custnum %>"><% mt('Bulk order and cancel packages') |h %></A> (<% mt('preserves services') |h %>)
55 <TD ALIGN="left" VALIGN="top">
59 <% mt('Current packages') |h %>
61 % if ( $cust_main->num_cancelled_pkgs ) {
62 % if ( $cgi->param('showcancelledpackages') eq '0' #see if it was set by me
63 % || ( $conf->exists('hidecancelledpackages')
64 % && ! $cgi->param('showcancelledpackages')
68 % my $prev = $cgi->param('showcancelledpackages');
69 % $cgi->param('showcancelledpackages', 1);
70 ( <a href="<% $cgi->self_url %>"><% mt('show') |h %>
71 % $cgi->param('showcancelledpackages', $prev);
73 % $cgi->param('showcancelledpackages', 0);
74 ( <a href="<% $cgi->self_url %>"><% mt('hide') |h %>
75 % $cgi->param('showcancelledpackages', 1);
78 <% mt('cancelled packages') |h %></a> )
80 % if ( $num_old_packages ) {
81 % $cgi->param('showoldpackages', 1);
82 ( <a href="<% $cgi->self_url %>"><% mt('show old packages') |h %></a> )
83 % } elsif ( $cgi->param('showoldpackages') ) {
84 % $cgi->param('showoldpackages', 0);
85 ( <a href="<% $cgi->self_url %>"><% mt('hide old packages') |h %></a> )
90 <A HREF="<%$p%>search/report_cust_pkg.html?custnum=<% $cust_main->custnum %>"><% mt('Package reports') |h %></A>
91 % if ( $curuser->access_right('Qualify service') ) {
92 | <A HREF="<%$p%>search/qual.cgi?custnum=<% $cust_main->custnum %>"><% mt('View Qualifications') |h %></A>
95 <% mt('Service reports:') |h %>
96 <A HREF="<%$p%>search/report_svc_acct.html?custnum=<% $cust_main->custnum %>"><% mt('accounts') |h %></A><BR>
97 <% mt('Usage reports:') |h %>
98 <A HREF="<%$p%>search/report_cdr.html?custnum=<% $cust_main->custnum %>"><% mt('CDRs') |h %></A>
104 % if ( $conf->exists('cust_pkg-group_by_location') and $show_location ) {
106 'cust_main' => $cust_main,
107 'packages' => $packages,
111 % # in this format, put all packages in one section
112 <& /elements/table-grid.html &>
113 <& packages/section.html,
114 'cust_main' => $cust_main,
115 'packages' => $packages,
116 'show_location' => $show_location,
123 % if ( $cgi->param('fragment') =~ /^cust_pkg(\d+)$/ ) {
125 // IE-specific hack. other browsers listen to #fragments
126 // is this even working? or is the #target redirection just working cause
127 // we set the URL params differently?
128 var el = document.getElementById( 'cust_pkg<% $1 %>' );
129 if ( el ) el.scrollIntoView(true);
135 my $cust_main = shift;
137 my $conf = new FS::Conf;
139 my $curuser = $FS::CurrentUser::CurrentUser;
141 my( $packages, $num_old_packages ) = get_packages($cust_main, $conf);
144 my $show_location = $conf->exists('cust_pkg-always_show_location')
145 || (grep $_->locationnum ne $cust_main->ship_locationnum, @$packages);
147 my $countrydefault = scalar($conf->config('countrydefault')) || 'US';
151 my $cust_main = shift or return undef;
155 if ( $cgi->param('showcancelledpackages') eq '0' #see if it was set by me
156 || ( $conf->exists('hidecancelledpackages')
157 && ! $cgi->param('showcancelledpackages') )
160 $method = 'ncancelled_pkgs';
162 $method = 'all_pkgs';
165 my $cust_pkg_fields =
166 join(', ', map { "cust_pkg.$_ AS $_" } fields('cust_pkg') );
168 my $part_pkg_fields =
169 join(', ', map { "part_pkg.$_ AS part_pkg_$_" } fields('part_pkg') );
172 join(', ', map "cust_pkg.$_", fields('cust_pkg') ). ', '.
173 join(', ', map "part_pkg.$_", fields('part_pkg') );
175 my $num_svcs = '( SELECT COUNT(*) FROM cust_svc '.
176 ' WHERE cust_svc.pkgnum = cust_pkg.pkgnum ) AS num_svcs';
178 my @packages = $cust_main->$method( {
179 'select' => "$cust_pkg_fields, $part_pkg_fields, $num_svcs",
180 'addl_from' => 'LEFT JOIN part_pkg USING ( pkgpart )',
182 my $num_old_packages = scalar(@packages);
184 foreach my $cust_pkg ( @packages ) {
185 my %hash = $cust_pkg->hash;
186 my %part_pkg = map { /^part_pkg_(.+)$/ or die; ( $1 => $hash{$_} ); }
187 grep { /^part_pkg_/ } keys %hash;
188 $cust_pkg->{'_pkgpart'} = new FS::part_pkg \%part_pkg;
191 unless ( $cgi->param('showoldpackages') ) {
192 my $years = $conf->config('cust_main-packages-years') || 2;
193 my $then = time - $years * 31556926; #60*60*24*365.2422 is close enough
195 my %hide = ( 'cancelled' => 'cancel',
196 'one-time charge' => 'setup',
200 grep { !exists($hide{$_->status}) or $_->get($hide{$_->status}) > $then
201 or $_->num_svcs #don't hide packages w/services
206 $num_old_packages -= scalar(@packages);
208 # don't include supplemental packages in this list; they'll be found from
209 # their main packages
210 @packages = grep !$_->main_pkgnum, @packages;
212 ( \@packages, $num_old_packages );