incompatible with translation
[freeside.git] / httemplate / view / cust_main / packages / status.html
1 <TD CLASS="inv" BGCOLOR="<% $bgcolor %>">
2   <TABLE CLASS="inv" BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH="100%">
3
4 %#this should use cust_pkg->status and cust_pkg->statuscolor eventually
5
6 % if ( $cust_pkg->order_date ) {
7     <% pkg_status_row($cust_pkg, emt('Ordered'), 'order_date', %opt ) %>
8 % }
9
10 % if ( $cust_pkg->get('cancel') ) { #status: cancelled
11 %   my $cpr = $cust_pkg->last_cust_pkg_reason('cancel');
12
13     <% pkg_status_row($cust_pkg, emt('Cancelled'), 'cancel', 'color'=>'FF0000', %opt ) %>
14
15     <% pkg_status_row_colspan( $cust_pkg,
16          ( $cpr ? $cpr->reasontext. ' by '. $cpr->otaker : '' ), '',
17          'align'=>'right', 'color'=>'ff0000', 'size'=>'-2', 'colspan'=>$colspan,
18          %opt
19        )
20     %>
21
22 %   unless ( $cust_pkg->get('setup') ) { 
23
24         <% pkg_status_row_colspan( $cust_pkg, emt('Never billed'), '', 'colspan'=>$colspan, %opt, ) %>
25
26 %   } else { 
27
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 ) %>
32
33 %   } 
34 %
35 % } else { 
36 %
37 %   if ( $cust_pkg->get('susp') ) { #status: suspended
38 %     my $cpr = $cust_pkg->last_cust_pkg_reason('susp');
39
40     <% pkg_status_row( $cust_pkg, emt('Suspended'), 'susp', 'color'=>'FF9900', %opt ) %>
41
42     <% pkg_status_row_colspan( $cust_pkg,
43          ( $cpr ? $cpr->reasontext. ' by '. $cpr->otaker : '' ), '',
44          'align'=>'right', 'color'=>'FF9900', 'size'=>'-2', 'colspan'=>$colspan,
45          %opt,
46        )
47     %>
48
49     <% pkg_status_row_noauto( $cust_pkg, %opt, 'colspan'=>$colspan ) %>
50
51     <% pkg_status_row_discount( $cust_pkg, %opt, 'colspan'=>$colspan ) %>
52
53 %   unless ( $cust_pkg->get('setup') ) { 
54       <% pkg_status_row_colspan( $cust_pkg, emt('Never billed'), '', 'colspan'=>$colspan, %opt ) %>
55 %   } else { 
56       <% pkg_status_row($cust_pkg, emt('Setup'), 'setup', %opt ) %>
57 %   } 
58
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, emt('Next bill'), 'bill', %opt, curuser=>$curuser ) %>
63 %   }
64     <% pkg_status_row_if( $cust_pkg, emt('Expires'), 'expire', %opt, curuser=>$curuser ) %>
65     <% pkg_status_row_if( $cust_pkg, emt('Contract ends'), 'contract_end', %opt ) %>
66
67     <TR>
68       <TD COLSPAN=<%$colspan%>>
69         <FONT SIZE=-1>
70 %         if ( $curuser->access_right('Unsuspend customer package') ) { 
71             (&nbsp;<% pkg_unsuspend_link($cust_pkg) %>&nbsp;)
72 %         } 
73 %         if ( $curuser->access_right('Cancel customer package immediately') ) {
74             (&nbsp;<% pkg_cancel_link($cust_pkg) %>&nbsp;)
75 %         } 
76         </FONT>
77       </TD>
78     </TR>
79
80 %   } else { #status: active
81 %
82 %     unless ( $cust_pkg->get('setup') ) { #not setup
83 %
84 %       unless ( $part_pkg->freq ) {
85
86           <% pkg_status_row_colspan( $cust_pkg, emt('Not yet billed (one-time charge)'), '', 'colspan'=>$colspan, %opt ) %>
87
88           <% pkg_status_row_noauto( $cust_pkg, %opt, 'colspan'=>$colspan ) %>
89
90           <% pkg_status_row_discount( $cust_pkg, %opt, 'colspan'=>$colspan ) %>
91
92           <% pkg_status_row_if(
93                $cust_pkg,
94                ( $part_pkg->freq ? emt('Start billing') : emt('Bill on') ),
95                'start_date',
96                %opt
97              )
98           %>
99
100           <TR>
101             <TD COLSPAN=<%$colspan%>>
102               <FONT SIZE=-1>
103 %               if ( $curuser->access_right('Cancel customer package immediately') ) { 
104                   (&nbsp;<% pkg_cancel_link($cust_pkg) %>&nbsp;)
105 %               } 
106               </FONT>
107             </TD>
108           </TR>
109
110 %       } else { 
111
112           <% pkg_status_row_colspan($cust_pkg, emt("Not yet billed ($billed_or_prepaid [_1])", myfreq($part_pkg) ), '', 'colspan'=>$colspan, %opt ) %>
113
114           <% pkg_status_row_noauto( $cust_pkg, %opt, 'colspan'=>$colspan ) %>
115
116           <% pkg_status_row_discount( $cust_pkg, %opt, 'colspan'=>$colspan ) %>
117
118           <% pkg_status_row_if($cust_pkg, emt('Start billing'), 'start_date', %opt) %>
119
120 %       } 
121 %
122 %     } else { #setup
123 %
124 %       unless ( $part_pkg->freq ) { 
125
126           <% pkg_status_row_colspan($cust_pkg, emt('One-time charge'), '', 'colspan'=>$colspan, %opt ) %>
127
128           <% pkg_status_row($cust_pkg, emt('Billed'), 'setup', %opt) %>
129
130           <% pkg_status_row_noauto( $cust_pkg, %opt, 'colspan'=>$colspan ) %>
131
132           <% pkg_status_row_discount( $cust_pkg, %opt, 'colspan'=>$colspan ) %>
133
134 %       } else { 
135 %
136 %         my $num_cust_svc = $cust_pkg->num_cust_svc;
137 %         my $summarize = $opt{'cust_pkg-large_pkg_size'} > 0
138 %                           && $opt{'cust_pkg-large_pkg_size'} <= $num_cust_svc;
139 %
140 %         #overlimit process is expensive with many services, so skip w/summary
141 %         if ( !$summarize && scalar($cust_pkg->overlimit) ) {
142
143             <% pkg_status_row_colspan( $cust_pkg,
144                  emt('Overlimit'),
145                  $billed_or_prepaid. '&nbsp;'. myfreq($part_pkg),
146                  'color'=>'FFD000', 'colspan'=>$colspan,
147                  %opt
148                )
149             %>
150
151 %         } else {
152             <% pkg_status_row_colspan( $cust_pkg,
153                  emt('Active'),
154                  $billed_or_prepaid. '&nbsp;'. myfreq($part_pkg),
155                  'color'=>'00CC00', 'colspan'=>$colspan,
156                  %opt
157                )
158             %>
159 %         } 
160
161           <% pkg_status_row_noauto( $cust_pkg, %opt, 'colspan'=>$colspan ) %>
162
163           <% pkg_status_row_discount( $cust_pkg, %opt, 'colspan'=>$colspan ) %>
164
165           <% pkg_status_row($cust_pkg, emt('Setup'), 'setup', %opt) %>
166
167 %       } 
168 %
169 %     } 
170 %
171 %     if ( $opt{'cust_pkg-show_autosuspend'} ) {
172 %       my $autosuspend = pkg_autosuspend_time( $cust_pkg );
173 %       $cust_pkg->set('autosuspend', $autosuspend) if $autosuspend;
174 %     }
175
176       <% pkg_status_row_changed( $cust_pkg, %opt, 'colspan'=>$colspan ) %>
177       <% pkg_status_row_if( $cust_pkg, $last_bill_or_renewed, 'last_bill', %opt, curuser=>$curuser ) %>
178       <% pkg_status_row_if( $cust_pkg, $next_bill_or_prepaid_until, 'bill', %opt, curuser=>$curuser ) %>
179       <% pkg_status_row_if($cust_pkg, emt('Will automatically suspend by'), 'autosuspend', %opt) %>
180       <% pkg_status_row_if($cust_pkg, emt('Automatic suspension delayed until'), 'dundate', %opt) %>
181       <% pkg_status_row_if( $cust_pkg, emt('Will suspend on'), 'adjourn', %opt, curuser=>$curuser ) %>
182       <% pkg_status_row_if( $cust_pkg, emt('Expires'), 'expire', %opt, curuser=>$curuser ) %>
183       <% pkg_status_row_if( $cust_pkg, emt('Contract ends'), 'contract_end', %opt ) %>
184
185 %     if ( $part_pkg->freq ) { 
186
187         <TR>
188           <TD COLSPAN=<%$colspan%>>
189             <FONT SIZE=-1>
190 %             if ( $curuser->access_right('Suspend customer package') ) { 
191                 (&nbsp;<% pkg_suspend_link($cust_pkg) %>&nbsp;)
192 %             } 
193 %             if ( $curuser->access_right('Suspend customer package later') ) { 
194                 (&nbsp;<% pkg_adjourn_link($cust_pkg) %>&nbsp;)
195 %             } 
196 %             if ( $curuser->access_right('Delay suspension events') ) { 
197                 (&nbsp;<% pkg_delay_link($cust_pkg) %>&nbsp;)
198 %             } 
199 %             if ( $curuser->access_right('Cancel customer package immediately') ) { 
200                 (&nbsp;<% pkg_cancel_link($cust_pkg) %>&nbsp;)
201 %             } 
202 %             if ( $curuser->access_right('Cancel customer package later') ) { 
203                 (&nbsp;<% pkg_expire_link($cust_pkg) %>&nbsp;)
204 %             } 
205
206             <FONT>
207           </TD>
208         </TR>
209 %     }
210 %
211 %   } 
212 % } 
213
214   </TABLE>
215 </TD>
216 <%init>
217
218 my %opt = @_;
219
220 my $bgcolor  = $opt{'bgcolor'};
221 my $cust_pkg = $opt{'cust_pkg'};
222 my $part_pkg = $opt{'part_pkg'};
223 my $curuser  = $FS::CurrentUser::CurrentUser;
224 my $colspan  = $opt{'cust_pkg-display_times'} ? 8 : 4;
225 my $width    = $opt{'cust_pkg-display_times'} ? '38%' : '56%';
226
227 #false laziness w/edit/REAL_cust_pkg.cgi
228 my( $billed_or_prepaid, $last_bill_or_renewed, $next_bill_or_prepaid_until );
229 unless ( $part_pkg->is_prepaid ) {
230   $billed_or_prepaid = 'billed';
231   $last_bill_or_renewed = 'Last&nbsp;bill';
232   $next_bill_or_prepaid_until = 'Next&nbsp;bill';
233 } else {
234   $billed_or_prepaid = 'prepaid';
235   $last_bill_or_renewed = 'Renewed';
236   $next_bill_or_prepaid_until = 'Prepaid&nbsp;until';
237 }
238
239 #subroutines
240
241 sub myfreq {
242   my $part_pkg = shift;
243   my $freq = $part_pkg->freq_pretty;
244   #$freq =~ s/ /&nbsp;/g;
245   $freq;
246 }
247
248 #false laziness w/package.html
249 sub pkg_link {
250   my($action, $label, $cust_pkg) = @_;
251   return '' unless $cust_pkg;
252   qq!<a href="$p$action.cgi?!. $cust_pkg->pkgnum. qq!">$label</a>!;
253 }
254
255 sub pkg_status_row {
256   my( $cust_pkg, $title, $field, %opt ) = @_;
257
258   my $color = $opt{'color'};
259
260   my $html = qq(<TR><TD WIDTH="<%$width%>" ALIGN="right">);
261   $html   .= qq(<FONT COLOR="#$color"><B>) if length($color);
262   $html   .= qq($title&nbsp;);
263   $html   .= qq(</B></FONT>) if length($color);
264
265   if ( $opt{'pkg_balances'} && ! $cust_pkg->{_printed_balance}++ ) { #kludge
266     $html .= ' (Balance:&nbsp;<B>'. $opt{'money_char'}.
267              $cust_pkg->cust_main->balance_pkgnum($cust_pkg->pkgnum).
268              '</B>)';
269   }
270
271   $html   .= qq(</TD>);
272   $html   .= pkg_datestr($cust_pkg, $field, %opt). '</TR>';
273
274   $html;
275 }
276
277 sub pkg_status_row_if {
278   my( $cust_pkg, $title, $field, %opt ) = @_;
279   
280   $title = '<FONT SIZE=-1>(&nbsp;'. pkg_unadjourn_link($cust_pkg). '&nbsp;)&nbsp;</FONT>'. $title
281     if ( $field eq 'adjourn' &&
282          $opt{curuser}->access_right('Suspend customer package later')
283        );
284
285   $title = '<FONT SIZE=-1>(&nbsp;'. pkg_unexpire_link($cust_pkg). '&nbsp;)&nbsp;</FONT>'. $title
286     if ( $field eq 'expire' &&
287          $opt{curuser}->access_right('Cancel customer package later')
288        );
289
290   $cust_pkg->get($field) ? pkg_status_row($cust_pkg, $title, $field, %opt) : '';
291 }
292
293 sub pkg_status_row_changed {
294   my( $cust_pkg, %opt ) = @_;
295
296   return '' unless $cust_pkg->change_date;
297
298   my $html =
299     pkg_status_row( $cust_pkg, emt('Package changed'), 'change_date', %opt );
300
301   my $old = $cust_pkg->old_cust_pkg;
302   if ( $old ) {
303     my $part_pkg = $old->part_pkg;
304     $html .= pkg_status_row_colspan( $cust_pkg, 
305                                      emt("Changed from [_1]: [_2]",
306                                             $cust_pkg->change_pkgnum,
307                                             $part_pkg->pkg_comment(nopartpkg => 1) ),
308                                      '',
309                                      'size'    => '-1',
310                                      'align'   => 'right',
311                                      'colspan' => $opt{'colspan'},
312                                    );
313   }
314
315   $html;
316 }
317
318 sub pkg_status_row_noauto {
319   my( $cust_pkg, %opt ) = @_;
320   my $part_pkg = $opt{'part_pkg'};
321   return '' unless $cust_pkg->no_auto || $part_pkg->no_auto;
322
323   #inefficient, should be passed in
324   my $cust_main = $cust_pkg->cust_main;
325
326   return '' unless $cust_main->payby =~ /^(CARD|CHEK)$/;
327   my $what = lc(FS::payby->shortname($cust_main->payby));
328
329   pkg_status_row_colspan( $cust_pkg, emt("No automatic $what charge"), '',
330                           'colspan' => $opt{'colspan'},
331                         );
332 }
333
334 sub pkg_status_row_discount {
335   my( $cust_pkg, %opt ) = @_;
336
337   my $html;
338
339   foreach my $cust_pkg_discount ( $cust_pkg->cust_pkg_discount_active ) {
340
341     my $discount = $cust_pkg_discount->discount;
342
343     my $label = '<B>'.emt('Discount').'</B>: '. $discount->description;
344     if ( $discount->months ) {
345       my $remaining = $discount->months - $cust_pkg_discount->months_used;
346       $remaining = sprintf('%.2f', $remaining) if $remaining =~ /\./;
347       $label .= emt("([_1] months remaining)",$remaining);
348     }
349
350     $label .= ' <FONT SIZE="-1">('.
351                 '<A HREF="../misc/delete-cust_pkg_discount.html?'.
352                   $cust_pkg_discount->pkgdiscountnum.
353                 '">'.emt('remove discount').'</A>)</FONT>';
354
355     $html .= pkg_status_row_colspan( $cust_pkg, $label, '',
356                                      'colspan' => $opt{'colspan'},
357                                    );
358
359   }
360
361   $html;
362 }
363
364 sub pkg_status_row_colspan {
365   my($cust_pkg, $title, $addl, %opt) = @_;
366
367   my $colspan  = $opt{'colspan'};
368
369   my $align = $opt{'align'} ? 'ALIGN="'. $opt{'align'}.'"' : '';
370   my $color = $opt{'color'} ? 'COLOR="#'.$opt{'color'}.'"' : '';
371   my $size  = $opt{'size'}  ? 'SIZE="'.  $opt{'size'}. '"' : '';
372
373   my $html = qq(<TR><TD COLSPAN=$colspan $align>);
374   $html   .= qq(<FONT $color $size>) if length($color) || $size;
375   $html   .= qq(<B>) if $color && !$size;
376   $html   .= $title;
377   $html   .= qq(</B>) if $color && !$size;
378   $html   .= qq(</FONT>) if length($color) || $size;
379   $html   .= ",&nbsp;$addl" if length($addl);
380
381   if ( $opt{'pkg-balances'} && ! $cust_pkg->{_printed_balance}++ ) { #kludge
382     $html .= ' (Balance:&nbsp;<B>'. $opt{'money_char'}.
383              $cust_pkg->cust_main->balance_pkgnum($cust_pkg->pkgnum).
384              '</B>)';
385   }
386
387   $html   .= qq(</TD></TR>);
388
389   $html;
390
391 }
392
393 sub pkg_datestr {
394   my($cust_pkg, $field, %opt) = @_ or return '';
395   return '&nbsp;' unless $cust_pkg->get($field);
396   my $format = '<TD align="left"><B>%b</B></TD>'.
397                '<TD align="right"><B>&nbsp;%o,</B></TD>'.
398                '<TD align="right"><B>&nbsp;%Y</B></TD>';
399   #$format .= '&nbsp;<FONT SIZE=-3>%l:%M:%S%P&nbsp;%z</FONT>'
400   $format .= '<TD ALIGN="right"><B>&nbsp;%l</TD>'.
401              '<TD ALIGN="center"><B>:</B></TD>'.
402              '<TD ALIGN="left"><B>%M</B></TD>'.
403              '<TD ALIGN="left"><B>&nbsp;%P</B></TD>'
404     if $opt{'cust_pkg-display_times'};
405   my $strip = time2str($format, $cust_pkg->get($field) );
406   $strip =~ s/ (\d)/$1/g;
407   $strip;
408 }
409
410 sub pkg_suspend_link {
411   include( '/elements/popup_link-cust_pkg.html',
412              'action'      => $p. 'misc/cancel_pkg.html?method=suspend',
413              'label'       => emt('Suspend now'),
414              'actionlabel' => emt('Suspend'),
415              'color'       => '#FF9900',
416              'cust_pkg'    => shift,
417          )
418 }
419
420 sub pkg_adjourn_link {
421   include( '/elements/popup_link-cust_pkg.html',
422              'action'      => $p. 'misc/cancel_pkg.html?method=adjourn',
423              'label'       => emt('Suspend later'),
424              'actionlabel' => emt('Adjourn'),
425              'color'       => '#CC6600',
426              'cust_pkg'    => shift,
427          )
428 }
429
430 sub pkg_delay_link  {
431   my($cust_pkg) = shift;
432   include( '/elements/popup_link-cust_pkg.html',
433              'action'      => $p. 'misc/delay_susp_pkg.html',
434              'label'       => ( $cust_pkg->dundate
435                                   ? emt('Edit suspension delay')
436                                   : emt('Delay suspend')
437                               ),
438              'actionlabel' => emt('Delay suspend for'),
439              'cust_pkg'    => $cust_pkg,
440          )
441 }
442
443 sub pkg_unsuspend_link { pkg_link('misc/unsusp_pkg',    emt('Unsuspend'), @_ ); }
444 sub pkg_unadjourn_link { pkg_link('misc/unadjourn_pkg', emt('Abort'),     @_ ); }
445 sub pkg_unexpire_link  { pkg_link('misc/unexpire_pkg',  emt('Abort'),     @_ ); }
446
447 sub pkg_cancel_link {
448   include( '/elements/popup_link-cust_pkg.html',
449              'action'      => $p. 'misc/cancel_pkg.html?method=cancel',
450              'label'       => emt('Cancel now'),
451              'actionlabel' => emt('Cancel'),
452              'color'       => '#ff0000',
453              'cust_pkg'    => shift,
454          )
455 }
456
457 sub pkg_expire_link {
458   include( '/elements/popup_link-cust_pkg.html',
459              'action'      => $p. 'misc/cancel_pkg.html?method=expire',
460              'label'       => emt('Cancel later'),
461              'actionlabel' => emt('Expire'),
462              'color'       => '#CC0000',
463              'cust_pkg'    => shift,
464          )
465 }
466
467 sub svc_recharge_link {
468   include( '/elements/popup_link-cust_svc.html',
469              'action'      => $p. 'misc/recharge_svc.html',
470              'label'       => emt('Recharge'),
471              'actionlabel' => emt('Recharge'),
472              'color'       => '#333399',
473              'cust_svc'    => shift,
474          )
475 }
476
477 sub pkg_autosuspend_time {
478   my $cust_pkg = shift or return '';
479   my $days = 7;
480   my $time = time;
481   my $pending_suspend = 0;
482   #this seems to be extremely inefficient...  and is slowing down all customer
483   #views
484   while ( $days > 0 &&
485           scalar(
486             grep { $_->part_event->action eq 'suspend' }
487             @{$cust_pkg->cust_main->due_cust_event( time => $time + 86400*$days,
488                                                     testonly => 1,
489                                                   ) }
490           )
491         )
492   {
493     $pending_suspend = 1;
494     $days--;
495   }
496
497   $pending_suspend ? time + ($days + 1) * 86400 : '';
498
499 }
500
501 </%init>