1 <STYLE TYPE="text/css">
14 border: 1px solid black;
20 background-color: #ffffaa;
22 .row0 { background-color: #eeeeee; }
23 .row1 { background-color: #ffffff; }
27 % unless ( $opt{no_links} ) {
31 % if ( $curuser->access_right('Qualify service') ) {
32 <% $s++ ? ' | ' : '' %>
33 <& qual_link.html, $cust_main &>
36 % if ( $curuser->access_right('Order customer package') ) {
37 <% $s++ ? ' | ' : '' %>
38 <& /elements/order_pkg_link.html, 'cust_main'=>$cust_main &>
41 % if ( $curuser->access_right('One-time charge')
42 % && $conf->config('payby-default') ne 'HIDE'
44 <% $s++ ? ' | ' : '' %>
45 <& one_time_charge_link.html, $cust_main &>
48 % if ( $curuser->access_right('Bulk move customer services') ) {
49 <% $s++ ? ' | ' : '' %>
51 <& /elements/popup_link-cust_main.html,
52 'label' => emt('Move services between packages'),
53 'action' => "${p}edit/bulk-cust_svc-pkgnum.html",
54 'cust_main' => $cust_main,
55 'actionlabel' => emt('Move services'),
62 % if ( $curuser->access_right('Bulk change customer packages') ) {
63 <% $s++ ? ' | ' : '' %>
64 <A HREF="<% $p %>edit/cust_pkg.cgi?<% $cust_main->custnum %>"><% mt('Bulk order and cancel packages') |h %></A>
69 % } # unless $opt{no_links}
73 <TD ALIGN="left" VALIGN="top">
75 % if ( $cust_main->num_cancelled_pkgs ) {
76 % if ( $cgi->param('showcancelledpackages') eq '0' #see if it was set by me
77 % || ( $conf->exists('hidecancelledpackages')
78 % && ! $cgi->param('showcancelledpackages')
82 % my $prev = $cgi->param('showcancelledpackages');
83 % $cgi->param('showcancelledpackages', 1);
84 ( <a href="<% $cgi->self_url %>"><% mt('show') |h %>
85 % $cgi->param('showcancelledpackages', $prev);
87 % $cgi->param('showcancelledpackages', 0);
88 ( <a href="<% $cgi->self_url %>"><% mt('hide') |h %>
89 % $cgi->param('showcancelledpackages', 1);
92 <% mt('cancelled packages') |h %></a> )
94 % if ( $num_old_packages ) {
95 % $cgi->param('showoldpackages', 1);
96 ( <a href="<% $cgi->self_url %>"><% mt('show old packages') |h %></a> )
97 % } elsif ( $cgi->param('showoldpackages') ) {
98 % $cgi->param('showoldpackages', 0);
99 ( <a href="<% $cgi->self_url %>"><% mt('hide old packages') |h %></a> )
104 % unless ( $opt{no_links} ) {
107 <A HREF="<%$p%>search/report_cust_pkg.html?custnum=<% $cust_main->custnum %>"><% mt('Package reports') |h %></A>
108 % if ( $curuser->access_right('Qualify service') ) {
109 | <A HREF="<%$p%>search/qual.cgi?custnum=<% $cust_main->custnum %>"><% mt('View Qualifications') |h %></A>
112 <% mt('Service reports:') |h %>
113 <A HREF="<%$p%>search/report_svc_acct.html?custnum=<% $cust_main->custnum %>"><% mt('accounts') |h %></A><BR>
114 <% mt('Usage reports:') |h %>
115 <A HREF="<%$p%>search/report_cdr.html?custnum=<% $cust_main->custnum %>"><% mt('CDRs') |h %></A>
118 % } # unless $opt{no_links}
125 % $opt{cust_main} = $cust_main;
126 % $opt{packages} = $packages;
127 % $opt{cust_location_cache} = {};
128 % if ( $conf->exists('cust_pkg-group_by_location') ) {
129 <& locations.html, %opt &>
130 % } else { # in this format, put all packages in one section
131 <& /elements/table-grid.html &>
132 <& packages/section.html, %opt &>
139 % if ( $cgi->param('fragment') =~ /^cust_pkg(\d+)$/ ) {
141 // IE-specific hack. other browsers listen to #fragments
142 // is this even working? or is the #target redirection just working cause
143 // we set the URL params differently?
144 var el = document.getElementById( 'cust_pkg<% $1 %>' );
145 if ( el ) el.scrollIntoView(true);
151 my $cust_main = shift;
153 my $conf = new FS::Conf;
155 my $curuser = $FS::CurrentUser::CurrentUser;
157 my( $packages, $num_old_packages ) = get_packages($cust_main, $conf);
159 my $countrydefault = scalar($conf->config('countrydefault')) || 'US';
163 my $cust_main = shift or return undef;
167 if ( $cgi->param('showcancelledpackages') eq '0' #see if it was set by me
168 || ( $conf->exists('hidecancelledpackages')
169 && ! $cgi->param('showcancelledpackages') )
172 $method = 'ncancelled_pkgs';
174 $method = 'all_pkgs';
177 my $cust_pkg_fields =
178 join(', ', map { "cust_pkg.$_ AS $_" } fields('cust_pkg') );
180 my $part_pkg_fields =
181 join(', ', ( map { "part_pkg.$_ AS part_pkg_$_" } fields('part_pkg') ),
182 'setup_option.optionvalue AS part_pkg__setup_fee',
183 'recur_option.optionvalue AS part_pkg__recur_fee',
187 join(', ', map "cust_pkg.$_", fields('cust_pkg') ). ', '.
188 join(', ', map "part_pkg.$_", fields('part_pkg') );
190 my $num_svcs = '( SELECT COUNT(*) FROM cust_svc '.
191 ' WHERE cust_svc.pkgnum = cust_pkg.pkgnum ) AS num_svcs';
193 my @packages = $cust_main->$method( {
194 'select' => "$cust_pkg_fields, $part_pkg_fields, $num_svcs",
196 LEFT JOIN part_pkg USING ( pkgpart )
197 LEFT JOIN part_pkg_option AS setup_option
198 ON ( cust_pkg.pkgpart = setup_option.pkgpart
199 AND setup_option.optionname = 'setup_fee' )
200 LEFT JOIN part_pkg_option AS recur_option
201 ON ( cust_pkg.pkgpart = recur_option.pkgpart
202 AND recur_option.optionname = 'recur_fee' )
205 my $num_old_packages = scalar(@packages);
207 my %change_to_from; # target pkgnum => current cust_pkg, for future changes
209 foreach my $cust_pkg ( @packages ) {
210 my %hash = $cust_pkg->hash;
211 my %part_pkg = map { /^part_pkg_(.+)$/ or die; ( $1 => $hash{$_} ); }
212 grep { /^part_pkg_/ } keys %hash;
213 $cust_pkg->{'_pkgpart'} = new FS::part_pkg \%part_pkg;
214 if ( $cust_pkg->change_to_pkgnum ) {
215 $change_to_from{$cust_pkg->change_to_pkgnum} = $cust_pkg;
219 if ( keys %change_to_from ) {
220 my @not_future_packages;
221 foreach my $cust_pkg (@packages) {
222 if ( exists( $change_to_from{$cust_pkg->pkgnum} ) ) {
223 my $change_from = $change_to_from{ $cust_pkg->pkgnum };
224 $cust_pkg->set('change_from_pkg', $change_from);
225 $change_from->set('change_to_pkg', $cust_pkg);
227 push @not_future_packages, $cust_pkg;
230 @packages = @not_future_packages;
233 unless ( $cgi->param('showoldpackages') ) {
234 my $years = $conf->config('cust_main-packages-years') || 2;
235 my $then = time - $years * 31556926; #60*60*24*365.2422 is close enough
237 my %hide = ( 'cancelled' => 'cancel',
238 'one-time charge' => 'setup',
242 grep { !exists($hide{$_->status}) or $_->get($hide{$_->status}) > $then
243 or $_->num_svcs #don't hide packages w/services
248 $num_old_packages -= scalar(@packages);
250 # don't include supplemental packages in this list; they'll be found from
251 # their main packages
252 # (as will change-target packages)
253 @packages = grep !$_->main_pkgnum, @packages;
255 foreach my $cust_pkg ( @packages ) {
256 $cust_pkg->{'_cust_pkg_discount_active'} =
257 [ $cust_pkg->cust_pkg_discount_active ];
260 ( \@packages, $num_old_packages );