1 <TD CLASS="inv" BGCOLOR="<% $bgcolor %>">
2 <TABLE CLASS="inv" BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH="100%">
4 %#this should use cust_pkg->status and cust_pkg->statuscolor eventually
6 % if ( $cust_pkg->order_date ) {
7 <% pkg_status_row($cust_pkg, emt('Ordered'), 'order_date', %opt ) %>
10 % if ( $cust_pkg->get('cancel') ) { #status: cancelled
11 % my $cpr = $cust_pkg->last_cust_pkg_reason('cancel');
13 <% pkg_status_row($cust_pkg, emt('Cancelled'), 'cancel', 'color'=>'FF0000', %opt ) %>
15 <% pkg_status_row_colspan( $cust_pkg,
16 ( $cpr ? $cpr->reasontext. ' by '. $cpr->otaker : '' ), '',
17 'align'=>'right', 'color'=>'ff0000', 'size'=>'-2', 'colspan'=>$colspan,
22 % unless ( $cust_pkg->get('setup') ) {
24 <% pkg_status_row_colspan( $cust_pkg, emt('Never billed'), '', 'colspan'=>$colspan, %opt, ) %>
28 <% pkg_status_row( $cust_pkg, emt('Setup'), 'setup', %opt ) %>
29 <% pkg_status_row_changed( $cust_pkg, %opt, 'colspan'=>$colspan ) %>
30 <% pkg_status_row_if( $cust_pkg, $last_bill_or_renewed, 'last_bill', %opt, curuser=>$curuser ) %>
31 <% pkg_status_row_if( $cust_pkg, emt('Suspended'), 'susp', %opt, curuser=>$curuser ) %>
35 % if ( $part_pkg->freq ) { #?
38 <TD COLSPAN=<%$colspan%>>
40 % if ( $curuser->access_right('Un-cancel customer package') ) {
41 ( <% pkg_uncancel_link($cust_pkg) %> )
50 % if ( $cust_pkg->get('susp') ) { #status: suspended
51 % my $cpr = $cust_pkg->last_cust_pkg_reason('susp');
53 <% pkg_status_row( $cust_pkg, emt('Suspended'), 'susp', 'color'=>'FF9900', %opt ) %>
55 <% pkg_status_row_colspan( $cust_pkg,
56 ( $cpr ? $cpr->reasontext. ' by '. $cpr->otaker : '' ), '',
57 'align'=>'right', 'color'=>'FF9900', 'size'=>'-2', 'colspan'=>$colspan,
62 <% pkg_status_row_noauto( $cust_pkg, %opt, 'colspan'=>$colspan ) %>
64 <% pkg_status_row_discount( $cust_pkg, %opt, 'colspan'=>$colspan ) %>
66 % unless ( $cust_pkg->get('setup') ) {
67 <% pkg_status_row_colspan( $cust_pkg, emt('Never billed'), '', 'colspan'=>$colspan, %opt ) %>
69 <% pkg_status_row($cust_pkg, emt('Setup'), 'setup', %opt ) %>
72 <% pkg_status_row_if($cust_pkg, emt('Un-cancelled'), 'uncancel', %opt ) %>
74 <% pkg_status_row_changed( $cust_pkg, %opt, 'colspan'=>$colspan ) %>
75 <% pkg_status_row_if( $cust_pkg, $last_bill_or_renewed, 'last_bill', %opt, curuser=>$curuser ) %>
76 % if ( $cust_pkg->option('suspend_bill', 1)
77 % || ( $part_pkg->option('suspend_bill', 1)
78 % && ! $cust_pkg->option('no_suspend_bill',1)
82 <% pkg_status_row_if( $cust_pkg, emt('Next bill'), 'bill', %opt, curuser=>$curuser ) %>
84 <% pkg_status_row_if( $cust_pkg, emt('Will resume'), 'resume', %opt, curuser=>$curuser ) %>
85 <% pkg_status_row_if( $cust_pkg, emt('Expires'), 'expire', %opt, curuser=>$curuser ) %>
86 <% pkg_status_row_if( $cust_pkg, emt('Contract ends'), 'contract_end', %opt ) %>
89 <TD COLSPAN=<%$colspan%>>
91 % if ( $curuser->access_right('Unsuspend customer package') ) {
92 ( <% pkg_unsuspend_link($cust_pkg) %> )
93 ( <% pkg_resume_link($cust_pkg) %> )
95 % if ( $curuser->access_right('Cancel customer package immediately') ) {
96 ( <% pkg_cancel_link($cust_pkg) %> )
102 % } else { #status: active
104 % unless ( $cust_pkg->get('setup') ) { #not setup
106 % unless ( $part_pkg->freq ) {
108 <% pkg_status_row_colspan( $cust_pkg, emt('Not yet billed (one-time charge)'), '', 'colspan'=>$colspan, %opt ) %>
110 <% pkg_status_row_noauto( $cust_pkg, %opt, 'colspan'=>$colspan ) %>
112 <% pkg_status_row_discount( $cust_pkg, %opt, 'colspan'=>$colspan ) %>
114 <% pkg_status_row_if(
116 ( $part_pkg->freq ? emt('Start billing') : emt('Bill on') ),
122 <% pkg_status_row_if($cust_pkg, emt('Un-cancelled'), 'uncancel', %opt ) %>
125 <TD COLSPAN=<%$colspan%>>
127 % if ( $curuser->access_right('Cancel customer package immediately') ) {
128 ( <% pkg_cancel_link($cust_pkg) %> )
136 <% pkg_status_row_colspan($cust_pkg, emt("Not yet billed ($billed_or_prepaid [_1])", myfreq($part_pkg) ), '', 'colspan'=>$colspan, %opt ) %>
138 <% pkg_status_row_noauto( $cust_pkg, %opt, 'colspan'=>$colspan ) %>
140 <% pkg_status_row_discount( $cust_pkg, %opt, 'colspan'=>$colspan ) %>
142 <% pkg_status_row_if($cust_pkg, emt('Start billing'), 'start_date', %opt) %>
143 <% pkg_status_row_if($cust_pkg, emt('Un-cancelled'), 'uncancel', %opt ) %>
149 % unless ( $part_pkg->freq ) {
151 <% pkg_status_row_colspan($cust_pkg, emt('One-time charge'), '', 'colspan'=>$colspan, %opt ) %>
153 <% pkg_status_row($cust_pkg, emt('Billed'), 'setup', %opt) %>
155 <% pkg_status_row_noauto( $cust_pkg, %opt, 'colspan'=>$colspan ) %>
157 <% pkg_status_row_discount( $cust_pkg, %opt, 'colspan'=>$colspan ) %>
159 <% pkg_status_row_if($cust_pkg, emt('Un-cancelled'), 'uncancel', %opt ) %>
163 % my $num_cust_svc = $cust_pkg->num_cust_svc;
164 % my $summarize = $opt{'cust_pkg-large_pkg_size'} > 0
165 % && $opt{'cust_pkg-large_pkg_size'} <= $num_cust_svc;
167 % #overlimit process is expensive with many services, so skip w/summary
168 % if ( !$summarize && scalar($cust_pkg->overlimit) ) {
170 <% pkg_status_row_colspan( $cust_pkg,
172 $billed_or_prepaid. ' '. myfreq($part_pkg),
173 'color'=>'FFD000', 'colspan'=>$colspan,
179 <% pkg_status_row_colspan( $cust_pkg,
181 $billed_or_prepaid. ' '. myfreq($part_pkg),
182 'color'=>'00CC00', 'colspan'=>$colspan,
188 <% pkg_status_row_noauto( $cust_pkg, %opt, 'colspan'=>$colspan ) %>
190 <% pkg_status_row_discount( $cust_pkg, %opt, 'colspan'=>$colspan ) %>
192 <% pkg_status_row($cust_pkg, emt('Setup'), 'setup', %opt) %>
194 <% pkg_status_row_if($cust_pkg, emt('Un-cancelled'), 'uncancel', %opt ) %>
200 % if ( $opt{'cust_pkg-show_autosuspend'} ) {
201 % my $autosuspend = pkg_autosuspend_time( $cust_pkg );
202 % $cust_pkg->set('autosuspend', $autosuspend) if $autosuspend;
205 <% pkg_status_row_changed( $cust_pkg, %opt, 'colspan'=>$colspan ) %>
206 <% pkg_status_row_if( $cust_pkg, $last_bill_or_renewed, 'last_bill', %opt, curuser=>$curuser ) %>
207 <% pkg_status_row_if( $cust_pkg, $next_bill_or_prepaid_until, 'bill', %opt, curuser=>$curuser ) %>
208 <% pkg_status_row_if($cust_pkg, emt('Will automatically suspend by'), 'autosuspend', %opt) %>
209 <% pkg_status_row_if($cust_pkg, emt('Automatic suspension delayed until'), 'dundate', %opt) %>
210 <% pkg_status_row_if( $cust_pkg, emt('Will suspend on'), 'adjourn', %opt, curuser=>$curuser ) %>
211 <% pkg_status_row_if( $cust_pkg, emt('Will resume on'), 'resume', %opt, curuser=>$curuser ) %>
212 <% pkg_status_row_if( $cust_pkg, emt('Expires'), 'expire', %opt, curuser=>$curuser ) %>
213 <% pkg_status_row_if( $cust_pkg, emt('Contract ends'), 'contract_end', %opt ) %>
215 % if ( $part_pkg->freq ) {
218 <TD COLSPAN=<%$colspan%>>
220 % if ( $curuser->access_right('Suspend customer package') ) {
221 ( <% pkg_suspend_link($cust_pkg) %> )
223 % if ( $curuser->access_right('Suspend customer package later') ) {
224 ( <% pkg_adjourn_link($cust_pkg) %> )
226 % if ( $curuser->access_right('Delay suspension events') ) {
227 ( <% pkg_delay_link($cust_pkg) %> )
229 % if ( $curuser->access_right('Cancel customer package immediately') ) {
230 ( <% pkg_cancel_link($cust_pkg) %> )
232 % if ( $curuser->access_right('Cancel customer package later') ) {
233 ( <% pkg_expire_link($cust_pkg) %> )
250 my $bgcolor = $opt{'bgcolor'};
251 my $cust_pkg = $opt{'cust_pkg'};
252 my $part_pkg = $opt{'part_pkg'};
253 my $curuser = $FS::CurrentUser::CurrentUser;
254 my $colspan = $opt{'cust_pkg-display_times'} ? 8 : 4;
255 my $width = $opt{'cust_pkg-display_times'} ? '38%' : '56%';
257 #false laziness w/edit/REAL_cust_pkg.cgi
258 my( $billed_or_prepaid, $last_bill_or_renewed, $next_bill_or_prepaid_until );
259 unless ( $part_pkg->is_prepaid ) {
260 $billed_or_prepaid = 'billed';
261 $last_bill_or_renewed = 'Last bill';
262 $next_bill_or_prepaid_until = 'Next bill';
264 $billed_or_prepaid = 'prepaid';
265 $last_bill_or_renewed = 'Renewed';
266 $next_bill_or_prepaid_until = 'Prepaid until';
272 my $part_pkg = shift;
273 my $freq = $part_pkg->freq_pretty;
274 #$freq =~ s/ / /g;
278 #false laziness w/package.html
280 my($action, $label, $cust_pkg) = @_;
281 return '' unless $cust_pkg;
282 qq!<a href="$p$action.cgi?!. $cust_pkg->pkgnum. qq!">$label</a>!;
286 my( $cust_pkg, $title, $field, %opt ) = @_;
288 my $color = $opt{'color'};
290 my $html = qq(<TR><TD WIDTH="<%$width%>" ALIGN="right">);
291 $html .= qq(<FONT COLOR="#$color"><B>) if length($color);
292 $html .= qq($title );
293 $html .= qq(</B></FONT>) if length($color);
295 if ( $opt{'pkg_balances'} && ! $cust_pkg->{_printed_balance}++ ) { #kludge
296 $html .= ' (Balance: <B>'. $opt{'money_char'}.
297 $cust_pkg->cust_main->balance_pkgnum($cust_pkg->pkgnum).
302 $html .= pkg_datestr($cust_pkg, $field, %opt). '</TR>';
307 sub pkg_status_row_if {
308 my( $cust_pkg, $title, $field, %opt ) = @_;
310 $title = '<FONT SIZE=-1>( '. pkg_unadjourn_link($cust_pkg). ' ) </FONT>'. $title
311 if ( $field eq 'adjourn' &&
312 $opt{curuser}->access_right('Suspend customer package later')
315 $title = '<FONT SIZE=-1>( '. pkg_unexpire_link($cust_pkg). ' ) </FONT>'. $title
316 if ( $field eq 'expire' &&
317 $opt{curuser}->access_right('Cancel customer package later')
320 $cust_pkg->get($field) ? pkg_status_row($cust_pkg, $title, $field, %opt) : '';
323 sub pkg_status_row_changed {
324 my( $cust_pkg, %opt ) = @_;
326 return '' unless $cust_pkg->change_date;
329 pkg_status_row( $cust_pkg, emt('Package changed'), 'change_date', %opt );
331 my $old = $cust_pkg->old_cust_pkg;
333 my $part_pkg = $old->part_pkg;
334 $html .= pkg_status_row_colspan( $cust_pkg,
335 emt("Changed from [_1]: [_2]",
336 $cust_pkg->change_pkgnum,
337 $part_pkg->pkg_comment(nopartpkg => 1) ),
341 'colspan' => $opt{'colspan'},
348 sub pkg_status_row_noauto {
349 my( $cust_pkg, %opt ) = @_;
350 my $part_pkg = $opt{'part_pkg'};
351 return '' unless $cust_pkg->no_auto || $part_pkg->no_auto;
353 #inefficient, should be passed in
354 my $cust_main = $cust_pkg->cust_main;
356 return '' unless $cust_main->payby =~ /^(CARD|CHEK)$/;
357 my $what = lc(FS::payby->shortname($cust_main->payby));
359 pkg_status_row_colspan( $cust_pkg, emt("No automatic $what charge"), '',
360 'colspan' => $opt{'colspan'},
364 sub pkg_status_row_discount {
365 my( $cust_pkg, %opt ) = @_;
369 foreach my $cust_pkg_discount ( $cust_pkg->cust_pkg_discount_active ) {
371 my $discount = $cust_pkg_discount->discount;
373 my $label = '<B>'.emt('Discount').'</B>: '. $discount->description;
374 if ( $discount->months ) {
375 my $remaining = $discount->months - $cust_pkg_discount->months_used;
376 $remaining = sprintf('%.2f', $remaining) if $remaining =~ /\./;
377 $label .= emt("([_1] months remaining)",$remaining);
380 $label .= ' <FONT SIZE="-1">('.
381 '<A HREF="../misc/delete-cust_pkg_discount.html?'.
382 $cust_pkg_discount->pkgdiscountnum.
383 '">'.emt('remove discount').'</A>)</FONT>';
385 $html .= pkg_status_row_colspan( $cust_pkg, $label, '',
386 'colspan' => $opt{'colspan'},
394 sub pkg_status_row_colspan {
395 my($cust_pkg, $title, $addl, %opt) = @_;
397 my $colspan = $opt{'colspan'};
399 my $align = $opt{'align'} ? 'ALIGN="'. $opt{'align'}.'"' : '';
400 my $color = $opt{'color'} ? 'COLOR="#'.$opt{'color'}.'"' : '';
401 my $size = $opt{'size'} ? 'SIZE="'. $opt{'size'}. '"' : '';
403 my $html = qq(<TR><TD COLSPAN=$colspan $align>);
404 $html .= qq(<FONT $color $size>) if length($color) || $size;
405 $html .= qq(<B>) if $color && !$size;
407 $html .= qq(</B>) if $color && !$size;
408 $html .= qq(</FONT>) if length($color) || $size;
409 $html .= ", $addl" if length($addl);
411 if ( $opt{'pkg-balances'} && ! $cust_pkg->{_printed_balance}++ ) { #kludge
412 $html .= ' (Balance: <B>'. $opt{'money_char'}.
413 $cust_pkg->cust_main->balance_pkgnum($cust_pkg->pkgnum).
417 $html .= qq(</TD></TR>);
424 my($cust_pkg, $field, %opt) = @_ or return '';
425 return ' ' unless $cust_pkg->get($field);
426 my $format = '<TD align="left"><B>%b</B></TD>'.
427 '<TD align="right"><B> %o,</B></TD>'.
428 '<TD align="right"><B> %Y</B></TD>';
429 #$format .= ' <FONT SIZE=-3>%l:%M:%S%P %z</FONT>'
430 $format .= '<TD ALIGN="right"><B> %l</TD>'.
431 '<TD ALIGN="center"><B>:</B></TD>'.
432 '<TD ALIGN="left"><B>%M</B></TD>'.
433 '<TD ALIGN="left"><B> %P</B></TD>'
434 if $opt{'cust_pkg-display_times'};
435 my $strip = time2str($format, $cust_pkg->get($field) );
436 $strip =~ s/ (\d)/$1/g;
440 sub pkg_suspend_link {
441 include( '/elements/popup_link-cust_pkg.html',
442 'action' => $p. 'misc/cancel_pkg.html?method=suspend',
443 'label' => emt('Suspend now'),
444 'actionlabel' => emt('Suspend'),
445 'color' => '#FF9900',
450 sub pkg_adjourn_link {
451 include( '/elements/popup_link-cust_pkg.html',
452 'action' => $p. 'misc/cancel_pkg.html?method=adjourn',
453 'label' => emt('Suspend later'),
454 'actionlabel' => emt('Adjourn'),
455 'color' => '#CC6600',
461 my($cust_pkg) = shift;
462 include( '/elements/popup_link-cust_pkg.html',
463 'action' => $p. 'misc/delay_susp_pkg.html',
464 'label' => ( $cust_pkg->dundate
465 ? emt('Edit suspension delay')
466 : emt('Delay suspend')
468 'actionlabel' => emt('Delay suspend for'),
469 'cust_pkg' => $cust_pkg,
473 sub pkg_resume_link {
474 include( '/elements/popup_link-cust_pkg.html',
475 'action' => $p. 'misc/cancel_pkg.html?method=resume',
476 'label' => emt('Unsuspend later'),
477 'actionlabel' => emt('Resume'),
478 'color' => '#00CC00',
483 sub pkg_unsuspend_link { pkg_link('misc/unsusp_pkg', emt('Unsuspend now'), @_ ); }
484 sub pkg_unadjourn_link { pkg_link('misc/unadjourn_pkg', emt('Abort'), @_ ); }
485 sub pkg_unexpire_link { pkg_link('misc/unexpire_pkg', emt('Abort'), @_ ); }
487 sub pkg_cancel_link {
488 include( '/elements/popup_link-cust_pkg.html',
489 'action' => $p. 'misc/cancel_pkg.html?method=cancel',
490 'label' => emt('Cancel now'),
491 'actionlabel' => emt('Cancel'),
492 'color' => '#ff0000',
497 sub pkg_uncancel_link {
498 include( '/elements/popup_link-cust_pkg.html',
499 'action' => $p. 'misc/cancel_pkg.html?method=uncancel',
500 'label' => emt('Un-cancel'),
501 'actionlabel' => emt('Un-cancel'),
507 sub pkg_expire_link {
508 include( '/elements/popup_link-cust_pkg.html',
509 'action' => $p. 'misc/cancel_pkg.html?method=expire',
510 'label' => emt('Cancel later'),
511 'actionlabel' => emt('Expire'),
512 'color' => '#CC0000',
517 sub svc_recharge_link {
518 include( '/elements/popup_link-cust_svc.html',
519 'action' => $p. 'misc/recharge_svc.html',
520 'label' => emt('Recharge'),
521 'actionlabel' => emt('Recharge'),
522 'color' => '#333399',
527 sub pkg_autosuspend_time {
528 my $cust_pkg = shift or return '';
531 my $pending_suspend = 0;
532 #this seems to be extremely inefficient... and is slowing down all customer
536 grep { $_->part_event->action eq 'suspend' }
537 @{$cust_pkg->cust_main->due_cust_event( time => $time + 86400*$days,
543 $pending_suspend = 1;
547 $pending_suspend ? time + ($days + 1) * 86400 : '';