1 <A NAME="cust_pkg"><FONT SIZE="+2">Packages</FONT></A><BR>
4 % if ( $curuser->access_right('Order customer package') ) {
5 <% $s++ ? ' | ' : '' %>
6 <% include( '/elements/popup_link-cust_main.html',
7 'action' => $p. 'misc/order_pkg.html',
8 'label' => 'Order new package',
9 'actionlabel' => 'Order new package',
11 'cust_main' => $cust_main,
12 'closetext' => 'Close',
18 % if ( $curuser->access_right('One-time charge')
19 % && $conf->config('payby-default') ne 'HIDE'
21 <% $s++ ? ' | ' : '' %>
22 <% include('one_time_charge_link.html', $cust_main) %>
25 % if ( $curuser->access_right('Bulk change customer packages') ) {
26 <% $s++ ? ' | ' : '' %>
27 <A HREF="<% $p %>edit/cust_pkg.cgi?<% $cust_main->custnum %>">Bulk order and cancel packages</A> (preserves services)
36 % if ( $cust_main->num_cancelled_pkgs ) {
37 % if ( $cgi->param('showcancelledpackages') eq '0' #see if it was set by me
38 % || ( $conf->exists('hidecancelledpackages')
39 % && ! $cgi->param('showcancelledpackages')
43 % $cgi->param('showcancelledpackages', 1);
46 ( <a href="<% $cgi->self_url %>">show
48 % $cgi->param('showcancelledpackages', 0);
51 ( <a href="<% $cgi->self_url %>">hide
54 cancelled packages</a> )
56 % if ( $num_old_packages ) {
57 % $cgi->param('showoldpackages', 1);
58 ( <a href="<% $cgi->self_url %>">show old packages</a> )
59 % } elsif ( $cgi->param('showoldpackages') ) {
60 % $cgi->param('showoldpackages', 0);
61 ( <a href="<% $cgi->self_url %>">hide old packages</a> )
65 <% include('/elements/table-grid.html') %>
66 % my $bgcolor1 = '#eeeeee';
67 % my $bgcolor2 = '#ffffff';
71 <TH CLASS="grid" BGCOLOR="#cccccc">Package</TH>
72 <TH CLASS="grid" BGCOLOR="#cccccc">Status</TH>
73 % if ( $show_location ) {
74 <TH CLASS="grid" BGCOLOR="#cccccc">Location</TH>
76 <TH CLASS="grid" BGCOLOR="#cccccc">Services</TH>
79 % $FS::cust_pkg::DEBUG = 2;
80 % foreach my $cust_pkg (@$packages) {
82 % if ( $bgcolor eq $bgcolor1 ) {
83 % $bgcolor = $bgcolor2;
85 % $bgcolor = $bgcolor1;
88 % my %hash = $cust_pkg->hash;
89 % my %part_pkg = map { /^part_pkg_(.+)$/ or die; ( $1 => $hash{$_} ); }
90 % grep { /^part_pkg_/ } keys %hash;
91 % $cust_pkg->{'_pkgpart'} = new FS::part_pkg \%part_pkg;
94 % 'bgcolor' => $bgcolor,
95 % 'cust_pkg' => $cust_pkg,
96 % 'part_pkg' => $cust_pkg->part_pkg,
101 <!--pkgnum: <% $cust_pkg->pkgnum %>-->
103 <% include('packages/package.html', %iopt) %>
104 <% include('packages/status.html', %iopt) %>
105 % if ( $show_location ) {
106 <% include('packages/location.html', %iopt) %>
108 <% include('packages/services.html', %iopt) %>
119 % if ( $cgi->param('fragment') =~ /^cust_pkg(\d+)$/ ) {
121 // IE-specific hack. other browsers listen to #fragments
122 // is this even working? or is the #target redirection just working cause
123 // we set the URL params differently?
124 var el = document.getElementById( 'cust_pkg<% $1 %>' );
125 if ( el ) el.scrollIntoView(true);
131 my( $cust_main ) = @_;
132 my $conf = new FS::Conf;
134 my $curuser = $FS::CurrentUser::CurrentUser;
136 my( $packages, $num_old_packages ) = get_packages($cust_main, $conf);
138 my $show_location = $conf->exists('cust_pkg-always_show_location')
139 || ( grep $_->locationnum, @$packages ); # ? '1' : '0';
141 my $countrydefault = scalar($conf->config('countrydefault')) || 'US';
143 #for services.html and status.html
144 'cust_pkg-display_times' => $conf->exists('cust_pkg-display_times'),
147 'cust_pkg-show_autosuspend' => $conf->exists('cust_pkg-show_autosuspend'),
150 'countrydefault' => $countrydefault,
151 'statedefault' => ( scalar($conf->config('statedefault'))
152 || ($countrydefault eq 'US' ? 'CA' : '') ),
154 'svc_external-skip_manual' => $conf->exists('svc_external-skip_manual'),
155 'legacy_link' => $conf->exists('legacy_link'),
161 my $cust_main = shift or return undef;
165 if ( $cgi->param('showcancelledpackages') eq '0' #see if it was set by me
166 || ( $conf->exists('hidecancelledpackages')
167 && ! $cgi->param('showcancelledpackages') )
170 $method = 'ncancelled_pkgs';
172 $method = 'all_pkgs';
175 my $cust_pkg_fields =
176 join(', ', map { "cust_pkg.$_ AS $_" } fields('cust_pkg') );
178 my $part_pkg_fields =
179 join(', ', map { "part_pkg.$_ AS part_pkg_$_" } fields('part_pkg') );
181 my @packages = $cust_main->$method( {
182 'select' => "$cust_pkg_fields, $part_pkg_fields",
183 'addl_from' => 'LEFT JOIN part_pkg USING ( pkgpart )'
185 my $num_old_packages = scalar(@packages);
187 unless ( $cgi->param('showoldpackages') ) {
188 my $years = $conf->config('cust_main-packages-years') || 2;
189 my $seconds = 31556926; #60*60*24*365.2422 is close enough
190 my $then = time - $seconds;
192 my %hide = ( 'cancelled' => 'cancel',
193 'one-time charge' => 'setup',
197 grep { !exists($hide{$_->status}) or $_->get($hide{$_->status}) > $then }
201 $num_old_packages -= scalar(@packages);
203 ( \@packages, $num_old_packages );