2 % if ( $curuser->access_right('Order customer package') ) {
3 <% $s++ ? ' | ' : '' %>
4 <% include( '/elements/popup_link-cust_main.html',
5 'action' => $p. 'misc/order_pkg.html',
6 'label' => 'Order new package',
7 'actionlabel' => 'Order new package',
9 'cust_main' => $cust_main,
10 'closetext' => 'Close',
17 % if ( $curuser->access_right('One-time charge')
18 % && $conf->config('payby-default') ne 'HIDE'
20 <% $s++ ? ' | ' : '' %>
21 <% include('one_time_charge_link.html', $cust_main) %>
24 % if ( $curuser->access_right('Bulk change customer packages') ) {
25 <% $s++ ? ' | ' : '' %>
26 <A HREF="<% $p %>edit/cust_pkg.cgi?<% $cust_main->custnum %>">Bulk order and cancel packages</A> (preserves services)
35 % if ( $cust_main->num_cancelled_pkgs ) {
36 % if ( $cgi->param('showcancelledpackages') eq '0' #see if it was set by me
37 % || ( $conf->exists('hidecancelledpackages')
38 % && ! $cgi->param('showcancelledpackages')
42 % $cgi->param('showcancelledpackages', 1);
45 ( <a href="<% $cgi->self_url %>">show
47 % $cgi->param('showcancelledpackages', 0);
50 ( <a href="<% $cgi->self_url %>">hide
53 cancelled packages</a> )
55 % if ( $num_old_packages ) {
56 % $cgi->param('showoldpackages', 1);
57 ( <a href="<% $cgi->self_url %>">show old packages</a> )
58 % } elsif ( $cgi->param('showoldpackages') ) {
59 % $cgi->param('showoldpackages', 0);
60 ( <a href="<% $cgi->self_url %>">hide old packages</a> )
64 <% include('/elements/table-grid.html') %>
65 % my $bgcolor1 = '#eeeeee';
66 % my $bgcolor2 = '#ffffff';
70 <TH CLASS="grid" BGCOLOR="#cccccc">Package</TH>
71 <TH CLASS="grid" BGCOLOR="#cccccc">Status</TH>
72 % if ( $show_location ) {
73 <TH CLASS="grid" BGCOLOR="#cccccc">Location</TH>
75 <TH CLASS="grid" BGCOLOR="#cccccc">Services</TH>
78 % #$FS::cust_pkg::DEBUG = 2;
79 % foreach my $cust_pkg (@$packages) {
81 % if ( $bgcolor eq $bgcolor1 ) {
82 % $bgcolor = $bgcolor2;
84 % $bgcolor = $bgcolor1;
88 % 'bgcolor' => $bgcolor,
89 % 'cust_pkg' => $cust_pkg,
90 % 'part_pkg' => $cust_pkg->part_pkg,
95 <!--pkgnum: <% $cust_pkg->pkgnum %>-->
97 <% include('packages/package.html', %iopt) %>
98 <% include('packages/status.html', %iopt) %>
99 % if ( $show_location ) {
100 <% include('packages/location.html', %iopt) %>
102 <% include('packages/services.html', %iopt) %>
113 % if ( $cgi->param('fragment') =~ /^cust_pkg(\d+)$/ ) {
115 // IE-specific hack. other browsers listen to #fragments
116 // is this even working? or is the #target redirection just working cause
117 // we set the URL params differently?
118 var el = document.getElementById( 'cust_pkg<% $1 %>' );
119 if ( el ) el.scrollIntoView(true);
125 my( $cust_main ) = @_;
126 my $conf = new FS::Conf;
128 my $curuser = $FS::CurrentUser::CurrentUser;
130 my( $packages, $num_old_packages ) = get_packages($cust_main, $conf);
132 my $show_location = $conf->exists('cust_pkg-always_show_location')
133 || ( grep $_->locationnum, @$packages ); # ? '1' : '0';
135 my $countrydefault = scalar($conf->config('countrydefault')) || 'US';
137 #for services.html and status.html
138 'cust_pkg-display_times' => $conf->exists('cust_pkg-display_times'),
141 'cust_pkg-show_autosuspend' => $conf->exists('cust_pkg-show_autosuspend'),
142 #for status.html pkg-balances
143 'pkg-balances' => $conf->exists('pkg-balances'),
144 'money_char' => ( $conf->config('money_char') || '$' ),
147 'countrydefault' => $countrydefault,
148 'statedefault' => ( scalar($conf->config('statedefault'))
149 || ($countrydefault eq 'US' ? 'CA' : '') ),
151 'svc_external-skip_manual' => $conf->exists('svc_external-skip_manual'),
152 'legacy_link' => $conf->exists('legacy_link'),
153 'svc_broadband-manage_link' => $conf->config('svc_broadband-manage_link'),
159 my $cust_main = shift or return undef;
163 if ( $cgi->param('showcancelledpackages') eq '0' #see if it was set by me
164 || ( $conf->exists('hidecancelledpackages')
165 && ! $cgi->param('showcancelledpackages') )
168 $method = 'ncancelled_pkgs';
170 $method = 'all_pkgs';
173 my $cust_pkg_fields =
174 join(', ', map { "cust_pkg.$_ AS $_" } fields('cust_pkg') );
176 my $part_pkg_fields =
177 join(', ', map { "part_pkg.$_ AS part_pkg_$_" } fields('part_pkg') );
180 join(', ', map "cust_pkg.$_", fields('cust_pkg') ). ', '.
181 join(', ', map "part_pkg.$_", fields('part_pkg') );
183 my $num_svcs = '( SELECT COUNT(*) FROM cust_svc '.
184 ' WHERE cust_svc.pkgnum = cust_pkg.pkgnum ) AS num_svcs';
186 my @packages = $cust_main->$method( {
187 'select' => "$cust_pkg_fields, $part_pkg_fields, $num_svcs",
188 'addl_from' => 'LEFT JOIN part_pkg USING ( pkgpart )',
190 my $num_old_packages = scalar(@packages);
192 foreach my $cust_pkg ( @packages ) {
193 my %hash = $cust_pkg->hash;
194 my %part_pkg = map { /^part_pkg_(.+)$/ or die; ( $1 => $hash{$_} ); }
195 grep { /^part_pkg_/ } keys %hash;
196 $cust_pkg->{'_pkgpart'} = new FS::part_pkg \%part_pkg;
199 unless ( $cgi->param('showoldpackages') ) {
200 my $years = $conf->config('cust_main-packages-years') || 2;
201 my $seconds = 31556926; #60*60*24*365.2422 is close enough
202 my $then = time - $seconds;
204 my %hide = ( 'cancelled' => 'cancel',
205 'one-time charge' => 'setup',
209 grep { !exists($hide{$_->status}) or $_->get($hide{$_->status}) > $then
210 or $_->num_svcs #don't hide packages w/services
215 $num_old_packages -= scalar(@packages);
217 ( \@packages, $num_old_packages );