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, '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, '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, 'Never billed', '', 'colspan'=>$colspan, %opt, ) %>
28 <% pkg_status_row( $cust_pkg, '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, 'Suspended', 'susp', %opt, curuser=>$curuser ) %>
37 % if ( $cust_pkg->get('susp') ) { #status: suspended
38 % my $cpr = $cust_pkg->last_cust_pkg_reason('susp');
40 <% pkg_status_row( $cust_pkg, 'Suspended', 'susp', 'color'=>'FF9900', %opt ) %>
42 <% pkg_status_row_colspan( $cust_pkg,
43 ( $cpr ? $cpr->reasontext. ' by '. $cpr->otaker : '' ), '',
44 'align'=>'right', 'color'=>'FF9900', 'size'=>'-2', 'colspan'=>$colspan,
49 <% pkg_status_row_noauto( $cust_pkg, %opt, 'colspan'=>$colspan ) %>
51 <% pkg_status_row_discount( $cust_pkg, %opt, 'colspan'=>$colspan ) %>
53 % unless ( $cust_pkg->get('setup') ) {
54 <% pkg_status_row_colspan( $cust_pkg, 'Never billed', '', 'colspan'=>$colspan, %opt ) %>
56 <% pkg_status_row($cust_pkg, 'Setup', 'setup', %opt ) %>
59 <% pkg_status_row_changed( $cust_pkg, %opt, 'colspan'=>$colspan ) %>
60 <% pkg_status_row_if( $cust_pkg, $last_bill_or_renewed, 'last_bill', %opt, curuser=>$curuser ) %>
61 % if ( $part_pkg->option('suspend_bill', 1) ) {
62 <% pkg_status_row_if( $cust_pkg, 'Next bill', 'bill', %opt, curuser=>$curuser ) %>
64 <% pkg_status_row_if( $cust_pkg, 'Expires', 'expire', %opt, curuser=>$curuser ) %>
65 <% pkg_status_row_if( $cust_pkg, 'Contract ends', 'contract_end', %opt ) %>
68 <TD COLSPAN=<%$colspan%>>
70 % if ( $curuser->access_right('Unsuspend customer package') ) {
71 ( <% pkg_unsuspend_link($cust_pkg) %> )
73 % if ( $curuser->access_right('Cancel customer package immediately') ) {
74 ( <% pkg_cancel_link($cust_pkg) %> )
80 % } else { #status: active
82 % unless ( $cust_pkg->get('setup') ) { #not setup
84 % unless ( $part_pkg->freq ) {
86 <% pkg_status_row_colspan( $cust_pkg, 'Not yet billed (one-time charge)', '', 'colspan'=>$colspan, %opt ) %>
88 <% pkg_status_row_noauto( $cust_pkg, %opt, 'colspan'=>$colspan ) %>
90 <% pkg_status_row_discount( $cust_pkg, %opt, 'colspan'=>$colspan ) %>
94 ( $part_pkg->freq ? 'Start billing' : 'Bill on' ),
101 <TD COLSPAN=<%$colspan%>>
103 % if ( $curuser->access_right('Cancel customer package immediately') ) {
104 ( <% pkg_cancel_link($cust_pkg) %> )
112 <% pkg_status_row_colspan($cust_pkg, "Not yet billed ($billed_or_prepaid ". myfreq($part_pkg). ')', '', 'colspan'=>$colspan, %opt ) %>
114 <% pkg_status_row_noauto( $cust_pkg, %opt, 'colspan'=>$colspan ) %>
116 <% pkg_status_row_discount( $cust_pkg, %opt, 'colspan'=>$colspan ) %>
118 <% pkg_status_row_if($cust_pkg, 'Start billing', 'start_date', %opt) %>
124 % unless ( $part_pkg->freq ) {
126 <% pkg_status_row_colspan($cust_pkg, 'One-time charge', '', 'colspan'=>$colspan, %opt ) %>
128 <% pkg_status_row($cust_pkg, 'Billed', 'setup', %opt) %>
130 <% pkg_status_row_noauto( $cust_pkg, %opt, 'colspan'=>$colspan ) %>
132 <% pkg_status_row_discount( $cust_pkg, %opt, 'colspan'=>$colspan ) %>
136 % if (scalar($cust_pkg->overlimit)) {
138 <% pkg_status_row_colspan( $cust_pkg,
140 $billed_or_prepaid. ' '. myfreq($part_pkg),
141 'color'=>'FFD000', 'colspan'=>$colspan,
147 <% pkg_status_row_colspan( $cust_pkg,
149 $billed_or_prepaid. ' '. myfreq($part_pkg),
150 'color'=>'00CC00', 'colspan'=>$colspan,
156 <% pkg_status_row_noauto( $cust_pkg, %opt, 'colspan'=>$colspan ) %>
158 <% pkg_status_row_discount( $cust_pkg, %opt, 'colspan'=>$colspan ) %>
160 <% pkg_status_row($cust_pkg, 'Setup', 'setup', %opt) %>
166 % if ( $opt{'cust_pkg-show_autosuspend'} ) {
167 % my $autosuspend = pkg_autosuspend_time( $cust_pkg );
168 % $cust_pkg->set('autosuspend', $autosuspend) if $autosuspend;
171 <% pkg_status_row_changed( $cust_pkg, %opt, 'colspan'=>$colspan ) %>
172 <% pkg_status_row_if( $cust_pkg, $last_bill_or_renewed, 'last_bill', %opt, curuser=>$curuser ) %>
173 <% pkg_status_row_if( $cust_pkg, $next_bill_or_prepaid_until, 'bill', %opt, curuser=>$curuser ) %>
174 <% pkg_status_row_if($cust_pkg, 'Will automatically suspend by', 'autosuspend', %opt) %>
175 <% pkg_status_row_if( $cust_pkg, 'Will suspend on', 'adjourn', %opt, curuser=>$curuser ) %>
176 <% pkg_status_row_if( $cust_pkg, 'Expires', 'expire', %opt, curuser=>$curuser ) %>
177 <% pkg_status_row_if( $cust_pkg, 'Contract ends', 'contract_end', %opt ) %>
179 % if ( $part_pkg->freq ) {
182 <TD COLSPAN=<%$colspan%>>
184 % if ( $curuser->access_right('Suspend customer package') ) {
185 ( <% pkg_suspend_link($cust_pkg) %> )
187 % if ( $curuser->access_right('Suspend customer package later') ) {
188 ( <% pkg_adjourn_link($cust_pkg) %> )
190 % if ( $curuser->access_right('Delay suspension events') ) {
191 ( <% pkg_delay_link($cust_pkg) %> )
193 % if ( $curuser->access_right('Cancel customer package immediately') ) {
194 ( <% pkg_cancel_link($cust_pkg) %> )
196 % if ( $curuser->access_right('Cancel customer package later') ) {
197 ( <% pkg_expire_link($cust_pkg) %> )
214 my $bgcolor = $opt{'bgcolor'};
215 my $cust_pkg = $opt{'cust_pkg'};
216 my $part_pkg = $opt{'part_pkg'};
217 my $curuser = $FS::CurrentUser::CurrentUser;
218 my $colspan = $opt{'cust_pkg-display_times'} ? 8 : 4;
219 my $width = $opt{'cust_pkg-display_times'} ? '38%' : '56%';
221 #false laziness w/edit/REAL_cust_pkg.cgi
222 my( $billed_or_prepaid, $last_bill_or_renewed, $next_bill_or_prepaid_until );
223 unless ( $part_pkg->is_prepaid ) {
224 $billed_or_prepaid = 'billed';
225 $last_bill_or_renewed = 'Last bill';
226 $next_bill_or_prepaid_until = 'Next bill';
228 $billed_or_prepaid = 'prepaid';
229 $last_bill_or_renewed = 'Renewed';
230 $next_bill_or_prepaid_until = 'Prepaid until';
236 my $part_pkg = shift;
237 my $freq = $part_pkg->freq_pretty;
238 $freq =~ s/ / /g;
242 #false laziness w/package.html
244 my($action, $label, $cust_pkg) = @_;
245 return '' unless $cust_pkg;
246 qq!<a href="$p$action.cgi?!. $cust_pkg->pkgnum. qq!">$label</a>!;
250 my( $cust_pkg, $title, $field, %opt ) = @_;
252 my $color = $opt{'color'};
254 my $html = qq(<TR><TD WIDTH="<%$width%>" ALIGN="right">);
255 $html .= qq(<FONT COLOR="#$color"><B>) if length($color);
256 $html .= qq($title );
257 $html .= qq(</B></FONT>) if length($color);
259 if ( $opt{'pkg_balances'} && ! $cust_pkg->{_printed_balance}++ ) { #kludge
260 $html .= ' (Balance: <B>'. $opt{'money_char'}.
261 $cust_pkg->cust_main->balance_pkgnum($cust_pkg->pkgnum).
266 $html .= pkg_datestr($cust_pkg, $field, %opt). '</TR>';
271 sub pkg_status_row_if {
272 my( $cust_pkg, $title, $field, %opt ) = @_;
274 $title = '<FONT SIZE=-1>( '. pkg_unadjourn_link($cust_pkg). ' ) </FONT>'. $title
275 if ( $field eq 'adjourn' &&
276 $opt{curuser}->access_right('Suspend customer package later')
279 $title = '<FONT SIZE=-1>( '. pkg_unexpire_link($cust_pkg). ' ) </FONT>'. $title
280 if ( $field eq 'expire' &&
281 $opt{curuser}->access_right('Cancel customer package later')
284 $cust_pkg->get($field) ? pkg_status_row($cust_pkg, $title, $field, %opt) : '';
287 sub pkg_status_row_changed {
288 my( $cust_pkg, %opt ) = @_;
290 return '' unless $cust_pkg->change_date;
293 pkg_status_row( $cust_pkg, 'Package changed', 'change_date', %opt );
295 my $old = $cust_pkg->old_cust_pkg;
297 my $part_pkg = $old->part_pkg;
298 my $label = 'Changed from '. $cust_pkg->change_pkgnum. ': '.
299 $part_pkg->pkg_comment(nopartpkg => 1);
300 $html .= pkg_status_row_colspan( $cust_pkg, $label, '',
303 'colspan' => $opt{'colspan'},
311 sub pkg_status_row_noauto {
312 my( $cust_pkg, %opt ) = @_;
313 my $part_pkg = $opt{'part_pkg'};
314 return '' unless $cust_pkg->no_auto || $part_pkg->no_auto;
316 #inefficient, should be passed in
317 my $cust_main = $cust_pkg->cust_main;
319 return '' unless $cust_main->payby =~ /^(CARD|CHEK)$/;
320 my $what = lc(FS::payby->shortname($cust_main->payby));
322 pkg_status_row_colspan( $cust_pkg, "No automatic $what charge", '',
323 'colspan' => $opt{'colspan'},
328 sub pkg_status_row_discount {
329 my( $cust_pkg, %opt ) = @_;
333 foreach my $cust_pkg_discount ( $cust_pkg->cust_pkg_discount_active ) {
335 my $discount = $cust_pkg_discount->discount;
337 my $label = '<B>Discount</B>: '. $discount->description;
338 if ( $discount->months ) {
339 my $remaining = $discount->months - $cust_pkg_discount->months_used;
340 $remaining = sprintf('%.2f', $remaining) if $remaining =~ /\./;
341 $label .= " ($remaining months remaining)"
344 $label .= ' <FONT SIZE="-1">('.
345 '<A HREF="../misc/delete-cust_pkg_discount.html?'.
346 $cust_pkg_discount->pkgdiscountnum.
347 '">remove discount</A>)</FONT>';
349 $html .= pkg_status_row_colspan( $cust_pkg, $label, '',
350 'colspan' => $opt{'colspan'},
359 sub pkg_status_row_colspan {
360 my($cust_pkg, $title, $addl, %opt) = @_;
362 my $colspan = $opt{'colspan'};
364 my $align = $opt{'align'} ? 'ALIGN="'. $opt{'align'}.'"' : '';
365 my $color = $opt{'color'} ? 'COLOR="#'.$opt{'color'}.'"' : '';
366 my $size = $opt{'size'} ? 'SIZE="'. $opt{'size'}. '"' : '';
368 my $html = qq(<TR><TD COLSPAN=$colspan $align>);
369 $html .= qq(<FONT $color $size>) if length($color) || $size;
370 $html .= qq(<B>) if $color && !$size;
372 $html .= qq(</B>) if $color && !$size;
373 $html .= qq(</FONT>) if length($color) || $size;
374 $html .= ", $addl" if length($addl);
376 if ( $opt{'pkg-balances'} && ! $cust_pkg->{_printed_balance}++ ) { #kludge
377 $html .= ' (Balance: <B>'. $opt{'money_char'}.
378 $cust_pkg->cust_main->balance_pkgnum($cust_pkg->pkgnum).
382 $html .= qq(</TD></TR>);
389 my($cust_pkg, $field, %opt) = @_ or return '';
390 return ' ' unless $cust_pkg->get($field);
391 my $format = '<TD align="left"><B>%b</B></TD>'.
392 '<TD align="right"><B> %o,</B></TD>'.
393 '<TD align="right"><B> %Y</B></TD>';
394 #$format .= ' <FONT SIZE=-3>%l:%M:%S%P %z</FONT>'
395 $format .= '<TD ALIGN="right"><B> %l</TD>'.
396 '<TD ALIGN="center"><B>:</B></TD>'.
397 '<TD ALIGN="left"><B>%M</B></TD>'.
398 '<TD ALIGN="left"><B> %P</B></TD>'
399 if $opt{'cust_pkg-display_times'};
400 my $strip = time2str($format, $cust_pkg->get($field) );
401 $strip =~ s/ (\d)/$1/g;
405 sub pkg_suspend_link {
406 include( '/elements/popup_link-cust_pkg.html',
407 'action' => $p. 'misc/cancel_pkg.html?method=suspend',
408 'label' => 'Suspend now',
409 'actionlabel' => 'Suspend',
410 'color' => '#FF9900',
415 sub pkg_adjourn_link {
416 include( '/elements/popup_link-cust_pkg.html',
417 'action' => $p. 'misc/cancel_pkg.html?method=adjourn',
418 'label' => 'Suspend later',
419 'actionlabel' => 'Adjourn',
420 'color' => '#CC6600',
426 include( '/elements/popup_link-cust_pkg.html',
427 'action' => $p. 'misc/delay_susp_pkg.html',
428 'label' => 'Delay suspend',
429 'actionlabel' => 'Delay suspend for',
434 sub pkg_unsuspend_link { pkg_link('misc/unsusp_pkg', 'Unsuspend', @_ ); }
435 sub pkg_unadjourn_link { pkg_link('misc/unadjourn_pkg', 'Abort', @_ ); }
436 sub pkg_unexpire_link { pkg_link('misc/unexpire_pkg', 'Abort', @_ ); }
438 sub pkg_cancel_link {
439 include( '/elements/popup_link-cust_pkg.html',
440 'action' => $p. 'misc/cancel_pkg.html?method=cancel',
441 'label' => 'Cancel now',
442 'actionlabel' => 'Cancel',
443 'color' => '#ff0000',
448 sub pkg_expire_link {
449 include( '/elements/popup_link-cust_pkg.html',
450 'action' => $p. 'misc/cancel_pkg.html?method=expire',
451 'label' => 'Cancel later',
452 'actionlabel' => 'Expire', #"Cancel package $num later"
453 'color' => '#CC0000',
458 sub svc_recharge_link {
459 include( '/elements/popup_link-cust_svc.html',
460 'action' => $p. 'misc/recharge_svc.html',
461 'label' => 'Recharge',
462 'actionlabel' => 'Recharge',
463 'color' => '#333399',
468 sub pkg_autosuspend_time {
469 my $cust_pkg = shift or return '';
472 my $pending_suspend = 0;
473 #this seems to be extremely inefficient... and is slowing down all customer
477 grep { $_->part_event->action eq 'suspend' }
478 @{$cust_pkg->cust_main->due_cust_event( time => $time + 86400*$days,
484 $pending_suspend = 1;
488 $pending_suspend ? time + ($days + 1) * 86400 : '';