1 <STYLE TYPE="text/css">
14 border: 1px solid black;
20 background-color: #ffffaa;
22 .row0 { background-color: #eeeeee; }
23 .row1 { background-color: #ffffff; }
28 border: 1px solid #7E0079;
29 background-color: #cccccc;
40 background-color: #efefef;
41 border: 1px solid #7e0079;
46 % # activate rolldown buttons for hidden package blocks
47 <SCRIPT TYPE="text/javascript">
48 function toggle_rolldown() {
49 var up_arrow = <% decode_entities('⬆') |js_string %>;
50 var dn_arrow = <% decode_entities('⬇') |js_string %>;
51 var pkgnum = this.id.replace('rolldown_', '');
52 var hidden = document.getElementById('cust_pkg'+pkgnum+'_block');
53 if (hidden.style.display == 'none') {
54 hidden.style.display = '';
55 this.textContent = this.textContent.replace(dn_arrow, up_arrow);
57 hidden.style.display = 'none';
58 this.textContent = this.textContent.replace(up_arrow, dn_arrow);
61 <&| /elements/onload.js &>
63 % if ( $cgi->param('fragment') =~ /^cust_pkg(\d+)$/ ) {
64 % # IE-specific hack, but also unhide the row if it's in a hidden block
65 el = document.getElementById('cust_pkg<% $1 %>');
67 var all_buttons = document.getElementsByClassName('rolldown_button');
68 for (var i = 0; i < all_buttons.length; i++) {
69 all_buttons[i].onclick = toggle_rolldown;
70 var block_id = all_buttons[i].id.replace('rolldown_', '');
71 if ( el && document.getElementById('cust_pkg'+block_id+'_block')
75 all_buttons[i].click();
78 if ( el ) el.scrollIntoView(true);
81 % unless ( $opt{no_links} ) {
85 % if ( $curuser->access_right('Qualify service') ) {
86 <% $s++ ? ' | ' : '' %>
87 <& qual_link.html, $cust_main &>
90 % if ( $curuser->access_right('Order customer package') ) {
91 <% $s++ ? ' | ' : '' %>
92 <& /elements/order_pkg_link.html, 'cust_main'=>$cust_main &>
95 % if ( $curuser->access_right('One-time charge') ) {
96 <% $s++ ? ' | ' : '' %>
97 <& /elements/one_time_charge_link.html, 'custnum'=>$cust_main->custnum &>
100 % if ( $curuser->access_right('Bulk move customer services') ) {
101 <% $s++ ? ' | ' : '' %>
103 <& /elements/popup_link-cust_main.html,
104 'label' => emt('Move services between packages'),
105 'action' => "${p}edit/bulk-cust_svc-pkgnum.html",
106 'cust_main' => $cust_main,
107 'actionlabel' => emt('Move services'),
108 'width' => 968, #763,
114 % if ( $curuser->access_right('Bulk change customer packages') ) {
115 <% $s++ ? ' | ' : '' %>
116 <A HREF="<% $p %>edit/cust_pkg.cgi?<% $cust_main->custnum %>"><% mt('Bulk order and cancel packages') |h %></A>
121 % } # unless $opt{no_links}
125 <TD ALIGN="left" VALIGN="top">
127 % if ( $cust_main->num_cancelled_pkgs ) {
128 % if ( $cgi->param('showcancelledpackages') eq '0' #see if it was set by me
129 % || ( $conf->exists('hidecancelledpackages')
130 % && ! $cgi->param('showcancelledpackages')
134 % my $prev = $cgi->param('showcancelledpackages');
135 % $cgi->param('showcancelledpackages', 1);
136 ( <a href="<% $cgi->self_url %>"><% mt('show') |h %>
137 % $cgi->param('showcancelledpackages', $prev);
139 % $cgi->param('showcancelledpackages', 0);
140 ( <a href="<% $cgi->self_url %>"><% mt('hide') |h %>
141 % $cgi->param('showcancelledpackages', 1);
144 <% mt('cancelled packages') |h %></a> )
146 % if ( $num_old_packages ) {
147 % $cgi->param('showoldpackages', 1);
148 ( <a href="<% $cgi->self_url %>"><% mt('show old packages') |h %></a> )
149 % } elsif ( $cgi->param('showoldpackages') ) {
150 % $cgi->param('showoldpackages', 0);
151 ( <a href="<% $cgi->self_url %>"><% mt('hide old packages') |h %></a> )
156 % unless ( $opt{no_links} ) {
159 <A HREF="<%$p%>search/report_cust_pkg.html?custnum=<% $cust_main->custnum %>"><% mt('Package reports') |h %></A>
160 % if ( $curuser->access_right('Qualify service') ) {
161 | <A HREF="<%$p%>search/qual.cgi?custnum=<% $cust_main->custnum %>"><% mt('View Qualifications') |h %></A>
164 <% mt('Service reports:') |h %>
165 <A HREF="<%$p%>search/report_svc_acct.html?custnum=<% $cust_main->custnum %>"><% mt('accounts') |h %></A><BR>
166 <% mt('Usage reports:') |h %>
167 <A HREF="<%$p%>search/report_cdr.html?custnum=<% $cust_main->custnum %>"><% mt('CDRs') |h %></A>
170 % } # unless $opt{no_links}
177 % $opt{cust_main} = $cust_main;
178 % $opt{packages} = \@packages;
179 % $opt{cust_location_cache} = {};
180 % if ( $conf->exists('cust_pkg-group_by_location') ) {
181 <& locations.html, %opt &>
182 % } else { # in this format, put all packages in one section
183 <& /elements/table-grid.html &>
184 <& packages/section.html, %opt &>
194 my $cust_main = shift;
196 my $conf = new FS::Conf;
198 my $curuser = $FS::CurrentUser::CurrentUser;
200 my $countrydefault = scalar($conf->config('countrydefault')) || 'US';
202 my $hide_cancelled = 0;
203 if ( $cgi->param('showcancelledpackages') eq '0' #see if it was set by me
204 || ( $conf->exists('hidecancelledpackages')
205 && ! $cgi->param('showcancelledpackages') )
211 my $cust_pkg_fields =
212 join(', ', map { "cust_pkg.$_ AS $_" } fields('cust_pkg') );
214 my $part_pkg_fields =
215 join(', ', ( map { "part_pkg.$_ AS part_pkg_$_" } fields('part_pkg') ),
216 'setup_option.optionvalue AS part_pkg__setup_fee',
217 'recur_option.optionvalue AS part_pkg__recur_fee',
221 join(', ', map "cust_pkg.$_", fields('cust_pkg') ). ', '.
222 join(', ', map "part_pkg.$_", fields('part_pkg') );
224 my $num_svcs = '( SELECT COUNT(*) FROM cust_svc '.
225 ' WHERE cust_svc.pkgnum = cust_pkg.pkgnum ) AS num_svcs';
227 # don't exclude cancelled packages at this stage
228 my @packages = $cust_main->all_pkgs( {
229 'select' => "$cust_pkg_fields, $part_pkg_fields, $num_svcs",
231 LEFT JOIN part_pkg USING ( pkgpart )
232 LEFT JOIN part_pkg_option AS setup_option
233 ON ( cust_pkg.pkgpart = setup_option.pkgpart
234 AND setup_option.optionname = 'setup_fee' )
235 LEFT JOIN part_pkg_option AS recur_option
236 ON ( cust_pkg.pkgpart = recur_option.pkgpart
237 AND recur_option.optionname = 'recur_fee' )
241 my %change_to_from; # target pkgnum => current cust_pkg, for future changes
242 my %changed_from; # old pkgnum => new cust_pkg, for past changes
244 foreach my $cust_pkg ( @packages ) {
245 my %hash = $cust_pkg->hash;
246 my %part_pkg = map { /^part_pkg_(.+)$/ or die; ( $1 => $hash{$_} ); }
247 grep { /^part_pkg_/ } keys %hash;
248 $cust_pkg->{'_pkgpart'} = new FS::part_pkg \%part_pkg;
249 if ( $cust_pkg->change_to_pkgnum ) {
250 $change_to_from{$cust_pkg->change_to_pkgnum} = $cust_pkg;
252 if ( $cust_pkg->change_pkgnum ) {
253 $changed_from{$cust_pkg->change_pkgnum} = $cust_pkg;
257 # filter out hidden package changes
258 if ( keys %change_to_from or keys %changed_from ) {
259 my @displayable_packages;
260 foreach my $cust_pkg (@packages) {
262 if ( exists( $change_to_from{$cust_pkg->pkgnum} ) ) {
264 # $cust_pkg is an ordered, not-yet-active package change target
265 my $change_from = $change_to_from{ $cust_pkg->pkgnum };
266 $cust_pkg->set('change_from_pkg', $change_from);
267 $change_from->set('change_to_pkg', $cust_pkg);
269 } elsif ( exists( $changed_from{$cust_pkg->pkgnum} ) ) {
271 # $cust_pkg is a canceled package changed into another packge
272 # hide it under the destination package's history
273 my $changed_to = $changed_from{$cust_pkg->pkgnum};
274 $cust_pkg->set('changed_to_pkg', $changed_to);
275 $changed_to->set('changed_from_pkg', $cust_pkg);
278 push @displayable_packages, $cust_pkg;
282 @packages = @displayable_packages;
285 # filter all cancelled packages if the user wants
286 if ( $hide_cancelled ) {
287 @packages = grep { !$_->get('cancel') } @packages;
290 # filter out 'old' packages
291 my $num_old_packages = scalar(@packages);
293 unless ( $cgi->param('showoldpackages') ) {
294 my $years = $conf->config('cust_main-packages-years') || 2;
295 my $then = time - $years * 31556926; #60*60*24*365.2422 is close enough
297 my %hide = ( 'cancelled' => 'cancel',
298 'one-time charge' => 'setup',
302 grep { !exists($hide{$_->status}) or $_->get($hide{$_->status}) > $then
303 or $_->num_svcs #don't hide packages w/services
308 $num_old_packages -= scalar(@packages);
310 # don't include supplemental packages in this list; they'll be found from
311 # their main packages
312 # (as will change-target packages)
313 @packages = grep !$_->main_pkgnum, @packages;
315 foreach my $cust_pkg ( @packages ) {
316 $cust_pkg->{'_cust_pkg_discount_active'} =
317 [ $cust_pkg->cust_pkg_discount_active ];