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)
39 % if ( $cust_main->num_cancelled_pkgs ) {
40 % if ( $cgi->param('showcancelledpackages') eq '0' #see if it was set by me
41 % || ( $conf->exists('hidecancelledpackages')
42 % && ! $cgi->param('showcancelledpackages')
46 % my $prev = $cgi->param('showcancelledpackages');
47 % $cgi->param('showcancelledpackages', 1);
48 ( <a href="<% $cgi->self_url %>">show
49 % $cgi->param('showcancelledpackages', $prev);
51 % $cgi->param('showcancelledpackages', 0);
52 ( <a href="<% $cgi->self_url %>">hide
53 % $cgi->param('showcancelledpackages', 1);
56 cancelled packages</a> )
58 % if ( $num_old_packages ) {
59 % $cgi->param('showoldpackages', 1);
60 ( <a href="<% $cgi->self_url %>">show old packages</a> )
61 % } elsif ( $cgi->param('showoldpackages') ) {
62 % $cgi->param('showoldpackages', 0);
63 ( <a href="<% $cgi->self_url %>">hide old packages</a> )
68 <A HREF="<%$p%>search/report_cust_pkg.html?custnum=<% $cust_main->custnum %>">Package reports</A><BR>
70 <A HREF="<%$p%>search/report_svc_acct.html?custnum=<% $cust_main->custnum %>">accounts</A>
79 <% include('/elements/table-grid.html') %>
80 % my $bgcolor1 = '#eeeeee';
81 % my $bgcolor2 = '#ffffff';
85 <TH CLASS="grid" BGCOLOR="#cccccc">Package</TH>
86 <TH CLASS="grid" BGCOLOR="#cccccc">Status</TH>
87 % if ( $show_location ) {
88 <TH CLASS="grid" BGCOLOR="#cccccc">Location</TH>
90 <TH CLASS="grid" BGCOLOR="#cccccc">Services</TH>
93 % #$FS::cust_pkg::DEBUG = 2;
94 % foreach my $cust_pkg (@$packages) {
96 % if ( $bgcolor eq $bgcolor1 ) {
97 % $bgcolor = $bgcolor2;
99 % $bgcolor = $bgcolor1;
103 % 'bgcolor' => $bgcolor,
104 % 'cust_pkg' => $cust_pkg,
105 % 'part_pkg' => $cust_pkg->part_pkg,
110 <!--pkgnum: <% $cust_pkg->pkgnum %>-->
112 <% include('packages/package.html', %iopt) %>
113 <% include('packages/status.html', %iopt) %>
114 % if ( $show_location ) {
115 <% include('packages/location.html', %iopt) %>
117 <% include('packages/services.html', %iopt) %>
132 % if ( $cgi->param('fragment') =~ /^cust_pkg(\d+)$/ ) {
134 // IE-specific hack. other browsers listen to #fragments
135 // is this even working? or is the #target redirection just working cause
136 // we set the URL params differently?
137 var el = document.getElementById( 'cust_pkg<% $1 %>' );
138 if ( el ) el.scrollIntoView(true);
144 my( $cust_main ) = @_;
145 my $conf = new FS::Conf;
147 my $curuser = $FS::CurrentUser::CurrentUser;
149 my( $packages, $num_old_packages ) = get_packages($cust_main, $conf);
151 my $show_location = $conf->exists('cust_pkg-always_show_location')
152 || ( grep $_->locationnum, @$packages ); # ? '1' : '0';
154 my $countrydefault = scalar($conf->config('countrydefault')) || 'US';
156 #for services.html and status.html
157 'cust_pkg-display_times' => $conf->exists('cust_pkg-display_times'),
160 'cust_pkg-show_autosuspend' => $conf->exists('cust_pkg-show_autosuspend'),
161 #for status.html pkg-balances
162 'pkg-balances' => $conf->exists('pkg-balances'),
163 'money_char' => ( $conf->config('money_char') || '$' ),
166 'countrydefault' => $countrydefault,
167 'statedefault' => ( scalar($conf->config('statedefault'))
168 || ($countrydefault eq 'US' ? 'CA' : '') ),
170 'svc_external-skip_manual' => $conf->exists('svc_external-skip_manual'),
171 'legacy_link' => $conf->exists('legacy_link'),
172 'svc_broadband-manage_link' => $conf->config('svc_broadband-manage_link'),
178 my $cust_main = shift or return undef;
182 if ( $cgi->param('showcancelledpackages') eq '0' #see if it was set by me
183 || ( $conf->exists('hidecancelledpackages')
184 && ! $cgi->param('showcancelledpackages') )
187 $method = 'ncancelled_pkgs';
189 $method = 'all_pkgs';
192 my $cust_pkg_fields =
193 join(', ', map { "cust_pkg.$_ AS $_" } fields('cust_pkg') );
195 my $part_pkg_fields =
196 join(', ', map { "part_pkg.$_ AS part_pkg_$_" } fields('part_pkg') );
199 join(', ', map "cust_pkg.$_", fields('cust_pkg') ). ', '.
200 join(', ', map "part_pkg.$_", fields('part_pkg') );
202 my $num_svcs = '( SELECT COUNT(*) FROM cust_svc '.
203 ' WHERE cust_svc.pkgnum = cust_pkg.pkgnum ) AS num_svcs';
205 my @packages = $cust_main->$method( {
206 'select' => "$cust_pkg_fields, $part_pkg_fields, $num_svcs",
207 'addl_from' => 'LEFT JOIN part_pkg USING ( pkgpart )',
209 my $num_old_packages = scalar(@packages);
211 foreach my $cust_pkg ( @packages ) {
212 my %hash = $cust_pkg->hash;
213 my %part_pkg = map { /^part_pkg_(.+)$/ or die; ( $1 => $hash{$_} ); }
214 grep { /^part_pkg_/ } keys %hash;
215 $cust_pkg->{'_pkgpart'} = new FS::part_pkg \%part_pkg;
218 unless ( $cgi->param('showoldpackages') ) {
219 my $years = $conf->config('cust_main-packages-years') || 2;
220 my $then = time - $years * 31556926; #60*60*24*365.2422 is close enough
222 my %hide = ( 'cancelled' => 'cancel',
223 'one-time charge' => 'setup',
227 grep { !exists($hide{$_->status}) or $_->get($hide{$_->status}) > $then
228 or $_->num_svcs #don't hide packages w/services
233 $num_old_packages -= scalar(@packages);
235 ( \@packages, $num_old_packages );