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 <% popup_link('edit/quick-charge.html?custnum='. $cust_main->custnum, 'One-time charge', 'One-time charge', '#333399', 545) %>
16 % if ( $curuser->access_right('Bulk change customer packages') ) {
17 <% $s++ ? ' | ' : '' %>
18 <A HREF="<% $p %>edit/cust_pkg.cgi?<% $cust_main->custnum %>">Bulk order and cancel packages</A> (preserves services)
27 % if ( $cust_main->num_cancelled_pkgs ) {
28 % if ( $cgi->param('showcancelledpackages') eq '0' #see if it was set by me
29 % || ( $conf->exists('hidecancelledpackages')
30 % && ! $cgi->param('showcancelledpackages')
34 % $cgi->param('showcancelledpackages', 1);
37 ( <a href="<% $cgi->self_url %>">show
39 % $cgi->param('showcancelledpackages', 0);
42 ( <a href="<% $cgi->self_url %>">hide
45 cancelled packages</a> )
50 <% include('/elements/table-grid.html') %>
51 % my $bgcolor1 = '#eeeeee';
52 % my $bgcolor2 = '#ffffff';
56 <TH CLASS="grid" BGCOLOR="#cccccc">Package</TH>
57 <TH CLASS="grid" BGCOLOR="#cccccc">Status</TH>
58 <TH CLASS="grid" BGCOLOR="#cccccc">Services</TH>
61 %foreach my $cust_pkg (@$packages) {
63 % my $part_pkg = $cust_pkg->part_pkg;
65 % if ( $bgcolor eq $bgcolor1 ) {
66 % $bgcolor = $bgcolor2;
68 % $bgcolor = $bgcolor1;
72 <!--pkgnum: <% $cust_pkg->pkgnum %>-->
75 <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
77 <A NAME="cust_pkg<% $cust_pkg->pkgnum %>" ID="cust_pkg<% $cust_pkg->pkgnum %>"><% $cust_pkg->pkgnum %></A>:
78 <% $part_pkg->pkg %> - <% $part_pkg->comment %>
82 % unless ( $cust_pkg->get('cancel') ) {
84 % if ( $curuser->access_right('Change customer package') ) { $br=1;
86 ( <%pkg_change_link($cust_pkg)%> )
88 % if ( $curuser->access_right('Edit customer package dates') ) { $br=1;
90 ( <%pkg_dates_link($cust_pkg)%> )
92 % if ( $curuser->access_right('Customize customer package') ) { $br=1;
94 ( <%pkg_customize_link($cust_pkg,$cust_main->custnum)%> )
96 <% $br ? '<BR>' : '' %>
99 % if ( $cust_pkg->num_cust_event
100 % && ( $curuser->access_right('Billing event reports')
101 % || $curuser->access_right('View customer billing events')
104 ( <%pkg_event_link($cust_pkg)%> )
111 <TD CLASS="inv" BGCOLOR="<% $bgcolor %>">
112 <TABLE CLASS="inv" BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH="100%">
115 % my $part_pkg = shift;
116 % my $freq = $part_pkg->freq_pretty;
117 % $freq =~ s/ / /g;
121 % #this should use cust_pkg->status and cust_pkg->statuscolor eventually
122 % #my $colspan = $conf->exists('cust_pkg-display_times') ? 8 : 4;
123 % #my $width = $conf->exists('cust_pkg-display_times') ? '38%' : '56%';
125 % #false laziness w/edit/REAL_cust_pkg.cgi
126 % my( $billed_or_prepaid, $last_bill_or_renewed, $next_bill_or_prepaid_until );
127 % unless ( $part_pkg->is_prepaid ) {
128 % $billed_or_prepaid = 'billed';
129 % $last_bill_or_renewed = 'Last bill';
130 % $next_bill_or_prepaid_until = 'Next bill';
132 % $billed_or_prepaid = 'prepaid';
133 % $last_bill_or_renewed = 'Renewed';
134 % $next_bill_or_prepaid_until = 'Prepaid until';
138 % if ( $cust_pkg->get('cancel') ) { #status: cancelled
140 <% pkg_status_row($cust_pkg, 'Cancelled', 'cancel', 'color'=>'FF0000' ) %>
142 <% pkg_status_row_colspan(
143 ( $cust_pkg->last_reason ? $cust_pkg->last_reason->reason : '' ), '',
144 'align' => 'right', 'color' => 'ff0000', 'size' => '-2',
148 % unless ( $cust_pkg->get('setup') ) {
150 <% pkg_status_row_colspan('Never billed') %>
154 <% pkg_status_row( $cust_pkg, 'Setup', 'setup' ) %>
155 <% pkg_status_row_changed( $cust_pkg ) %>
156 <% pkg_status_row_if( $cust_pkg, $last_bill_or_renewed, 'last_bill' ) %>
157 <% pkg_status_row_if( $cust_pkg, 'Suspended', 'susp' ) %>
163 % if ( $cust_pkg->get('susp') ) { #status: suspended
165 <% pkg_status_row( $cust_pkg, 'Suspended', 'susp', 'color'=>'FF9900' ) %>
167 <% pkg_status_row_colspan(
168 ( $cust_pkg->last_reason ? $cust_pkg->last_reason->reason : '' ), '',
169 'align' => 'right', 'color' => 'FF9900', 'size' => '-2',
173 % unless ( $cust_pkg->get('setup') ) {
174 <% pkg_status_row_colspan('Never billed') %>
176 <% pkg_status_row($cust_pkg, 'Setup', 'setup' ) %>
179 <% pkg_status_row_changed( $cust_pkg ) %>
180 <% pkg_status_row_if( $cust_pkg, $last_bill_or_renewed, 'last_bill' ) %>
181 % # pkg_status_row($cust_pkg, 'Next bill', 'bill')
182 <% pkg_status_row_if( $cust_pkg, 'Expires', 'expire' ) %>
185 <TD COLSPAN=<%$colspan%>>
187 % if ( $curuser->access_right('Unsuspend customer package') ) {
188 ( <% pkg_unsuspend_link($cust_pkg) %> )
190 % if ( $curuser->access_right('Cancel customer package immediately') ) {
191 ( <% pkg_cancel_link($cust_pkg) %> )
197 % } else { #status: active
199 % unless ( $cust_pkg->get('setup') ) { #not setup
201 % unless ( $part_pkg->freq ) {
203 <% pkg_status_row_colspan('Not yet billed (one-time charge)') %>
206 <TD COLSPAN=<%$colspan%>>
208 % if ( $curuser->access_right('Cancel customer package immediately') ) {
209 ( <% pkg_cancel_link($cust_pkg) %> )
217 <% pkg_status_row_colspan("Not yet billed ($billed_or_prepaid ". myfreq($part_pkg). ')' ) %>
223 % unless ( $part_pkg->freq ) {
225 <% pkg_status_row_colspan('One-time charge') %>
227 <% pkg_status_row($cust_pkg, 'Billed', 'setup') %>
231 % if (scalar($cust_pkg->overlimit)) {
233 <% pkg_status_row_colspan(
235 $billed_or_prepaid. ' '. myfreq($part_pkg),
241 <% pkg_status_row_colspan(
243 $billed_or_prepaid. ' '. myfreq($part_pkg),
249 <% pkg_status_row($cust_pkg, 'Setup', 'setup') %>
255 <% pkg_status_row_changed( $cust_pkg ) %>
256 <% pkg_status_row_if( $cust_pkg, $last_bill_or_renewed, 'last_bill' ) %>
257 <% pkg_status_row_if( $cust_pkg, $next_bill_or_prepaid_until, 'bill' ) %>
258 <% pkg_status_row_if( $cust_pkg, 'Will suspend on', 'adjourn' ) %>
259 <% pkg_status_row_if( $cust_pkg, 'Expires', 'expire' ) %>
261 % if ( $part_pkg->freq ) {
264 <TD COLSPAN=<%$colspan%>>
266 % if ( $curuser->access_right('Suspend customer package') ) {
267 ( <% pkg_suspend_link($cust_pkg) %> )
269 % if ( $curuser->access_right('Suspend customer package later') ) {
270 ( <% pkg_adjourn_link($cust_pkg) %> )
272 % if ( $curuser->access_right('Cancel customer package immediately') ) {
273 ( <% pkg_cancel_link($cust_pkg) %> )
275 % if ( $curuser->access_right('Cancel customer package later') ) {
276 ( <% pkg_expire_link($cust_pkg) %> )
290 <TD CLASS="inv" BGCOLOR="<% $bgcolor %>">
291 <TABLE CLASS="inv" BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH="100%">
293 % #foreach my $svcpart (sort {$a->{svcpart} <=> $b->{svcpart}} @{$pkg->{svcparts}}) {
294 % foreach my $part_svc ( $cust_pkg->part_svc ) {
296 % #foreach my $service (@{$svcpart->{services}}) {
297 % foreach my $cust_svc ( @{ $part_svc->cust_pkg_svc } ) {
300 <TD ALIGN="right" VALIGN="top"><% FS::UI::Web::svc_link($m, $part_svc, $cust_svc) %></TD>
301 <TD STYLE="padding-bottom:0px"><B><% FS::UI::Web::svc_label_link($m, $part_svc, $cust_svc) %></B></TD>
305 <TD ALIGN="right" COLSPAN="2" VALIGN="top" STYLE="padding-bottom:1px;padding-top:0px"><FONT SIZE="-2" COLOR="#FFD000">
307 <% $cust_svc->overlimit ? "Overlimit: ". time2str('%b %o %Y' . ($conf->exists('cust_pkg-display_times') ? ' %l:%M %P' : ''), $cust_svc->overlimit) : '' %>
312 <TD ALIGN="right" VALIGN="top" STYLE="padding-bottom:5px;padding-top:0px"><FONT SIZE="-2">
314 % if ( $curuser->access_right('Recharge customer service')
315 % && $part_svc->svcdb eq 'svc_acct'
316 % && ( $cust_svc->svc_x->seconds ne ''
317 % || $cust_svc->svc_x->upbytes ne ''
318 % || $cust_svc->svc_x->downbytes ne ''
319 % || $cust_svc->svc_x->totalbytes ne ''
322 ( <%svc_recharge_link($cust_svc)%> )
326 <TD ALIGN="right" VALIGN="top" STYLE="padding-bottom:5px;padding-top:0px"><FONT SIZE="-2">
328 % if ( $curuser->access_right('Unprovision customer service') ) {
329 ( <%svc_unprovision_link($cust_svc)%> )
335 % if ( ! $cust_pkg->get('cancel')
336 % && $curuser->access_right('Provision customer service')
337 % && $part_svc->num_avail
341 <TD COLSPAN=2 ALIGN="center" STYLE="padding-bottom:4px;padding-top:0px">
342 <B><% svc_provision_link($cust_pkg, $part_svc, $conf, $curuser) %></B>
352 % } #end display packages
361 % if ( $cgi->param('fragment') =~ /^cust_pkg(\d+)$/ ) {
363 // IE-specific hack. other browsers listen to #fragments
364 // is this even working? or is the #target redirection just working cause
365 // we set the URL params differently?
366 var el = document.getElementById( 'cust_pkg<% $1 %>' );
367 if ( el ) el.scrollIntoView(true);
372 my( $cust_main ) = @_;
373 my $conf = new FS::Conf;
375 my $curuser = $FS::CurrentUser::CurrentUser;
377 my $packages = get_packages($cust_main, $conf);
379 my $colspan = $conf->exists('cust_pkg-display_times') ? 8 : 4;
380 my $width = $conf->exists('cust_pkg-display_times') ? '38%' : '56%';
383 my( $cust_pkg, $title, $field, %opt ) = @_;
385 my $color = $opt{'color'};
387 my $html = qq(<TR><TD WIDTH="<%$width%>" ALIGN="right">);
388 $html .= qq(<FONT COLOR="#$color"><B>) if length($color);
389 $html .= qq($title );
390 $html .= qq(</B></FONT>) if length($color);
392 $html .= pkg_datestr($cust_pkg, $field, $conf).'</TR>';
397 sub pkg_status_row_if {
398 my( $cust_pkg, $title, $field, %opt ) = @_;
399 $cust_pkg->get($field) ? pkg_status_row(@_) : '';
402 sub pkg_status_row_changed {
404 return '' unless $cust_pkg->change_date;
405 my $html = pkg_status_row( $cust_pkg, 'Package changed', 'change_date' );
406 my $old = $cust_pkg->old_cust_pkg;
408 my $part_pkg = $old->part_pkg;
409 my $label = 'Changed from '. $cust_pkg->change_pkgnum. ': '.
410 $part_pkg->pkg. ' - '. $part_pkg->comment;
411 $html .= pkg_status_row_colspan( $label, '', size=>'-1', align=>'right' );
416 sub pkg_status_row_colspan {
417 my($title, $addl, %opt) = @_;
419 my $align = $opt{'align'} ? 'ALIGN="'. $opt{'align'}.'"' : '';
420 my $color = $opt{'color'} ? 'COLOR="#'.$opt{'color'}.'"' : '';
421 my $size = $opt{'size'} ? 'SIZE="'. $opt{'size'}. '"' : '';
423 my $html = qq(<TR><TD COLSPAN=$colspan $align>);
424 $html .= qq(<FONT $color $size>) if length($color) || $size;
425 $html .= qq(<B>) if $color && !$size;
427 $html .= qq(</B>) if $color && !$size;
428 $html .= qq(</FONT>) if length($color) || $size;
429 $html .= ", $addl" if length($addl);
430 $html .= qq(</TD></TR>);
442 my $cust_main = shift or return undef;
447 if ( $cgi->param('showcancelledpackages') eq '0' #see if it was set by me
448 || ( $conf->exists('hidecancelledpackages')
449 && ! $cgi->param('showcancelledpackages') )
452 $method = 'ncancelled_pkgs';
454 $method = 'all_pkgs';
457 [ $cust_main->$method() ];
460 sub svc_provision_link {
461 my ($cust_pkg, $part_svc, $conf, $curuser) = @_;
462 ( my $svc_nbsp = $part_svc->svc ) =~ s/\s+/ /g;
463 my $num_avail = $part_svc->num_avail;
464 my $pkgnum_svcpart = "pkgnum=". $cust_pkg->pkgnum. ';'.
465 "svcpart=". $part_svc->svcpart;
467 if ( $part_svc->svcdb eq 'svc_external' #could be generalized
468 && $conf->exists('svc_external-skip_manual')
470 $url = "${p}edit/process/". $part_svc->svcdb. ".cgi?$pkgnum_svcpart";
475 'part_svc' => $part_svc,
476 'query' => $pkgnum_svcpart,
478 #$url = "${p}edit/$svcpart->{svcdb}.cgi?$pkgnum_svcpart";
481 my $link = qq!<A CLASS="provision" HREF="$url">!.
482 "Provision $svc_nbsp ($num_avail)</A>";
483 if ( $conf->exists('legacy_link')
484 && $curuser->access_right('View/link unlinked services')
488 qq!<A CLASS="provision" HREF="${p}misc/link.cgi?!.
489 qq!$pkgnum_svcpart">!.
490 "Link to legacy $svc_nbsp ($num_avail)</A>";
495 sub svc_unprovision_link {
496 my $cust_svc = shift or return '';
497 qq!<A HREF="javascript:areyousure('${p}misc/unprovision.cgi?!. $cust_svc->svcnum.
498 qq!', 'Permanently unprovision and delete this service?')">Unprovision</A>!;
502 my($cust_pkg, $field, $conf) = @_ or return '';
503 return ' ' unless $cust_pkg->get($field);
504 my $format = '<TD align="left"><B>%b</B></TD>'.
505 '<TD align="right"><B> %o,</B></TD>'.
506 '<TD align="right"><B> %Y</B></TD>';
507 #$format .= ' <FONT SIZE=-3>%l:%M:%S%P %z</FONT>'
508 $format .= '<TD ALIGN="right"><B> %l</TD>'.
509 '<TD ALIGN="center"><B>:</B></TD>'.
510 '<TD ALIGN="left"><B>%M</B></TD>'.
511 '<TD ALIGN="left"><B> %P</B></TD>'
512 if $conf->exists('cust_pkg-display_times');
513 my $strip = time2str($format, $cust_pkg->get($field) );
514 $strip =~ s/ (\d)/$1/g;
518 sub pkg_change_link { pkg_popup_link('misc/change_pkg.cgi?dummy=value',
519 'Change package',
526 sub pkg_suspend_link { pkg_popup_link( 'misc/cancel_pkg.html?method=suspend',
534 sub pkg_adjourn_link { pkg_popup_link( 'misc/cancel_pkg.html?method=adjourn',
535 'Suspend later',
542 sub pkg_unsuspend_link { pkg_link('misc/unsusp_pkg', 'Unsuspend', @_ ); }
543 sub pkg_expire_link { pkg_link('misc/expire_pkg', 'Cancel later', @_ ); }
544 sub pkg_dates_link { pkg_link('edit/REAL_cust_pkg', 'Edit dates', @_ ); }
546 sub pkg_cancel_link { pkg_popup_link( 'misc/cancel_pkg.html?method=cancel',
554 sub pkg_expire_link { pkg_popup_link( 'misc/cancel_pkg.html?method=expire',
556 'Expire', #"Cancel package $num later"
562 sub svc_recharge_link { svc_popup_link( 'misc/recharge_svc.html',
570 sub order_pkg_link { cust_popup_link( 'misc/order_pkg.html',
571 'Order new package',
580 qq!<a href="${p}search/cust_event.html?pkgnum=!. $cust_pkg->pkgnum. qq!">!.
581 'View package events'.
586 my($action, $label, $cust_pkg) = @_;
587 return '' unless $cust_pkg;
588 qq!<a href="$p$action.cgi?!. $cust_pkg->pkgnum. qq!">$label</a>!;
592 my($action, $label, $actionlabel, $color, $cust_pkg) = @_;
593 $action .= '&pkgnum='. $cust_pkg->pkgnum;
594 $actionlabel .= ' package '. $cust_pkg->pkgnum;
595 popup_link($action, $label, $actionlabel, $color, 768);
599 my($action, $label, $actionlabel, $color, $cust_svc) = @_;
600 $action .= '?svcnum='. $cust_svc->svcnum;
601 $actionlabel .= ' service '. $cust_svc->svcnum;
602 popup_link($action, $label, $actionlabel, $color);
605 sub cust_popup_link {
606 my($action, $label, $actionlabel, $color, $cust_main) = @_;
607 $action .= '?'. $cust_main->custnum;
608 popup_link($action, $label, $actionlabel, $color);
612 my($action, $label, $actionlabel, $color, $width) = @_;
613 $color ||= '#333399';
615 qq!<A HREF="javascript:void(0);" onClick="overlib( OLiframeContent('$p$action', $width, 336, 'pkg_or_svc_action_popup' ), CAPTION, '$actionlabel', STICKY, AUTOSTATUSCAP, MIDX, 0, MIDY, 0, DRAGGABLE, CLOSECLICK, BGCOLOR, '$color', CGCOLOR, '$color' ); return false;">$label</A>!;
618 sub pkg_customize_link {
619 my $cust_pkg = shift or return '';
620 my $custnum = $cust_pkg->custnum;
621 qq!<A HREF="${p}edit/part_pkg.cgi?!.
622 "keywords=$custnum;".
623 "clone=". $cust_pkg->part_pkg->pkgpart. ';'.
624 "pkgnum=". $cust_pkg->pkgnum.