3 my $conf = new FS::Conf;
5 my $curuser = $FS::CurrentUser::CurrentUser;
7 my $packages = get_packages($cust_main, $conf);
10 <STYLE TYPE="text/css">
11 .package .provision { font-weight: bold }
14 <A NAME="cust_pkg"><FONT SIZE="+2">Packages</FONT></A>
16 <% if ( $curuser->access_right('Order customer package') ) { %>
17 <%= include('order_pkg.html', $cust_main ) %>
20 <% if ( $curuser->access_right('One-time charge')
21 && $conf->config('payby-default') ne 'HIDE'
24 <%= include('quick-charge.html', $cust_main ) %>
27 <% if ( $curuser->access_right('Bulk change customer packages') ) { %>
28 <A HREF="<%= $p %>edit/cust_pkg.cgi?<%= $cust_main->custnum %>">Bulk order and cancel packages</A> (preserves services)
33 <% if ( @$packages ) { %>
37 <% if ( $cust_main->num_cancelled_pkgs ) {
38 if ( $cgi->param('showcancelledpackages') eq '0' #see if it was set by me
39 || ( $conf->exists('hidecancelledpackages')
40 && ! $cgi->param('showcancelledpackages')
44 $cgi->param('showcancelledpackages', 1);
46 ( <a href="<%= $cgi->self_url %>">show
48 $cgi->param('showcancelledpackages', 0);
50 ( <a href="<%= $cgi->self_url %>">hide
52 cancelled packages</a> )
55 <% if ( @$packages ) { %>
57 <TABLE CLASS="package" BORDER=1 CELLSPACING=0 CELLPADDING=2 BORDERCOLOR="#999999">
61 <TH COLSPAN=2>Services</TH>
65 foreach my $pkg (sort pkgsort_pkgnum_cancel @$packages) {
71 foreach my $svcpart (@{$pkg->{svcparts}}) {
72 $rowspan += $svcpart->{count};
73 $rowspan++ if ($svcpart->{count} < $svcpart->{quantity});
78 <!--pkgnum: <%=$pkg->{pkgnum}%>-->
80 <TD ROWSPAN=<%= $rowspan || 1 %>>
81 <A NAME="cust_pkg<%=$pkg->{pkgnum}%>"><%=$pkg->{pkgnum}%></A>:
82 <%=$pkg->{pkg}%> - <%=$pkg->{comment}%><BR>
84 <% unless ( $pkg->{cancel} ) { %>
85 <% if ( $curuser->access_right('Change customer package') ) { %>
86 ( <%=pkg_change_link($pkg)%> )
88 <% if ( $curuser->access_right('Edit customer package dates') ) { %>
89 ( <%=pkg_dates_link($pkg)%> )
91 <% if ( $curuser->access_right('Customize customer package') ) { %>
92 ( <%=pkg_customize_link($pkg,$cust_main->custnum)%> )
97 <TD ROWSPAN=<%= $rowspan || 1 %>>
98 <TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH="100%">
102 my $part_pkg = shift;
103 my $freq = $part_pkg->freq_pretty;
104 $freq =~ s/ / /g;
108 #this should use cust_pkg->status and cust_pkg->statuscolor eventually
110 my $colspan = $conf->exists('cust_pkg-display_times') ? 8 : 4;
111 my $width = $conf->exists('cust_pkg-display_times') ? '38%' : '56%';
113 #false laziness w/edit/REAL_cust_pkg.cgi
114 my( $billed_or_prepaid, $last_bill_or_renewed, $next_bill_or_prepaid_until );
115 unless ( $pkg->{'part_pkg'}->is_prepaid ) {
116 $billed_or_prepaid = 'billed';
117 $last_bill_or_renewed = 'Last bill';
118 $next_bill_or_prepaid_until = 'Next bill';
120 $billed_or_prepaid = 'prepaid';
121 $last_bill_or_renewed = 'Renewed';
122 $next_bill_or_prepaid_until = 'Prepaid until';
127 <% if ( $pkg->{cancel} ) { %> <!-- #status: cancelled -->
130 <TD WIDTH="<%=$width%>" ALIGN="right"><FONT COLOR="#ff0000"><B>Cancelled </B></FONT></TD>
131 <%= pkg_datestr($pkg,'cancel',$conf) %>
134 <% unless ( $pkg->{setup} ) { %>
137 <TD COLSPAN=<%=$colspan%>>Never billed</TD>
143 <TD WIDTH="<%=$width%>" ALIGN="right">Setup </TD>
144 <%= pkg_datestr($pkg, 'setup',$conf) %>
147 <% if ( $pkg->{'last_bill'} ) { %>
149 <TD WIDTH="<%=$width%>" ALIGN="right"><%= $last_bill_or_renewed %> </TD>
150 <%= pkg_datestr($pkg, 'last_bill',$conf) %>
154 <% if ( $pkg->{'susp'} ) { %>
156 <TD WIDTH="<%=$width%>" ALIGN="right">Suspended </TD>
157 <%= pkg_datestr($pkg, 'susp',$conf) %>
165 <% if ( $pkg->{susp} ) { %> <!-- #status: suspended -->
168 <TD WIDTH="<%=$width%>" ALIGN="right"><FONT COLOR="#FF9900"><B>Suspended</B> </FONT></TD>
169 <%= pkg_datestr($pkg,'susp',$conf) %>
172 <% unless ( $pkg->{setup} ) { %>
175 <TD COLSPAN=<%=$colspan%>>Never billed</TD>
181 <TD WIDTH="<%=$width%>" ALIGN="right">Setup </TD>
182 <%= pkg_datestr($pkg, 'setup',$conf) %>
187 <% if ( $pkg->{'last_bill'} ) { %>
189 <TD WIDTH="<%=$width%>" ALIGN="right"><%= $last_bill_or_renewed %> </TD>
190 <%= pkg_datestr($pkg, 'last_bill',$conf) %>
194 <!-- # next bill ?? -->
196 <% if ( $pkg->{'expire'} ) { %>
198 <TD WIDTH="<%=$width%>" ALIGN="right">Expires </TD>
199 <%= pkg_datestr($pkg, 'expire',$conf) %>
204 <TD COLSPAN=<%=$colspan%>>
206 <% if ( $curuser->access_right('Unsuspend customer package') ) { %>
207 ( <%= pkg_unsuspend_link($pkg) %> )
209 <% if ( $curuser->access_right('Cancel customer package') ) { %>
210 ( <%= pkg_cancel_link($pkg) %> )
216 <% } else { %> <!-- #status: active -->
218 <% unless ( $pkg->{setup} ) { %> <!-- #not setup -->
220 <% unless ( $pkg->{'freq'} ) { %>
223 <TD COLSPAN=<%=$colspan%>>Not yet billed (one-time charge)</TD>
227 <TD COLSPAN=<%=$colspan%>>
229 <% if ( $curuser->access_right('Cancel customer package immediately') ) { %>
230 ( <%= pkg_cancel_link($pkg) %> )
239 <TD COLSPAN=<%=$colspan%>>Not yet billed (<%= $billed_or_prepaid %> <%= myfreq($pkg->{part_pkg}) %>)</TD>
244 <% } else { %> <!-- #setup -->
246 <% unless ( $pkg->{freq} ) { %>
249 <TD COLSPAN=<%=$colspan%>>One-time charge</TD>
253 <TD WIDTH="<%=$width%>" ALIGN="right">Billed </TD>
254 <%= pkg_datestr($pkg,'setup',$conf) %>
260 <TD COLSPAN=<%=$colspan%>><FONT COLOR="#00CC00"><B>Active</B></FONT>, <%= $billed_or_prepaid %> <%= myfreq($pkg->{part_pkg}) %></TD>
264 <TD WIDTH="<%=$width%>" ALIGN="right">Setup </TD>
265 <%= pkg_datestr($pkg, 'setup',$conf) %>
272 <% if ( $pkg->{'last_bill'} ) { %>
274 <TD WIDTH="<%=$width%>" ALIGN="right"><%= $last_bill_or_renewed %> </TD>
275 <%= pkg_datestr($pkg, 'last_bill',$conf) %>
279 <% if ( $pkg->{'next_bill'} ) { %>
281 <TD WIDTH="<%=$width%>" ALIGN="right"><%= $next_bill_or_prepaid_until %> </TD>
282 <%= pkg_datestr($pkg, 'next_bill',$conf) %>
286 <% if ( $pkg->{'expire'} ) { %>
288 <TD WIDTH="<%=$width%>" ALIGN="right">Expires </TD>
289 <%= pkg_datestr($pkg, 'expire',$conf) %>
293 <% if ( $pkg->{freq} ) { %>
295 <TD COLSPAN=<%=$colspan%>>
297 <% if ( $curuser->access_right('Suspend customer package') ) { %>
298 ( <%= pkg_suspend_link($pkg) %> )
300 <% if ( $curuser->access_right('Cancel customer package immediately') ) { %>
301 ( <%= pkg_cancel_link($pkg) %> )
303 <% if ( $curuser->access_right('Cancel customer package later') ) { %>
304 ( <%= pkg_expire_link($pkg) %> )
319 if ($rowspan == 0) { print qq!</TR>\n!; next; }
322 foreach my $svcpart (sort {$a->{svcpart} <=> $b->{svcpart}} @{$pkg->{svcparts}}) {
323 foreach my $service (@{$svcpart->{services}}) {
324 print '<TR>' if ($cnt > 0);
326 <TD><%=svc_link($svcpart,$service)%></TD>
327 <TD><%=svc_label_link($svcpart,$service)%>
328 <% if ( $curuser->access_right('Unprovision customer service') ) { %>
329 <BR>( <%=svc_unprovision_link($service)%> )
336 if ( $svcpart->{count} < $svcpart->{quantity} ) {
337 print '<TR>' if ($cnt > 0);
338 if ( $curuser->access_right('Provision customer service') ) {
339 print '<TD COLSPAN=2>'.
340 svc_provision_link($pkg, $svcpart, $conf, $curuser).
343 #print '<TD COLSPAN=2> </TD></TR>';
344 print '<TD COLSPAN=2></TD></TR>';
350 #end display packages
362 my $cust_main = shift or return undef;
367 if ( $cgi->param('showcancelledpackages') eq '0' #see if it was set by me
368 || ( $conf->exists('hidecancelledpackages')
369 && ! $cgi->param('showcancelledpackages') )
372 $method = 'ncancelled_pkgs';
374 $method = 'all_pkgs';
377 foreach my $cust_pkg ( $cust_main->$method() ) {
379 my $part_pkg = $cust_pkg->part_pkg;
383 #to get back to the original object... should use it in the first place!!
384 $pkg{cust_pkg} = $cust_pkg;
385 $pkg{part_pkg} = $part_pkg;
387 $pkg{pkgnum} = $cust_pkg->pkgnum;
388 $pkg{pkg} = $part_pkg->pkg;
389 $pkg{pkgpart} = $part_pkg->pkgpart;
390 $pkg{comment} = $part_pkg->getfield('comment');
391 $pkg{freq} = $part_pkg->freq;
392 $pkg{setup} = $cust_pkg->getfield('setup');
393 $pkg{last_bill} = $cust_pkg->getfield('last_bill');
394 $pkg{next_bill} = $cust_pkg->getfield('bill');
395 $pkg{susp} = $cust_pkg->getfield('susp');
396 $pkg{expire} = $cust_pkg->getfield('expire');
397 $pkg{cancel} = $cust_pkg->getfield('cancel');
403 'quantity' => $_->quantity,
404 'count' => $cust_pkg->num_cust_svc($_->svcpart),
407 } $part_pkg->pkg_svc;
409 foreach my $cust_svc ( $cust_pkg->cust_svc ) {
410 #warn "svcnum ". $cust_svc->svcnum. " / svcpart ". $cust_svc->svcpart. "\n";
412 'svcnum' => $cust_svc->svcnum,
413 'label' => ($cust_svc->label)[1],
416 #false laziness with above, to catch extraneous services. whole
417 #damn thing should be OO...
418 my $svcpart = ( $svcparts{$cust_svc->svcpart} ||= {
419 $cust_svc->part_svc->hash,
421 'count' => $cust_pkg->num_cust_svc($cust_svc->svcpart),
425 push @{$svcpart->{services}}, $svc;
429 $pkg{svcparts} = [ values %svcparts ];
431 push @packages, \%pkg;
441 my ($svcpart, $svc) = (shift,shift) or return '';
442 return qq!<A HREF="${p}view/$svcpart->{svcdb}.cgi?$svc->{svcnum}">$svcpart->{svc}</A>!;
448 my ($svcpart, $svc) = (shift,shift) or return '';
449 return qq!<A HREF="${p}view/$svcpart->{svcdb}.cgi?$svc->{svcnum}">$svc->{label}</A>!;
453 sub svc_provision_link {
454 my ($pkg, $svcpart, $conf, $curuser) = @_;
455 ( my $svc_nbsp = $svcpart->{svc} ) =~ s/\s+/ /g;
456 my $num_left = $svcpart->{quantity} - $svcpart->{count};
457 my $pkgnum_svcpart = "pkgnum$pkg->{pkgnum}-svcpart$svcpart->{svcpart}";
460 if ( $svcpart->{svcdb} eq 'svc_external'
461 && $conf->exists('svc_external-skip_manual')
463 $url = "${p}edit/process/$svcpart->{svcdb}.cgi?".
464 "pkgnum=$pkg->{pkgnum}&".
465 "svcpart=$svcpart->{svcpart}";
467 $url = "${p}edit/$svcpart->{svcdb}.cgi?$pkgnum_svcpart";
470 my $link = qq!<A CLASS="provision" HREF="$url">!.
471 "Provision $svc_nbsp ($num_left)</A>";
472 if ( $conf->exists('legacy_link')
473 && $curuser->access_right('View/link unlinked services')
477 qq!<A CLASS="provision" HREF="${p}misc/link.cgi?!.
478 qq!$pkgnum_svcpart">!.
479 "Link to legacy $svc_nbsp ($num_left)</A>";
484 sub svc_unprovision_link {
485 my $svc = shift or return '';
486 qq!<A HREF="javascript:areyousure('${p}misc/unprovision.cgi?$svc->{svcnum}',!.
487 qq!'Permanently unprovision and delete this service?')">Unprovision</A>!;
490 # This should be generalized to use config options to determine order.
491 sub pkgsort_pkgnum_cancel {
492 if ($a->{cancel} and $b->{cancel}) {
493 return ($a->{pkgnum} <=> $b->{pkgnum});
494 } elsif ($a->{cancel} or $b->{cancel}) {
495 return (-1) if ($b->{cancel});
496 return (1) if ($a->{cancel});
499 return($a->{pkgnum} <=> $b->{pkgnum});
504 my($pkg, $field, $conf) = @_ or return '';
505 return ' ' unless $pkg->{$field};
506 my $format = '<TD align="left"><B>%b</B></TD>'.
507 '<TD align="right"><B> %o,</B></TD>'.
508 '<TD align="right"><B> %Y</B></TD>';
509 #$format .= ' <FONT SIZE=-3>%l:%M:%S%P %z</FONT>'
510 $format .= '<TD ALIGN="right"><B> %l</TD>'.
511 '<TD ALIGN="center"><B>:</B></TD>'.
512 '<TD ALIGN="left"><B>%M</B></TD>'.
513 '<TD ALIGN="left"><B> %P</B></TD>'
514 if $conf->exists('cust_pkg-display_times');
515 ( my $strip = time2str($format, $pkg->{$field}) ) =~ s/ (\d)/$1/g;
519 sub pkg_change_link {
520 my $pkg = shift or return '';
521 return qq!<a href="${p}misc/change_pkg.cgi?$pkg->{pkgnum}">!.
522 qq!Change package</a>!;
525 sub pkg_suspend_link {
526 my $pkg = shift or return '';
527 return qq!<a href="${p}misc/susp_pkg.cgi?$pkg->{pkgnum}">Suspend</a>!;
530 sub pkg_unsuspend_link {
531 my $pkg = shift or return '';
532 return qq!<a href="${p}misc/unsusp_pkg.cgi?$pkg->{pkgnum}">Unsuspend</a>!;
535 sub pkg_cancel_link {
536 my $pkg = shift or return '';
537 qq!<A HREF="javascript:areyousure('${p}misc/cancel_pkg.cgi?$pkg->{pkgnum}', !.
538 qq!'Permanently delete included services and cancel this package?')">!.
542 sub pkg_expire_link {
543 my $pkg = shift or return '';
544 qq!<A HREF="${p}misc/expire_pkg.cgi?$pkg->{pkgnum}">Cancel later</A>!;
548 my $pkg = shift or return '';
549 qq!<A HREF="${p}edit/REAL_cust_pkg.cgi?$pkg->{pkgnum}">Edit dates</A>!;
552 sub pkg_customize_link {
553 my $pkg = shift or return '';
555 qq!<A HREF="${p}edit/part_pkg.cgi?keywords=$custnum;clone=$pkg->{pkgpart};!.
556 qq!pkgnum=$pkg->{pkgnum}">Customize</A>!;