3 my $conf = new FS::Conf;
5 my $curuser = $FS::CurrentUser::CurrentUser;
7 my $packages = get_packages($cust_main, $conf);
10 <A NAME="cust_pkg"><FONT SIZE="+2">Packages</FONT></A>
12 <% if ( $curuser->access_right('Order customer package') ) { %>
13 <%= include('order_pkg.html', $cust_main ) %>
16 <% if ( $curuser->access_right('One-time charge')
17 && $conf->config('payby-default') ne 'HIDE'
20 <%= include('quick-charge.html', $cust_main ) %>
23 <% if ( $curuser->access_right('Bulk change customer packages') ) { %>
24 <A HREF="<%= $p %>edit/cust_pkg.cgi?<%= $cust_main->custnum %>">Bulk order and cancel packages</A> (preserves services)
29 <% if ( @$packages ) { %>
33 <% if ( $cust_main->num_cancelled_pkgs ) {
34 if ( $cgi->param('showcancelledpackages') eq '0' #see if it was set by me
35 || ( $conf->exists('hidecancelledpackages')
36 && ! $cgi->param('showcancelledpackages')
40 $cgi->param('showcancelledpackages', 1);
42 ( <a href="<%= $cgi->self_url %>">show
44 $cgi->param('showcancelledpackages', 0);
46 ( <a href="<%= $cgi->self_url %>">hide
48 cancelled packages</a> )
51 <% if ( @$packages ) { %>
53 <%= include('/elements/table-grid.html') %>
55 <% my $bgcolor1 = '#eeeeee';
56 my $bgcolor2 = '#ffffff';
61 <TH CLASS="grid" BGCOLOR="#cccccc">Package</TH>
62 <TH CLASS="grid" BGCOLOR="#cccccc">Status</TH>
63 <TH CLASS="grid" BGCOLOR="#cccccc">Services</TH>
67 foreach my $pkg (sort pkgsort_pkgnum_cancel @$packages) {
69 if ( $bgcolor eq $bgcolor1 ) {
77 <!--pkgnum: <%=$pkg->{pkgnum}%>-->
79 <TD CLASS="grid" BGCOLOR="<%= $bgcolor %>">
80 <A NAME="cust_pkg<%=$pkg->{pkgnum}%>"><%=$pkg->{pkgnum}%></A>:
81 <%=$pkg->{pkg}%> - <%=$pkg->{comment}%><BR>
83 <% unless ( $pkg->{cancel} ) { %>
84 <% if ( $curuser->access_right('Change customer package') ) { %>
85 ( <%=pkg_change_link($pkg)%> )
87 <% if ( $curuser->access_right('Edit customer package dates') ) { %>
88 ( <%=pkg_dates_link($pkg)%> )
90 <% if ( $curuser->access_right('Customize customer package') ) { %>
91 ( <%=pkg_customize_link($pkg,$cust_main->custnum)%> )
96 <TD CLASS="inv" BGCOLOR="<%= $bgcolor %>">
97 <TABLE CLASS="inv" BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH="100%">
101 my $part_pkg = shift;
102 my $freq = $part_pkg->freq_pretty;
103 $freq =~ s/ / /g;
107 #this should use cust_pkg->status and cust_pkg->statuscolor eventually
109 my $colspan = $conf->exists('cust_pkg-display_times') ? 8 : 4;
110 my $width = $conf->exists('cust_pkg-display_times') ? '38%' : '56%';
112 #false laziness w/edit/REAL_cust_pkg.cgi
113 my( $billed_or_prepaid, $last_bill_or_renewed, $next_bill_or_prepaid_until );
114 unless ( $pkg->{'part_pkg'}->is_prepaid ) {
115 $billed_or_prepaid = 'billed';
116 $last_bill_or_renewed = 'Last bill';
117 $next_bill_or_prepaid_until = 'Next bill';
119 $billed_or_prepaid = 'prepaid';
120 $last_bill_or_renewed = 'Renewed';
121 $next_bill_or_prepaid_until = 'Prepaid until';
126 <% if ( $pkg->{cancel} ) { %> <!-- #status: cancelled -->
129 <TD WIDTH="<%=$width%>" ALIGN="right"><FONT COLOR="#ff0000"><B>Cancelled </B></FONT></TD>
130 <%= pkg_datestr($pkg,'cancel',$conf) %>
133 <% unless ( $pkg->{setup} ) { %>
136 <TD COLSPAN=<%=$colspan%>>Never billed</TD>
142 <TD WIDTH="<%=$width%>" ALIGN="right">Setup </TD>
143 <%= pkg_datestr($pkg, 'setup',$conf) %>
146 <% if ( $pkg->{'last_bill'} ) { %>
148 <TD WIDTH="<%=$width%>" ALIGN="right"><%= $last_bill_or_renewed %> </TD>
149 <%= pkg_datestr($pkg, 'last_bill',$conf) %>
153 <% if ( $pkg->{'susp'} ) { %>
155 <TD WIDTH="<%=$width%>" ALIGN="right">Suspended </TD>
156 <%= pkg_datestr($pkg, 'susp',$conf) %>
164 <% if ( $pkg->{susp} ) { %> <!-- #status: suspended -->
167 <TD WIDTH="<%=$width%>" ALIGN="right"><FONT COLOR="#FF9900"><B>Suspended</B> </FONT></TD>
168 <%= pkg_datestr($pkg,'susp',$conf) %>
171 <% unless ( $pkg->{setup} ) { %>
174 <TD COLSPAN=<%=$colspan%>>Never billed</TD>
180 <TD WIDTH="<%=$width%>" ALIGN="right">Setup </TD>
181 <%= pkg_datestr($pkg, 'setup',$conf) %>
186 <% if ( $pkg->{'last_bill'} ) { %>
188 <TD WIDTH="<%=$width%>" ALIGN="right"><%= $last_bill_or_renewed %> </TD>
189 <%= pkg_datestr($pkg, 'last_bill',$conf) %>
193 <!-- # next bill ?? -->
195 <% if ( $pkg->{'expire'} ) { %>
197 <TD WIDTH="<%=$width%>" ALIGN="right">Expires </TD>
198 <%= pkg_datestr($pkg, 'expire',$conf) %>
203 <TD COLSPAN=<%=$colspan%>>
205 <% if ( $curuser->access_right('Unsuspend customer package') ) { %>
206 ( <%= pkg_unsuspend_link($pkg) %> )
208 <% if ( $curuser->access_right('Cancel customer package') ) { %>
209 ( <%= pkg_cancel_link($pkg) %> )
215 <% } else { %> <!-- #status: active -->
217 <% unless ( $pkg->{setup} ) { %> <!-- #not setup -->
219 <% unless ( $pkg->{'freq'} ) { %>
222 <TD COLSPAN=<%=$colspan%>>Not yet billed (one-time charge)</TD>
226 <TD COLSPAN=<%=$colspan%>>
228 <% if ( $curuser->access_right('Cancel customer package immediately') ) { %>
229 ( <%= pkg_cancel_link($pkg) %> )
238 <TD COLSPAN=<%=$colspan%>>Not yet billed (<%= $billed_or_prepaid %> <%= myfreq($pkg->{part_pkg}) %>)</TD>
243 <% } else { %> <!-- #setup -->
245 <% unless ( $pkg->{freq} ) { %>
248 <TD COLSPAN=<%=$colspan%>>One-time charge</TD>
252 <TD WIDTH="<%=$width%>" ALIGN="right">Billed </TD>
253 <%= pkg_datestr($pkg,'setup',$conf) %>
259 <TD COLSPAN=<%=$colspan%>><FONT COLOR="#00CC00"><B>Active</B></FONT>, <%= $billed_or_prepaid %> <%= myfreq($pkg->{part_pkg}) %></TD>
263 <TD WIDTH="<%=$width%>" ALIGN="right">Setup </TD>
264 <%= pkg_datestr($pkg, 'setup',$conf) %>
271 <% if ( $pkg->{'last_bill'} ) { %>
273 <TD WIDTH="<%=$width%>" ALIGN="right"><%= $last_bill_or_renewed %> </TD>
274 <%= pkg_datestr($pkg, 'last_bill',$conf) %>
278 <% if ( $pkg->{'next_bill'} ) { %>
280 <TD WIDTH="<%=$width%>" ALIGN="right"><%= $next_bill_or_prepaid_until %> </TD>
281 <%= pkg_datestr($pkg, 'next_bill',$conf) %>
285 <% if ( $pkg->{'expire'} ) { %>
287 <TD WIDTH="<%=$width%>" ALIGN="right">Expires </TD>
288 <%= pkg_datestr($pkg, 'expire',$conf) %>
292 <% if ( $pkg->{freq} ) { %>
294 <TD COLSPAN=<%=$colspan%>>
296 <% if ( $curuser->access_right('Suspend customer package') ) { %>
297 ( <%= pkg_suspend_link($pkg) %> )
299 <% if ( $curuser->access_right('Cancel customer package immediately') ) { %>
300 ( <%= pkg_cancel_link($pkg) %> )
302 <% if ( $curuser->access_right('Cancel customer package later') ) { %>
303 ( <%= pkg_expire_link($pkg) %> )
317 <TD CLASS="inv" BGCOLOR="<%= $bgcolor %>">
318 <TABLE CLASS="inv" BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH="100%">
322 foreach my $svcpart (sort {$a->{svcpart} <=> $b->{svcpart}} @{$pkg->{svcparts}}) {
323 foreach my $service (@{$svcpart->{services}}) {
326 <TD ALIGN="right" VALIGN="top" ROWSPAN=2><%=svc_link($svcpart,$service)%></TD>
327 <TD STYLE="padding-bottom:0px"><B><%=svc_label_link($svcpart,$service)%></B></TD>
330 <% if ( $curuser->access_right('Unprovision customer service') ) { %>
332 <TD ALIGN="right" VALIGN="top" STYLE="padding-bottom:5px;padding-top:0px"><FONT SIZE="-2">( <%=svc_unprovision_link($service)%> )</FONT></TD>
338 <% if ( $curuser->access_right('Provision customer service')
339 && $svcpart->{count} < $svcpart->{quantity}
345 <TD COLSPAN=2 ALIGN="center" STYLE="padding-bottom:4px;padding-top:0px">
346 <B><%= svc_provision_link($pkg, $svcpart, $conf, $curuser) %></B>
357 <% } #end display packages
370 my $cust_main = shift or return undef;
375 if ( $cgi->param('showcancelledpackages') eq '0' #see if it was set by me
376 || ( $conf->exists('hidecancelledpackages')
377 && ! $cgi->param('showcancelledpackages') )
380 $method = 'ncancelled_pkgs';
382 $method = 'all_pkgs';
385 foreach my $cust_pkg ( $cust_main->$method() ) {
387 my $part_pkg = $cust_pkg->part_pkg;
391 #to get back to the original object... should use it in the first place!!
392 $pkg{cust_pkg} = $cust_pkg;
393 $pkg{part_pkg} = $part_pkg;
395 $pkg{pkgnum} = $cust_pkg->pkgnum;
396 $pkg{pkg} = $part_pkg->pkg;
397 $pkg{pkgpart} = $part_pkg->pkgpart;
398 $pkg{comment} = $part_pkg->getfield('comment');
399 $pkg{freq} = $part_pkg->freq;
400 $pkg{setup} = $cust_pkg->getfield('setup');
401 $pkg{last_bill} = $cust_pkg->getfield('last_bill');
402 $pkg{next_bill} = $cust_pkg->getfield('bill');
403 $pkg{susp} = $cust_pkg->getfield('susp');
404 $pkg{expire} = $cust_pkg->getfield('expire');
405 $pkg{cancel} = $cust_pkg->getfield('cancel');
411 'quantity' => $_->quantity,
412 'count' => $cust_pkg->num_cust_svc($_->svcpart),
415 } $part_pkg->pkg_svc;
417 foreach my $cust_svc ( $cust_pkg->cust_svc ) {
418 #warn "svcnum ". $cust_svc->svcnum. " / svcpart ". $cust_svc->svcpart. "\n";
420 'svcnum' => $cust_svc->svcnum,
421 'label' => ($cust_svc->label)[1],
424 #false laziness with above, to catch extraneous services. whole
425 #damn thing should be OO...
426 my $svcpart = ( $svcparts{$cust_svc->svcpart} ||= {
427 $cust_svc->part_svc->hash,
429 'count' => $cust_pkg->num_cust_svc($cust_svc->svcpart),
433 push @{$svcpart->{services}}, $svc;
437 $pkg{svcparts} = [ values %svcparts ];
439 push @packages, \%pkg;
449 my ($svcpart, $svc) = (shift,shift) or return '';
450 return qq!<A HREF="${p}view/$svcpart->{svcdb}.cgi?$svc->{svcnum}">$svcpart->{svc}</A>!;
456 my ($svcpart, $svc) = (shift,shift) or return '';
457 return qq!<A HREF="${p}view/$svcpart->{svcdb}.cgi?$svc->{svcnum}">$svc->{label}</A>!;
461 sub svc_provision_link {
462 my ($pkg, $svcpart, $conf, $curuser) = @_;
463 ( my $svc_nbsp = $svcpart->{svc} ) =~ s/\s+/ /g;
464 my $num_left = $svcpart->{quantity} - $svcpart->{count};
465 my $pkgnum_svcpart = "pkgnum$pkg->{pkgnum}-svcpart$svcpart->{svcpart}";
468 if ( $svcpart->{svcdb} eq 'svc_external'
469 && $conf->exists('svc_external-skip_manual')
471 $url = "${p}edit/process/$svcpart->{svcdb}.cgi?".
472 "pkgnum=$pkg->{pkgnum}&".
473 "svcpart=$svcpart->{svcpart}";
475 $url = "${p}edit/$svcpart->{svcdb}.cgi?$pkgnum_svcpart";
478 my $link = qq!<A CLASS="provision" HREF="$url">!.
479 "Provision $svc_nbsp ($num_left)</A>";
480 if ( $conf->exists('legacy_link')
481 && $curuser->access_right('View/link unlinked services')
485 qq!<A CLASS="provision" HREF="${p}misc/link.cgi?!.
486 qq!$pkgnum_svcpart">!.
487 "Link to legacy $svc_nbsp ($num_left)</A>";
492 sub svc_unprovision_link {
493 my $svc = shift or return '';
494 qq!<A HREF="javascript:areyousure('${p}misc/unprovision.cgi?$svc->{svcnum}',!.
495 qq!'Permanently unprovision and delete this service?')">Unprovision</A>!;
498 # This should be generalized to use config options to determine order.
499 sub pkgsort_pkgnum_cancel {
500 if ($a->{cancel} and $b->{cancel}) {
501 return ($a->{pkgnum} <=> $b->{pkgnum});
502 } elsif ($a->{cancel} or $b->{cancel}) {
503 return (-1) if ($b->{cancel});
504 return (1) if ($a->{cancel});
507 return($a->{pkgnum} <=> $b->{pkgnum});
512 my($pkg, $field, $conf) = @_ or return '';
513 return ' ' unless $pkg->{$field};
514 my $format = '<TD align="left"><B>%b</B></TD>'.
515 '<TD align="right"><B> %o,</B></TD>'.
516 '<TD align="right"><B> %Y</B></TD>';
517 #$format .= ' <FONT SIZE=-3>%l:%M:%S%P %z</FONT>'
518 $format .= '<TD ALIGN="right"><B> %l</TD>'.
519 '<TD ALIGN="center"><B>:</B></TD>'.
520 '<TD ALIGN="left"><B>%M</B></TD>'.
521 '<TD ALIGN="left"><B> %P</B></TD>'
522 if $conf->exists('cust_pkg-display_times');
523 ( my $strip = time2str($format, $pkg->{$field}) ) =~ s/ (\d)/$1/g;
527 sub pkg_change_link {
528 my $pkg = shift or return '';
529 return qq!<a href="${p}misc/change_pkg.cgi?$pkg->{pkgnum}">!.
530 qq!Change package</a>!;
533 sub pkg_suspend_link {
534 my $pkg = shift or return '';
535 return qq!<a href="${p}misc/susp_pkg.cgi?$pkg->{pkgnum}">Suspend</a>!;
538 sub pkg_unsuspend_link {
539 my $pkg = shift or return '';
540 return qq!<a href="${p}misc/unsusp_pkg.cgi?$pkg->{pkgnum}">Unsuspend</a>!;
543 sub pkg_cancel_link {
544 my $pkg = shift or return '';
545 qq!<A HREF="javascript:areyousure('${p}misc/cancel_pkg.cgi?$pkg->{pkgnum}', !.
546 qq!'Permanently delete included services and cancel this package?')">!.
550 sub pkg_expire_link {
551 my $pkg = shift or return '';
552 qq!<A HREF="${p}misc/expire_pkg.cgi?$pkg->{pkgnum}">Cancel later</A>!;
556 my $pkg = shift or return '';
557 qq!<A HREF="${p}edit/REAL_cust_pkg.cgi?$pkg->{pkgnum}">Edit dates</A>!;
560 sub pkg_customize_link {
561 my $pkg = shift or return '';
563 qq!<A HREF="${p}edit/part_pkg.cgi?keywords=$custnum;clone=$pkg->{pkgpart};!.
564 qq!pkgnum=$pkg->{pkgnum}">Customize</A>!;