2 % my( $cust_main ) = @_;
3 % my $conf = new FS::Conf;
5 % my $curuser = $FS::CurrentUser::CurrentUser;
7 % my $packages = get_packages($cust_main, $conf);
11 <A NAME="cust_pkg"><FONT SIZE="+2">Packages</FONT></A>
12 % if ( $curuser->access_right('Order customer package') ) {
14 <% include('order_pkg.html', $cust_main ) %>
16 % if ( $curuser->access_right('One-time charge')
17 % && $conf->config('payby-default') ne 'HIDE'
21 <% include('quick-charge.html', $cust_main ) %>
23 % if ( $curuser->access_right('Bulk change customer packages') ) {
25 <A HREF="<% $p %>edit/cust_pkg.cgi?<% $cust_main->custnum %>">Bulk order and cancel packages</A> (preserves services)
34 % if ( $cust_main->num_cancelled_pkgs ) {
35 % if ( $cgi->param('showcancelledpackages') eq '0' #see if it was set by me
36 % || ( $conf->exists('hidecancelledpackages')
37 % && ! $cgi->param('showcancelledpackages')
41 % $cgi->param('showcancelledpackages', 1);
44 ( <a href="<% $cgi->self_url %>">show
46 % $cgi->param('showcancelledpackages', 0);
49 ( <a href="<% $cgi->self_url %>">hide
52 cancelled packages</a> )
57 <% include('/elements/table-grid.html') %>
58 % my $bgcolor1 = '#eeeeee';
59 % my $bgcolor2 = '#ffffff';
65 <TH CLASS="grid" BGCOLOR="#cccccc">Package</TH>
66 <TH CLASS="grid" BGCOLOR="#cccccc">Status</TH>
67 <TH CLASS="grid" BGCOLOR="#cccccc">Services</TH>
70 %foreach my $pkg (sort pkgsort_pkgnum_cancel @$packages) {
72 % if ( $bgcolor eq $bgcolor1 ) {
73 % $bgcolor = $bgcolor2;
75 % $bgcolor = $bgcolor1;
81 <!--pkgnum: <%$pkg->{pkgnum}%>-->
83 <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
84 <A NAME="cust_pkg<%$pkg->{pkgnum}%>"><%$pkg->{pkgnum}%></A>:
85 <%$pkg->{pkg}%> - <%$pkg->{comment}%><BR>
87 % unless ( $pkg->{cancel} ) {
88 % if ( $curuser->access_right('Change customer package') ) {
90 ( <%pkg_change_link($pkg)%> )
92 % if ( $curuser->access_right('Edit customer package dates') ) {
94 ( <%pkg_dates_link($pkg)%> )
96 % if ( $curuser->access_right('Customize customer package') ) {
98 ( <%pkg_customize_link($pkg,$cust_main->custnum)%> )
104 <TD CLASS="inv" BGCOLOR="<% $bgcolor %>">
105 <TABLE CLASS="inv" BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH="100%">
108 % my $part_pkg = shift;
109 % my $freq = $part_pkg->freq_pretty;
110 % $freq =~ s/ / /g;
114 % #this should use cust_pkg->status and cust_pkg->statuscolor eventually
116 % my $colspan = $conf->exists('cust_pkg-display_times') ? 8 : 4;
117 % my $width = $conf->exists('cust_pkg-display_times') ? '38%' : '56%';
119 % #false laziness w/edit/REAL_cust_pkg.cgi
120 % my( $billed_or_prepaid, $last_bill_or_renewed, $next_bill_or_prepaid_until );
121 % unless ( $pkg->{'part_pkg'}->is_prepaid ) {
122 % $billed_or_prepaid = 'billed';
123 % $last_bill_or_renewed = 'Last bill';
124 % $next_bill_or_prepaid_until = 'Next bill';
126 % $billed_or_prepaid = 'prepaid';
127 % $last_bill_or_renewed = 'Renewed';
128 % $next_bill_or_prepaid_until = 'Prepaid until';
132 % if ( $pkg->{cancel} ) {
133 <!-- #status: cancelled -->
136 <TD WIDTH="<%$width%>" ALIGN="right"><FONT COLOR="#ff0000"><B>Cancelled </B></FONT></TD>
137 <% pkg_datestr($pkg,'cancel',$conf) %>
140 <TD WIDTH="<%$width%>" ALIGN="right"><FONT COLOR="#ff0000" SIZE="-2">
144 % unless ( $pkg->{setup} ) {
148 <TD COLSPAN=<%$colspan%>>Never billed</TD>
154 <TD WIDTH="<%$width%>" ALIGN="right">Setup </TD>
155 <% pkg_datestr($pkg, 'setup',$conf) %>
157 % if ( $pkg->{'last_bill'} ) {
160 <TD WIDTH="<%$width%>" ALIGN="right"><% $last_bill_or_renewed %> </TD>
161 <% pkg_datestr($pkg, 'last_bill',$conf) %>
164 % if ( $pkg->{'susp'} ) {
167 <TD WIDTH="<%$width%>" ALIGN="right">Suspended </TD>
168 <% pkg_datestr($pkg, 'susp',$conf) %>
173 % if ( $pkg->{susp} ) {
174 <!-- #status: suspended -->
177 <TD WIDTH="<%$width%>" ALIGN="right"><FONT COLOR="#FF9900"><B>Suspended</B> </FONT></TD>
178 <% pkg_datestr($pkg,'susp',$conf) %>
181 <TD WIDTH="<%$width%>" ALIGN="right"><FONT COLOR="#FF9900" SIZE="-2">
185 % unless ( $pkg->{setup} ) {
189 <TD COLSPAN=<%$colspan%>>Never billed</TD>
195 <TD WIDTH="<%$width%>" ALIGN="right">Setup </TD>
196 <% pkg_datestr($pkg, 'setup',$conf) %>
199 % if ( $pkg->{'last_bill'} ) {
202 <TD WIDTH="<%$width%>" ALIGN="right"><% $last_bill_or_renewed %> </TD>
203 <% pkg_datestr($pkg, 'last_bill',$conf) %>
208 <!-- # next bill ?? -->
209 % if ( $pkg->{'expire'} ) {
212 <TD WIDTH="<%$width%>" ALIGN="right">Expires </TD>
213 <% pkg_datestr($pkg, 'expire',$conf) %>
219 <TD COLSPAN=<%$colspan%>>
221 % if ( $curuser->access_right('Unsuspend customer package') ) {
223 ( <% pkg_unsuspend_link($pkg) %> )
225 % if ( $curuser->access_right('Cancel customer package') ) {
227 ( <% pkg_cancel_link($pkg) %> )
234 <!-- #status: active -->
235 % unless ( $pkg->{setup} ) {
237 % unless ( $pkg->{'freq'} ) {
241 <TD COLSPAN=<%$colspan%>>Not yet billed (one-time charge)</TD>
245 <TD COLSPAN=<%$colspan%>>
247 % if ( $curuser->access_right('Cancel customer package immediately') ) {
249 ( <% pkg_cancel_link($pkg) %> )
259 <TD COLSPAN=<%$colspan%>>Not yet billed (<% $billed_or_prepaid %> <% myfreq($pkg->{part_pkg}) %>)</TD>
264 % unless ( $pkg->{freq} ) {
268 <TD COLSPAN=<%$colspan%>>One-time charge</TD>
272 <TD WIDTH="<%$width%>" ALIGN="right">Billed </TD>
273 <% pkg_datestr($pkg,'setup',$conf) %>
279 <TD COLSPAN=<%$colspan%>><FONT COLOR="#00CC00"><B>Active</B></FONT>, <% $billed_or_prepaid %> <% myfreq($pkg->{part_pkg}) %></TD>
283 <TD WIDTH="<%$width%>" ALIGN="right">Setup </TD>
284 <% pkg_datestr($pkg, 'setup',$conf) %>
288 % if ( $pkg->{'last_bill'} ) {
291 <TD WIDTH="<%$width%>" ALIGN="right"><% $last_bill_or_renewed %> </TD>
292 <% pkg_datestr($pkg, 'last_bill',$conf) %>
295 % if ( $pkg->{'next_bill'} ) {
298 <TD WIDTH="<%$width%>" ALIGN="right"><% $next_bill_or_prepaid_until %> </TD>
299 <% pkg_datestr($pkg, 'next_bill',$conf) %>
302 % if ( $pkg->{'expire'} ) {
305 <TD WIDTH="<%$width%>" ALIGN="right">Expires </TD>
306 <% pkg_datestr($pkg, 'expire',$conf) %>
309 % if ( $pkg->{freq} ) {
312 <TD COLSPAN=<%$colspan%>>
314 % if ( $curuser->access_right('Suspend customer package') ) {
316 ( <% pkg_suspend_link($pkg) %> )
318 % if ( $curuser->access_right('Cancel customer package immediately') ) {
320 ( <% pkg_cancel_link($pkg) %> )
322 % if ( $curuser->access_right('Cancel customer package later') ) {
324 ( <% pkg_expire_link($pkg) %> )
338 <TD CLASS="inv" BGCOLOR="<% $bgcolor %>">
339 <TABLE CLASS="inv" BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH="100%">
341 % foreach my $svcpart (sort {$a->{svcpart} <=> $b->{svcpart}} @{$pkg->{svcparts}}) {
343 % foreach my $service (@{$svcpart->{services}}) {
346 <TD ALIGN="right" VALIGN="top"><%svc_link($svcpart,$service)%></TD>
347 <TD STYLE="padding-bottom:0px"><B><%svc_label_link($svcpart,$service)%></B></TD>
351 <TD ALIGN="right" VALIGN="top" STYLE="padding-bottom:5px;padding-top:0px"><FONT SIZE="-2">
353 % if ( $curuser->access_right('Recharge customer service')
354 % && ($svcpart->{'svcdb'} eq 'svc_acct')
355 % && ($service->{seconds} ne ''
356 % || $service->{upbytes} ne ''
357 % || $service->{downbytes} ne ''
358 % || $service->{totalbytes} ne '' )
360 ( <%svc_recharge_link($service)%> )
364 <TD ALIGN="right" VALIGN="top" STYLE="padding-bottom:5px;padding-top:0px"><FONT SIZE="-2">
366 % if ( $curuser->access_right('Unprovision customer service') ) {
367 ( <%svc_unprovision_link($service)%> )
373 % if ( ! $pkg->{'cancel'}
374 % && $curuser->access_right('Provision customer service')
375 % && $svcpart->{count} < $svcpart->{quantity}
379 <TD COLSPAN=2 ALIGN="center" STYLE="padding-bottom:4px;padding-top:0px">
380 <B><% svc_provision_link($pkg, $svcpart, $conf, $curuser) %></B>
390 % } #end display packages
403 % my $cust_main = shift or return undef;
408 % if ( $cgi->param('showcancelledpackages') eq '0' #see if it was set by me
409 % || ( $conf->exists('hidecancelledpackages')
410 % && ! $cgi->param('showcancelledpackages') )
413 % $method = 'ncancelled_pkgs';
415 % $method = 'all_pkgs';
418 % foreach my $cust_pkg ( $cust_main->$method() ) {
420 % my $part_pkg = $cust_pkg->part_pkg;
424 % #to get back to the original object... should use it in the first place!!
425 % $pkg{cust_pkg} = $cust_pkg;
426 % $pkg{part_pkg} = $part_pkg;
428 % $pkg{pkgnum} = $cust_pkg->pkgnum;
429 % $pkg{pkg} = $part_pkg->pkg;
430 % $pkg{pkgpart} = $part_pkg->pkgpart;
431 % $pkg{comment} = $part_pkg->getfield('comment');
432 % $pkg{freq} = $part_pkg->freq;
433 % $pkg{setup} = $cust_pkg->getfield('setup');
434 % $pkg{last_bill} = $cust_pkg->getfield('last_bill');
435 % $pkg{next_bill} = $cust_pkg->getfield('bill');
436 % $pkg{susp} = $cust_pkg->getfield('susp');
437 % $pkg{expire} = $cust_pkg->getfield('expire');
438 % $pkg{cancel} = $cust_pkg->getfield('cancel');
439 % $pkg{reason} = $cust_pkg->last_reason->reason if $cust_pkg->last_reason;
442 % my %svcparts = map {
444 % $_->part_svc->hash,
445 % 'quantity' => $_->quantity,
446 % 'count' => $cust_pkg->num_cust_svc($_->svcpart),
449 % } $part_pkg->pkg_svc;
451 % foreach my $cust_svc ( $cust_pkg->cust_svc ) {
452 % #warn "svcnum ". $cust_svc->svcnum. " / svcpart ". $cust_svc->svcpart. "\n";
454 % 'svcnum' => $cust_svc->svcnum,
455 % 'label' => ($cust_svc->label)[1],
456 % $cust_svc->svc_x->hash,
459 % #false laziness with above, to catch extraneous services. whole
460 % #damn thing should be OO...
461 % my $svcpart = ( $svcparts{$cust_svc->svcpart} ||= {
462 % $cust_svc->part_svc->hash,
464 % 'count' => $cust_pkg->num_cust_svc($cust_svc->svcpart),
468 % push @{$svcpart->{services}}, $svc;
472 % $pkg{svcparts} = [ values %svcparts ];
474 % push @packages, \%pkg;
484 % my ($svcpart, $svc) = (shift,shift) or return '';
485 % return qq!<A HREF="${p}view/$svcpart->{svcdb}.cgi?$svc->{svcnum}">$svcpart->{svc}</A>!;
489 %sub svc_label_link {
491 % my ($svcpart, $svc) = (shift,shift) or return '';
492 % return qq!<A HREF="${p}view/$svcpart->{svcdb}.cgi?$svc->{svcnum}">$svc->{label}</A>!;
496 %sub svc_provision_link {
497 % my ($pkg, $svcpart, $conf, $curuser) = @_;
498 % ( my $svc_nbsp = $svcpart->{svc} ) =~ s/\s+/ /g;
499 % my $num_left = $svcpart->{quantity} - $svcpart->{count};
500 % my $pkgnum_svcpart = "pkgnum$pkg->{pkgnum}-svcpart$svcpart->{svcpart}";
503 % if ( $svcpart->{svcdb} eq 'svc_external'
504 % && $conf->exists('svc_external-skip_manual')
506 % $url = "${p}edit/process/$svcpart->{svcdb}.cgi?".
507 % "pkgnum=$pkg->{pkgnum}&".
508 % "svcpart=$svcpart->{svcpart}";
510 % $url = "${p}edit/$svcpart->{svcdb}.cgi?$pkgnum_svcpart";
513 % my $link = qq!<A CLASS="provision" HREF="$url">!.
514 % "Provision $svc_nbsp ($num_left)</A>";
515 % if ( $conf->exists('legacy_link')
516 % && $curuser->access_right('View/link unlinked services')
520 % qq!<A CLASS="provision" HREF="${p}misc/link.cgi?!.
521 % qq!$pkgnum_svcpart">!.
522 % "Link to legacy $svc_nbsp ($num_left)</A>";
527 %sub svc_unprovision_link {
528 % my $svc = shift or return '';
529 % qq!<A HREF="javascript:areyousure('${p}misc/unprovision.cgi?$svc->{svcnum}',!.
530 % qq!'Permanently unprovision and delete this service?')">Unprovision</A>!;
533 %sub svc_recharge_link {
534 % my $svc = shift or return '';
536 % qq!<A HREF="javascript:void(0);" onClick="overlib( OLiframeContent('${p}misc/recharge_svc.html?svcnum=$svc->{svcnum}', 392, 336, 'recharge_svc_popup' ), CAPTION, 'Recharge service $svc->{svcnum}', STICKY, AUTOSTATUSCAP, MIDX, 0, MIDY, 0, DRAGGABLE, CLOSECLICK ); return false;">Recharge</A>!;
539 %# This should be generalized to use config options to determine order.
540 %sub pkgsort_pkgnum_cancel {
541 % if ($a->{cancel} and $b->{cancel}) {
542 % return ($a->{pkgnum} <=> $b->{pkgnum});
543 % } elsif ($a->{cancel} or $b->{cancel}) {
544 % return (-1) if ($b->{cancel});
545 % return (1) if ($a->{cancel});
548 % return($a->{pkgnum} <=> $b->{pkgnum});
553 % my($pkg, $field, $conf) = @_ or return '';
554 % return ' ' unless $pkg->{$field};
555 % my $format = '<TD align="left"><B>%b</B></TD>'.
556 % '<TD align="right"><B> %o,</B></TD>'.
557 % '<TD align="right"><B> %Y</B></TD>';
558 % #$format .= ' <FONT SIZE=-3>%l:%M:%S%P %z</FONT>'
559 % $format .= '<TD ALIGN="right"><B> %l</TD>'.
560 % '<TD ALIGN="center"><B>:</B></TD>'.
561 % '<TD ALIGN="left"><B>%M</B></TD>'.
562 % '<TD ALIGN="left"><B> %P</B></TD>'
563 % if $conf->exists('cust_pkg-display_times');
564 % ( my $strip = time2str($format, $pkg->{$field}) ) =~ s/ (\d)/$1/g;
568 %sub pkg_change_link {
569 % my $pkg = shift or return '';
570 % return qq!<a href="${p}misc/change_pkg.cgi?$pkg->{pkgnum}">!.
571 % qq!Change package</a>!;
574 %sub pkg_suspend_link {
575 % my $pkg = shift or return '';
576 % qq!<A HREF="javascript:void(0);" onClick="overlib( OLiframeContent('${p}misc/cancel_pkg.html?method=suspend&pkgnum=$pkg->{pkgnum}', 392, 336, 'suspend_pkg_popup' ), CAPTION, 'Suspend package $pkg->{pkgnum}', STICKY, AUTOSTATUSCAP, MIDX, 0, MIDY, 0, DRAGGABLE, CLOSECLICK ); return false;">Suspend</A>!;
579 %sub pkg_unsuspend_link {
580 % my $pkg = shift or return '';
581 % return qq!<a href="${p}misc/unsusp_pkg.cgi?$pkg->{pkgnum}">Unsuspend</a>!;
584 %sub pkg_cancel_link {
585 % my $pkg = shift or return '';
587 % qq!<A HREF="javascript:void(0);" onClick="overlib( OLiframeContent('${p}misc/cancel_pkg.html?method=cancel&pkgnum=$pkg->{pkgnum}', 392, 336, 'cancel_pkg_popup' ), CAPTION, 'Cancel package $pkg->{pkgnum}', STICKY, AUTOSTATUSCAP, MIDX, 0, MIDY, 0, DRAGGABLE, CLOSECLICK ); return false;">Cancel now</A>!;
590 %sub pkg_expire_link {
591 % my $pkg = shift or return '';
592 % qq!<A HREF="javascript:void(0);" onClick="overlib( OLiframeContent('${p}misc/cancel_pkg.html?method=expire&pkgnum=$pkg->{pkgnum}', 392, 336, 'expire_pkg_popup' ), CAPTION, 'Expire package $pkg->{pkgnum}', STICKY, AUTOSTATUSCAP, MIDX, 0, MIDY, 0, DRAGGABLE, CLOSECLICK ); return false;">Cancel later</A>!;
595 %sub pkg_dates_link {
596 % my $pkg = shift or return '';
597 % qq!<A HREF="${p}edit/REAL_cust_pkg.cgi?$pkg->{pkgnum}">Edit dates</A>!;
600 %sub pkg_customize_link {
601 % my $pkg = shift or return '';
602 % my $custnum = shift;
603 % qq!<A HREF="${p}edit/part_pkg.cgi?keywords=$custnum;clone=$pkg->{pkgpart};!.
604 % qq!pkgnum=$pkg->{pkgnum}">Customize</A>!;