1 <A NAME="cust_pkg"><FONT SIZE="+2">Packages</FONT></A>
2 % if ( $curuser->access_right('Order customer package') ) {
4 <% include('order_pkg.html', $cust_main ) %>
6 % if ( $curuser->access_right('One-time charge')
7 % && $conf->config('payby-default') ne 'HIDE'
11 <% include('/elements/popup_link.html',
13 'action' => $p. 'edit/quick-charge.html?custnum='. $cust_main->custnum,
14 'label' => 'One-time charge',
15 'actionlabel' => 'One-time charge',
21 % if ( $curuser->access_right('Bulk change customer packages') ) {
23 <A HREF="<% $p %>edit/cust_pkg.cgi?<% $cust_main->custnum %>">Bulk order and cancel packages</A> (preserves services)
32 % if ( $cust_main->num_cancelled_pkgs ) {
33 % if ( $cgi->param('showcancelledpackages') eq '0' #see if it was set by me
34 % || ( $conf->exists('hidecancelledpackages')
35 % && ! $cgi->param('showcancelledpackages')
39 % $cgi->param('showcancelledpackages', 1);
42 ( <a href="<% $cgi->self_url %>">show
44 % $cgi->param('showcancelledpackages', 0);
47 ( <a href="<% $cgi->self_url %>">hide
50 cancelled packages</a> )
55 <% include('/elements/table-grid.html') %>
56 % my $bgcolor1 = '#eeeeee';
57 % my $bgcolor2 = '#ffffff';
61 <TH CLASS="grid" BGCOLOR="#cccccc">Package</TH>
62 <TH CLASS="grid" BGCOLOR="#cccccc">Status</TH>
63 <TH CLASS="grid" BGCOLOR="#cccccc">Services</TH>
66 %foreach my $cust_pkg (@$packages) {
68 % my $part_pkg = $cust_pkg->part_pkg;
70 % if ( $bgcolor eq $bgcolor1 ) {
71 % $bgcolor = $bgcolor2;
73 % $bgcolor = $bgcolor1;
77 <!--pkgnum: <% $cust_pkg->pkgnum %>-->
79 <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
80 <A NAME="cust_pkg<% $cust_pkg->pkgnum %>"><% $cust_pkg->pkgnum %></A>:
81 <% $part_pkg->pkg %> - <% $part_pkg->comment %>
84 % if ( $cust_pkg->quantity > 1 ) {
85 Quantity: <B><% $cust_pkg->quantity %></B><BR>
89 % unless ( $cust_pkg->get('cancel') ) {
90 % if ( $curuser->access_right('Change customer package') ) {
92 ( <%pkg_change_link($cust_pkg)%> )
94 % if ( $curuser->access_right('Edit customer package dates') ) {
96 ( <%pkg_dates_link($cust_pkg)%> )
98 % if ( $curuser->access_right('Customize customer package') ) {
100 ( <%pkg_customize_link($cust_pkg,$cust_main->custnum)%> )
106 <TD CLASS="inv" BGCOLOR="<% $bgcolor %>">
107 <TABLE CLASS="inv" BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH="100%">
110 % my $part_pkg = shift;
111 % my $freq = $part_pkg->freq_pretty;
112 % $freq =~ s/ / /g;
116 % #this should use cust_pkg->status and cust_pkg->statuscolor eventually
117 % #my $colspan = $conf->exists('cust_pkg-display_times') ? 8 : 4;
118 % #my $width = $conf->exists('cust_pkg-display_times') ? '38%' : '56%';
120 % #false laziness w/edit/REAL_cust_pkg.cgi
121 % my( $billed_or_prepaid, $last_bill_or_renewed, $next_bill_or_prepaid_until );
122 % unless ( $part_pkg->is_prepaid ) {
123 % $billed_or_prepaid = 'billed';
124 % $last_bill_or_renewed = 'Last bill';
125 % $next_bill_or_prepaid_until = 'Next bill';
127 % $billed_or_prepaid = 'prepaid';
128 % $last_bill_or_renewed = 'Renewed';
129 % $next_bill_or_prepaid_until = 'Prepaid until';
133 % if ( $cust_pkg->get('cancel') ) { #status: cancelled
134 % my $cpr = $cust_pkg->last_cust_pkg_reason;
136 <% pkg_status_row($cust_pkg, 'Cancelled', 'cancel', 'color'=>'FF0000', conf=>$conf ) %>
138 <% pkg_status_row_colspan(
139 ( ( $cpr && ( $cpr->date == $cust_pkg->get('cancel') ||
140 $cpr->date == $cust_pkg->expire
142 ) ? $cpr->reasontext. ' by '. $cpr->otaker : '' ), '',
143 'align' => 'right', 'color' => 'ff0000', 'size' => '-2',
147 % unless ( $cust_pkg->get('setup') ) {
149 <% pkg_status_row_colspan('Never billed') %>
153 <% pkg_status_row( $cust_pkg, 'Setup', 'setup', conf=>$conf ) %>
154 <% pkg_status_row_changed( $cust_pkg, conf=>$conf ) %>
155 <% pkg_status_row_if( $cust_pkg, $last_bill_or_renewed, 'last_bill', conf=>$conf ) %>
156 <% pkg_status_row_if( $cust_pkg, 'Suspended', 'susp', conf=>$conf ) %>
162 % if ( $cust_pkg->get('susp') ) { #status: suspended
163 % my $cpr = $cust_pkg->last_cust_pkg_reason;
165 <% pkg_status_row( $cust_pkg, 'Suspended', 'susp', 'color'=>'FF9900', conf=>$conf ) %>
167 <% pkg_status_row_colspan(
168 ( ( $cpr && ( $cpr->date == $cust_pkg->susp ||
169 $cpr->date == $cust_pkg->adjourn
171 ) ? $cpr->reasontext. ' by '. $cpr->otaker : '' ), '',
172 'align' => 'right', 'color' => 'FF9900', 'size' => '-2',
176 % unless ( $cust_pkg->get('setup') ) {
177 <% pkg_status_row_colspan('Never billed') %>
179 <% pkg_status_row($cust_pkg, 'Setup', 'setup', conf=>$conf ) %>
182 <% pkg_status_row_changed( $cust_pkg, conf=>$conf ) %>
183 <% pkg_status_row_if( $cust_pkg, $last_bill_or_renewed, 'last_bill', conf=>$conf ) %>
184 % # pkg_status_row($cust_pkg, 'Next bill', 'bill', conf=>$conf)
185 <% pkg_status_row_if( $cust_pkg, 'Expires', 'expire', conf=>$conf ) %>
188 <TD COLSPAN=<%$colspan%>>
190 % if ( $curuser->access_right('Unsuspend customer package') ) {
191 ( <% pkg_unsuspend_link($cust_pkg) %> )
193 % if ( $curuser->access_right('Cancel customer package immediately') ) {
194 ( <% pkg_cancel_link($cust_pkg) %> )
200 % } else { #status: active
202 % unless ( $cust_pkg->get('setup') ) { #not setup
204 % unless ( $part_pkg->freq ) {
206 <% pkg_status_row_colspan('Not yet billed (one-time charge)') %>
209 <TD COLSPAN=<%$colspan%>>
211 % if ( $curuser->access_right('Cancel customer package immediately') ) {
212 ( <% pkg_cancel_link($cust_pkg) %> )
220 <% pkg_status_row_colspan("Not yet billed ($billed_or_prepaid ". myfreq($part_pkg). ')' ) %>
226 % unless ( $part_pkg->freq ) {
228 <% pkg_status_row_colspan('One-time charge') %>
230 <% pkg_status_row($cust_pkg, 'Billed', 'setup', conf=>$conf) %>
234 % if (scalar($cust_pkg->overlimit)) {
236 <% pkg_status_row_colspan(
238 $billed_or_prepaid. ' '. myfreq($part_pkg),
244 <% pkg_status_row_colspan(
246 $billed_or_prepaid. ' '. myfreq($part_pkg),
252 <% pkg_status_row($cust_pkg, 'Setup', 'setup', conf=>$conf) %>
258 <% pkg_status_row_changed( $cust_pkg, conf=>$conf ) %>
259 <% pkg_status_row_if( $cust_pkg, $last_bill_or_renewed, 'last_bill', conf=>$conf ) %>
260 <% pkg_status_row_if( $cust_pkg, $next_bill_or_prepaid_until, 'bill', conf=>$conf ) %>
261 <% pkg_status_row_if( $cust_pkg, 'Will suspend on', 'adjourn', conf=>$conf ) %>
262 <% pkg_status_row_if( $cust_pkg, 'Expires', 'expire', conf=>$conf ) %>
264 % if ( $part_pkg->freq ) {
267 <TD COLSPAN=<%$colspan%>>
269 % if ( $curuser->access_right('Suspend customer package') ) {
270 ( <% pkg_suspend_link($cust_pkg) %> )
272 % if ( $curuser->access_right('Suspend customer package later') ) {
273 ( <% pkg_adjourn_link($cust_pkg) %> )
275 % if ( $curuser->access_right('Cancel customer package immediately') ) {
276 ( <% pkg_cancel_link($cust_pkg) %> )
278 % if ( $curuser->access_right('Cancel customer package later') ) {
279 ( <% pkg_expire_link($cust_pkg) %> )
293 <TD CLASS="inv" BGCOLOR="<% $bgcolor %>">
294 <TABLE CLASS="inv" BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH="100%">
296 % #foreach my $svcpart (sort {$a->{svcpart} <=> $b->{svcpart}} @{$pkg->{svcparts}}) {
297 % foreach my $part_svc ( $cust_pkg->part_svc ) {
299 % #foreach my $service (@{$svcpart->{services}}) {
300 % foreach my $cust_svc ( @{ $part_svc->cust_pkg_svc } ) {
303 <TD ALIGN="right" VALIGN="top"><% FS::UI::Web::svc_link($m, $part_svc, $cust_svc) %></TD>
304 <TD STYLE="padding-bottom:0px"><B><% FS::UI::Web::svc_label_link($m, $part_svc, $cust_svc) %></B></TD>
305 <TD><% FS::UI::Web::svc_export_links($m, $part_svc, $cust_svc) %></TD>
309 <TD ALIGN="right" COLSPAN="3" VALIGN="top" STYLE="padding-bottom:1px;padding-top:0px"><FONT SIZE="-2" COLOR="#FFD000">
311 <% $cust_svc->overlimit ? "Overlimit: ". time2str('%b %o %Y' . ($conf->exists('cust_pkg-display_times') ? ' %l:%M %P' : ''), $cust_svc->overlimit) : '' %>
316 <TD ALIGN="right" VALIGN="top" STYLE="padding-bottom:5px;padding-top:0px"><FONT SIZE="-2">
318 % if ( $curuser->access_right('Recharge customer service')
319 % && $part_svc->svcdb eq 'svc_acct'
320 % && ( $cust_svc->svc_x->seconds ne ''
321 % || $cust_svc->svc_x->upbytes ne ''
322 % || $cust_svc->svc_x->downbytes ne ''
323 % || $cust_svc->svc_x->totalbytes ne ''
326 ( <%svc_recharge_link($cust_svc)%> )
330 <TD ALIGN="right" VALIGN="top" STYLE="padding-bottom:5px;padding-top:0px"><FONT SIZE="-2">
332 % if ( $curuser->access_right('Unprovision customer service') ) {
333 ( <%svc_unprovision_link($cust_svc)%> )
339 % if ( ! $cust_pkg->get('cancel')
340 % && $curuser->access_right('Provision customer service')
341 % && $part_svc->num_avail
345 <TD COLSPAN=3 ALIGN="center" STYLE="padding-bottom:4px;padding-top:0px">
346 <B><% svc_provision_link($cust_pkg, $part_svc, $conf, $curuser) %></B>
356 % } #end display packages
367 my( $cust_main ) = @_;
368 my $conf = new FS::Conf;
370 my $curuser = $FS::CurrentUser::CurrentUser;
372 my $packages = get_packages($cust_main, $conf);
374 my $colspan = $conf->exists('cust_pkg-display_times') ? 8 : 4;
375 my $width = $conf->exists('cust_pkg-display_times') ? '38%' : '56%';
378 my( $cust_pkg, $title, $field, %opt ) = @_;
380 my $color = $opt{'color'};
382 my $html = qq(<TR><TD WIDTH="<%$width%>" ALIGN="right">);
383 $html .= qq(<FONT COLOR="#$color"><B>) if length($color);
384 $html .= qq($title );
385 $html .= qq(</B></FONT>) if length($color);
387 $html .= pkg_datestr($cust_pkg, $field, $opt{conf}).'</TR>';
392 sub pkg_status_row_if {
393 my( $cust_pkg, $title, $field, %opt ) = @_;
394 $cust_pkg->get($field) ? pkg_status_row(@_) : '';
397 sub pkg_status_row_changed {
398 my( $cust_pkg, %opt ) = @_;
399 return '' unless $cust_pkg->change_date;
400 my $html = pkg_status_row( $cust_pkg, 'Package changed', 'change_date', conf=>$opt{'conf'} );
401 my $old = $cust_pkg->old_cust_pkg;
403 my $part_pkg = $old->part_pkg;
404 my $label = 'Changed from '. $cust_pkg->change_pkgnum. ': '.
405 $part_pkg->pkg. ' - '. $part_pkg->comment;
406 $html .= pkg_status_row_colspan( $label, '', size=>'-1', align=>'right' );
411 sub pkg_status_row_colspan {
412 my($title, $addl, %opt) = @_;
414 my $align = $opt{'align'} ? 'ALIGN="'. $opt{'align'}.'"' : '';
415 my $color = $opt{'color'} ? 'COLOR="#'.$opt{'color'}.'"' : '';
416 my $size = $opt{'size'} ? 'SIZE="'. $opt{'size'}. '"' : '';
418 my $html = qq(<TR><TD COLSPAN=$colspan $align>);
419 $html .= qq(<FONT $color $size>) if length($color) || $size;
420 $html .= qq(<B>) if $color && !$size;
422 $html .= qq(</B>) if $color && !$size;
423 $html .= qq(</FONT>) if length($color) || $size;
424 $html .= ", $addl" if length($addl);
425 $html .= qq(</TD></TR>);
434 my $cust_main = shift or return undef;
439 if ( $cgi->param('showcancelledpackages') eq '0' #see if it was set by me
440 || ( $conf->exists('hidecancelledpackages')
441 && ! $cgi->param('showcancelledpackages') )
444 $method = 'ncancelled_pkgs';
446 $method = 'all_pkgs';
449 [ $cust_main->$method() ];
452 sub svc_provision_link {
453 my ($cust_pkg, $part_svc, $conf, $curuser) = @_;
454 ( my $svc_nbsp = $part_svc->svc ) =~ s/\s+/ /g;
455 my $num_avail = $part_svc->num_avail;
456 my $pkgnum_svcpart = "pkgnum=". $cust_pkg->pkgnum. ';'.
457 "svcpart=". $part_svc->svcpart;
459 if ( $part_svc->svcdb eq 'svc_external' #could be generalized
460 && $conf->exists('svc_external-skip_manual')
462 $url = "${p}edit/process/". $part_svc->svcdb. ".cgi?$pkgnum_svcpart";
467 'part_svc' => $part_svc,
468 'query' => $pkgnum_svcpart,
470 #$url = "${p}edit/$svcpart->{svcdb}.cgi?$pkgnum_svcpart";
473 my $link = qq!<A CLASS="provision" HREF="$url">!.
474 "Provision $svc_nbsp ($num_avail)</A>";
475 if ( $conf->exists('legacy_link')
476 && $curuser->access_right('View/link unlinked services')
480 qq!<A CLASS="provision" HREF="${p}misc/link.cgi?!.
481 qq!$pkgnum_svcpart">!.
482 "Link to legacy $svc_nbsp ($num_avail)</A>";
487 sub svc_unprovision_link {
488 my $cust_svc = shift or return '';
489 qq!<A HREF="javascript:areyousure('${p}misc/unprovision.cgi?!. $cust_svc->svcnum.
490 qq!', 'Permanently unprovision and delete this service?')">Unprovision</A>!;
494 my($cust_pkg, $field, $conf) = @_ or return '';
495 return ' ' unless $cust_pkg->get($field);
496 my $format = '<TD align="left"><B>%b</B></TD>'.
497 '<TD align="right"><B> %o,</B></TD>'.
498 '<TD align="right"><B> %Y</B></TD>';
499 #$format .= ' <FONT SIZE=-3>%l:%M:%S%P %z</FONT>'
500 $format .= '<TD ALIGN="right"><B> %l</TD>'.
501 '<TD ALIGN="center"><B>:</B></TD>'.
502 '<TD ALIGN="left"><B>%M</B></TD>'.
503 '<TD ALIGN="left"><B> %P</B></TD>'
504 if $conf->exists('cust_pkg-display_times');
505 my $strip = time2str($format, $cust_pkg->get($field) );
506 $strip =~ s/ (\d)/$1/g;
510 sub pkg_change_link { include( '/elements/popup_link-cust_pkg.html',
511 { 'action' => $p. 'misc/change_pkg.cgi?dummy=value',
512 'label' => 'Change package',
513 'actionlabel' => 'Change',
519 sub pkg_suspend_link { include( '/elements/popup_link-cust_pkg.html',
520 { 'action' => $p. 'misc/cancel_pkg.html?method=suspend',
521 'label' => 'Suspend now',
522 'actionlabel' => 'Suspend',
528 sub pkg_unsuspend_link { pkg_link('misc/unsusp_pkg', 'Unsuspend', @_ ); }
529 sub pkg_expire_link { pkg_link('misc/expire_pkg', 'Cancel later', @_ ); }
530 sub pkg_dates_link { pkg_link('edit/REAL_cust_pkg', 'Edit dates', @_ ); }
532 sub pkg_cancel_link { include( '/elements/popup_link-cust_pkg.html',
533 { 'action' => $p. 'misc/cancel_pkg.html?method=cancel',
534 'label' => 'Cancel now',
535 'actionlabel' => 'Cancel',
541 sub pkg_adjourn_link { include( '/elements/popup_link-cust_pkg.html',
542 { 'action' => $p. 'misc/cancel_pkg.html?method=adjourn',
543 'label' => 'Suspend later',
544 'actionlabel' => 'Adjourn',
550 sub pkg_expire_link { include( '/elements/popup_link-cust_pkg.html',
551 { 'action' => $p. 'misc/cancel_pkg.html?method=expire',
552 'label' => 'Cancel later',
553 'actionlabel' => 'Expire',
559 sub svc_recharge_link { include( '/elements/popup_link-cust_svc.html',
560 { 'action' => $p. 'misc/recharge_svc.html',
561 'label' => 'Recharge',
562 'actionlabel' => 'Recharge',
569 my($action, $label, $cust_pkg) = @_;
570 return '' unless $cust_pkg;
571 qq!<a href="$p$action.cgi?!. $cust_pkg->pkgnum. qq!">$label</a>!;
574 sub pkg_customize_link {
575 my $cust_pkg = shift or return '';
576 my $custnum = $cust_pkg->custnum;
577 qq!<A HREF="${p}edit/part_pkg.cgi?!.
578 "keywords=$custnum;".
579 "clone=". $cust_pkg->part_pkg->pkgpart. ';'.
580 "pkgnum=". $cust_pkg->pkgnum.