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}
124 % if ( $conf->exists('cust_pkg-group_by_location') ) {
126 'cust_main' => $cust_main,
127 'packages' => $packages,
132 % # in this format, put all packages in one section
133 <& /elements/table-grid.html &>
134 <& packages/section.html,
135 'cust_main' => $cust_main,
136 'packages' => $packages,
144 % if ( $cgi->param('fragment') =~ /^cust_pkg(\d+)$/ ) {
146 // IE-specific hack. other browsers listen to #fragments
147 // is this even working? or is the #target redirection just working cause
148 // we set the URL params differently?
149 var el = document.getElementById( 'cust_pkg<% $1 %>' );
150 if ( el ) el.scrollIntoView(true);
156 my $cust_main = shift;
158 my $conf = new FS::Conf;
160 my $curuser = $FS::CurrentUser::CurrentUser;
162 my( $packages, $num_old_packages ) = get_packages($cust_main, $conf);
164 my $countrydefault = scalar($conf->config('countrydefault')) || 'US';
168 my $cust_main = shift or return undef;
172 if ( $cgi->param('showcancelledpackages') eq '0' #see if it was set by me
173 || ( $conf->exists('hidecancelledpackages')
174 && ! $cgi->param('showcancelledpackages') )
177 $method = 'ncancelled_pkgs';
179 $method = 'all_pkgs';
182 my $cust_pkg_fields =
183 join(', ', map { "cust_pkg.$_ AS $_" } fields('cust_pkg') );
185 my $part_pkg_fields =
186 join(', ', map { "part_pkg.$_ AS part_pkg_$_" } fields('part_pkg') );
189 join(', ', map "cust_pkg.$_", fields('cust_pkg') ). ', '.
190 join(', ', map "part_pkg.$_", fields('part_pkg') );
192 my $num_svcs = '( SELECT COUNT(*) FROM cust_svc '.
193 ' WHERE cust_svc.pkgnum = cust_pkg.pkgnum ) AS num_svcs';
195 my @packages = $cust_main->$method( {
196 'select' => "$cust_pkg_fields, $part_pkg_fields, $num_svcs",
197 'addl_from' => 'LEFT JOIN part_pkg USING ( pkgpart )',
199 my $num_old_packages = scalar(@packages);
201 my %change_to_from; # target pkgnum => current cust_pkg, for future changes
203 foreach my $cust_pkg ( @packages ) {
204 my %hash = $cust_pkg->hash;
205 my %part_pkg = map { /^part_pkg_(.+)$/ or die; ( $1 => $hash{$_} ); }
206 grep { /^part_pkg_/ } keys %hash;
207 $cust_pkg->{'_pkgpart'} = new FS::part_pkg \%part_pkg;
208 if ( $cust_pkg->change_to_pkgnum ) {
209 $change_to_from{$cust_pkg->change_to_pkgnum} = $cust_pkg;
213 if ( keys %change_to_from ) {
214 my @not_future_packages;
215 foreach my $cust_pkg (@packages) {
216 if ( exists( $change_to_from{$cust_pkg->pkgnum} ) ) {
217 my $change_from = $change_to_from{ $cust_pkg->pkgnum };
218 $cust_pkg->set('change_from_pkg', $change_from);
219 $change_from->set('change_to_pkg', $cust_pkg);
221 push @not_future_packages, $cust_pkg;
224 @packages = @not_future_packages;
227 unless ( $cgi->param('showoldpackages') ) {
228 my $years = $conf->config('cust_main-packages-years') || 2;
229 my $then = time - $years * 31556926; #60*60*24*365.2422 is close enough
231 my %hide = ( 'cancelled' => 'cancel',
232 'one-time charge' => 'setup',
236 grep { !exists($hide{$_->status}) or $_->get($hide{$_->status}) > $then
237 or $_->num_svcs #don't hide packages w/services
242 $num_old_packages -= scalar(@packages);
244 # don't include supplemental packages in this list; they'll be found from
245 # their main packages
246 # (as will change-target packages)
247 @packages = grep !$_->main_pkgnum, @packages;
249 foreach my $cust_pkg ( @packages ) {
250 $cust_pkg->{'_cust_pkg_discount_active'} =
251 [ $cust_pkg->cust_pkg_discount_active ];
254 ( \@packages, $num_old_packages );