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 %>
91 % unless ( $cust_pkg->get('cancel') ) {
93 % if ( $curuser->access_right('Change customer package') ) { $br=1;
95 ( <%pkg_change_link($cust_pkg)%> )
97 % if ( $curuser->access_right('Edit customer package dates') ) { $br=1;
99 ( <%pkg_dates_link($cust_pkg)%> )
101 % if ( $curuser->access_right('Customize customer package') ) { $br=1;
103 ( <%pkg_customize_link($cust_pkg,$cust_main->custnum)%> )
105 <% $br ? '<BR>' : '' %>
108 % if ( $cust_pkg->num_cust_event
109 % && ( $curuser->access_right('Billing event reports')
110 % || $curuser->access_right('View customer billing events')
113 ( <%pkg_event_link($cust_pkg)%> )
120 <TD CLASS="inv" BGCOLOR="<% $bgcolor %>">
121 <TABLE CLASS="inv" BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH="100%">
124 % my $part_pkg = shift;
125 % my $freq = $part_pkg->freq_pretty;
126 % $freq =~ s/ / /g;
130 % #this should use cust_pkg->status and cust_pkg->statuscolor eventually
131 % #my $colspan = $conf->exists('cust_pkg-display_times') ? 8 : 4;
132 % #my $width = $conf->exists('cust_pkg-display_times') ? '38%' : '56%';
134 % #false laziness w/edit/REAL_cust_pkg.cgi
135 % my( $billed_or_prepaid, $last_bill_or_renewed, $next_bill_or_prepaid_until );
136 % unless ( $part_pkg->is_prepaid ) {
137 % $billed_or_prepaid = 'billed';
138 % $last_bill_or_renewed = 'Last bill';
139 % $next_bill_or_prepaid_until = 'Next bill';
141 % $billed_or_prepaid = 'prepaid';
142 % $last_bill_or_renewed = 'Renewed';
143 % $next_bill_or_prepaid_until = 'Prepaid until';
147 % if ( $cust_pkg->get('cancel') ) { #status: cancelled
149 <% pkg_status_row($cust_pkg, 'Cancelled', 'cancel', 'color'=>'FF0000' ) %>
151 <% pkg_status_row_colspan(
152 ( $cust_pkg->last_reason ? $cust_pkg->last_reason->reason : '' ), '',
153 'align' => 'right', 'color' => 'ff0000', 'size' => '-2',
157 % unless ( $cust_pkg->get('setup') ) {
159 <% pkg_status_row_colspan('Never billed') %>
163 <% pkg_status_row( $cust_pkg, 'Setup', 'setup' ) %>
164 <% pkg_status_row_changed( $cust_pkg ) %>
165 <% pkg_status_row_if( $cust_pkg, $last_bill_or_renewed, 'last_bill' ) %>
166 <% pkg_status_row_if( $cust_pkg, 'Suspended', 'susp' ) %>
172 % if ( $cust_pkg->get('susp') ) { #status: suspended
174 <% pkg_status_row( $cust_pkg, 'Suspended', 'susp', 'color'=>'FF9900' ) %>
176 <% pkg_status_row_colspan(
177 ( $cust_pkg->last_reason ? $cust_pkg->last_reason->reason : '' ), '',
178 'align' => 'right', 'color' => 'FF9900', 'size' => '-2',
182 % unless ( $cust_pkg->get('setup') ) {
183 <% pkg_status_row_colspan('Never billed') %>
185 <% pkg_status_row($cust_pkg, 'Setup', 'setup' ) %>
188 <% pkg_status_row_changed( $cust_pkg ) %>
189 <% pkg_status_row_if( $cust_pkg, $last_bill_or_renewed, 'last_bill' ) %>
190 % # pkg_status_row($cust_pkg, 'Next bill', 'bill')
191 <% pkg_status_row_if( $cust_pkg, 'Expires', 'expire' ) %>
194 <TD COLSPAN=<%$colspan%>>
196 % if ( $curuser->access_right('Unsuspend customer package') ) {
197 ( <% pkg_unsuspend_link($cust_pkg) %> )
199 % if ( $curuser->access_right('Cancel customer package immediately') ) {
200 ( <% pkg_cancel_link($cust_pkg) %> )
206 % } else { #status: active
208 % unless ( $cust_pkg->get('setup') ) { #not setup
210 % unless ( $part_pkg->freq ) {
212 <% pkg_status_row_colspan('Not yet billed (one-time charge)') %>
215 <TD COLSPAN=<%$colspan%>>
217 % if ( $curuser->access_right('Cancel customer package immediately') ) {
218 ( <% pkg_cancel_link($cust_pkg) %> )
226 <% pkg_status_row_colspan("Not yet billed ($billed_or_prepaid ". myfreq($part_pkg). ')' ) %>
232 % unless ( $part_pkg->freq ) {
234 <% pkg_status_row_colspan('One-time charge') %>
236 <% pkg_status_row($cust_pkg, 'Billed', 'setup') %>
240 % if (scalar($cust_pkg->overlimit)) {
242 <% pkg_status_row_colspan(
244 $billed_or_prepaid. ' '. myfreq($part_pkg),
250 <% pkg_status_row_colspan(
252 $billed_or_prepaid. ' '. myfreq($part_pkg),
258 <% pkg_status_row($cust_pkg, 'Setup', 'setup') %>
264 <% pkg_status_row_changed( $cust_pkg ) %>
265 <% pkg_status_row_if( $cust_pkg, $last_bill_or_renewed, 'last_bill' ) %>
266 <% pkg_status_row_if( $cust_pkg, $next_bill_or_prepaid_until, 'bill' ) %>
267 <% pkg_status_row_if( $cust_pkg, 'Will suspend on', 'adjourn' ) %>
268 <% pkg_status_row_if( $cust_pkg, 'Expires', 'expire' ) %>
270 % if ( $part_pkg->freq ) {
273 <TD COLSPAN=<%$colspan%>>
275 % if ( $curuser->access_right('Suspend customer package') ) {
276 ( <% pkg_suspend_link($cust_pkg) %> )
278 % if ( $curuser->access_right('Suspend customer package later') ) {
279 ( <% pkg_adjourn_link($cust_pkg) %> )
281 % if ( $curuser->access_right('Cancel customer package immediately') ) {
282 ( <% pkg_cancel_link($cust_pkg) %> )
284 % if ( $curuser->access_right('Cancel customer package later') ) {
285 ( <% pkg_expire_link($cust_pkg) %> )
299 <TD CLASS="inv" BGCOLOR="<% $bgcolor %>">
300 <TABLE CLASS="inv" BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH="100%">
302 % #foreach my $svcpart (sort {$a->{svcpart} <=> $b->{svcpart}} @{$pkg->{svcparts}}) {
303 % foreach my $part_svc ( $cust_pkg->part_svc ) {
305 % #foreach my $service (@{$svcpart->{services}}) {
306 % foreach my $cust_svc ( @{ $part_svc->cust_pkg_svc } ) {
309 <TD ALIGN="right" VALIGN="top"><% FS::UI::Web::svc_link($m, $part_svc, $cust_svc) %></TD>
310 <TD STYLE="padding-bottom:0px"><B><% FS::UI::Web::svc_label_link($m, $part_svc, $cust_svc) %></B></TD>
311 <TD><% FS::UI::Web::svc_export_links($m, $part_svc, $cust_svc) %></TD>
315 <TD ALIGN="right" COLSPAN="3" VALIGN="top" STYLE="padding-bottom:1px;padding-top:0px"><FONT SIZE="-2" COLOR="#FFD000">
317 <% $cust_svc->overlimit ? "Overlimit: ". time2str('%b %o %Y' . ($conf->exists('cust_pkg-display_times') ? ' %l:%M %P' : ''), $cust_svc->overlimit) : '' %>
322 <TD ALIGN="right" VALIGN="top" STYLE="padding-bottom:5px;padding-top:0px"><FONT SIZE="-2">
324 % if ( $curuser->access_right('Recharge customer service')
325 % && $part_svc->svcdb eq 'svc_acct'
326 % && ( $cust_svc->svc_x->seconds ne ''
327 % || $cust_svc->svc_x->upbytes ne ''
328 % || $cust_svc->svc_x->downbytes ne ''
329 % || $cust_svc->svc_x->totalbytes ne ''
332 ( <%svc_recharge_link($cust_svc)%> )
336 <TD ALIGN="right" VALIGN="top" STYLE="padding-bottom:5px;padding-top:0px"><FONT SIZE="-2">
338 % if ( $curuser->access_right('Unprovision customer service') ) {
339 ( <%svc_unprovision_link($cust_svc)%> )
345 % if ( ! $cust_pkg->get('cancel')
346 % && $curuser->access_right('Provision customer service')
347 % && $part_svc->num_avail
351 <TD COLSPAN=3 ALIGN="center" STYLE="padding-bottom:4px;padding-top:0px">
352 <B><% svc_provision_link($cust_pkg, $part_svc, $conf, $curuser) %></B>
362 % } #end display packages
371 % if ( $cgi->param('fragment') =~ /^cust_pkg(\d+)$/ ) {
373 // IE-specific hack. other browsers listen to #fragments
374 // is this even working? or is the #target redirection just working cause
375 // we set the URL params differently?
376 var el = document.getElementById( 'cust_pkg<% $1 %>' );
377 if ( el ) el.scrollIntoView(true);
382 my( $cust_main ) = @_;
383 my $conf = new FS::Conf;
385 my $curuser = $FS::CurrentUser::CurrentUser;
387 my $packages = get_packages($cust_main, $conf);
389 my $colspan = $conf->exists('cust_pkg-display_times') ? 8 : 4;
390 my $width = $conf->exists('cust_pkg-display_times') ? '38%' : '56%';
393 my( $cust_pkg, $title, $field, %opt ) = @_;
395 my $color = $opt{'color'};
397 my $html = qq(<TR><TD WIDTH="<%$width%>" ALIGN="right">);
398 $html .= qq(<FONT COLOR="#$color"><B>) if length($color);
399 $html .= qq($title );
400 $html .= qq(</B></FONT>) if length($color);
402 $html .= pkg_datestr($cust_pkg, $field, $conf).'</TR>';
407 sub pkg_status_row_if {
408 my( $cust_pkg, $title, $field, %opt ) = @_;
409 $cust_pkg->get($field) ? pkg_status_row(@_) : '';
412 sub pkg_status_row_changed {
414 return '' unless $cust_pkg->change_date;
415 my $html = pkg_status_row( $cust_pkg, 'Package changed', 'change_date' );
416 my $old = $cust_pkg->old_cust_pkg;
418 my $part_pkg = $old->part_pkg;
419 my $label = 'Changed from '. $cust_pkg->change_pkgnum. ': '.
420 $part_pkg->pkg. ' - '. $part_pkg->comment;
421 $html .= pkg_status_row_colspan( $label, '', size=>'-1', align=>'right' );
426 sub pkg_status_row_colspan {
427 my($title, $addl, %opt) = @_;
429 my $align = $opt{'align'} ? 'ALIGN="'. $opt{'align'}.'"' : '';
430 my $color = $opt{'color'} ? 'COLOR="#'.$opt{'color'}.'"' : '';
431 my $size = $opt{'size'} ? 'SIZE="'. $opt{'size'}. '"' : '';
433 my $html = qq(<TR><TD COLSPAN=$colspan $align>);
434 $html .= qq(<FONT $color $size>) if length($color) || $size;
435 $html .= qq(<B>) if $color && !$size;
437 $html .= qq(</B>) if $color && !$size;
438 $html .= qq(</FONT>) if length($color) || $size;
439 $html .= ", $addl" if length($addl);
440 $html .= qq(</TD></TR>);
449 my $cust_main = shift or return undef;
454 if ( $cgi->param('showcancelledpackages') eq '0' #see if it was set by me
455 || ( $conf->exists('hidecancelledpackages')
456 && ! $cgi->param('showcancelledpackages') )
459 $method = 'ncancelled_pkgs';
461 $method = 'all_pkgs';
464 [ $cust_main->$method() ];
467 sub svc_provision_link {
468 my ($cust_pkg, $part_svc, $conf, $curuser) = @_;
469 ( my $svc_nbsp = $part_svc->svc ) =~ s/\s+/ /g;
470 my $num_avail = $part_svc->num_avail;
471 my $pkgnum_svcpart = "pkgnum=". $cust_pkg->pkgnum. ';'.
472 "svcpart=". $part_svc->svcpart;
474 if ( $part_svc->svcdb eq 'svc_external' #could be generalized
475 && $conf->exists('svc_external-skip_manual')
477 $url = "${p}edit/process/". $part_svc->svcdb. ".cgi?$pkgnum_svcpart";
482 'part_svc' => $part_svc,
483 'query' => $pkgnum_svcpart,
485 #$url = "${p}edit/$svcpart->{svcdb}.cgi?$pkgnum_svcpart";
488 my $link = qq!<A CLASS="provision" HREF="$url">!.
489 "Provision $svc_nbsp ($num_avail)</A>";
490 if ( $conf->exists('legacy_link')
491 && $curuser->access_right('View/link unlinked services')
495 qq!<A CLASS="provision" HREF="${p}misc/link.cgi?!.
496 qq!$pkgnum_svcpart">!.
497 "Link to legacy $svc_nbsp ($num_avail)</A>";
502 sub svc_unprovision_link {
503 my $cust_svc = shift or return '';
504 qq!<A HREF="javascript:areyousure('${p}misc/unprovision.cgi?!. $cust_svc->svcnum.
505 qq!', 'Permanently unprovision and delete this service?')">Unprovision</A>!;
509 my($cust_pkg, $field, $conf) = @_ or return '';
510 return ' ' unless $cust_pkg->get($field);
511 my $format = '<TD align="left"><B>%b</B></TD>'.
512 '<TD align="right"><B> %o,</B></TD>'.
513 '<TD align="right"><B> %Y</B></TD>';
514 #$format .= ' <FONT SIZE=-3>%l:%M:%S%P %z</FONT>'
515 $format .= '<TD ALIGN="right"><B> %l</TD>'.
516 '<TD ALIGN="center"><B>:</B></TD>'.
517 '<TD ALIGN="left"><B>%M</B></TD>'.
518 '<TD ALIGN="left"><B> %P</B></TD>'
519 if $conf->exists('cust_pkg-display_times');
520 my $strip = time2str($format, $cust_pkg->get($field) );
521 $strip =~ s/ (\d)/$1/g;
525 sub pkg_change_link { include( '/elements/popup_link-cust_pkg.html',
526 { 'action' => $p. 'misc/change_pkg.cgi?dummy=value',
527 'label' => 'Change package',
528 'actionlabel' => 'Change',
534 sub pkg_suspend_link { include( '/elements/popup_link-cust_pkg.html',
535 { 'action' => $p. 'misc/cancel_pkg.html?method=suspend',
536 'label' => 'Suspend now',
537 'actionlabel' => 'Suspend',
538 'color' => '#FF9900',
545 sub pkg_adjourn_link { include( '/elements/popup_link-cust_pkg.html',
546 { 'action' => $p. 'misc/cancel_pkg.html?method=adjourn',
547 'label' => 'Suspend later',
548 'actionlabel' => 'Adjourn',
549 'color' => '#CC6600',
555 sub pkg_unsuspend_link { pkg_link('misc/unsusp_pkg', 'Unsuspend', @_ ); }
556 sub pkg_dates_link { pkg_link('edit/REAL_cust_pkg', 'Edit dates', @_ ); }
558 sub pkg_cancel_link { include( '/elements/popup_link-cust_pkg.html',
559 { 'action' => $p. 'misc/cancel_pkg.html?method=cancel',
560 'label' => 'Cancel now',
561 'actionlabel' => 'Cancel',
562 'color' => '#ff0000',
568 sub pkg_expire_link { include( '/elements/popup_link-cust_pkg.html',
569 { 'action' => $p. 'misc/cancel_pkg.html?method=expire',
570 'label' => 'Cancel later',
571 'actionlabel' => 'Expire', #"Cancel package $num later"
572 'color' => '#CC0000',
578 sub svc_recharge_link { include( '/elements/popup_link-cust_svc.html',
579 { 'action' => $p. 'misc/recharge_svc.html',
580 'label' => 'Recharge',
581 'actionlabel' => 'Recharge',
582 'color' => '#333399',
588 sub order_pkg_link { include( '/elements/popup_link-cust_main.html',
589 { 'action' => $p. 'misc/order_pkg.html',
590 'label' => 'Order new package',
591 'actionlabel' => 'Order new package',
592 'color' => '#333399',
593 'cust_main' => shift,
600 qq!<a href="${p}search/cust_event.html?pkgnum=!. $cust_pkg->pkgnum. qq!">!.
601 'View package events'.
606 my($action, $label, $cust_pkg) = @_;
607 return '' unless $cust_pkg;
608 qq!<a href="$p$action.cgi?!. $cust_pkg->pkgnum. qq!">$label</a>!;
611 sub pkg_customize_link {
612 my $cust_pkg = shift or return '';
613 my $custnum = $cust_pkg->custnum;
614 qq!<A HREF="${p}edit/part_pkg.cgi?!.
615 "keywords=$custnum;".
616 "clone=". $cust_pkg->part_pkg->pkgpart. ';'.
617 "pkgnum=". $cust_pkg->pkgnum.