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 % && $conf->config('payby-default') ne 'HIDE'
98 <% $s++ ? ' | ' : '' %>
99 <& one_time_charge_link.html, $cust_main &>
102 % if ( $curuser->access_right('Bulk move customer services') ) {
103 <% $s++ ? ' | ' : '' %>
105 <& /elements/popup_link-cust_main.html,
106 'label' => emt('Move services between packages'),
107 'action' => "${p}edit/bulk-cust_svc-pkgnum.html",
108 'cust_main' => $cust_main,
109 'actionlabel' => emt('Move services'),
110 'width' => 968, #763,
116 % if ( $curuser->access_right('Bulk change customer packages') ) {
117 <% $s++ ? ' | ' : '' %>
118 <A HREF="<% $p %>edit/cust_pkg.cgi?<% $cust_main->custnum %>"><% mt('Bulk order and cancel packages') |h %></A>
123 % } # unless $opt{no_links}
127 <TD ALIGN="left" VALIGN="top">
129 % if ( $cust_main->num_cancelled_pkgs ) {
130 % if ( $cgi->param('showcancelledpackages') eq '0' #see if it was set by me
131 % || ( $conf->exists('hidecancelledpackages')
132 % && ! $cgi->param('showcancelledpackages')
136 % my $prev = $cgi->param('showcancelledpackages');
137 % $cgi->param('showcancelledpackages', 1);
138 ( <a href="<% $cgi->self_url %>"><% mt('show') |h %>
139 % $cgi->param('showcancelledpackages', $prev);
141 % $cgi->param('showcancelledpackages', 0);
142 ( <a href="<% $cgi->self_url %>"><% mt('hide') |h %>
143 % $cgi->param('showcancelledpackages', 1);
146 <% mt('cancelled packages') |h %></a> )
148 % if ( $num_old_packages ) {
149 % $cgi->param('showoldpackages', 1);
150 ( <a href="<% $cgi->self_url %>"><% mt('show old packages') |h %></a> )
151 % } elsif ( $cgi->param('showoldpackages') ) {
152 % $cgi->param('showoldpackages', 0);
153 ( <a href="<% $cgi->self_url %>"><% mt('hide old packages') |h %></a> )
158 % unless ( $opt{no_links} ) {
161 <A HREF="<%$p%>search/report_cust_pkg.html?custnum=<% $cust_main->custnum %>"><% mt('Package reports') |h %></A>
162 % if ( $curuser->access_right('Qualify service') ) {
163 | <A HREF="<%$p%>search/qual.cgi?custnum=<% $cust_main->custnum %>"><% mt('View Qualifications') |h %></A>
166 <% mt('Service reports:') |h %>
167 <A HREF="<%$p%>search/report_svc_acct.html?custnum=<% $cust_main->custnum %>"><% mt('accounts') |h %></A><BR>
168 <% mt('Usage reports:') |h %>
169 <A HREF="<%$p%>search/report_cdr.html?custnum=<% $cust_main->custnum %>"><% mt('CDRs') |h %></A>
172 % } # unless $opt{no_links}
178 % if ( $conf->exists('cust_pkg-group_by_location') ) {
180 'cust_main' => $cust_main,
181 'packages' => \@packages,
186 % # in this format, put all packages in one section
187 <& /elements/table-grid.html &>
188 <& packages/section.html,
189 'cust_main' => $cust_main,
190 'packages' => \@packages,
201 my $cust_main = shift;
203 my $conf = new FS::Conf;
205 my $curuser = $FS::CurrentUser::CurrentUser;
207 my $countrydefault = scalar($conf->config('countrydefault')) || 'US';
209 my $hide_changed = $curuser->option('hide_package_changes');
211 my $hide_cancelled = 0;
212 if ( $cgi->param('showcancelledpackages') eq '0' #see if it was set by me
213 || ( $conf->exists('hidecancelledpackages')
214 && ! $cgi->param('showcancelledpackages') )
220 my $cust_pkg_fields =
221 join(', ', map { "cust_pkg.$_ AS $_" } fields('cust_pkg') );
223 my $part_pkg_fields =
224 join(', ', map { "part_pkg.$_ AS part_pkg_$_" } fields('part_pkg') );
227 join(', ', map "cust_pkg.$_", fields('cust_pkg') ). ', '.
228 join(', ', map "part_pkg.$_", fields('part_pkg') );
230 my $num_svcs = '( SELECT COUNT(*) FROM cust_svc '.
231 ' WHERE cust_svc.pkgnum = cust_pkg.pkgnum ) AS num_svcs';
233 # don't exclude cancelled packages at this stage
234 my @packages = $cust_main->all_pkgs( {
235 'select' => "$cust_pkg_fields, $part_pkg_fields, $num_svcs",
236 'addl_from' => 'LEFT JOIN part_pkg USING ( pkgpart )',
239 my %change_to_from; # target pkgnum => current cust_pkg, for future changes
240 my %changed_from; # old pkgnum => new cust_pkg, for past changes
242 foreach my $cust_pkg ( @packages ) {
243 my %hash = $cust_pkg->hash;
244 my %part_pkg = map { /^part_pkg_(.+)$/ or die; ( $1 => $hash{$_} ); }
245 grep { /^part_pkg_/ } keys %hash;
246 $cust_pkg->{'_pkgpart'} = new FS::part_pkg \%part_pkg;
247 if ( $cust_pkg->change_to_pkgnum ) {
248 $change_to_from{$cust_pkg->change_to_pkgnum} = $cust_pkg;
250 if ( $cust_pkg->change_pkgnum ) {
251 $changed_from{$cust_pkg->change_pkgnum} = $cust_pkg;
255 # filter out hidden package changes
256 if ( keys %change_to_from or keys %changed_from ) {
257 my @displayable_packages;
258 foreach my $cust_pkg (@packages) {
259 if ( exists( $change_to_from{$cust_pkg->pkgnum} ) ) {
260 # $cust_pkg is an ordered, not-yet-active package change target
261 my $change_from = $change_to_from{ $cust_pkg->pkgnum };
262 $cust_pkg->set('change_from_pkg', $change_from);
263 $change_from->set('change_to_pkg', $cust_pkg);
264 } elsif ( exists( $changed_from{$cust_pkg->pkgnum} ) ) {
265 # $cust_pkg is a canceled package changed into another packge
266 my $changed_to = $changed_from{$cust_pkg->pkgnum};
267 if ( ( $hide_changed eq 'all' ) or
268 ( $hide_changed eq 'location'
269 and $changed_to->pkgpart == $cust_pkg->pkgpart
270 and $changed_to->refnum == $cust_pkg->refnum
271 and $changed_to->quantity == $cust_pkg->quantity )
273 # then we're hiding it
274 $cust_pkg->set('changed_to_pkg', $changed_to);
275 $changed_to->set('changed_from_pkg', $cust_pkg);
276 } else { # show it anyway
277 push @displayable_packages, $cust_pkg;
280 push @displayable_packages, $cust_pkg;
283 @packages = @displayable_packages;
286 # filter all cancelled packages if the user wants
287 if ( $hide_cancelled ) {
288 @packages = grep { !$_->get('cancel') } @packages;
291 # filter out 'old' packages
292 my $num_old_packages = scalar(@packages);
294 unless ( $cgi->param('showoldpackages') ) {
295 my $years = $conf->config('cust_main-packages-years') || 2;
296 my $then = time - $years * 31556926; #60*60*24*365.2422 is close enough
298 my %hide = ( 'cancelled' => 'cancel',
299 'one-time charge' => 'setup',
303 grep { !exists($hide{$_->status}) or $_->get($hide{$_->status}) > $then
304 or $_->num_svcs #don't hide packages w/services
309 $num_old_packages -= scalar(@packages);
311 # don't include supplemental packages in this list; they'll be found from
312 # their main packages
313 # (as will change-target packages)
314 @packages = grep !$_->main_pkgnum, @packages;
316 foreach my $cust_pkg ( @packages ) {
317 $cust_pkg->{'_cust_pkg_discount_active'} =
318 [ $cust_pkg->cust_pkg_discount_active ];