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><BR>
62 <A HREF="<%$p%>search/report_cdr.html?custnum=<% $cust_main->custnum %>">CDRs</A>
71 <% include('/elements/table-grid.html') %>
72 % my $bgcolor1 = '#eeeeee';
73 % my $bgcolor2 = '#ffffff';
77 <TH CLASS="grid" BGCOLOR="#cccccc">Package</TH>
78 <TH CLASS="grid" BGCOLOR="#cccccc">Status</TH>
79 % if ( $show_location ) {
80 <TH CLASS="grid" BGCOLOR="#cccccc">Location</TH>
82 <TH CLASS="grid" BGCOLOR="#cccccc">Services</TH>
85 % #$FS::cust_pkg::DEBUG = 2;
86 % foreach my $cust_pkg (@$packages) {
88 % if ( $bgcolor eq $bgcolor1 ) {
89 % $bgcolor = $bgcolor2;
91 % $bgcolor = $bgcolor1;
95 % 'bgcolor' => $bgcolor,
96 % 'cust_pkg' => $cust_pkg,
97 % 'part_pkg' => $cust_pkg->part_pkg,
102 <!--pkgnum: <% $cust_pkg->pkgnum %>-->
104 <% include('packages/package.html', %iopt) %>
105 <% include('packages/status.html', %iopt) %>
106 % if ( $show_location ) {
107 <% include('packages/location.html', %iopt) %>
109 <% include('packages/services.html', %iopt) %>
124 % if ( $cgi->param('fragment') =~ /^cust_pkg(\d+)$/ ) {
126 // IE-specific hack. other browsers listen to #fragments
127 // is this even working? or is the #target redirection just working cause
128 // we set the URL params differently?
129 var el = document.getElementById( 'cust_pkg<% $1 %>' );
130 if ( el ) el.scrollIntoView(true);
136 my( $cust_main ) = @_;
137 my $conf = new FS::Conf;
139 my $curuser = $FS::CurrentUser::CurrentUser;
141 my( $packages, $num_old_packages ) = get_packages($cust_main, $conf);
143 my $show_location = $conf->exists('cust_pkg-always_show_location')
144 || ( grep $_->locationnum, @$packages ); # ? '1' : '0';
146 my $countrydefault = scalar($conf->config('countrydefault')) || 'US';
148 #for services.html and status.html
149 'cust_pkg-display_times' => $conf->exists('cust_pkg-display_times'),
152 'cust_pkg-show_autosuspend' => $conf->exists('cust_pkg-show_autosuspend'),
153 #for status.html pkg-balances
154 'pkg-balances' => $conf->exists('pkg-balances'),
155 'money_char' => ( $conf->config('money_char') || '$' ),
158 'countrydefault' => $countrydefault,
159 'statedefault' => ( scalar($conf->config('statedefault'))
160 || ($countrydefault eq 'US' ? 'CA' : '') ),
162 'svc_external-skip_manual' => $conf->exists('svc_external-skip_manual'),
163 'legacy_link' => $conf->exists('legacy_link'),
164 'svc_broadband-manage_link' => scalar($conf->config('svc_broadband-manage_link')),
165 'maestro-status_test' => $conf->exists('maestro-status_test'),
166 'cust_pkg-large_pkg_size' => $conf->config('cust_pkg-large_pkg_size'),
172 my $cust_main = shift or return undef;
176 if ( $cgi->param('showcancelledpackages') eq '0' #see if it was set by me
177 || ( $conf->exists('hidecancelledpackages')
178 && ! $cgi->param('showcancelledpackages') )
181 $method = 'ncancelled_pkgs';
183 $method = 'all_pkgs';
186 my $cust_pkg_fields =
187 join(', ', map { "cust_pkg.$_ AS $_" } fields('cust_pkg') );
189 my $part_pkg_fields =
190 join(', ', map { "part_pkg.$_ AS part_pkg_$_" } fields('part_pkg') );
193 join(', ', map "cust_pkg.$_", fields('cust_pkg') ). ', '.
194 join(', ', map "part_pkg.$_", fields('part_pkg') );
196 my $num_svcs = '( SELECT COUNT(*) FROM cust_svc '.
197 ' WHERE cust_svc.pkgnum = cust_pkg.pkgnum ) AS num_svcs';
199 my @packages = $cust_main->$method( {
200 'select' => "$cust_pkg_fields, $part_pkg_fields, $num_svcs",
201 'addl_from' => 'LEFT JOIN part_pkg USING ( pkgpart )',
203 my $num_old_packages = scalar(@packages);
205 foreach my $cust_pkg ( @packages ) {
206 my %hash = $cust_pkg->hash;
207 my %part_pkg = map { /^part_pkg_(.+)$/ or die; ( $1 => $hash{$_} ); }
208 grep { /^part_pkg_/ } keys %hash;
209 $cust_pkg->{'_pkgpart'} = new FS::part_pkg \%part_pkg;
212 unless ( $cgi->param('showoldpackages') ) {
213 my $years = $conf->config('cust_main-packages-years') || 2;
214 my $then = time - $years * 31556926; #60*60*24*365.2422 is close enough
216 my %hide = ( 'cancelled' => 'cancel',
217 'one-time charge' => 'setup',
221 grep { !exists($hide{$_->status}) or $_->get($hide{$_->status}) > $then
222 or $_->num_svcs #don't hide packages w/services
227 $num_old_packages -= scalar(@packages);
229 ( \@packages, $num_old_packages );