1 <A NAME="cust_pkg"><FONT SIZE="+2">Packages</FONT></A><BR>
4 % if ( $curuser->access_right('Order customer package') ) {
5 <% $s++ ? ' | ' : '' %>
6 <% order_pkg_link($cust_main) %>
9 % if ( $curuser->access_right('One-time charge')
10 % && $conf->config('payby-default') ne 'HIDE'
13 <% $s++ ? ' | ' : '' %>
14 <% include('/elements/popup_link.html',
16 'action' => $p. 'edit/quick-charge.html?custnum='. $cust_main->custnum,
17 'label' => 'One-time charge',
18 'actionlabel' => 'One-time charge',
25 % if ( $curuser->access_right('Bulk change customer packages') ) {
26 <% $s++ ? ' | ' : '' %>
27 <A HREF="<% $p %>edit/cust_pkg.cgi?<% $cust_main->custnum %>">Bulk order and cancel packages</A> (preserves services)
36 % if ( $cust_main->num_cancelled_pkgs ) {
37 % if ( $cgi->param('showcancelledpackages') eq '0' #see if it was set by me
38 % || ( $conf->exists('hidecancelledpackages')
39 % && ! $cgi->param('showcancelledpackages')
43 % $cgi->param('showcancelledpackages', 1);
46 ( <a href="<% $cgi->self_url %>">show
48 % $cgi->param('showcancelledpackages', 0);
51 ( <a href="<% $cgi->self_url %>">hide
54 cancelled packages</a> )
59 <% include('/elements/table-grid.html') %>
60 % my $bgcolor1 = '#eeeeee';
61 % 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 $cust_pkg (@$packages) {
72 % my $part_pkg = $cust_pkg->part_pkg;
74 % if ( $bgcolor eq $bgcolor1 ) {
75 % $bgcolor = $bgcolor2;
77 % $bgcolor = $bgcolor1;
81 <!--pkgnum: <% $cust_pkg->pkgnum %>-->
84 <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
86 <A NAME="cust_pkg<% $cust_pkg->pkgnum %>" ID="cust_pkg<% $cust_pkg->pkgnum %>"><% $cust_pkg->pkgnum %></A>:
87 <% $part_pkg->pkg %> - <% $part_pkg->comment %>
90 % if ( $cust_pkg->quantity > 1 ) {
91 Quantity: <B><% $cust_pkg->quantity %></B><BR>
95 % unless ( $cust_pkg->get('cancel') ) {
97 % if ( $curuser->access_right('Change customer package') ) { $br=1;
99 ( <%pkg_change_link($cust_pkg)%> )
101 % if ( $curuser->access_right('Edit customer package dates') ) { $br=1;
103 ( <%pkg_dates_link($cust_pkg)%> )
105 % if ( $curuser->access_right('Customize customer package') ) { $br=1;
107 ( <%pkg_customize_link($cust_pkg,$cust_main->custnum)%> )
109 <% $br ? '<BR>' : '' %>
112 % if ( $cust_pkg->num_cust_event
113 % && ( $curuser->access_right('Billing event reports')
114 % || $curuser->access_right('View customer billing events')
117 ( <%pkg_event_link($cust_pkg)%> )
124 <TD CLASS="inv" BGCOLOR="<% $bgcolor %>">
125 <TABLE CLASS="inv" BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH="100%">
128 % my $part_pkg = shift;
129 % my $freq = $part_pkg->freq_pretty;
130 % $freq =~ s/ / /g;
134 % #this should use cust_pkg->status and cust_pkg->statuscolor eventually
135 % #my $colspan = $conf->exists('cust_pkg-display_times') ? 8 : 4;
136 % #my $width = $conf->exists('cust_pkg-display_times') ? '38%' : '56%';
138 % #false laziness w/edit/REAL_cust_pkg.cgi
139 % my( $billed_or_prepaid, $last_bill_or_renewed, $next_bill_or_prepaid_until );
140 % unless ( $part_pkg->is_prepaid ) {
141 % $billed_or_prepaid = 'billed';
142 % $last_bill_or_renewed = 'Last bill';
143 % $next_bill_or_prepaid_until = 'Next bill';
145 % $billed_or_prepaid = 'prepaid';
146 % $last_bill_or_renewed = 'Renewed';
147 % $next_bill_or_prepaid_until = 'Prepaid until';
151 % if ( $cust_pkg->get('cancel') ) { #status: cancelled
152 % my $cpr = $cust_pkg->last_cust_pkg_reason;
154 <% pkg_status_row($cust_pkg, 'Cancelled', 'cancel', 'color'=>'FF0000', conf=>$conf ) %>
156 <% pkg_status_row_colspan(
157 ( ( $cpr && ( $cpr->date == $cust_pkg->get('cancel') ||
158 $cpr->date == $cust_pkg->expire
160 ) ? $cpr->reasontext. ' by '. $cpr->otaker : '' ), '',
161 'align' => 'right', 'color' => 'ff0000', 'size' => '-2',
165 % unless ( $cust_pkg->get('setup') ) {
167 <% pkg_status_row_colspan('Never billed') %>
171 <% pkg_status_row( $cust_pkg, 'Setup', 'setup', conf=>$conf ) %>
172 <% pkg_status_row_changed( $cust_pkg, conf=>$conf ) %>
173 <% pkg_status_row_if( $cust_pkg, $last_bill_or_renewed, 'last_bill', conf=>$conf ) %>
174 <% pkg_status_row_if( $cust_pkg, 'Suspended', 'susp', conf=>$conf ) %>
180 % if ( $cust_pkg->get('susp') ) { #status: suspended
181 % my $cpr = $cust_pkg->last_cust_pkg_reason;
183 <% pkg_status_row( $cust_pkg, 'Suspended', 'susp', 'color'=>'FF9900', conf=>$conf ) %>
185 <% pkg_status_row_colspan(
186 ( ( $cpr && ( $cpr->date == $cust_pkg->susp ||
187 $cpr->date == $cust_pkg->adjourn
189 ) ? $cpr->reasontext. ' by '. $cpr->otaker : '' ), '',
190 'align' => 'right', 'color' => 'FF9900', 'size' => '-2',
194 % unless ( $cust_pkg->get('setup') ) {
195 <% pkg_status_row_colspan('Never billed') %>
197 <% pkg_status_row($cust_pkg, 'Setup', 'setup', conf=>$conf ) %>
200 <% pkg_status_row_changed( $cust_pkg, conf=>$conf ) %>
201 <% pkg_status_row_if( $cust_pkg, $last_bill_or_renewed, 'last_bill', conf=>$conf ) %>
202 % # pkg_status_row($cust_pkg, 'Next bill', 'bill', conf=>$conf)
203 <% pkg_status_row_if( $cust_pkg, 'Expires', 'expire', conf=>$conf ) %>
206 <TD COLSPAN=<%$colspan%>>
208 % if ( $curuser->access_right('Unsuspend customer package') ) {
209 ( <% pkg_unsuspend_link($cust_pkg) %> )
211 % if ( $curuser->access_right('Cancel customer package immediately') ) {
212 ( <% pkg_cancel_link($cust_pkg) %> )
218 % } else { #status: active
220 % unless ( $cust_pkg->get('setup') ) { #not setup
222 % unless ( $part_pkg->freq ) {
224 <% pkg_status_row_colspan('Not yet billed (one-time charge)') %>
227 <TD COLSPAN=<%$colspan%>>
229 % if ( $curuser->access_right('Cancel customer package immediately') ) {
230 ( <% pkg_cancel_link($cust_pkg) %> )
238 <% pkg_status_row_colspan("Not yet billed ($billed_or_prepaid ". myfreq($part_pkg). ')' ) %>
244 % unless ( $part_pkg->freq ) {
246 <% pkg_status_row_colspan('One-time charge') %>
248 <% pkg_status_row($cust_pkg, 'Billed', 'setup', conf=>$conf) %>
252 % if (scalar($cust_pkg->overlimit)) {
254 <% pkg_status_row_colspan(
256 $billed_or_prepaid. ' '. myfreq($part_pkg),
262 <% pkg_status_row_colspan(
264 $billed_or_prepaid. ' '. myfreq($part_pkg),
270 <% pkg_status_row($cust_pkg, 'Setup', 'setup', conf=>$conf) %>
276 <% pkg_status_row_changed( $cust_pkg, conf=>$conf ) %>
277 <% pkg_status_row_if( $cust_pkg, $last_bill_or_renewed, 'last_bill', conf=>$conf ) %>
278 <% pkg_status_row_if( $cust_pkg, $next_bill_or_prepaid_until, 'bill', conf=>$conf ) %>
279 <% pkg_status_row_if( $cust_pkg, 'Will suspend on', 'adjourn', conf=>$conf ) %>
280 <% pkg_status_row_if( $cust_pkg, 'Expires', 'expire', conf=>$conf ) %>
282 % if ( $part_pkg->freq ) {
285 <TD COLSPAN=<%$colspan%>>
287 % if ( $curuser->access_right('Suspend customer package') ) {
288 ( <% pkg_suspend_link($cust_pkg) %> )
290 % if ( $curuser->access_right('Suspend customer package later') ) {
291 ( <% pkg_adjourn_link($cust_pkg) %> )
293 % if ( $curuser->access_right('Cancel customer package immediately') ) {
294 ( <% pkg_cancel_link($cust_pkg) %> )
296 % if ( $curuser->access_right('Cancel customer package later') ) {
297 ( <% pkg_expire_link($cust_pkg) %> )
311 <TD CLASS="inv" BGCOLOR="<% $bgcolor %>">
312 <TABLE CLASS="inv" BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH="100%">
314 % #foreach my $svcpart (sort {$a->{svcpart} <=> $b->{svcpart}} @{$pkg->{svcparts}}) {
315 % foreach my $part_svc ( $cust_pkg->part_svc ) {
317 % #foreach my $service (@{$svcpart->{services}}) {
318 % foreach my $cust_svc ( @{ $part_svc->cust_pkg_svc } ) {
321 <TD ALIGN="right" VALIGN="top"><% FS::UI::Web::svc_link($m, $part_svc, $cust_svc) %></TD>
322 <TD STYLE="padding-bottom:0px"><B><% FS::UI::Web::svc_label_link($m, $part_svc, $cust_svc) %></B></TD>
323 <TD><% FS::UI::Web::svc_export_links($m, $part_svc, $cust_svc) %></TD>
327 <TD ALIGN="right" COLSPAN="3" VALIGN="top" STYLE="padding-bottom:1px;padding-top:0px"><FONT SIZE="-2" COLOR="#FFD000">
329 <% $cust_svc->overlimit ? "Overlimit: ". time2str('%b %o %Y' . ($conf->exists('cust_pkg-display_times') ? ' %l:%M %P' : ''), $cust_svc->overlimit) : '' %>
334 <TD ALIGN="right" VALIGN="top" STYLE="padding-bottom:5px;padding-top:0px"><FONT SIZE="-2">
336 % if ( $curuser->access_right('Recharge customer service')
337 % && $part_svc->svcdb eq 'svc_acct'
338 % && ( $cust_svc->svc_x->seconds ne ''
339 % || $cust_svc->svc_x->upbytes ne ''
340 % || $cust_svc->svc_x->downbytes ne ''
341 % || $cust_svc->svc_x->totalbytes ne ''
344 ( <%svc_recharge_link($cust_svc)%> )
348 <TD ALIGN="right" VALIGN="top" STYLE="padding-bottom:5px;padding-top:0px"><FONT SIZE="-2">
350 % if ( $curuser->access_right('Unprovision customer service') ) {
351 ( <%svc_unprovision_link($cust_svc)%> )
357 % if ( ! $cust_pkg->get('cancel')
358 % && $curuser->access_right('Provision customer service')
359 % && $part_svc->num_avail
363 <TD COLSPAN=3 ALIGN="center" STYLE="padding-bottom:4px;padding-top:0px">
364 <B><% svc_provision_link($cust_pkg, $part_svc, $conf, $curuser) %></B>
374 % } #end display packages
383 % if ( $cgi->param('fragment') =~ /^cust_pkg(\d+)$/ ) {
385 // IE-specific hack. other browsers listen to #fragments
386 // is this even working? or is the #target redirection just working cause
387 // we set the URL params differently?
388 var el = document.getElementById( 'cust_pkg<% $1 %>' );
389 if ( el ) el.scrollIntoView(true);
394 my( $cust_main ) = @_;
395 my $conf = new FS::Conf;
397 my $curuser = $FS::CurrentUser::CurrentUser;
399 my $packages = get_packages($cust_main, $conf);
401 my $colspan = $conf->exists('cust_pkg-display_times') ? 8 : 4;
402 my $width = $conf->exists('cust_pkg-display_times') ? '38%' : '56%';
405 my( $cust_pkg, $title, $field, %opt ) = @_;
407 my $color = $opt{'color'};
409 my $html = qq(<TR><TD WIDTH="<%$width%>" ALIGN="right">);
410 $html .= qq(<FONT COLOR="#$color"><B>) if length($color);
411 $html .= qq($title );
412 $html .= qq(</B></FONT>) if length($color);
414 $html .= pkg_datestr($cust_pkg, $field, $opt{conf}).'</TR>';
419 sub pkg_status_row_if {
420 my( $cust_pkg, $title, $field, %opt ) = @_;
421 $cust_pkg->get($field) ? pkg_status_row(@_) : '';
424 sub pkg_status_row_changed {
425 my( $cust_pkg, %opt ) = @_;
426 return '' unless $cust_pkg->change_date;
427 my $html = pkg_status_row( $cust_pkg, 'Package changed', 'change_date', conf=>$opt{'conf'} );
428 my $old = $cust_pkg->old_cust_pkg;
430 my $part_pkg = $old->part_pkg;
431 my $label = 'Changed from '. $cust_pkg->change_pkgnum. ': '.
432 $part_pkg->pkg. ' - '. $part_pkg->comment;
433 $html .= pkg_status_row_colspan( $label, '', size=>'-1', align=>'right' );
438 sub pkg_status_row_colspan {
439 my($title, $addl, %opt) = @_;
441 my $align = $opt{'align'} ? 'ALIGN="'. $opt{'align'}.'"' : '';
442 my $color = $opt{'color'} ? 'COLOR="#'.$opt{'color'}.'"' : '';
443 my $size = $opt{'size'} ? 'SIZE="'. $opt{'size'}. '"' : '';
445 my $html = qq(<TR><TD COLSPAN=$colspan $align>);
446 $html .= qq(<FONT $color $size>) if length($color) || $size;
447 $html .= qq(<B>) if $color && !$size;
449 $html .= qq(</B>) if $color && !$size;
450 $html .= qq(</FONT>) if length($color) || $size;
451 $html .= ", $addl" if length($addl);
452 $html .= qq(</TD></TR>);
461 my $cust_main = shift or return undef;
466 if ( $cgi->param('showcancelledpackages') eq '0' #see if it was set by me
467 || ( $conf->exists('hidecancelledpackages')
468 && ! $cgi->param('showcancelledpackages') )
471 $method = 'ncancelled_pkgs';
473 $method = 'all_pkgs';
476 [ $cust_main->$method() ];
479 sub svc_provision_link {
480 my ($cust_pkg, $part_svc, $conf, $curuser) = @_;
481 ( my $svc_nbsp = $part_svc->svc ) =~ s/\s+/ /g;
482 my $num_avail = $part_svc->num_avail;
483 my $pkgnum_svcpart = "pkgnum=". $cust_pkg->pkgnum. ';'.
484 "svcpart=". $part_svc->svcpart;
486 if ( $part_svc->svcdb eq 'svc_external' #could be generalized
487 && $conf->exists('svc_external-skip_manual')
489 $url = "${p}edit/process/". $part_svc->svcdb. ".cgi?$pkgnum_svcpart";
494 'part_svc' => $part_svc,
495 'query' => $pkgnum_svcpart,
497 #$url = "${p}edit/$svcpart->{svcdb}.cgi?$pkgnum_svcpart";
500 my $link = qq!<A CLASS="provision" HREF="$url">!.
501 "Provision $svc_nbsp ($num_avail)</A>";
502 if ( $conf->exists('legacy_link')
503 && $curuser->access_right('View/link unlinked services')
507 qq!<A CLASS="provision" HREF="${p}misc/link.cgi?!.
508 qq!$pkgnum_svcpart">!.
509 "Link to legacy $svc_nbsp ($num_avail)</A>";
514 sub svc_unprovision_link {
515 my $cust_svc = shift or return '';
516 qq!<A HREF="javascript:areyousure('${p}misc/unprovision.cgi?!. $cust_svc->svcnum.
517 qq!', 'Permanently unprovision and delete this service?')">Unprovision</A>!;
521 my($cust_pkg, $field, $conf) = @_ or return '';
522 return ' ' unless $cust_pkg->get($field);
523 my $format = '<TD align="left"><B>%b</B></TD>'.
524 '<TD align="right"><B> %o,</B></TD>'.
525 '<TD align="right"><B> %Y</B></TD>';
526 #$format .= ' <FONT SIZE=-3>%l:%M:%S%P %z</FONT>'
527 $format .= '<TD ALIGN="right"><B> %l</TD>'.
528 '<TD ALIGN="center"><B>:</B></TD>'.
529 '<TD ALIGN="left"><B>%M</B></TD>'.
530 '<TD ALIGN="left"><B> %P</B></TD>'
531 if $conf->exists('cust_pkg-display_times');
532 my $strip = time2str($format, $cust_pkg->get($field) );
533 $strip =~ s/ (\d)/$1/g;
537 sub pkg_change_link { include( '/elements/popup_link-cust_pkg.html',
538 { 'action' => $p. 'misc/change_pkg.cgi?dummy=value',
539 'label' => 'Change package',
540 'actionlabel' => 'Change',
546 sub pkg_suspend_link { include( '/elements/popup_link-cust_pkg.html',
547 { 'action' => $p. 'misc/cancel_pkg.html?method=suspend',
548 'label' => 'Suspend now',
549 'actionlabel' => 'Suspend',
550 'color' => '#FF9900',
557 sub pkg_adjourn_link { include( '/elements/popup_link-cust_pkg.html',
558 { 'action' => $p. 'misc/cancel_pkg.html?method=adjourn',
559 'label' => 'Suspend later',
560 'actionlabel' => 'Adjourn',
561 'color' => '#CC6600',
567 sub pkg_unsuspend_link { pkg_link('misc/unsusp_pkg', 'Unsuspend', @_ ); }
568 sub pkg_dates_link { pkg_link('edit/REAL_cust_pkg', 'Edit dates', @_ ); }
570 sub pkg_cancel_link { include( '/elements/popup_link-cust_pkg.html',
571 { 'action' => $p. 'misc/cancel_pkg.html?method=cancel',
572 'label' => 'Cancel now',
573 'actionlabel' => 'Cancel',
574 'color' => '#ff0000',
580 sub pkg_expire_link { include( '/elements/popup_link-cust_pkg.html',
581 { 'action' => $p. 'misc/cancel_pkg.html?method=expire',
582 'label' => 'Cancel later',
583 'actionlabel' => 'Expire', #"Cancel package $num later"
584 'color' => '#CC0000',
590 sub svc_recharge_link { include( '/elements/popup_link-cust_svc.html',
591 { 'action' => $p. 'misc/recharge_svc.html',
592 'label' => 'Recharge',
593 'actionlabel' => 'Recharge',
594 'color' => '#333399',
600 sub order_pkg_link { include( '/elements/popup_link-cust_main.html',
601 { 'action' => $p. 'misc/order_pkg.html',
602 'label' => 'Order new package',
603 'actionlabel' => 'Order new package',
604 'color' => '#333399',
605 'cust_main' => shift,
606 'closetext' => 'Close',
613 qq!<a href="${p}search/cust_event.html?pkgnum=!. $cust_pkg->pkgnum. qq!">!.
614 'View package events'.
619 my($action, $label, $cust_pkg) = @_;
620 return '' unless $cust_pkg;
621 qq!<a href="$p$action.cgi?!. $cust_pkg->pkgnum. qq!">$label</a>!;
624 sub pkg_customize_link {
625 my $cust_pkg = shift or return '';
626 my $custnum = $cust_pkg->custnum;
627 qq!<A HREF="${p}edit/part_pkg.cgi?!.
628 "clone=". $cust_pkg->part_pkg->pkgpart. ';'.
629 "pkgnum=". $cust_pkg->pkgnum.