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_discount( $cust_pkg, %opt, 'colspan'=>$colspan ) %>
47 % unless ( $cust_pkg->get('setup') ) {
48 <% pkg_status_row_colspan( $cust_pkg, 'Never billed', '', 'colspan'=>$colspan, %opt ) %>
50 <% pkg_status_row($cust_pkg, 'Setup', 'setup', %opt ) %>
53 <% pkg_status_row_changed( $cust_pkg, %opt, 'colspan'=>$colspan ) %>
54 <% pkg_status_row_if( $cust_pkg, $last_bill_or_renewed, 'last_bill', %opt, curuser=>$curuser ) %>
55 % # pkg_status_row($cust_pkg, 'Next bill', 'bill', %opt)
56 <% pkg_status_row_if( $cust_pkg, 'Expires', 'expire', %opt, curuser=>$curuser ) %>
59 <TD COLSPAN=<%$colspan%>>
61 % if ( $curuser->access_right('Unsuspend customer package') ) {
62 ( <% pkg_unsuspend_link($cust_pkg) %> )
64 % if ( $curuser->access_right('Cancel customer package immediately') ) {
65 ( <% pkg_cancel_link($cust_pkg) %> )
71 % } else { #status: active
73 % unless ( $cust_pkg->get('setup') ) { #not setup
75 % unless ( $part_pkg->freq ) {
77 <% pkg_status_row_colspan( $cust_pkg, 'Not yet billed (one-time charge)', '', 'colspan'=>$colspan, %opt ) %>
79 <% pkg_status_row_discount( $cust_pkg, %opt, 'colspan'=>$colspan ) %>
83 ( $part_pkg->freq ? 'Start billing' : 'Bill on' ),
90 <TD COLSPAN=<%$colspan%>>
92 % if ( $curuser->access_right('Cancel customer package immediately') ) {
93 ( <% pkg_cancel_link($cust_pkg) %> )
101 <% pkg_status_row_colspan($cust_pkg, "Not yet billed ($billed_or_prepaid ". myfreq($part_pkg). ')', '', 'colspan'=>$colspan, %opt ) %>
103 <% pkg_status_row_discount( $cust_pkg, %opt, 'colspan'=>$colspan ) %>
105 <% pkg_status_row_if($cust_pkg, 'Start billing', 'start_date', %opt) %>
111 % unless ( $part_pkg->freq ) {
113 <% pkg_status_row_colspan($cust_pkg, 'One-time charge', '', 'colspan'=>$colspan, %opt ) %>
115 <% pkg_status_row($cust_pkg, 'Billed', 'setup', %opt) %>
117 <% pkg_status_row_discount( $cust_pkg, %opt, 'colspan'=>$colspan ) %>
121 % if (scalar($cust_pkg->overlimit)) {
123 <% pkg_status_row_colspan( $cust_pkg,
125 $billed_or_prepaid. ' '. myfreq($part_pkg),
126 'color'=>'FFD000', 'colspan'=>$colspan,
132 <% pkg_status_row_colspan( $cust_pkg,
134 $billed_or_prepaid. ' '. myfreq($part_pkg),
135 'color'=>'00CC00', 'colspan'=>$colspan,
141 <% pkg_status_row_discount( $cust_pkg, %opt, 'colspan'=>$colspan ) %>
143 <% pkg_status_row($cust_pkg, 'Setup', 'setup', %opt) %>
149 % if ( $opt{'cust_pkg-show_autosuspend'} ) {
150 % my $autosuspend = pkg_autosuspend_time( $cust_pkg );
151 % $cust_pkg->set('autosuspend', $autosuspend) if $autosuspend;
154 <% pkg_status_row_changed( $cust_pkg, %opt, 'colspan'=>$colspan ) %>
155 <% pkg_status_row_if( $cust_pkg, $last_bill_or_renewed, 'last_bill', %opt, curuser=>$curuser ) %>
156 <% pkg_status_row_if( $cust_pkg, $next_bill_or_prepaid_until, 'bill', %opt, curuser=>$curuser ) %>
157 <% pkg_status_row_if($cust_pkg, 'Will automatically suspend by', 'autosuspend', %opt) %>
158 <% pkg_status_row_if( $cust_pkg, 'Will suspend on', 'adjourn', %opt, curuser=>$curuser ) %>
159 <% pkg_status_row_if( $cust_pkg, 'Expires', 'expire', %opt, curuser=>$curuser ) %>
161 % if ( $part_pkg->freq ) {
164 <TD COLSPAN=<%$colspan%>>
166 % if ( $curuser->access_right('Suspend customer package') ) {
167 ( <% pkg_suspend_link($cust_pkg) %> )
169 % if ( $curuser->access_right('Suspend customer package later') ) {
170 ( <% pkg_adjourn_link($cust_pkg) %> )
172 % if ( $curuser->access_right('Delay suspension events') ) {
173 ( <% pkg_delay_link($cust_pkg) %> )
175 % if ( $curuser->access_right('Cancel customer package immediately') ) {
176 ( <% pkg_cancel_link($cust_pkg) %> )
178 % if ( $curuser->access_right('Cancel customer package later') ) {
179 ( <% pkg_expire_link($cust_pkg) %> )
196 my $bgcolor = $opt{'bgcolor'};
197 my $cust_pkg = $opt{'cust_pkg'};
198 my $part_pkg = $opt{'part_pkg'};
199 my $curuser = $FS::CurrentUser::CurrentUser;
200 my $colspan = $opt{'cust_pkg-display_times'} ? 8 : 4;
201 my $width = $opt{'cust_pkg-display_times'} ? '38%' : '56%';
203 #false laziness w/edit/REAL_cust_pkg.cgi
204 my( $billed_or_prepaid, $last_bill_or_renewed, $next_bill_or_prepaid_until );
205 unless ( $part_pkg->is_prepaid ) {
206 $billed_or_prepaid = 'billed';
207 $last_bill_or_renewed = 'Last bill';
208 $next_bill_or_prepaid_until = 'Next bill';
210 $billed_or_prepaid = 'prepaid';
211 $last_bill_or_renewed = 'Renewed';
212 $next_bill_or_prepaid_until = 'Prepaid until';
218 my $part_pkg = shift;
219 my $freq = $part_pkg->freq_pretty;
220 $freq =~ s/ / /g;
224 #false laziness w/package.html
226 my($action, $label, $cust_pkg) = @_;
227 return '' unless $cust_pkg;
228 qq!<a href="$p$action.cgi?!. $cust_pkg->pkgnum. qq!">$label</a>!;
232 my( $cust_pkg, $title, $field, %opt ) = @_;
234 my $color = $opt{'color'};
236 my $html = qq(<TR><TD WIDTH="<%$width%>" ALIGN="right">);
237 $html .= qq(<FONT COLOR="#$color"><B>) if length($color);
238 $html .= qq($title );
239 $html .= qq(</B></FONT>) if length($color);
241 if ( $opt{'pkg_balances'} && ! $cust_pkg->{_printed_balance}++ ) { #kludge
242 $html .= ' (Balance: <B>'. $opt{'money_char'}.
243 $cust_pkg->cust_main->balance_pkgnum($cust_pkg->pkgnum).
248 $html .= pkg_datestr($cust_pkg, $field, %opt). '</TR>';
253 sub pkg_status_row_if {
254 my( $cust_pkg, $title, $field, %opt ) = @_;
256 $title = '<FONT SIZE=-1>( '. pkg_unadjourn_link($cust_pkg). ' ) </FONT>'. $title
257 if ( $field eq 'adjourn' &&
258 $opt{curuser}->access_right('Suspend customer package later')
261 $title = '<FONT SIZE=-1>( '. pkg_unexpire_link($cust_pkg). ' ) </FONT>'. $title
262 if ( $field eq 'expire' &&
263 $opt{curuser}->access_right('Cancel customer package later')
266 $cust_pkg->get($field) ? pkg_status_row($cust_pkg, $title, $field, %opt) : '';
269 sub pkg_status_row_changed {
270 my( $cust_pkg, %opt ) = @_;
272 return '' unless $cust_pkg->change_date;
275 pkg_status_row( $cust_pkg, 'Package changed', 'change_date', %opt );
277 my $old = $cust_pkg->old_cust_pkg;
279 my $part_pkg = $old->part_pkg;
280 my $label = 'Changed from '. $cust_pkg->change_pkgnum. ': '.
281 $part_pkg->pkg_comment(nopartpkg => 1);
282 $html .= pkg_status_row_colspan( $cust_pkg, $label, '',
285 'colspan' => $opt{'colspan'},
293 sub pkg_status_row_discount {
294 my( $cust_pkg, %opt ) = @_;
298 foreach my $cust_pkg_discount ( $cust_pkg->cust_pkg_discount_active ) {
300 my $discount = $cust_pkg_discount->discount;
302 my $label = '<B>Discount</B>: '. $discount->description;
303 $label .= ' ('. ( $discount->months - $cust_pkg_discount->months_used ).
305 if $discount->months;
307 $label .= ' <FONT SIZE="-1">('.
308 '<A HREF="../misc/delete-cust_pkg_discount.html?'.
309 $cust_pkg_discount->pkgdiscountnum.
310 '">remove discount</A>)</FONT>';
312 $html .= pkg_status_row_colspan( $cust_pkg, $label, '',
313 'colspan' => $opt{'colspan'},
322 sub pkg_status_row_colspan {
323 my($cust_pkg, $title, $addl, %opt) = @_;
325 my $colspan = $opt{'colspan'};
327 my $align = $opt{'align'} ? 'ALIGN="'. $opt{'align'}.'"' : '';
328 my $color = $opt{'color'} ? 'COLOR="#'.$opt{'color'}.'"' : '';
329 my $size = $opt{'size'} ? 'SIZE="'. $opt{'size'}. '"' : '';
331 my $html = qq(<TR><TD COLSPAN=$colspan $align>);
332 $html .= qq(<FONT $color $size>) if length($color) || $size;
333 $html .= qq(<B>) if $color && !$size;
335 $html .= qq(</B>) if $color && !$size;
336 $html .= qq(</FONT>) if length($color) || $size;
337 $html .= ", $addl" if length($addl);
339 if ( $opt{'pkg-balances'} && ! $cust_pkg->{_printed_balance}++ ) { #kludge
340 $html .= ' (Balance: <B>'. $opt{'money_char'}.
341 $cust_pkg->cust_main->balance_pkgnum($cust_pkg->pkgnum).
345 $html .= qq(</TD></TR>);
352 my($cust_pkg, $field, %opt) = @_ or return '';
353 return ' ' unless $cust_pkg->get($field);
354 my $format = '<TD align="left"><B>%b</B></TD>'.
355 '<TD align="right"><B> %o,</B></TD>'.
356 '<TD align="right"><B> %Y</B></TD>';
357 #$format .= ' <FONT SIZE=-3>%l:%M:%S%P %z</FONT>'
358 $format .= '<TD ALIGN="right"><B> %l</TD>'.
359 '<TD ALIGN="center"><B>:</B></TD>'.
360 '<TD ALIGN="left"><B>%M</B></TD>'.
361 '<TD ALIGN="left"><B> %P</B></TD>'
362 if $opt{'cust_pkg-display_times'};
363 my $strip = time2str($format, $cust_pkg->get($field) );
364 $strip =~ s/ (\d)/$1/g;
368 sub pkg_suspend_link {
369 include( '/elements/popup_link-cust_pkg.html',
370 'action' => $p. 'misc/cancel_pkg.html?method=suspend',
371 'label' => 'Suspend now',
372 'actionlabel' => 'Suspend',
373 'color' => '#FF9900',
378 sub pkg_adjourn_link {
379 include( '/elements/popup_link-cust_pkg.html',
380 'action' => $p. 'misc/cancel_pkg.html?method=adjourn',
381 'label' => 'Suspend later',
382 'actionlabel' => 'Adjourn',
383 'color' => '#CC6600',
389 include( '/elements/popup_link-cust_pkg.html',
390 'action' => $p. 'misc/delay_susp_pkg.html',
391 'label' => 'Delay suspend',
392 'actionlabel' => 'Delay suspend for',
397 sub pkg_unsuspend_link { pkg_link('misc/unsusp_pkg', 'Unsuspend', @_ ); }
398 sub pkg_unadjourn_link { pkg_link('misc/unadjourn_pkg', 'Abort', @_ ); }
399 sub pkg_unexpire_link { pkg_link('misc/unexpire_pkg', 'Abort', @_ ); }
401 sub pkg_cancel_link {
402 include( '/elements/popup_link-cust_pkg.html',
403 'action' => $p. 'misc/cancel_pkg.html?method=cancel',
404 'label' => 'Cancel now',
405 'actionlabel' => 'Cancel',
406 'color' => '#ff0000',
411 sub pkg_expire_link {
412 include( '/elements/popup_link-cust_pkg.html',
413 'action' => $p. 'misc/cancel_pkg.html?method=expire',
414 'label' => 'Cancel later',
415 'actionlabel' => 'Expire', #"Cancel package $num later"
416 'color' => '#CC0000',
421 sub svc_recharge_link {
422 include( '/elements/popup_link-cust_svc.html',
423 'action' => $p. 'misc/recharge_svc.html',
424 'label' => 'Recharge',
425 'actionlabel' => 'Recharge',
426 'color' => '#333399',
431 sub pkg_autosuspend_time {
432 my $cust_pkg = shift or return '';
435 my $pending_suspend = 0;
436 #this seems to be extremely inefficient... and is slowing down all customer
440 grep { $_->part_event->action eq 'suspend' }
441 @{$cust_pkg->cust_main->due_cust_event( time => $time + 86400*$days,
447 $pending_suspend = 1;
451 $pending_suspend ? time + ($days + 1) * 86400 : '';