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',
166 <% pkg_status_row( $cust_pkg, 'Suspended', 'susp', 'color'=>'FF9900', conf=>$conf ) %>
168 % unless ( $cust_pkg->get('setup') ) {
170 <% pkg_status_row_colspan('Never billed') %>
174 <% pkg_status_row( $cust_pkg, 'Setup', 'setup', conf=>$conf ) %>
175 <% pkg_status_row_changed( $cust_pkg, conf=>$conf ) %>
176 <% pkg_status_row_if( $cust_pkg, $last_bill_or_renewed, 'last_bill', conf=>$conf ) %>
177 <% pkg_status_row_if( $cust_pkg, 'Suspended', 'susp', conf=>$conf ) %>
183 % if ( $cust_pkg->get('susp') ) { #status: suspended
184 % my $cpr = $cust_pkg->last_cust_pkg_reason;
186 <% pkg_status_row( $cust_pkg, 'Suspended', 'susp', 'color'=>'FF9900', conf=>$conf ) %>
188 <% pkg_status_row_colspan(
189 ( ( $cpr && ( $cpr->date == $cust_pkg->susp ||
190 $cpr->date == $cust_pkg->adjourn
192 ) ? $cpr->reasontext. ' by '. $cpr->otaker : '' ), '',
193 'align' => 'right', 'color' => 'FF9900', 'size' => '-2',
197 % unless ( $cust_pkg->get('setup') ) {
198 <% pkg_status_row_colspan('Never billed') %>
200 <% pkg_status_row($cust_pkg, 'Setup', 'setup', conf=>$conf ) %>
203 <% pkg_status_row_changed( $cust_pkg, conf=>$conf ) %>
204 <% pkg_status_row_if( $cust_pkg, $last_bill_or_renewed, 'last_bill', conf=>$conf ) %>
205 % # pkg_status_row($cust_pkg, 'Next bill', 'bill', conf=>$conf)
206 <% pkg_status_row_if( $cust_pkg, 'Expires', 'expire', conf=>$conf ) %>
209 <TD COLSPAN=<%$colspan%>>
211 % if ( $curuser->access_right('Unsuspend customer package') ) {
212 ( <% pkg_unsuspend_link($cust_pkg) %> )
214 % if ( $curuser->access_right('Cancel customer package immediately') ) {
215 ( <% pkg_cancel_link($cust_pkg) %> )
221 % } else { #status: active
223 % unless ( $cust_pkg->get('setup') ) { #not setup
225 % unless ( $part_pkg->freq ) {
227 <% pkg_status_row_colspan('Not yet billed (one-time charge)') %>
230 <TD COLSPAN=<%$colspan%>>
232 % if ( $curuser->access_right('Cancel customer package immediately') ) {
233 ( <% pkg_cancel_link($cust_pkg) %> )
241 <% pkg_status_row_colspan("Not yet billed ($billed_or_prepaid ". myfreq($part_pkg). ')' ) %>
247 % unless ( $part_pkg->freq ) {
249 <% pkg_status_row_colspan('One-time charge') %>
251 <% pkg_status_row($cust_pkg, 'Billed', 'setup', conf=>$conf) %>
255 % if (scalar($cust_pkg->overlimit)) {
257 <% pkg_status_row_colspan(
259 $billed_or_prepaid. ' '. myfreq($part_pkg),
265 <% pkg_status_row_colspan(
267 $billed_or_prepaid. ' '. myfreq($part_pkg),
273 <% pkg_status_row($cust_pkg, 'Setup', 'setup', conf=>$conf) %>
279 <% pkg_status_row_changed( $cust_pkg, conf=>$conf ) %>
280 <% pkg_status_row_if( $cust_pkg, $last_bill_or_renewed, 'last_bill', conf=>$conf ) %>
281 <% pkg_status_row_if( $cust_pkg, $next_bill_or_prepaid_until, 'bill', conf=>$conf ) %>
282 <% pkg_status_row_if( $cust_pkg, 'Will suspend on', 'adjourn', conf=>$conf ) %>
283 <% pkg_status_row_if( $cust_pkg, 'Expires', 'expire', conf=>$conf ) %>
285 % if ( $part_pkg->freq ) {
288 <TD COLSPAN=<%$colspan%>>
290 % if ( $curuser->access_right('Suspend customer package') ) {
291 ( <% pkg_suspend_link($cust_pkg) %> )
293 % if ( $curuser->access_right('Suspend customer package later') ) {
294 ( <% pkg_adjourn_link($cust_pkg) %> )
296 % if ( $curuser->access_right('Cancel customer package immediately') ) {
297 ( <% pkg_cancel_link($cust_pkg) %> )
299 % if ( $curuser->access_right('Cancel customer package later') ) {
300 ( <% pkg_expire_link($cust_pkg) %> )
314 <TD CLASS="inv" BGCOLOR="<% $bgcolor %>">
315 <TABLE CLASS="inv" BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH="100%">
317 % #foreach my $svcpart (sort {$a->{svcpart} <=> $b->{svcpart}} @{$pkg->{svcparts}}) {
318 % foreach my $part_svc ( $cust_pkg->part_svc ) {
320 % #foreach my $service (@{$svcpart->{services}}) {
321 % foreach my $cust_svc ( @{ $part_svc->cust_pkg_svc } ) {
324 <TD ALIGN="right" VALIGN="top"><% FS::UI::Web::svc_link($m, $part_svc, $cust_svc) %></TD>
325 <TD STYLE="padding-bottom:0px"><B><% FS::UI::Web::svc_label_link($m, $part_svc, $cust_svc) %></B></TD>
326 <TD><% FS::UI::Web::svc_export_links($m, $part_svc, $cust_svc) %></TD>
330 <TD ALIGN="right" COLSPAN="3" VALIGN="top" STYLE="padding-bottom:1px;padding-top:0px"><FONT SIZE="-2" COLOR="#FFD000">
332 <% $cust_svc->overlimit ? "Overlimit: ". time2str('%b %o %Y' . ($conf->exists('cust_pkg-display_times') ? ' %l:%M %P' : ''), $cust_svc->overlimit) : '' %>
337 <TD ALIGN="right" VALIGN="top" STYLE="padding-bottom:5px;padding-top:0px"><FONT SIZE="-2">
339 % if ( $curuser->access_right('Recharge customer service')
340 % && $part_svc->svcdb eq 'svc_acct'
341 % && ( $cust_svc->svc_x->seconds ne ''
342 % || $cust_svc->svc_x->upbytes ne ''
343 % || $cust_svc->svc_x->downbytes ne ''
344 % || $cust_svc->svc_x->totalbytes ne ''
347 ( <%svc_recharge_link($cust_svc)%> )
351 <TD ALIGN="right" VALIGN="top" STYLE="padding-bottom:5px;padding-top:0px"><FONT SIZE="-2">
353 % if ( $curuser->access_right('Unprovision customer service') ) {
354 ( <%svc_unprovision_link($cust_svc)%> )
360 % if ( ! $cust_pkg->get('cancel')
361 % && $curuser->access_right('Provision customer service')
362 % && $part_svc->num_avail
366 <TD COLSPAN=3 ALIGN="center" STYLE="padding-bottom:4px;padding-top:0px">
367 <B><% svc_provision_link($cust_pkg, $part_svc, $conf, $curuser) %></B>
377 % } #end display packages
386 % if ( $cgi->param('fragment') =~ /^cust_pkg(\d+)$/ ) {
388 // IE-specific hack. other browsers listen to #fragments
389 // is this even working? or is the #target redirection just working cause
390 // we set the URL params differently?
391 var el = document.getElementById( 'cust_pkg<% $1 %>' );
392 if ( el ) el.scrollIntoView(true);
397 my( $cust_main ) = @_;
398 my $conf = new FS::Conf;
400 my $curuser = $FS::CurrentUser::CurrentUser;
402 my $packages = get_packages($cust_main, $conf);
404 my $colspan = $conf->exists('cust_pkg-display_times') ? 8 : 4;
405 my $width = $conf->exists('cust_pkg-display_times') ? '38%' : '56%';
408 my( $cust_pkg, $title, $field, %opt ) = @_;
410 my $color = $opt{'color'};
412 my $html = qq(<TR><TD WIDTH="<%$width%>" ALIGN="right">);
413 $html .= qq(<FONT COLOR="#$color"><B>) if length($color);
414 $html .= qq($title );
415 $html .= qq(</B></FONT>) if length($color);
417 $html .= pkg_datestr($cust_pkg, $field, $opt{conf}).'</TR>';
422 sub pkg_status_row_if {
423 my( $cust_pkg, $title, $field, %opt ) = @_;
424 $cust_pkg->get($field) ? pkg_status_row(@_) : '';
427 sub pkg_status_row_changed {
428 my( $cust_pkg, %opt ) = @_;
429 return '' unless $cust_pkg->change_date;
430 my $html = pkg_status_row( $cust_pkg, 'Package changed', 'change_date', conf=>$opt{'conf'} );
431 my $old = $cust_pkg->old_cust_pkg;
433 my $part_pkg = $old->part_pkg;
434 my $label = 'Changed from '. $cust_pkg->change_pkgnum. ': '.
435 $part_pkg->pkg. ' - '. $part_pkg->comment;
436 $html .= pkg_status_row_colspan( $label, '', size=>'-1', align=>'right' );
441 sub pkg_status_row_colspan {
442 my($title, $addl, %opt) = @_;
444 my $align = $opt{'align'} ? 'ALIGN="'. $opt{'align'}.'"' : '';
445 my $color = $opt{'color'} ? 'COLOR="#'.$opt{'color'}.'"' : '';
446 my $size = $opt{'size'} ? 'SIZE="'. $opt{'size'}. '"' : '';
448 my $html = qq(<TR><TD COLSPAN=$colspan $align>);
449 $html .= qq(<FONT $color $size>) if length($color) || $size;
450 $html .= qq(<B>) if $color && !$size;
452 $html .= qq(</B>) if $color && !$size;
453 $html .= qq(</FONT>) if length($color) || $size;
454 $html .= ", $addl" if length($addl);
455 $html .= qq(</TD></TR>);
464 my $cust_main = shift or return undef;
469 if ( $cgi->param('showcancelledpackages') eq '0' #see if it was set by me
470 || ( $conf->exists('hidecancelledpackages')
471 && ! $cgi->param('showcancelledpackages') )
474 $method = 'ncancelled_pkgs';
476 $method = 'all_pkgs';
479 [ $cust_main->$method() ];
482 sub svc_provision_link {
483 my ($cust_pkg, $part_svc, $conf, $curuser) = @_;
484 ( my $svc_nbsp = $part_svc->svc ) =~ s/\s+/ /g;
485 my $num_avail = $part_svc->num_avail;
486 my $pkgnum_svcpart = "pkgnum=". $cust_pkg->pkgnum. ';'.
487 "svcpart=". $part_svc->svcpart;
489 if ( $part_svc->svcdb eq 'svc_external' #could be generalized
490 && $conf->exists('svc_external-skip_manual')
492 $url = "${p}edit/process/". $part_svc->svcdb. ".cgi?$pkgnum_svcpart";
497 'part_svc' => $part_svc,
498 'query' => $pkgnum_svcpart,
500 #$url = "${p}edit/$svcpart->{svcdb}.cgi?$pkgnum_svcpart";
503 my $link = qq!<A CLASS="provision" HREF="$url">!.
504 "Provision $svc_nbsp ($num_avail)</A>";
505 if ( $conf->exists('legacy_link')
506 && $curuser->access_right('View/link unlinked services')
510 qq!<A CLASS="provision" HREF="${p}misc/link.cgi?!.
511 qq!$pkgnum_svcpart">!.
512 "Link to legacy $svc_nbsp ($num_avail)</A>";
517 sub svc_unprovision_link {
518 my $cust_svc = shift or return '';
519 qq!<A HREF="javascript:areyousure('${p}misc/unprovision.cgi?!. $cust_svc->svcnum.
520 qq!', 'Permanently unprovision and delete this service?')">Unprovision</A>!;
524 my($cust_pkg, $field, $conf) = @_ or return '';
525 return ' ' unless $cust_pkg->get($field);
526 my $format = '<TD align="left"><B>%b</B></TD>'.
527 '<TD align="right"><B> %o,</B></TD>'.
528 '<TD align="right"><B> %Y</B></TD>';
529 #$format .= ' <FONT SIZE=-3>%l:%M:%S%P %z</FONT>'
530 $format .= '<TD ALIGN="right"><B> %l</TD>'.
531 '<TD ALIGN="center"><B>:</B></TD>'.
532 '<TD ALIGN="left"><B>%M</B></TD>'.
533 '<TD ALIGN="left"><B> %P</B></TD>'
534 if $conf->exists('cust_pkg-display_times');
535 my $strip = time2str($format, $cust_pkg->get($field) );
536 $strip =~ s/ (\d)/$1/g;
540 sub pkg_change_link { include( '/elements/popup_link-cust_pkg.html',
541 { 'action' => $p. 'misc/change_pkg.cgi?dummy=value',
542 'label' => 'Change package',
543 'actionlabel' => 'Change',
549 sub pkg_suspend_link { include( '/elements/popup_link-cust_pkg.html',
550 { 'action' => $p. 'misc/cancel_pkg.html?method=suspend',
551 'label' => 'Suspend now',
552 'actionlabel' => 'Suspend',
553 'color' => '#FF9900',
560 sub pkg_adjourn_link { include( '/elements/popup_link-cust_pkg.html',
561 { 'action' => $p. 'misc/cancel_pkg.html?method=adjourn',
562 'label' => 'Suspend later',
563 'actionlabel' => 'Adjourn',
564 'color' => '#CC6600',
570 sub pkg_unsuspend_link { pkg_link('misc/unsusp_pkg', 'Unsuspend', @_ ); }
571 sub pkg_dates_link { pkg_link('edit/REAL_cust_pkg', 'Edit dates', @_ ); }
573 sub pkg_cancel_link { include( '/elements/popup_link-cust_pkg.html',
574 { 'action' => $p. 'misc/cancel_pkg.html?method=cancel',
575 'label' => 'Cancel now',
576 'actionlabel' => 'Cancel',
577 'color' => '#ff0000',
583 sub pkg_expire_link { include( '/elements/popup_link-cust_pkg.html',
584 { 'action' => $p. 'misc/cancel_pkg.html?method=expire',
585 'label' => 'Cancel later',
586 'actionlabel' => 'Expire', #"Cancel package $num later"
587 'color' => '#CC0000',
593 sub svc_recharge_link { include( '/elements/popup_link-cust_svc.html',
594 { 'action' => $p. 'misc/recharge_svc.html',
595 'label' => 'Recharge',
596 'actionlabel' => 'Recharge',
597 'color' => '#333399',
603 sub order_pkg_link { include( '/elements/popup_link-cust_main.html',
604 { 'action' => $p. 'misc/order_pkg.html',
605 'label' => 'Order new package',
606 'actionlabel' => 'Order new package',
607 'color' => '#333399',
608 'cust_main' => shift,
609 'closetext' => 'Close',
616 qq!<a href="${p}search/cust_event.html?pkgnum=!. $cust_pkg->pkgnum. qq!">!.
617 'View package events'.
622 my($action, $label, $cust_pkg) = @_;
623 return '' unless $cust_pkg;
624 qq!<a href="$p$action.cgi?!. $cust_pkg->pkgnum. qq!">$label</a>!;
627 sub pkg_customize_link {
628 my $cust_pkg = shift or return '';
629 my $custnum = $cust_pkg->custnum;
630 qq!<A HREF="${p}edit/part_pkg.cgi?!.
631 "clone=". $cust_pkg->part_pkg->pkgpart. ';'.
632 "pkgnum=". $cust_pkg->pkgnum.