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 % # pkg_status_row($cust_pkg, 'Next bill', 'bill', %opt)
58 <% pkg_status_row_if( $cust_pkg, 'Expires', 'expire', %opt, curuser=>$curuser ) %>
61 <TD COLSPAN=<%$colspan%>>
63 % if ( $curuser->access_right('Unsuspend customer package') ) {
64 ( <% pkg_unsuspend_link($cust_pkg) %> )
66 % if ( $curuser->access_right('Cancel customer package immediately') ) {
67 ( <% pkg_cancel_link($cust_pkg) %> )
73 % } else { #status: active
75 % unless ( $cust_pkg->get('setup') ) { #not setup
77 % unless ( $part_pkg->freq ) {
79 <% pkg_status_row_colspan( $cust_pkg, 'Not yet billed (one-time charge)', '', 'colspan'=>$colspan, %opt ) %>
81 <% pkg_status_row_noauto( $cust_pkg, %opt, 'colspan'=>$colspan ) %>
83 <% pkg_status_row_discount( $cust_pkg, %opt, 'colspan'=>$colspan ) %>
87 ( $part_pkg->freq ? 'Start billing' : 'Bill on' ),
94 <TD COLSPAN=<%$colspan%>>
96 % if ( $curuser->access_right('Cancel customer package immediately') ) {
97 ( <% pkg_cancel_link($cust_pkg) %> )
105 <% pkg_status_row_colspan($cust_pkg, "Not yet billed ($billed_or_prepaid ". myfreq($part_pkg). ')', '', 'colspan'=>$colspan, %opt ) %>
107 <% pkg_status_row_noauto( $cust_pkg, %opt, 'colspan'=>$colspan ) %>
109 <% pkg_status_row_discount( $cust_pkg, %opt, 'colspan'=>$colspan ) %>
111 <% pkg_status_row_if($cust_pkg, 'Start billing', 'start_date', %opt) %>
117 % unless ( $part_pkg->freq ) {
119 <% pkg_status_row_colspan($cust_pkg, 'One-time charge', '', 'colspan'=>$colspan, %opt ) %>
121 <% pkg_status_row($cust_pkg, 'Billed', 'setup', %opt) %>
123 <% pkg_status_row_noauto( $cust_pkg, %opt, 'colspan'=>$colspan ) %>
125 <% pkg_status_row_discount( $cust_pkg, %opt, 'colspan'=>$colspan ) %>
129 % if (scalar($cust_pkg->overlimit)) {
131 <% pkg_status_row_colspan( $cust_pkg,
133 $billed_or_prepaid. ' '. myfreq($part_pkg),
134 'color'=>'FFD000', 'colspan'=>$colspan,
140 <% pkg_status_row_colspan( $cust_pkg,
142 $billed_or_prepaid. ' '. myfreq($part_pkg),
143 'color'=>'00CC00', 'colspan'=>$colspan,
149 <% pkg_status_row_noauto( $cust_pkg, %opt, 'colspan'=>$colspan ) %>
151 <% pkg_status_row_discount( $cust_pkg, %opt, 'colspan'=>$colspan ) %>
153 <% pkg_status_row($cust_pkg, 'Setup', 'setup', %opt) %>
159 % if ( $opt{'cust_pkg-show_autosuspend'} ) {
160 % my $autosuspend = pkg_autosuspend_time( $cust_pkg );
161 % $cust_pkg->set('autosuspend', $autosuspend) if $autosuspend;
164 <% pkg_status_row_changed( $cust_pkg, %opt, 'colspan'=>$colspan ) %>
165 <% pkg_status_row_if( $cust_pkg, $last_bill_or_renewed, 'last_bill', %opt, curuser=>$curuser ) %>
166 <% pkg_status_row_if( $cust_pkg, $next_bill_or_prepaid_until, 'bill', %opt, curuser=>$curuser ) %>
167 <% pkg_status_row_if($cust_pkg, 'Will automatically suspend by', 'autosuspend', %opt) %>
168 <% pkg_status_row_if( $cust_pkg, 'Will suspend on', 'adjourn', %opt, curuser=>$curuser ) %>
169 <% pkg_status_row_if( $cust_pkg, 'Expires', 'expire', %opt, curuser=>$curuser ) %>
171 % if ( $part_pkg->freq ) {
174 <TD COLSPAN=<%$colspan%>>
176 % if ( $curuser->access_right('Suspend customer package') ) {
177 ( <% pkg_suspend_link($cust_pkg) %> )
179 % if ( $curuser->access_right('Suspend customer package later') ) {
180 ( <% pkg_adjourn_link($cust_pkg) %> )
182 % if ( $curuser->access_right('Delay suspension events') ) {
183 ( <% pkg_delay_link($cust_pkg) %> )
185 % if ( $curuser->access_right('Cancel customer package immediately') ) {
186 ( <% pkg_cancel_link($cust_pkg) %> )
188 % if ( $curuser->access_right('Cancel customer package later') ) {
189 ( <% pkg_expire_link($cust_pkg) %> )
206 my $bgcolor = $opt{'bgcolor'};
207 my $cust_pkg = $opt{'cust_pkg'};
208 my $part_pkg = $opt{'part_pkg'};
209 my $curuser = $FS::CurrentUser::CurrentUser;
210 my $colspan = $opt{'cust_pkg-display_times'} ? 8 : 4;
211 my $width = $opt{'cust_pkg-display_times'} ? '38%' : '56%';
213 #false laziness w/edit/REAL_cust_pkg.cgi
214 my( $billed_or_prepaid, $last_bill_or_renewed, $next_bill_or_prepaid_until );
215 unless ( $part_pkg->is_prepaid ) {
216 $billed_or_prepaid = 'billed';
217 $last_bill_or_renewed = 'Last bill';
218 $next_bill_or_prepaid_until = 'Next bill';
220 $billed_or_prepaid = 'prepaid';
221 $last_bill_or_renewed = 'Renewed';
222 $next_bill_or_prepaid_until = 'Prepaid until';
228 my $part_pkg = shift;
229 my $freq = $part_pkg->freq_pretty;
230 $freq =~ s/ / /g;
234 #false laziness w/package.html
236 my($action, $label, $cust_pkg) = @_;
237 return '' unless $cust_pkg;
238 qq!<a href="$p$action.cgi?!. $cust_pkg->pkgnum. qq!">$label</a>!;
242 my( $cust_pkg, $title, $field, %opt ) = @_;
244 my $color = $opt{'color'};
246 my $html = qq(<TR><TD WIDTH="<%$width%>" ALIGN="right">);
247 $html .= qq(<FONT COLOR="#$color"><B>) if length($color);
248 $html .= qq($title );
249 $html .= qq(</B></FONT>) if length($color);
251 if ( $opt{'pkg_balances'} && ! $cust_pkg->{_printed_balance}++ ) { #kludge
252 $html .= ' (Balance: <B>'. $opt{'money_char'}.
253 $cust_pkg->cust_main->balance_pkgnum($cust_pkg->pkgnum).
258 $html .= pkg_datestr($cust_pkg, $field, %opt). '</TR>';
263 sub pkg_status_row_if {
264 my( $cust_pkg, $title, $field, %opt ) = @_;
266 $title = '<FONT SIZE=-1>( '. pkg_unadjourn_link($cust_pkg). ' ) </FONT>'. $title
267 if ( $field eq 'adjourn' &&
268 $opt{curuser}->access_right('Suspend customer package later')
271 $title = '<FONT SIZE=-1>( '. pkg_unexpire_link($cust_pkg). ' ) </FONT>'. $title
272 if ( $field eq 'expire' &&
273 $opt{curuser}->access_right('Cancel customer package later')
276 $cust_pkg->get($field) ? pkg_status_row($cust_pkg, $title, $field, %opt) : '';
279 sub pkg_status_row_changed {
280 my( $cust_pkg, %opt ) = @_;
282 return '' unless $cust_pkg->change_date;
285 pkg_status_row( $cust_pkg, 'Package changed', 'change_date', %opt );
287 my $old = $cust_pkg->old_cust_pkg;
289 my $part_pkg = $old->part_pkg;
290 my $label = 'Changed from '. $cust_pkg->change_pkgnum. ': '.
291 $part_pkg->pkg_comment(nopartpkg => 1);
292 $html .= pkg_status_row_colspan( $cust_pkg, $label, '',
295 'colspan' => $opt{'colspan'},
303 sub pkg_status_row_noauto {
304 my( $cust_pkg, %opt ) = @_;
305 my $part_pkg = $opt{'part_pkg'};
306 return '' unless $cust_pkg->no_auto || $part_pkg->no_auto;
308 #inefficient, should be passed in
309 my $cust_main = $cust_pkg->cust_main;
311 return '' unless $cust_main->payby =~ /^(CARD|CHEK)$/;
312 my $what = lc(FS::payby->shortname($cust_main->payby));
314 pkg_status_row_colspan( $cust_pkg, "No automatic $what charge", '',
315 'colspan' => $opt{'colspan'},
320 sub pkg_status_row_discount {
321 my( $cust_pkg, %opt ) = @_;
325 foreach my $cust_pkg_discount ( $cust_pkg->cust_pkg_discount_active ) {
327 my $discount = $cust_pkg_discount->discount;
329 my $label = '<B>Discount</B>: '. $discount->description;
330 if ( $discount->months ) {
331 my $remaining = $discount->months - $cust_pkg_discount->months_used;
332 $remaining = sprintf('%.2f', $remaining) if $remaining =~ /\./;
333 $label .= " ($remaining months remaining)"
336 $label .= ' <FONT SIZE="-1">('.
337 '<A HREF="../misc/delete-cust_pkg_discount.html?'.
338 $cust_pkg_discount->pkgdiscountnum.
339 '">remove discount</A>)</FONT>';
341 $html .= pkg_status_row_colspan( $cust_pkg, $label, '',
342 'colspan' => $opt{'colspan'},
351 sub pkg_status_row_colspan {
352 my($cust_pkg, $title, $addl, %opt) = @_;
354 my $colspan = $opt{'colspan'};
356 my $align = $opt{'align'} ? 'ALIGN="'. $opt{'align'}.'"' : '';
357 my $color = $opt{'color'} ? 'COLOR="#'.$opt{'color'}.'"' : '';
358 my $size = $opt{'size'} ? 'SIZE="'. $opt{'size'}. '"' : '';
360 my $html = qq(<TR><TD COLSPAN=$colspan $align>);
361 $html .= qq(<FONT $color $size>) if length($color) || $size;
362 $html .= qq(<B>) if $color && !$size;
364 $html .= qq(</B>) if $color && !$size;
365 $html .= qq(</FONT>) if length($color) || $size;
366 $html .= ", $addl" if length($addl);
368 if ( $opt{'pkg-balances'} && ! $cust_pkg->{_printed_balance}++ ) { #kludge
369 $html .= ' (Balance: <B>'. $opt{'money_char'}.
370 $cust_pkg->cust_main->balance_pkgnum($cust_pkg->pkgnum).
374 $html .= qq(</TD></TR>);
381 my($cust_pkg, $field, %opt) = @_ or return '';
382 return ' ' unless $cust_pkg->get($field);
383 my $format = '<TD align="left"><B>%b</B></TD>'.
384 '<TD align="right"><B> %o,</B></TD>'.
385 '<TD align="right"><B> %Y</B></TD>';
386 #$format .= ' <FONT SIZE=-3>%l:%M:%S%P %z</FONT>'
387 $format .= '<TD ALIGN="right"><B> %l</TD>'.
388 '<TD ALIGN="center"><B>:</B></TD>'.
389 '<TD ALIGN="left"><B>%M</B></TD>'.
390 '<TD ALIGN="left"><B> %P</B></TD>'
391 if $opt{'cust_pkg-display_times'};
392 my $strip = time2str($format, $cust_pkg->get($field) );
393 $strip =~ s/ (\d)/$1/g;
397 sub pkg_suspend_link {
398 include( '/elements/popup_link-cust_pkg.html',
399 'action' => $p. 'misc/cancel_pkg.html?method=suspend',
400 'label' => 'Suspend now',
401 'actionlabel' => 'Suspend',
402 'color' => '#FF9900',
407 sub pkg_adjourn_link {
408 include( '/elements/popup_link-cust_pkg.html',
409 'action' => $p. 'misc/cancel_pkg.html?method=adjourn',
410 'label' => 'Suspend later',
411 'actionlabel' => 'Adjourn',
412 'color' => '#CC6600',
418 include( '/elements/popup_link-cust_pkg.html',
419 'action' => $p. 'misc/delay_susp_pkg.html',
420 'label' => 'Delay suspend',
421 'actionlabel' => 'Delay suspend for',
426 sub pkg_unsuspend_link { pkg_link('misc/unsusp_pkg', 'Unsuspend', @_ ); }
427 sub pkg_unadjourn_link { pkg_link('misc/unadjourn_pkg', 'Abort', @_ ); }
428 sub pkg_unexpire_link { pkg_link('misc/unexpire_pkg', 'Abort', @_ ); }
430 sub pkg_cancel_link {
431 include( '/elements/popup_link-cust_pkg.html',
432 'action' => $p. 'misc/cancel_pkg.html?method=cancel',
433 'label' => 'Cancel now',
434 'actionlabel' => 'Cancel',
435 'color' => '#ff0000',
440 sub pkg_expire_link {
441 include( '/elements/popup_link-cust_pkg.html',
442 'action' => $p. 'misc/cancel_pkg.html?method=expire',
443 'label' => 'Cancel later',
444 'actionlabel' => 'Expire', #"Cancel package $num later"
445 'color' => '#CC0000',
450 sub svc_recharge_link {
451 include( '/elements/popup_link-cust_svc.html',
452 'action' => $p. 'misc/recharge_svc.html',
453 'label' => 'Recharge',
454 'actionlabel' => 'Recharge',
455 'color' => '#333399',
460 sub pkg_autosuspend_time {
461 my $cust_pkg = shift or return '';
464 my $pending_suspend = 0;
465 #this seems to be extremely inefficient... and is slowing down all customer
469 grep { $_->part_event->action eq 'suspend' }
470 @{$cust_pkg->cust_main->due_cust_event( time => $time + 86400*$days,
476 $pending_suspend = 1;
480 $pending_suspend ? time + ($days + 1) * 86400 : '';