-<%
- my( $cust_main ) = @_;
- my $conf = new FS::Conf;
-
- my $packages = get_packages($cust_main, $conf);
-%>
-
-<A NAME="cust_pkg">Packages</A>
-( <A HREF="<%= $p %>edit/cust_pkg.cgi?<%= $cust_main->custnum %>">Bulk order and cancel packages</A> (preserves services) )
-
-<% if ( @$packages ) { %>
-
-<TABLE CLASS="package" BORDER=1 CELLSPACING=0 CELLPADDING=2 BORDERCOLOR="#999999">
-<TR>
- <TH>Package</TH>
- <TH>Status</TH>
- <TH COLSPAN=2>Services</TH>
-</TR>
-
-<%
-foreach my $pkg (sort pkgsort_pkgnum_cancel @$packages) {
- my $rowspan = 0;
-
- if ($pkg->{cancel}) {
- $rowspan = 0;
- } else {
- foreach my $svcpart (@{$pkg->{svcparts}}) {
- $rowspan += $svcpart->{count};
- $rowspan++ if ($svcpart->{count} < $svcpart->{quantity});
- }
- }
-%>
-
-<!--pkgnum: <%=$pkg->{pkgnum}%>-->
-<TR>
- <TD ROWSPAN=<%=$rowspan%>>
- <A NAME="cust_pkg<%=$pkg->{pkgnum}%>"><%=$pkg->{pkgnum}%></A>:
- <%=$pkg->{pkg}%> - <%=$pkg->{comment}%><BR>
-<% unless ($pkg->{cancel}) { %>
- ( <%=pkg_change_link($pkg)%> )
- ( <%=pkg_dates_link($pkg)%> | <%=pkg_customize_link($pkg,$cust_main->custnum)%> )
-<% } %>
- </TD>
-<%
- #foreach (qw(setup last_bill next_bill susp expire cancel)) {
- # print qq! <TD ROWSPAN=$rowspan>! . pkg_datestr($pkg,$_,$conf) . qq!</TD>\n!;
- #}
- print "<TD ROWSPAN=$rowspan>". &itable('');
-
- sub myfreq {
- my $part_pkg = shift;
- my $freq = $part_pkg->freq_pretty;
- $freq =~ s/ / /g;
- $freq;
- }
-
- if ( $pkg->{cancel} ) { #status: cancelled
-
- print '<TR><TD><FONT COLOR="#ff0000"><B>Cancelled </B></FONT></TD>'.
- '<TD>'. pkg_datestr($pkg,'cancel',$conf). '</TD></TR>';
- unless ( $pkg->{setup} ) {
- print '<TR><TD COLSPAN=2>Never billed</TD></TR>';
- } else {
- print "<TR><TD>Setup </TD><TD>".
- pkg_datestr($pkg, 'setup',$conf). '</TD></TR>';
- print "<TR><TD>Last bill </TD><TD>".
- pkg_datestr($pkg, 'last_bill',$conf). '</TD></TR>'
- if $pkg->{'last_bill'};
- print "<TR><TD>Suspended </TD><TD>".
- pkg_datestr($pkg, 'susp',$conf). '</TD></TR>'
- if $pkg->{'susp'};
- }
-
- } else {
-
- if ( $pkg->{susp} ) { #status: suspended
- print '<TR><TD><FONT COLOR="#FF9900"><B>Suspended</B> </FONT></TD>'.
- '<TD>'. pkg_datestr($pkg,'susp',$conf). '</TD></TR>';
- unless ( $pkg->{setup} ) {
- print '<TR><TD COLSPAN=2>Never billed</TD></TR>';
- } else {
- print "<TR><TD>Setup </TD><TD>".
- pkg_datestr($pkg, 'setup',$conf). '</TD></TR>';
- }
- print "<TR><TD>Last bill </TD><TD>".
- pkg_datestr($pkg, 'last_bill',$conf). '</TD></TR>'
- if $pkg->{'last_bill'};
- # next bill ??
- print "<TR><TD>Expires </TD><TD>".
- pkg_datestr($pkg, 'expire',$conf). '</TD></TR>'
- if $pkg->{'expire'};
- print '<TR><TD COLSPAN=2>( '. pkg_unsuspend_link($pkg).
- ' | '. pkg_cancel_link($pkg). ' )</TD></TR>';
-
- } else { #status: active
-
- unless ( $pkg->{setup} ) { #not setup
-
- print '<TR><TD COLSPAN=2>Not yet billed (';
- unless ( $pkg->{freq} ) {
- print 'one-time charge)</TD></TR>';
- print '<TR><TD COLSPAN=2>( '. pkg_cancel_link($pkg).
- ' )</TD</TR>';
- } else {
- print 'billed '. myfreq($pkg->{part_pkg}). ')</TD></TR>';
- }
-
- } else { #setup
-
- unless ( $pkg->{freq} ) {
- print "<TR><TD COLSPAN=2>One-time charge</TD></TR>".
- '<TR><TD>Billed </TD><TD>'.
- pkg_datestr($pkg,'setup',$conf). '</TD></TR>';
- } else {
- print '<TR><TD COLSPAN=2><FONT COLOR="#00CC00"><B>Active</B></FONT>'.
- ', billed '. myfreq($pkg->{part_pkg}). '</TD></TR>'.
- '<TR><TD>Setup </TD><TD>'.
- pkg_datestr($pkg, 'setup',$conf). '</TD></TR>';
- }
-
- }
-
- print "<TR><TD>Last bill </TD><TD>".
- pkg_datestr($pkg, 'last_bill',$conf). '</TD></TR>'
- if $pkg->{'last_bill'};
- print "<TR><TD>Next bill </TD><TD>".
- pkg_datestr($pkg, 'next_bill',$conf). '</TD></TR>'
- if $pkg->{'next_bill'};
- print "<TR><TD>Expires </TD><TD>".
- pkg_datestr($pkg, 'expire',$conf). '</TD></TR>'
- if $pkg->{'expire'};
- if ( $pkg->{freq} ) {
- print '<TR><TD COLSPAN=2>( '. pkg_suspend_link($pkg).
- ' | '. pkg_cancel_link($pkg). ' )</TD></TR>';
- }
-
- }
-
- }
-
- print "</TABLE></TD>\n";
-
- if ($rowspan == 0) { print qq!</TR>\n!; next; }
-
- my $cnt = 0;
- foreach my $svcpart (sort {$a->{svcpart} <=> $b->{svcpart}} @{$pkg->{svcparts}}) {
- foreach my $service (@{$svcpart->{services}}) {
- print '<TR>' if ($cnt > 0);
-%>
- <TD><%=svc_link($svcpart,$service)%></TD>
- <TD><%=svc_label_link($svcpart,$service)%><BR>( <%=svc_unprovision_link($service)%> )</TD>
-</TR>
-<%
- $cnt++;
- }
- if ($svcpart->{count} < $svcpart->{quantity}) {
- print qq!<TR>\n! if ($cnt > 0);
- print qq! <TD COLSPAN=2>!.svc_provision_link($pkg, $svcpart, $conf).qq!</TD>\n</TR>\n!;
- }
- }
-}
-print '</TABLE>';
-}
-
-#end display packages
-%>
-
-<%
+% my $s = 0;
+
+% if ( $curuser->access_right('Qualify service') ) {
+ <% $s++ ? ' | ' : '' %>
+ <% include('qual_link.html', $cust_main) %>
+% }
+
+% if ( $curuser->access_right('Order customer package') ) {
+ <% $s++ ? ' | ' : '' %>
+ <% include('order_pkg_link.html', $cust_main) %>
+% }
+
+% if ( $curuser->access_right('One-time charge')
+% && $conf->config('payby-default') ne 'HIDE'
+% ) {
+ <% $s++ ? ' | ' : '' %>
+ <% include('one_time_charge_link.html', $cust_main) %>
+% }
+
+% if ( $curuser->access_right('Bulk change customer packages') ) {
+ <% $s++ ? ' | ' : '' %>
+ <A HREF="<% $p %>edit/cust_pkg.cgi?<% $cust_main->custnum %>">Bulk order and cancel packages</A> (preserves services)
+% }
+
+<BR><BR>
+
+<TABLE>
+ <TR>
+ <TD ALIGN="left">
+
+% if ( @$packages ) {
+
+Current packages
+% }
+% if ( $cust_main->num_cancelled_pkgs ) {
+% if ( $cgi->param('showcancelledpackages') eq '0' #see if it was set by me
+% || ( $conf->exists('hidecancelledpackages')
+% && ! $cgi->param('showcancelledpackages')
+% )
+% )
+% {
+% my $prev = $cgi->param('showcancelledpackages');
+% $cgi->param('showcancelledpackages', 1);
+ ( <a href="<% $cgi->self_url %>">show
+% $cgi->param('showcancelledpackages', $prev);
+% } else {
+% $cgi->param('showcancelledpackages', 0);
+ ( <a href="<% $cgi->self_url %>">hide
+% $cgi->param('showcancelledpackages', 1);
+% }
+
+ cancelled packages</a> )
+% }
+% if ( $num_old_packages ) {
+% $cgi->param('showoldpackages', 1);
+ ( <a href="<% $cgi->self_url %>">show old packages</a> )
+% } elsif ( $cgi->param('showoldpackages') ) {
+% $cgi->param('showoldpackages', 0);
+ ( <a href="<% $cgi->self_url %>">hide old packages</a> )
+% }
+
+ </TD>
+ <TD ALIGN="right">
+ <A HREF="<%$p%>search/report_cust_pkg.html?custnum=<% $cust_main->custnum %>">Package reports</A>
+% if ( $curuser->access_right('Qualify service') ) {
+ | <A HREF="<%$p%>search/qual.cgi?custnum=<% $cust_main->custnum %>">View Qualifications</A>
+% }
+ <BR>
+ Service reports:
+ <A HREF="<%$p%>search/report_svc_acct.html?custnum=<% $cust_main->custnum %>">accounts</A><BR>
+ Usage reports:
+ <A HREF="<%$p%>search/report_cdr.html?custnum=<% $cust_main->custnum %>">CDRs</A>
+ </TD>
+ </TR>
+
+ <TR>
+ <TD COLSPAN=2>
+% if ( $conf->exists('cust_pkg-group_by_location') and $show_location ) {
+<% include('locations.html',
+ 'cust_main' => $cust_main,
+ 'packages' => $packages,
+) %>
+% }
+% else {
+% # in this format, put all packages in one section
+<% include('/elements/table-grid.html') %>
+<% include('packages/section.html',
+ 'packages' => $packages,
+ 'show_location' => $show_location,
+) %>
+</TABLE>
+% }
+ </TD>
+ </TR>
+
+% if ( $cgi->param('fragment') =~ /^cust_pkg(\d+)$/ ) {
+ <SCRIPT>
+ // IE-specific hack. other browsers listen to #fragments
+ // is this even working? or is the #target redirection just working cause
+ // we set the URL params differently?
+ var el = document.getElementById( 'cust_pkg<% $1 %>' );
+ if ( el ) el.scrollIntoView(true);
+ </SCRIPT>
+% }
+</TABLE>
+<%init>
+
+my $cust_main = shift;
+my %opt = @_;
+my $conf = new FS::Conf;
+
+my $curuser = $FS::CurrentUser::CurrentUser;
+
+my( $packages, $num_old_packages ) = get_packages($cust_main, $conf);
+
+
+my $show_location = $conf->exists('cust_pkg-always_show_location')
+ || (grep $_->locationnum, @$packages); # ? '1' : '0';
+
+my $countrydefault = scalar($conf->config('countrydefault')) || 'US';