2 % if ( $curuser->access_right('Order customer package') ) {
3 <% $s++ ? ' | ' : '' %>
4 <% include('order_pkg_link.html', $cust_main) %>
7 % if ( $curuser->access_right('One-time charge')
8 % && $conf->config('payby-default') ne 'HIDE'
10 <% $s++ ? ' | ' : '' %>
11 <% include('one_time_charge_link.html', $cust_main) %>
14 % if ( $curuser->access_right('Bulk change customer packages') ) {
15 <% $s++ ? ' | ' : '' %>
16 <A HREF="<% $p %>edit/cust_pkg.cgi?<% $cust_main->custnum %>">Bulk order and cancel packages</A> (preserves services)
29 % if ( $cust_main->num_cancelled_pkgs ) {
30 % if ( $cgi->param('showcancelledpackages') eq '0' #see if it was set by me
31 % || ( $conf->exists('hidecancelledpackages')
32 % && ! $cgi->param('showcancelledpackages')
36 % my $prev = $cgi->param('showcancelledpackages');
37 % $cgi->param('showcancelledpackages', 1);
38 ( <a href="<% $cgi->self_url %>">show
39 % $cgi->param('showcancelledpackages', $prev);
41 % $cgi->param('showcancelledpackages', 0);
42 ( <a href="<% $cgi->self_url %>">hide
43 % $cgi->param('showcancelledpackages', 1);
46 cancelled packages</a> )
48 % if ( $num_old_packages ) {
49 % $cgi->param('showoldpackages', 1);
50 ( <a href="<% $cgi->self_url %>">show old packages</a> )
51 % } elsif ( $cgi->param('showoldpackages') ) {
52 % $cgi->param('showoldpackages', 0);
53 ( <a href="<% $cgi->self_url %>">hide old packages</a> )
58 <A HREF="<%$p%>search/report_cust_pkg.html?custnum=<% $cust_main->custnum %>">Package reports</A><BR>
60 <A HREF="<%$p%>search/report_svc_acct.html?custnum=<% $cust_main->custnum %>">accounts</A>
69 <% include('/elements/table-grid.html') %>
70 % my $bgcolor1 = '#eeeeee';
71 % my $bgcolor2 = '#ffffff';
75 <TH CLASS="grid" BGCOLOR="#cccccc">Package</TH>
76 <TH CLASS="grid" BGCOLOR="#cccccc">Status</TH>
77 % if ( $show_location ) {
78 <TH CLASS="grid" BGCOLOR="#cccccc">Location</TH>
80 <TH CLASS="grid" BGCOLOR="#cccccc">Services</TH>
83 % #$FS::cust_pkg::DEBUG = 2;
84 % foreach my $cust_pkg (@$packages) {
86 % if ( $bgcolor eq $bgcolor1 ) {
87 % $bgcolor = $bgcolor2;
89 % $bgcolor = $bgcolor1;
93 % 'bgcolor' => $bgcolor,
94 % 'cust_pkg' => $cust_pkg,
95 % 'part_pkg' => $cust_pkg->part_pkg,
100 <!--pkgnum: <% $cust_pkg->pkgnum %>-->
102 <% include('packages/package.html', %iopt) %>
103 <% include('packages/status.html', %iopt) %>
104 % if ( $show_location ) {
105 <% include('packages/location.html', %iopt) %>
107 <% include('packages/services.html', %iopt) %>
122 % if ( $cgi->param('fragment') =~ /^cust_pkg(\d+)$/ ) {
124 // IE-specific hack. other browsers listen to #fragments
125 // is this even working? or is the #target redirection just working cause
126 // we set the URL params differently?
127 var el = document.getElementById( 'cust_pkg<% $1 %>' );
128 if ( el ) el.scrollIntoView(true);
134 my( $cust_main ) = @_;
135 my $conf = new FS::Conf;
137 my $curuser = $FS::CurrentUser::CurrentUser;
139 my( $packages, $num_old_packages ) = get_packages($cust_main, $conf);
141 my $show_location = $conf->exists('cust_pkg-always_show_location')
142 || ( grep $_->locationnum, @$packages ); # ? '1' : '0';
144 my $countrydefault = scalar($conf->config('countrydefault')) || 'US';
146 #for services.html and status.html
147 'cust_pkg-display_times' => $conf->exists('cust_pkg-display_times'),
150 'cust_pkg-show_autosuspend' => $conf->exists('cust_pkg-show_autosuspend'),
151 #for status.html pkg-balances
152 'pkg-balances' => $conf->exists('pkg-balances'),
153 'money_char' => ( $conf->config('money_char') || '$' ),
156 'countrydefault' => $countrydefault,
157 'statedefault' => ( scalar($conf->config('statedefault'))
158 || ($countrydefault eq 'US' ? 'CA' : '') ),
160 'svc_external-skip_manual' => $conf->exists('svc_external-skip_manual'),
161 'legacy_link' => $conf->exists('legacy_link'),
162 'svc_broadband-manage_link' => scalar($conf->config('svc_broadband-manage_link')),
163 'maestro-status_test' => $conf->exists('maestro-status_test'),
169 my $cust_main = shift or return undef;
173 if ( $cgi->param('showcancelledpackages') eq '0' #see if it was set by me
174 || ( $conf->exists('hidecancelledpackages')
175 && ! $cgi->param('showcancelledpackages') )
178 $method = 'ncancelled_pkgs';
180 $method = 'all_pkgs';
183 my $cust_pkg_fields =
184 join(', ', map { "cust_pkg.$_ AS $_" } fields('cust_pkg') );
186 my $part_pkg_fields =
187 join(', ', map { "part_pkg.$_ AS part_pkg_$_" } fields('part_pkg') );
190 join(', ', map "cust_pkg.$_", fields('cust_pkg') ). ', '.
191 join(', ', map "part_pkg.$_", fields('part_pkg') );
193 my $num_svcs = '( SELECT COUNT(*) FROM cust_svc '.
194 ' WHERE cust_svc.pkgnum = cust_pkg.pkgnum ) AS num_svcs';
196 my @packages = $cust_main->$method( {
197 'select' => "$cust_pkg_fields, $part_pkg_fields, $num_svcs",
198 'addl_from' => 'LEFT JOIN part_pkg USING ( pkgpart )',
200 my $num_old_packages = scalar(@packages);
202 foreach my $cust_pkg ( @packages ) {
203 my %hash = $cust_pkg->hash;
204 my %part_pkg = map { /^part_pkg_(.+)$/ or die; ( $1 => $hash{$_} ); }
205 grep { /^part_pkg_/ } keys %hash;
206 $cust_pkg->{'_pkgpart'} = new FS::part_pkg \%part_pkg;
209 unless ( $cgi->param('showoldpackages') ) {
210 my $years = $conf->config('cust_main-packages-years') || 2;
211 my $then = time - $years * 31556926; #60*60*24*365.2422 is close enough
213 my %hide = ( 'cancelled' => 'cancel',
214 'one-time charge' => 'setup',
218 grep { !exists($hide{$_->status}) or $_->get($hide{$_->status}) > $then
219 or $_->num_svcs #don't hide packages w/services
224 $num_old_packages -= scalar(@packages);
226 ( \@packages, $num_old_packages );