3 % # XXX: add qual access right
4 <% $s++ ? ' | ' : '' %>
5 <% include('qual_link.html', $cust_main) %>
7 % if ( $curuser->access_right('Order customer package') ) {
8 <% $s++ ? ' | ' : '' %>
9 <% include('order_pkg_link.html', $cust_main) %>
12 % if ( $curuser->access_right('One-time charge')
13 % && $conf->config('payby-default') ne 'HIDE'
15 <% $s++ ? ' | ' : '' %>
16 <% include('one_time_charge_link.html', $cust_main) %>
19 % if ( $curuser->access_right('Bulk change customer packages') ) {
20 <% $s++ ? ' | ' : '' %>
21 <A HREF="<% $p %>edit/cust_pkg.cgi?<% $cust_main->custnum %>">Bulk order and cancel packages</A> (preserves services)
34 % if ( $cust_main->num_cancelled_pkgs ) {
35 % if ( $cgi->param('showcancelledpackages') eq '0' #see if it was set by me
36 % || ( $conf->exists('hidecancelledpackages')
37 % && ! $cgi->param('showcancelledpackages')
41 % my $prev = $cgi->param('showcancelledpackages');
42 % $cgi->param('showcancelledpackages', 1);
43 ( <a href="<% $cgi->self_url %>">show
44 % $cgi->param('showcancelledpackages', $prev);
46 % $cgi->param('showcancelledpackages', 0);
47 ( <a href="<% $cgi->self_url %>">hide
48 % $cgi->param('showcancelledpackages', 1);
51 cancelled packages</a> )
53 % if ( $num_old_packages ) {
54 % $cgi->param('showoldpackages', 1);
55 ( <a href="<% $cgi->self_url %>">show old packages</a> )
56 % } elsif ( $cgi->param('showoldpackages') ) {
57 % $cgi->param('showoldpackages', 0);
58 ( <a href="<% $cgi->self_url %>">hide old packages</a> )
63 <A HREF="<%$p%>search/report_cust_pkg.html?custnum=<% $cust_main->custnum %>">Package reports</A><BR>
65 <A HREF="<%$p%>search/report_svc_acct.html?custnum=<% $cust_main->custnum %>">accounts</A><BR>
67 <A HREF="<%$p%>search/report_cdr.html?custnum=<% $cust_main->custnum %>">CDRs</A>
76 <% include('/elements/table-grid.html') %>
77 % my $bgcolor1 = '#eeeeee';
78 % my $bgcolor2 = '#ffffff';
82 <TH CLASS="grid" BGCOLOR="#cccccc">Package</TH>
83 <TH CLASS="grid" BGCOLOR="#cccccc">Status</TH>
84 % if ( $show_location ) {
85 <TH CLASS="grid" BGCOLOR="#cccccc">Location</TH>
87 <TH CLASS="grid" BGCOLOR="#cccccc">Services</TH>
90 % #$FS::cust_pkg::DEBUG = 2;
91 % foreach my $cust_pkg (@$packages) {
93 % if ( $bgcolor eq $bgcolor1 ) {
94 % $bgcolor = $bgcolor2;
96 % $bgcolor = $bgcolor1;
100 % 'bgcolor' => $bgcolor,
101 % 'cust_pkg' => $cust_pkg,
102 % 'part_pkg' => $cust_pkg->part_pkg,
107 <!--pkgnum: <% $cust_pkg->pkgnum %>-->
109 <% include('packages/package.html', %iopt) %>
110 <% include('packages/status.html', %iopt) %>
111 % if ( $show_location ) {
112 <% include('packages/location.html', %iopt) %>
114 <% include('packages/services.html', %iopt) %>
129 % if ( $cgi->param('fragment') =~ /^cust_pkg(\d+)$/ ) {
131 // IE-specific hack. other browsers listen to #fragments
132 // is this even working? or is the #target redirection just working cause
133 // we set the URL params differently?
134 var el = document.getElementById( 'cust_pkg<% $1 %>' );
135 if ( el ) el.scrollIntoView(true);
141 my( $cust_main ) = @_;
142 my $conf = new FS::Conf;
144 my $curuser = $FS::CurrentUser::CurrentUser;
146 my( $packages, $num_old_packages ) = get_packages($cust_main, $conf);
148 my $show_location = $conf->exists('cust_pkg-always_show_location')
149 || ( grep $_->locationnum, @$packages ); # ? '1' : '0';
151 my $countrydefault = scalar($conf->config('countrydefault')) || 'US';
153 #for services.html and status.html
154 'cust_pkg-display_times' => $conf->exists('cust_pkg-display_times'),
157 'cust_pkg-show_autosuspend' => $conf->exists('cust_pkg-show_autosuspend'),
158 #for status.html pkg-balances
159 'pkg-balances' => $conf->exists('pkg-balances'),
160 'money_char' => ( $conf->config('money_char') || '$' ),
163 'countrydefault' => $countrydefault,
164 'statedefault' => ( scalar($conf->config('statedefault'))
165 || ($countrydefault eq 'US' ? 'CA' : '') ),
167 'svc_external-skip_manual' => $conf->exists('svc_external-skip_manual'),
168 'legacy_link' => $conf->exists('legacy_link'),
169 'svc_broadband-manage_link' => scalar($conf->config('svc_broadband-manage_link')),
170 'maestro-status_test' => $conf->exists('maestro-status_test'),
171 'cust_pkg-large_pkg_size' => $conf->config('cust_pkg-large_pkg_size'),
177 my $cust_main = shift or return undef;
181 if ( $cgi->param('showcancelledpackages') eq '0' #see if it was set by me
182 || ( $conf->exists('hidecancelledpackages')
183 && ! $cgi->param('showcancelledpackages') )
186 $method = 'ncancelled_pkgs';
188 $method = 'all_pkgs';
191 my $cust_pkg_fields =
192 join(', ', map { "cust_pkg.$_ AS $_" } fields('cust_pkg') );
194 my $part_pkg_fields =
195 join(', ', map { "part_pkg.$_ AS part_pkg_$_" } fields('part_pkg') );
198 join(', ', map "cust_pkg.$_", fields('cust_pkg') ). ', '.
199 join(', ', map "part_pkg.$_", fields('part_pkg') );
201 my $num_svcs = '( SELECT COUNT(*) FROM cust_svc '.
202 ' WHERE cust_svc.pkgnum = cust_pkg.pkgnum ) AS num_svcs';
204 my @packages = $cust_main->$method( {
205 'select' => "$cust_pkg_fields, $part_pkg_fields, $num_svcs",
206 'addl_from' => 'LEFT JOIN part_pkg USING ( pkgpart )',
208 my $num_old_packages = scalar(@packages);
210 foreach my $cust_pkg ( @packages ) {
211 my %hash = $cust_pkg->hash;
212 my %part_pkg = map { /^part_pkg_(.+)$/ or die; ( $1 => $hash{$_} ); }
213 grep { /^part_pkg_/ } keys %hash;
214 $cust_pkg->{'_pkgpart'} = new FS::part_pkg \%part_pkg;
217 unless ( $cgi->param('showoldpackages') ) {
218 my $years = $conf->config('cust_main-packages-years') || 2;
219 my $then = time - $years * 31556926; #60*60*24*365.2422 is close enough
221 my %hide = ( 'cancelled' => 'cancel',
222 'one-time charge' => 'setup',
226 grep { !exists($hide{$_->status}) or $_->get($hide{$_->status}) > $then
227 or $_->num_svcs #don't hide packages w/services
232 $num_old_packages -= scalar(@packages);
234 ( \@packages, $num_old_packages );