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->get('cancel') ) { #status: cancelled
7 % my $cpr = $cust_pkg->last_cust_pkg_reason('cancel');
9 <% pkg_status_row($cust_pkg, 'Cancelled', 'cancel', 'color'=>'FF0000', %opt ) %>
11 <% pkg_status_row_colspan( $cust_pkg,
12 ( $cpr ? $cpr->reasontext. ' by '. $cpr->otaker : '' ), '',
13 'align'=>'right', 'color'=>'ff0000', 'size'=>'-2', 'colspan'=>$colspan,
18 % unless ( $cust_pkg->get('setup') ) {
20 <% pkg_status_row_colspan( $cust_pkg, 'Never billed', '', 'colspan'=>$colspan, %opt, ) %>
24 <% pkg_status_row( $cust_pkg, 'Setup', 'setup', %opt ) %>
25 <% pkg_status_row_changed( $cust_pkg, %opt, 'colspan'=>$colspan ) %>
26 <% pkg_status_row_if( $cust_pkg, $last_bill_or_renewed, 'last_bill', %opt, curuser=>$curuser ) %>
27 <% pkg_status_row_if( $cust_pkg, 'Suspended', 'susp', %opt, curuser=>$curuser ) %>
33 % if ( $cust_pkg->get('susp') ) { #status: suspended
34 % my $cpr = $cust_pkg->last_cust_pkg_reason('susp');
36 <% pkg_status_row( $cust_pkg, 'Suspended', 'susp', 'color'=>'FF9900', %opt ) %>
38 <% pkg_status_row_colspan( $cust_pkg,
39 ( $cpr ? $cpr->reasontext. ' by '. $cpr->otaker : '' ), '',
40 'align'=>'right', 'color'=>'FF9900', 'size'=>'-2', 'colspan'=>$colspan,
45 <% pkg_status_row_noauto( $cust_pkg, %opt, 'colspan'=>$colspan ) %>
47 <% pkg_status_row_discount( $cust_pkg, %opt, 'colspan'=>$colspan ) %>
49 % unless ( $cust_pkg->get('setup') ) {
50 <% pkg_status_row_colspan( $cust_pkg, 'Never billed', '', 'colspan'=>$colspan, %opt ) %>
52 <% pkg_status_row($cust_pkg, 'Setup', 'setup', %opt ) %>
55 <% pkg_status_row_changed( $cust_pkg, %opt, 'colspan'=>$colspan ) %>
56 <% pkg_status_row_if( $cust_pkg, $last_bill_or_renewed, 'last_bill', %opt, curuser=>$curuser ) %>
57 % if ( $part_pkg->option('suspend_bill', 1) ) {
58 <% pkg_status_row_if( $cust_pkg, 'Next bill', 'bill', %opt, curuser=>$curuser ) %>
60 <% pkg_status_row_if( $cust_pkg, 'Expires', 'expire', %opt, curuser=>$curuser ) %>
61 <% pkg_status_row_if( $cust_pkg, 'Contract ends', 'contract_end', %opt ) %>
64 <TD COLSPAN=<%$colspan%>>
66 % if ( $curuser->access_right('Unsuspend customer package') ) {
67 ( <% pkg_unsuspend_link($cust_pkg) %> )
69 % if ( $curuser->access_right('Cancel customer package immediately') ) {
70 ( <% pkg_cancel_link($cust_pkg) %> )
76 % } else { #status: active
78 % unless ( $cust_pkg->get('setup') ) { #not setup
80 % unless ( $part_pkg->freq ) {
82 <% pkg_status_row_colspan( $cust_pkg, 'Not yet billed (one-time charge)', '', 'colspan'=>$colspan, %opt ) %>
84 <% pkg_status_row_noauto( $cust_pkg, %opt, 'colspan'=>$colspan ) %>
86 <% pkg_status_row_discount( $cust_pkg, %opt, 'colspan'=>$colspan ) %>
90 ( $part_pkg->freq ? 'Start billing' : 'Bill on' ),
97 <TD COLSPAN=<%$colspan%>>
99 % if ( $curuser->access_right('Cancel customer package immediately') ) {
100 ( <% pkg_cancel_link($cust_pkg) %> )
108 <% pkg_status_row_colspan($cust_pkg, "Not yet billed ($billed_or_prepaid ". myfreq($part_pkg). ')', '', '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($cust_pkg, 'Start billing', 'start_date', %opt) %>
120 % unless ( $part_pkg->freq ) {
122 <% pkg_status_row_colspan($cust_pkg, 'One-time charge', '', 'colspan'=>$colspan, %opt ) %>
124 <% pkg_status_row($cust_pkg, 'Billed', 'setup', %opt) %>
126 <% pkg_status_row_noauto( $cust_pkg, %opt, 'colspan'=>$colspan ) %>
128 <% pkg_status_row_discount( $cust_pkg, %opt, 'colspan'=>$colspan ) %>
132 % if (scalar($cust_pkg->overlimit)) {
134 <% pkg_status_row_colspan( $cust_pkg,
136 $billed_or_prepaid. ' '. myfreq($part_pkg),
137 'color'=>'FFD000', 'colspan'=>$colspan,
143 <% pkg_status_row_colspan( $cust_pkg,
145 $billed_or_prepaid. ' '. myfreq($part_pkg),
146 'color'=>'00CC00', 'colspan'=>$colspan,
152 <% pkg_status_row_noauto( $cust_pkg, %opt, 'colspan'=>$colspan ) %>
154 <% pkg_status_row_discount( $cust_pkg, %opt, 'colspan'=>$colspan ) %>
156 <% pkg_status_row($cust_pkg, 'Setup', 'setup', %opt) %>
162 % if ( $opt{'cust_pkg-show_autosuspend'} ) {
163 % my $autosuspend = pkg_autosuspend_time( $cust_pkg );
164 % $cust_pkg->set('autosuspend', $autosuspend) if $autosuspend;
167 <% pkg_status_row_changed( $cust_pkg, %opt, 'colspan'=>$colspan ) %>
168 <% pkg_status_row_if( $cust_pkg, $last_bill_or_renewed, 'last_bill', %opt, curuser=>$curuser ) %>
169 <% pkg_status_row_if( $cust_pkg, $next_bill_or_prepaid_until, 'bill', %opt, curuser=>$curuser ) %>
170 <% pkg_status_row_if($cust_pkg, 'Will automatically suspend by', 'autosuspend', %opt) %>
171 <% pkg_status_row_if( $cust_pkg, 'Will suspend on', 'adjourn', %opt, curuser=>$curuser ) %>
172 <% pkg_status_row_if( $cust_pkg, 'Expires', 'expire', %opt, curuser=>$curuser ) %>
173 <% pkg_status_row_if( $cust_pkg, 'Contract ends', 'contract_end', %opt ) %>
175 % if ( $part_pkg->freq ) {
178 <TD COLSPAN=<%$colspan%>>
180 % if ( $curuser->access_right('Suspend customer package') ) {
181 ( <% pkg_suspend_link($cust_pkg) %> )
183 % if ( $curuser->access_right('Suspend customer package later') ) {
184 ( <% pkg_adjourn_link($cust_pkg) %> )
186 % if ( $curuser->access_right('Delay suspension events') ) {
187 ( <% pkg_delay_link($cust_pkg) %> )
189 % if ( $curuser->access_right('Cancel customer package immediately') ) {
190 ( <% pkg_cancel_link($cust_pkg) %> )
192 % if ( $curuser->access_right('Cancel customer package later') ) {
193 ( <% pkg_expire_link($cust_pkg) %> )
210 my $bgcolor = $opt{'bgcolor'};
211 my $cust_pkg = $opt{'cust_pkg'};
212 my $part_pkg = $opt{'part_pkg'};
213 my $curuser = $FS::CurrentUser::CurrentUser;
214 my $colspan = $opt{'cust_pkg-display_times'} ? 8 : 4;
215 my $width = $opt{'cust_pkg-display_times'} ? '38%' : '56%';
217 #false laziness w/edit/REAL_cust_pkg.cgi
218 my( $billed_or_prepaid, $last_bill_or_renewed, $next_bill_or_prepaid_until );
219 unless ( $part_pkg->is_prepaid ) {
220 $billed_or_prepaid = 'billed';
221 $last_bill_or_renewed = 'Last bill';
222 $next_bill_or_prepaid_until = 'Next bill';
224 $billed_or_prepaid = 'prepaid';
225 $last_bill_or_renewed = 'Renewed';
226 $next_bill_or_prepaid_until = 'Prepaid until';
232 my $part_pkg = shift;
233 my $freq = $part_pkg->freq_pretty;
234 $freq =~ s/ / /g;
238 #false laziness w/package.html
240 my($action, $label, $cust_pkg) = @_;
241 return '' unless $cust_pkg;
242 qq!<a href="$p$action.cgi?!. $cust_pkg->pkgnum. qq!">$label</a>!;
246 my( $cust_pkg, $title, $field, %opt ) = @_;
248 my $color = $opt{'color'};
250 my $html = qq(<TR><TD WIDTH="<%$width%>" ALIGN="right">);
251 $html .= qq(<FONT COLOR="#$color"><B>) if length($color);
252 $html .= qq($title );
253 $html .= qq(</B></FONT>) if length($color);
255 if ( $opt{'pkg_balances'} && ! $cust_pkg->{_printed_balance}++ ) { #kludge
256 $html .= ' (Balance: <B>'. $opt{'money_char'}.
257 $cust_pkg->cust_main->balance_pkgnum($cust_pkg->pkgnum).
262 $html .= pkg_datestr($cust_pkg, $field, %opt). '</TR>';
267 sub pkg_status_row_if {
268 my( $cust_pkg, $title, $field, %opt ) = @_;
270 $title = '<FONT SIZE=-1>( '. pkg_unadjourn_link($cust_pkg). ' ) </FONT>'. $title
271 if ( $field eq 'adjourn' &&
272 $opt{curuser}->access_right('Suspend customer package later')
275 $title = '<FONT SIZE=-1>( '. pkg_unexpire_link($cust_pkg). ' ) </FONT>'. $title
276 if ( $field eq 'expire' &&
277 $opt{curuser}->access_right('Cancel customer package later')
280 $cust_pkg->get($field) ? pkg_status_row($cust_pkg, $title, $field, %opt) : '';
283 sub pkg_status_row_changed {
284 my( $cust_pkg, %opt ) = @_;
286 return '' unless $cust_pkg->change_date;
289 pkg_status_row( $cust_pkg, 'Package changed', 'change_date', %opt );
291 my $old = $cust_pkg->old_cust_pkg;
293 my $part_pkg = $old->part_pkg;
294 my $label = 'Changed from '. $cust_pkg->change_pkgnum. ': '.
295 $part_pkg->pkg_comment(nopartpkg => 1);
296 $html .= pkg_status_row_colspan( $cust_pkg, $label, '',
299 'colspan' => $opt{'colspan'},
307 sub pkg_status_row_noauto {
308 my( $cust_pkg, %opt ) = @_;
309 my $part_pkg = $opt{'part_pkg'};
310 return '' unless $cust_pkg->no_auto || $part_pkg->no_auto;
312 #inefficient, should be passed in
313 my $cust_main = $cust_pkg->cust_main;
315 return '' unless $cust_main->payby =~ /^(CARD|CHEK)$/;
316 my $what = lc(FS::payby->shortname($cust_main->payby));
318 pkg_status_row_colspan( $cust_pkg, "No automatic $what charge", '',
319 'colspan' => $opt{'colspan'},
324 sub pkg_status_row_discount {
325 my( $cust_pkg, %opt ) = @_;
329 foreach my $cust_pkg_discount ( $cust_pkg->cust_pkg_discount_active ) {
331 my $discount = $cust_pkg_discount->discount;
333 my $label = '<B>Discount</B>: '. $discount->description;
334 if ( $discount->months ) {
335 my $remaining = $discount->months - $cust_pkg_discount->months_used;
336 $remaining = sprintf('%.2f', $remaining) if $remaining =~ /\./;
337 $label .= " ($remaining months remaining)"
340 $label .= ' <FONT SIZE="-1">('.
341 '<A HREF="../misc/delete-cust_pkg_discount.html?'.
342 $cust_pkg_discount->pkgdiscountnum.
343 '">remove discount</A>)</FONT>';
345 $html .= pkg_status_row_colspan( $cust_pkg, $label, '',
346 'colspan' => $opt{'colspan'},
355 sub pkg_status_row_colspan {
356 my($cust_pkg, $title, $addl, %opt) = @_;
358 my $colspan = $opt{'colspan'};
360 my $align = $opt{'align'} ? 'ALIGN="'. $opt{'align'}.'"' : '';
361 my $color = $opt{'color'} ? 'COLOR="#'.$opt{'color'}.'"' : '';
362 my $size = $opt{'size'} ? 'SIZE="'. $opt{'size'}. '"' : '';
364 my $html = qq(<TR><TD COLSPAN=$colspan $align>);
365 $html .= qq(<FONT $color $size>) if length($color) || $size;
366 $html .= qq(<B>) if $color && !$size;
368 $html .= qq(</B>) if $color && !$size;
369 $html .= qq(</FONT>) if length($color) || $size;
370 $html .= ", $addl" if length($addl);
372 if ( $opt{'pkg-balances'} && ! $cust_pkg->{_printed_balance}++ ) { #kludge
373 $html .= ' (Balance: <B>'. $opt{'money_char'}.
374 $cust_pkg->cust_main->balance_pkgnum($cust_pkg->pkgnum).
378 $html .= qq(</TD></TR>);
385 my($cust_pkg, $field, %opt) = @_ or return '';
386 return ' ' unless $cust_pkg->get($field);
387 my $format = '<TD align="left"><B>%b</B></TD>'.
388 '<TD align="right"><B> %o,</B></TD>'.
389 '<TD align="right"><B> %Y</B></TD>';
390 #$format .= ' <FONT SIZE=-3>%l:%M:%S%P %z</FONT>'
391 $format .= '<TD ALIGN="right"><B> %l</TD>'.
392 '<TD ALIGN="center"><B>:</B></TD>'.
393 '<TD ALIGN="left"><B>%M</B></TD>'.
394 '<TD ALIGN="left"><B> %P</B></TD>'
395 if $opt{'cust_pkg-display_times'};
396 my $strip = time2str($format, $cust_pkg->get($field) );
397 $strip =~ s/ (\d)/$1/g;
401 sub pkg_suspend_link {
402 include( '/elements/popup_link-cust_pkg.html',
403 'action' => $p. 'misc/cancel_pkg.html?method=suspend',
404 'label' => 'Suspend now',
405 'actionlabel' => 'Suspend',
406 'color' => '#FF9900',
411 sub pkg_adjourn_link {
412 include( '/elements/popup_link-cust_pkg.html',
413 'action' => $p. 'misc/cancel_pkg.html?method=adjourn',
414 'label' => 'Suspend later',
415 'actionlabel' => 'Adjourn',
416 'color' => '#CC6600',
422 include( '/elements/popup_link-cust_pkg.html',
423 'action' => $p. 'misc/delay_susp_pkg.html',
424 'label' => 'Delay suspend',
425 'actionlabel' => 'Delay suspend for',
430 sub pkg_unsuspend_link { pkg_link('misc/unsusp_pkg', 'Unsuspend', @_ ); }
431 sub pkg_unadjourn_link { pkg_link('misc/unadjourn_pkg', 'Abort', @_ ); }
432 sub pkg_unexpire_link { pkg_link('misc/unexpire_pkg', 'Abort', @_ ); }
434 sub pkg_cancel_link {
435 include( '/elements/popup_link-cust_pkg.html',
436 'action' => $p. 'misc/cancel_pkg.html?method=cancel',
437 'label' => 'Cancel now',
438 'actionlabel' => 'Cancel',
439 'color' => '#ff0000',
444 sub pkg_expire_link {
445 include( '/elements/popup_link-cust_pkg.html',
446 'action' => $p. 'misc/cancel_pkg.html?method=expire',
447 'label' => 'Cancel later',
448 'actionlabel' => 'Expire', #"Cancel package $num later"
449 'color' => '#CC0000',
454 sub svc_recharge_link {
455 include( '/elements/popup_link-cust_svc.html',
456 'action' => $p. 'misc/recharge_svc.html',
457 'label' => 'Recharge',
458 'actionlabel' => 'Recharge',
459 'color' => '#333399',
464 sub pkg_autosuspend_time {
465 my $cust_pkg = shift or return '';
468 my $pending_suspend = 0;
469 #this seems to be extremely inefficient... and is slowing down all customer
473 grep { $_->part_event->action eq 'suspend' }
474 @{$cust_pkg->cust_main->due_cust_event( time => $time + 86400*$days,
480 $pending_suspend = 1;
484 $pending_suspend ? time + ($days + 1) * 86400 : '';