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
148 % my $cpr = $cust_pkg->last_cust_pkg_reason;
150 <% pkg_status_row($cust_pkg, 'Cancelled', 'cancel', 'color'=>'FF0000', conf=>$conf ) %>
152 <% pkg_status_row_colspan(
153 ( ( $cpr && ( $cpr->date == $cust_pkg->get('cancel') ||
154 $cpr->date == $cust_pkg->expire
156 ) ? $cpr->reasontext. ' by '. $cpr->otaker : '' ), '',
157 'align' => 'right', 'color' => 'ff0000', 'size' => '-2',
162 <% pkg_status_row( $cust_pkg, 'Suspended', 'susp', 'color'=>'FF9900', conf=>$conf ) %>
164 % unless ( $cust_pkg->get('setup') ) {
166 <% pkg_status_row_colspan('Never billed') %>
170 <% pkg_status_row( $cust_pkg, 'Setup', 'setup', conf=>$conf ) %>
171 <% pkg_status_row_changed( $cust_pkg, conf=>$conf ) %>
172 <% pkg_status_row_if( $cust_pkg, $last_bill_or_renewed, 'last_bill', conf=>$conf ) %>
173 <% pkg_status_row_if( $cust_pkg, 'Suspended', 'susp', conf=>$conf ) %>
179 % if ( $cust_pkg->get('susp') ) { #status: suspended
180 % my $cpr = $cust_pkg->last_cust_pkg_reason;
182 <% pkg_status_row( $cust_pkg, 'Suspended', 'susp', 'color'=>'FF9900', conf=>$conf ) %>
184 <% pkg_status_row_colspan(
185 ( ( $cpr && ( $cpr->date == $cust_pkg->susp ||
186 $cpr->date == $cust_pkg->adjourn
188 ) ? $cpr->reasontext. ' by '. $cpr->otaker : '' ), '',
189 'align' => 'right', 'color' => 'FF9900', 'size' => '-2',
193 % unless ( $cust_pkg->get('setup') ) {
194 <% pkg_status_row_colspan('Never billed') %>
196 <% pkg_status_row($cust_pkg, 'Setup', 'setup', conf=>$conf ) %>
199 <% pkg_status_row_changed( $cust_pkg, conf=>$conf ) %>
200 <% pkg_status_row_if( $cust_pkg, $last_bill_or_renewed, 'last_bill', conf=>$conf ) %>
201 % # pkg_status_row($cust_pkg, 'Next bill', 'bill', conf=>$conf)
202 <% pkg_status_row_if( $cust_pkg, 'Expires', 'expire', conf=>$conf ) %>
205 <TD COLSPAN=<%$colspan%>>
207 % if ( $curuser->access_right('Unsuspend customer package') ) {
208 ( <% pkg_unsuspend_link($cust_pkg) %> )
210 % if ( $curuser->access_right('Cancel customer package immediately') ) {
211 ( <% pkg_cancel_link($cust_pkg) %> )
217 % } else { #status: active
219 % unless ( $cust_pkg->get('setup') ) { #not setup
221 % unless ( $part_pkg->freq ) {
223 <% pkg_status_row_colspan('Not yet billed (one-time charge)') %>
226 <TD COLSPAN=<%$colspan%>>
228 % if ( $curuser->access_right('Cancel customer package immediately') ) {
229 ( <% pkg_cancel_link($cust_pkg) %> )
237 <% pkg_status_row_colspan("Not yet billed ($billed_or_prepaid ". myfreq($part_pkg). ')' ) %>
243 % unless ( $part_pkg->freq ) {
245 <% pkg_status_row_colspan('One-time charge') %>
247 <% pkg_status_row($cust_pkg, 'Billed', 'setup', conf=>$conf) %>
251 % if (scalar($cust_pkg->overlimit)) {
253 <% pkg_status_row_colspan(
255 $billed_or_prepaid. ' '. myfreq($part_pkg),
261 <% pkg_status_row_colspan(
263 $billed_or_prepaid. ' '. myfreq($part_pkg),
269 <% pkg_status_row($cust_pkg, 'Setup', 'setup', conf=>$conf) %>
275 <% pkg_status_row_changed( $cust_pkg, conf=>$conf ) %>
276 <% pkg_status_row_if( $cust_pkg, $last_bill_or_renewed, 'last_bill', conf=>$conf ) %>
277 <% pkg_status_row_if( $cust_pkg, $next_bill_or_prepaid_until, 'bill', conf=>$conf ) %>
278 <% pkg_status_row_if( $cust_pkg, 'Will suspend on', 'adjourn', conf=>$conf ) %>
279 <% pkg_status_row_if( $cust_pkg, 'Expires', 'expire', conf=>$conf ) %>
281 % if ( $part_pkg->freq ) {
284 <TD COLSPAN=<%$colspan%>>
286 % if ( $curuser->access_right('Suspend customer package') ) {
287 ( <% pkg_suspend_link($cust_pkg) %> )
289 % if ( $curuser->access_right('Suspend customer package later') ) {
290 ( <% pkg_adjourn_link($cust_pkg) %> )
292 % if ( $curuser->access_right('Cancel customer package immediately') ) {
293 ( <% pkg_cancel_link($cust_pkg) %> )
295 % if ( $curuser->access_right('Cancel customer package later') ) {
296 ( <% pkg_expire_link($cust_pkg) %> )
310 <TD CLASS="inv" BGCOLOR="<% $bgcolor %>">
311 <TABLE CLASS="inv" BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH="100%">
313 % #foreach my $svcpart (sort {$a->{svcpart} <=> $b->{svcpart}} @{$pkg->{svcparts}}) {
314 % foreach my $part_svc ( $cust_pkg->part_svc ) {
316 % #foreach my $service (@{$svcpart->{services}}) {
317 % foreach my $cust_svc ( @{ $part_svc->cust_pkg_svc } ) {
320 <TD ALIGN="right" VALIGN="top"><% FS::UI::Web::svc_link($m, $part_svc, $cust_svc) %></TD>
321 <TD STYLE="padding-bottom:0px"><B><% FS::UI::Web::svc_label_link($m, $part_svc, $cust_svc) %></B></TD>
322 <TD><% FS::UI::Web::svc_export_links($m, $part_svc, $cust_svc) %></TD>
326 <TD ALIGN="right" COLSPAN="3" VALIGN="top" STYLE="padding-bottom:1px;padding-top:0px"><FONT SIZE="-2" COLOR="#FFD000">
328 <% $cust_svc->overlimit ? "Overlimit: ". time2str('%b %o %Y' . ($conf->exists('cust_pkg-display_times') ? ' %l:%M %P' : ''), $cust_svc->overlimit) : '' %>
333 <TD ALIGN="right" VALIGN="top" STYLE="padding-bottom:5px;padding-top:0px"><FONT SIZE="-2">
335 % if ( $curuser->access_right('Recharge customer service')
336 % && $part_svc->svcdb eq 'svc_acct'
337 % && ( $cust_svc->svc_x->seconds ne ''
338 % || $cust_svc->svc_x->upbytes ne ''
339 % || $cust_svc->svc_x->downbytes ne ''
340 % || $cust_svc->svc_x->totalbytes ne ''
343 ( <%svc_recharge_link($cust_svc)%> )
347 <TD ALIGN="right" VALIGN="top" STYLE="padding-bottom:5px;padding-top:0px"><FONT SIZE="-2">
349 % if ( $curuser->access_right('Unprovision customer service') ) {
350 ( <%svc_unprovision_link($cust_svc)%> )
356 % if ( ! $cust_pkg->get('cancel')
357 % && $curuser->access_right('Provision customer service')
358 % && $part_svc->num_avail
362 <TD COLSPAN=3 ALIGN="center" STYLE="padding-bottom:4px;padding-top:0px">
363 <B><% svc_provision_link($cust_pkg, $part_svc, $conf, $curuser) %></B>
373 % } #end display packages
382 % if ( $cgi->param('fragment') =~ /^cust_pkg(\d+)$/ ) {
384 // IE-specific hack. other browsers listen to #fragments
385 // is this even working? or is the #target redirection just working cause
386 // we set the URL params differently?
387 var el = document.getElementById( 'cust_pkg<% $1 %>' );
388 if ( el ) el.scrollIntoView(true);
393 my( $cust_main ) = @_;
394 my $conf = new FS::Conf;
396 my $curuser = $FS::CurrentUser::CurrentUser;
398 my $packages = get_packages($cust_main, $conf);
400 my $colspan = $conf->exists('cust_pkg-display_times') ? 8 : 4;
401 my $width = $conf->exists('cust_pkg-display_times') ? '38%' : '56%';
404 my( $cust_pkg, $title, $field, %opt ) = @_;
406 my $color = $opt{'color'};
408 my $html = qq(<TR><TD WIDTH="<%$width%>" ALIGN="right">);
409 $html .= qq(<FONT COLOR="#$color"><B>) if length($color);
410 $html .= qq($title );
411 $html .= qq(</B></FONT>) if length($color);
413 $html .= pkg_datestr($cust_pkg, $field, $opt{conf}).'</TR>';
418 sub pkg_status_row_if {
419 my( $cust_pkg, $title, $field, %opt ) = @_;
420 $cust_pkg->get($field) ? pkg_status_row(@_) : '';
423 sub pkg_status_row_changed {
424 my( $cust_pkg, %opt ) = @_;
425 return '' unless $cust_pkg->change_date;
426 my $html = pkg_status_row( $cust_pkg, 'Package changed', 'change_date', conf=>$opt{'conf'} );
427 my $old = $cust_pkg->old_cust_pkg;
429 my $part_pkg = $old->part_pkg;
430 my $label = 'Changed from '. $cust_pkg->change_pkgnum. ': '.
431 $part_pkg->pkg. ' - '. $part_pkg->comment;
432 $html .= pkg_status_row_colspan( $label, '', size=>'-1', align=>'right' );
437 sub pkg_status_row_colspan {
438 my($title, $addl, %opt) = @_;
440 my $align = $opt{'align'} ? 'ALIGN="'. $opt{'align'}.'"' : '';
441 my $color = $opt{'color'} ? 'COLOR="#'.$opt{'color'}.'"' : '';
442 my $size = $opt{'size'} ? 'SIZE="'. $opt{'size'}. '"' : '';
444 my $html = qq(<TR><TD COLSPAN=$colspan $align>);
445 $html .= qq(<FONT $color $size>) if length($color) || $size;
446 $html .= qq(<B>) if $color && !$size;
448 $html .= qq(</B>) if $color && !$size;
449 $html .= qq(</FONT>) if length($color) || $size;
450 $html .= ", $addl" if length($addl);
451 $html .= qq(</TD></TR>);
460 my $cust_main = shift or return undef;
465 if ( $cgi->param('showcancelledpackages') eq '0' #see if it was set by me
466 || ( $conf->exists('hidecancelledpackages')
467 && ! $cgi->param('showcancelledpackages') )
470 $method = 'ncancelled_pkgs';
472 $method = 'all_pkgs';
475 [ $cust_main->$method() ];
478 sub svc_provision_link {
479 my ($cust_pkg, $part_svc, $conf, $curuser) = @_;
480 ( my $svc_nbsp = $part_svc->svc ) =~ s/\s+/ /g;
481 my $num_avail = $part_svc->num_avail;
482 my $pkgnum_svcpart = "pkgnum=". $cust_pkg->pkgnum. ';'.
483 "svcpart=". $part_svc->svcpart;
485 if ( $part_svc->svcdb eq 'svc_external' #could be generalized
486 && $conf->exists('svc_external-skip_manual')
488 $url = "${p}edit/process/". $part_svc->svcdb. ".cgi?$pkgnum_svcpart";
493 'part_svc' => $part_svc,
494 'query' => $pkgnum_svcpart,
496 #$url = "${p}edit/$svcpart->{svcdb}.cgi?$pkgnum_svcpart";
499 my $link = qq!<A CLASS="provision" HREF="$url">!.
500 "Provision $svc_nbsp ($num_avail)</A>";
501 if ( $conf->exists('legacy_link')
502 && $curuser->access_right('View/link unlinked services')
506 qq!<A CLASS="provision" HREF="${p}misc/link.cgi?!.
507 qq!$pkgnum_svcpart">!.
508 "Link to legacy $svc_nbsp ($num_avail)</A>";
513 sub svc_unprovision_link {
514 my $cust_svc = shift or return '';
515 qq!<A HREF="javascript:areyousure('${p}misc/unprovision.cgi?!. $cust_svc->svcnum.
516 qq!', 'Permanently unprovision and delete this service?')">Unprovision</A>!;
520 my($cust_pkg, $field, $conf) = @_ or return '';
521 return ' ' unless $cust_pkg->get($field);
522 my $format = '<TD align="left"><B>%b</B></TD>'.
523 '<TD align="right"><B> %o,</B></TD>'.
524 '<TD align="right"><B> %Y</B></TD>';
525 #$format .= ' <FONT SIZE=-3>%l:%M:%S%P %z</FONT>'
526 $format .= '<TD ALIGN="right"><B> %l</TD>'.
527 '<TD ALIGN="center"><B>:</B></TD>'.
528 '<TD ALIGN="left"><B>%M</B></TD>'.
529 '<TD ALIGN="left"><B> %P</B></TD>'
530 if $conf->exists('cust_pkg-display_times');
531 my $strip = time2str($format, $cust_pkg->get($field) );
532 $strip =~ s/ (\d)/$1/g;
536 sub pkg_change_link { include( '/elements/popup_link-cust_pkg.html',
537 { 'action' => $p. 'misc/change_pkg.cgi?dummy=value',
538 'label' => 'Change package',
539 'actionlabel' => 'Change',
545 sub pkg_suspend_link { include( '/elements/popup_link-cust_pkg.html',
546 { 'action' => $p. 'misc/cancel_pkg.html?method=suspend',
547 'label' => 'Suspend now',
548 'actionlabel' => 'Suspend',
549 'color' => '#FF9900',
556 sub pkg_adjourn_link { include( '/elements/popup_link-cust_pkg.html',
557 { 'action' => $p. 'misc/cancel_pkg.html?method=adjourn',
558 'label' => 'Suspend later',
559 'actionlabel' => 'Adjourn',
560 'color' => '#CC6600',
566 sub pkg_unsuspend_link { pkg_link('misc/unsusp_pkg', 'Unsuspend', @_ ); }
567 sub pkg_dates_link { pkg_link('edit/REAL_cust_pkg', 'Edit dates', @_ ); }
569 sub pkg_cancel_link { include( '/elements/popup_link-cust_pkg.html',
570 { 'action' => $p. 'misc/cancel_pkg.html?method=cancel',
571 'label' => 'Cancel now',
572 'actionlabel' => 'Cancel',
573 'color' => '#ff0000',
579 sub pkg_expire_link { include( '/elements/popup_link-cust_pkg.html',
580 { 'action' => $p. 'misc/cancel_pkg.html?method=expire',
581 'label' => 'Cancel later',
582 'actionlabel' => 'Expire', #"Cancel package $num later"
583 'color' => '#CC0000',
589 sub svc_recharge_link { include( '/elements/popup_link-cust_svc.html',
590 { 'action' => $p. 'misc/recharge_svc.html',
591 'label' => 'Recharge',
592 'actionlabel' => 'Recharge',
593 'color' => '#333399',
599 sub order_pkg_link { include( '/elements/popup_link-cust_main.html',
600 { 'action' => $p. 'misc/order_pkg.html',
601 'label' => 'Order new package',
602 'actionlabel' => 'Order new package',
603 'color' => '#333399',
604 'cust_main' => shift,
605 'closetext' => 'Close',
612 qq!<a href="${p}search/cust_event.html?pkgnum=!. $cust_pkg->pkgnum. qq!">!.
613 'View package events'.
618 my($action, $label, $cust_pkg) = @_;
619 return '' unless $cust_pkg;
620 qq!<a href="$p$action.cgi?!. $cust_pkg->pkgnum. qq!">$label</a>!;
623 sub pkg_customize_link {
624 my $cust_pkg = shift or return '';
625 my $custnum = $cust_pkg->custnum;
626 qq!<A HREF="${p}edit/part_pkg.cgi?!.
627 "keywords=$custnum;".
628 "clone=". $cust_pkg->part_pkg->pkgpart. ';'.
629 "pkgnum=". $cust_pkg->pkgnum.