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;
47 % # activate rolldown buttons for hidden package blocks
48 <SCRIPT TYPE="text/javascript">
49 function toggle_rolldown() {
50 var up_arrow = <% decode_entities('⬆') |js_string %>;
51 var dn_arrow = <% decode_entities('⬇') |js_string %>;
52 var pkgnum = this.id.replace('rolldown_', '');
53 var hidden = document.getElementById('cust_pkg'+pkgnum+'_block');
54 if (hidden.style.display == 'none') {
55 hidden.style.display = '';
56 this.textContent = this.textContent.replace(dn_arrow, up_arrow);
58 hidden.style.display = 'none';
59 this.textContent = this.textContent.replace(up_arrow, dn_arrow);
62 <&| /elements/onload.js &>
64 % if ( $cgi->param('fragment') =~ /^cust_pkg(\d+)$/ ) {
65 % # IE-specific hack, but also unhide the row if it's in a hidden block
66 el = document.getElementById('cust_pkg<% $1 %>');
68 var all_buttons = document.getElementsByClassName('rolldown_button');
69 for (var i = 0; i < all_buttons.length; i++) {
70 all_buttons[i].onclick = toggle_rolldown;
71 var block_id = all_buttons[i].id.replace('rolldown_', '');
72 if ( el && document.getElementById('cust_pkg'+block_id+'_block')
76 all_buttons[i].click();
79 if ( el ) el.scrollIntoView(true);
84 <TD ALIGN="left" VALIGN="top">
86 % if ( $cust_main->num_cancelled_pkgs ) {
87 % if ( $cgi->param('showcancelledpackages') eq '0' #see if it was set by me
88 % || ( $conf->exists('hidecancelledpackages')
89 % && ! $cgi->param('showcancelledpackages')
93 % my $prev = $cgi->param('showcancelledpackages');
94 % $cgi->param('showcancelledpackages', 1);
95 ( <a href="<% $cgi->self_url %>"><% mt('show') |h %>
96 % $cgi->param('showcancelledpackages', $prev);
98 % $cgi->param('showcancelledpackages', 0);
99 ( <a href="<% $cgi->self_url %>"><% mt('hide') |h %>
100 % $cgi->param('showcancelledpackages', 1);
103 <% mt('cancelled packages') |h %></a> )
105 % if ( $num_old_packages ) {
106 % $cgi->param('showoldpackages', 1);
107 ( <a href="<% $cgi->self_url %>"><% mt('show old packages') |h %></a> )
108 % } elsif ( $cgi->param('showoldpackages') ) {
109 % $cgi->param('showoldpackages', 0);
110 ( <a href="<% $cgi->self_url %>"><% mt('hide old packages') |h %></a> )
120 % $opt{cust_main} = $cust_main;
121 % $opt{packages} = \@packages;
122 % $opt{cust_location_cache} = {};
123 % if ( $conf->exists('cust_pkg-group_by_location') ) {
124 <& locations.html, %opt &>
125 % } else { # in this format, put all packages in one section
126 <& /elements/table-grid.html &>
127 <& packages/section.html, %opt &>
137 my $cust_main = shift;
139 my $conf = new FS::Conf;
141 my $curuser = $FS::CurrentUser::CurrentUser;
143 my $countrydefault = scalar($conf->config('countrydefault')) || 'US';
145 my $hide_cancelled = 0;
146 if ( $cgi->param('showcancelledpackages') eq '0' #see if it was set by me
147 || ( $conf->exists('hidecancelledpackages')
148 && ! $cgi->param('showcancelledpackages') )
154 my $cust_pkg_fields =
155 join(', ', map { "cust_pkg.$_ AS $_" } fields('cust_pkg') );
157 my $part_pkg_fields =
158 join(', ', ( map { "part_pkg.$_ AS part_pkg_$_" } fields('part_pkg') ),
159 'setup_option.optionvalue AS part_pkg__setup_fee',
160 'recur_option.optionvalue AS part_pkg__recur_fee',
164 join(', ', map "cust_pkg.$_", fields('cust_pkg') ). ', '.
165 join(', ', map "part_pkg.$_", fields('part_pkg') );
167 my $num_svcs = '( SELECT COUNT(*) FROM cust_svc '.
168 ' WHERE cust_svc.pkgnum = cust_pkg.pkgnum ) AS num_svcs';
170 # don't exclude cancelled packages at this stage
171 my @packages = $cust_main->all_pkgs( {
172 'select' => "$cust_pkg_fields, $part_pkg_fields, $num_svcs",
174 LEFT JOIN part_pkg USING ( pkgpart )
175 LEFT JOIN part_pkg_option AS setup_option
176 ON ( cust_pkg.pkgpart = setup_option.pkgpart
177 AND setup_option.optionname = 'setup_fee' )
178 LEFT JOIN part_pkg_option AS recur_option
179 ON ( cust_pkg.pkgpart = recur_option.pkgpart
180 AND recur_option.optionname = 'recur_fee' )
184 my $is_anything_hidden = 0; # optimization
186 my %change_to_from; # target pkgnum => current cust_pkg, for future changes
187 my %changed_from; # old pkgnum => new cust_pkg, for past changes
188 my %supplementals_of; # main pkgnum => arrayref of supplementals
190 foreach my $cust_pkg ( @packages ) {
191 my %hash = $cust_pkg->hash;
192 my %part_pkg = map { /^part_pkg_(.+)$/ or die; ( $1 => $hash{$_} ); }
193 grep { /^part_pkg_/ } keys %hash;
194 $cust_pkg->{'_pkgpart'} = new FS::part_pkg \%part_pkg;
195 if ( $cust_pkg->change_to_pkgnum ) {
196 $change_to_from{$cust_pkg->change_to_pkgnum} = $cust_pkg;
197 $is_anything_hidden = 1;
199 if ( $cust_pkg->change_pkgnum ) {
200 $changed_from{$cust_pkg->change_pkgnum} = $cust_pkg;
201 $is_anything_hidden = 1;
203 if ( $cust_pkg->main_pkgnum ) {
204 $supplementals_of{$cust_pkg->main_pkgnum} ||= [];
205 push @{ $supplementals_of{$cust_pkg->main_pkgnum} }, $cust_pkg;
206 $is_anything_hidden = 1;
210 # filter out hidden package changes
211 if ( $is_anything_hidden ) {
212 my @displayable_packages;
213 foreach my $cust_pkg (@packages) {
215 # if this package has any supplemental packages, it should remember them
216 $cust_pkg->set('_supplemental', $supplementals_of{$cust_pkg->pkgnum});
218 if ( $cust_pkg->main_pkgnum ) {
220 # it's a supplemental package of something else, and shouldn't be on the
223 } elsif ( exists( $change_to_from{$cust_pkg->pkgnum} ) ) {
225 # $cust_pkg is an ordered, not-yet-active package change target
226 my $change_from = $change_to_from{ $cust_pkg->pkgnum };
227 $cust_pkg->set('change_from_pkg', $change_from);
228 $change_from->set('change_to_pkg', $cust_pkg);
230 } elsif ( exists( $changed_from{$cust_pkg->pkgnum} ) ) {
232 # $cust_pkg is a canceled package changed into another packge
233 # hide it under the destination package's history
234 my $changed_to = $changed_from{$cust_pkg->pkgnum};
235 $cust_pkg->set('changed_to_pkg', $changed_to);
236 $changed_to->set('changed_from_pkg', $cust_pkg);
240 push @displayable_packages, $cust_pkg;
245 @packages = @displayable_packages;
248 # filter all cancelled packages if the user wants
249 if ( $hide_cancelled ) {
250 @packages = grep { !$_->get('cancel') } @packages;
253 # filter out 'old' packages
254 my $num_old_packages = scalar(@packages);
256 unless ( $cgi->param('showoldpackages') ) {
257 my $years = $conf->config('cust_main-packages-years') || 2;
258 my $then = time - $years * 31556926; #60*60*24*365.2422 is close enough
260 my %hide = ( 'cancelled' => 'cancel',
261 'one-time charge' => 'setup',
265 grep { !exists($hide{$_->status}) or $_->get($hide{$_->status}) > $then
266 or $_->num_svcs #don't hide packages w/services
271 $num_old_packages -= scalar(@packages);
273 # don't include supplemental packages in this list; they'll be found from
274 # their main packages
275 # (as will change-target packages)
276 ####@packages = grep !$_->main_pkgnum, @packages;
278 foreach my $cust_pkg ( @packages ) {
279 $cust_pkg->{'_cust_pkg_discount_active'} =
280 [ $cust_pkg->cust_pkg_discount_active ];