1 <STYLE TYPE="text/css">
15 border: 1px solid black;
21 background-color: #ffffaa;
23 .row0 { background-color: #eeeeee; }
24 .row1 { background-color: #ffffff; }
28 % unless ( $opt{no_links} ) {
32 % if ( $curuser->access_right('Qualify service') ) {
33 <% $s++ ? ' | ' : '' %>
34 <& qual_link.html, $cust_main &>
37 % if ( $curuser->access_right('Order customer package') ) {
38 <% $s++ ? ' | ' : '' %>
39 <& /elements/order_pkg_link.html, 'cust_main'=>$cust_main &>
42 % if ( $curuser->access_right('One-time charge')
43 % && $conf->config('payby-default') ne 'HIDE'
45 <% $s++ ? ' | ' : '' %>
46 <& one_time_charge_link.html, $cust_main &>
49 % if ( $curuser->access_right('Bulk move customer services') ) {
50 <% $s++ ? ' | ' : '' %>
52 <& /elements/popup_link-cust_main.html,
53 'label' => emt('Move services between packages'),
54 'action' => "${p}edit/bulk-cust_svc-pkgnum.html",
55 'cust_main' => $cust_main,
56 'actionlabel' => emt('Move services'),
63 % if ( $curuser->access_right('Bulk change customer packages') ) {
64 <% $s++ ? ' | ' : '' %>
65 <A HREF="<% $p %>edit/cust_pkg.cgi?<% $cust_main->custnum %>"><% mt('Bulk order and cancel packages') |h %></A>
70 % } # unless $opt{no_links}
74 <TD ALIGN="left" VALIGN="top">
76 % if ( $cust_main->num_cancelled_pkgs ) {
77 % if ( $cgi->param('showcancelledpackages') eq '0' #see if it was set by me
78 % || ( $conf->exists('hidecancelledpackages')
79 % && ! $cgi->param('showcancelledpackages')
83 % my $prev = $cgi->param('showcancelledpackages');
84 % $cgi->param('showcancelledpackages', 1);
85 ( <a href="<% $cgi->self_url %>"><% mt('show') |h %>
86 % $cgi->param('showcancelledpackages', $prev);
88 % $cgi->param('showcancelledpackages', 0);
89 ( <a href="<% $cgi->self_url %>"><% mt('hide') |h %>
90 % $cgi->param('showcancelledpackages', 1);
93 <% mt('cancelled packages') |h %></a> )
95 % if ( $num_old_packages ) {
96 % $cgi->param('showoldpackages', 1);
97 ( <a href="<% $cgi->self_url %>"><% mt('show old packages') |h %></a> )
98 % } elsif ( $cgi->param('showoldpackages') ) {
99 % $cgi->param('showoldpackages', 0);
100 ( <a href="<% $cgi->self_url %>"><% mt('hide old packages') |h %></a> )
105 % unless ( $opt{no_links} ) {
108 <A HREF="<%$p%>search/report_cust_pkg.html?custnum=<% $cust_main->custnum %>"><% mt('Package reports') |h %></A>
109 % if ( $curuser->access_right('Qualify service') ) {
110 | <A HREF="<%$p%>search/qual.cgi?custnum=<% $cust_main->custnum %>"><% mt('View Qualifications') |h %></A>
113 <% mt('Service reports:') |h %>
114 <A HREF="<%$p%>search/report_svc_acct.html?custnum=<% $cust_main->custnum %>"><% mt('accounts') |h %></A><BR>
115 <% mt('Usage reports:') |h %>
116 <A HREF="<%$p%>search/report_cdr.html?custnum=<% $cust_main->custnum %>"><% mt('CDRs') |h %></A>
119 % } # unless $opt{no_links}
125 % if ( $conf->exists('cust_pkg-group_by_location') ) {
127 'cust_main' => $cust_main,
128 'packages' => $packages,
133 % # in this format, put all packages in one section
134 <& /elements/table-grid.html &>
135 <& packages/section.html,
136 'cust_main' => $cust_main,
137 'packages' => $packages,
145 % if ( $cgi->param('fragment') =~ /^cust_pkg(\d+)$/ ) {
147 // IE-specific hack. other browsers listen to #fragments
148 // is this even working? or is the #target redirection just working cause
149 // we set the URL params differently?
150 var el = document.getElementById( 'cust_pkg<% $1 %>' );
151 if ( el ) el.scrollIntoView(true);
157 my $cust_main = shift;
159 my $conf = new FS::Conf;
161 my $curuser = $FS::CurrentUser::CurrentUser;
163 my( $packages, $num_old_packages ) = get_packages($cust_main, $conf);
165 my $countrydefault = scalar($conf->config('countrydefault')) || 'US';
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 # don't include supplemental packages in this list; they'll be found from
227 # their main packages
228 @packages = grep !$_->main_pkgnum, @packages;
230 ( \@packages, $num_old_packages );