one-time charge enhancements
[freeside.git] / httemplate / view / cust_main / packages.html
1 %  my( $cust_main ) = @_;
2 %  my $conf = new FS::Conf;
3 %
4 %  my $curuser = $FS::CurrentUser::CurrentUser;
5 %
6 %  my $packages = get_packages($cust_main, $conf);
7
8
9 <A NAME="cust_pkg"><FONT SIZE="+2">Packages</FONT></A>
10 % if ( $curuser->access_right('Order customer package') ) { 
11
12   <% include('order_pkg.html', $cust_main ) %>
13 % } 
14 % if ( $curuser->access_right('One-time charge')
15 %        && $conf->config('payby-default') ne 'HIDE'
16 %      ) {
17 %
18
19   <% popup_link('edit/quick-charge.html?custnum='. $cust_main->custnum, 'One-time charge', 'One-time charge', 684) %>
20   <BR>
21 % } 
22 % if ( $curuser->access_right('Bulk change customer packages') ) { 
23
24   <A HREF="<% $p %>edit/cust_pkg.cgi?<% $cust_main->custnum %>">Bulk order and cancel packages</A> (preserves services)
25 % } 
26
27
28 <BR><BR>
29 % if ( @$packages ) { 
30
31 Current packages
32 % } 
33 % if ( $cust_main->num_cancelled_pkgs ) {
34 %     if ( $cgi->param('showcancelledpackages') eq '0' #see if it was set by me
35 %          || ( $conf->exists('hidecancelledpackages')
36 %               && ! $cgi->param('showcancelledpackages')
37 %             )
38 %        )
39 %     {
40 %       $cgi->param('showcancelledpackages', 1);
41 %
42
43   ( <a href="<% $cgi->self_url %>">show
44 %   } else {
45 %       $cgi->param('showcancelledpackages', 0);
46 %
47
48   ( <a href="<% $cgi->self_url %>">hide
49 %   } 
50
51  cancelled packages</a> )
52 % } 
53 % if ( @$packages ) { 
54
55
56 <% include('/elements/table-grid.html') %>
57 % my $bgcolor1 = '#eeeeee';
58 %   my $bgcolor2 = '#ffffff';
59 %   my $bgcolor = '';
60
61 <TR>
62   <TH CLASS="grid" BGCOLOR="#cccccc">Package</TH>
63   <TH CLASS="grid" BGCOLOR="#cccccc">Status</TH>
64   <TH CLASS="grid" BGCOLOR="#cccccc">Services</TH>
65 </TR>
66
67 %foreach my $cust_pkg (@$packages) {
68 %
69 %  my $part_pkg = $cust_pkg->part_pkg;
70 %
71 %  if ( $bgcolor eq $bgcolor1 ) {
72 %    $bgcolor = $bgcolor2;
73 %  } else {
74 %    $bgcolor = $bgcolor1;
75 %  }
76
77
78 <!--pkgnum: <% $cust_pkg->pkgnum %>-->
79 <TR>
80   <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
81     <A NAME="cust_pkg<% $cust_pkg->pkgnum %>"><% $cust_pkg->pkgnum %></A>:
82     <% $part_pkg->pkg %> - <% $part_pkg->comment %><BR>
83     <FONT SIZE=-1>
84 % unless ( $cust_pkg->get('cancel') ) { 
85 % if ( $curuser->access_right('Change customer package') ) { 
86
87             (&nbsp;<%pkg_change_link($cust_pkg)%>&nbsp;)
88 % } 
89 % if ( $curuser->access_right('Edit customer package dates') ) { 
90
91             (&nbsp;<%pkg_dates_link($cust_pkg)%>&nbsp;)
92 % } 
93 % if ( $curuser->access_right('Customize customer package') ) { 
94
95             (&nbsp;<%pkg_customize_link($cust_pkg,$cust_main->custnum)%>&nbsp;)
96 % } 
97 % } 
98
99     </FONT>
100   </TD>
101   <TD CLASS="inv" BGCOLOR="<% $bgcolor %>">
102     <TABLE CLASS="inv" BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH="100%">
103 %
104 %  sub myfreq {
105 %    my $part_pkg = shift;
106 %    my $freq = $part_pkg->freq_pretty;
107 %    $freq =~ s/ /&nbsp;/g;
108 %    $freq;
109 %  }
110 %
111 %  #this should use cust_pkg->status and cust_pkg->statuscolor eventually
112 %
113 %  my $colspan = $conf->exists('cust_pkg-display_times') ? 8 : 4;
114 %  my $width = $conf->exists('cust_pkg-display_times') ? '38%' : '56%';
115 %
116 %  #false laziness w/edit/REAL_cust_pkg.cgi
117 %  my( $billed_or_prepaid, $last_bill_or_renewed, $next_bill_or_prepaid_until );
118 %  unless ( $part_pkg->is_prepaid ) {
119 %    $billed_or_prepaid = 'billed';
120 %    $last_bill_or_renewed = 'Last&nbsp;bill';
121 %    $next_bill_or_prepaid_until = 'Next&nbsp;bill';
122 %  } else {
123 %    $billed_or_prepaid = 'prepaid';
124 %    $last_bill_or_renewed = 'Renewed';
125 %    $next_bill_or_prepaid_until = 'Prepaid&nbsp;until';
126 %  }
127 %
128 %
129 % if ( $cust_pkg->get('cancel') ) { 
130  <!-- #status: cancelled -->
131
132   <TR>
133     <TD WIDTH="<%$width%>" ALIGN="right"><FONT COLOR="#ff0000"><B>Cancelled&nbsp;</B></FONT></TD>
134     <% pkg_datestr($cust_pkg, 'cancel', $conf) %>
135   </TR>
136   <TR>
137     <TD WIDTH="<%$width%>" ALIGN="right"><FONT COLOR="#ff0000" SIZE="-2">
138       <% $cust_pkg->last_reason ? $cust_pkg->last_reason->reason : '' %>
139     </FONT></TD>
140   </TR>
141 % unless ( $cust_pkg->get('setup') ) { 
142
143
144     <TR>
145       <TD COLSPAN=<%$colspan%>>Never billed</TD>
146     </TR>
147 % } else { 
148
149
150     <TR>
151       <TD WIDTH="<%$width%>" ALIGN="right">Setup&nbsp;</TD>
152       <% pkg_datestr($cust_pkg, 'setup', $conf) %>
153     </TR>
154 % if ( $cust_pkg->get('last_bill') ) { 
155
156       <TR>
157         <TD WIDTH="<%$width%>" ALIGN="right"><% $last_bill_or_renewed %>&nbsp;</TD>
158         <% pkg_datestr($cust_pkg, 'last_bill',$conf) %>
159       </TR>
160 % } 
161 % if ( $cust_pkg->get('susp') ) { 
162
163       <TR>
164         <TD WIDTH="<%$width%>" ALIGN="right">Suspended&nbsp;</TD>
165         <% pkg_datestr($cust_pkg, 'susp', $conf) %>
166       </TR>
167 % } 
168 % } 
169 % } else { 
170 % if ( $cust_pkg->get('susp') ) { 
171  <!-- #status: suspended -->
172
173     <TR>
174       <TD WIDTH="<%$width%>" ALIGN="right"><FONT COLOR="#FF9900"><B>Suspended</B>&nbsp;</FONT></TD>
175       <% pkg_datestr($cust_pkg, 'susp', $conf) %>
176     </TR>
177     <TR>
178       <TD WIDTH="<%$width%>" ALIGN="right"><FONT COLOR="#FF9900" SIZE="-2">
179         <% $cust_pkg->last_reason ? $cust_pkg->last_reason->reason : '' %>
180       </FONT></TD>
181     </TR>
182 % unless ( $cust_pkg->get('setup') ) { 
183
184
185       <TR>
186         <TD COLSPAN=<%$colspan%>>Never billed</TD>
187       </TR>
188 % } else { 
189
190
191       <TR>
192         <TD WIDTH="<%$width%>" ALIGN="right">Setup&nbsp;</TD>
193         <% pkg_datestr($cust_pkg, 'setup', $conf) %>
194       </TR>
195 % } 
196 % if ( $cust_pkg->get('last_bill') ) { 
197
198       <TR>
199         <TD WIDTH="<%$width%>" ALIGN="right"><% $last_bill_or_renewed %>&nbsp;</TD>
200         <% pkg_datestr($cust_pkg, 'last_bill', $conf) %>
201       </TR>
202 % } 
203
204
205     <!-- # next bill ?? -->
206 % if ( $cust_pkg->get('expire') ) { 
207
208       <TR>
209         <TD WIDTH="<%$width%>" ALIGN="right">Expires&nbsp;</TD>
210         <% pkg_datestr($cust_pkg, 'expire', $conf) %>
211       </TR>
212 % } 
213
214
215     <TR>
216       <TD COLSPAN=<%$colspan%>>
217         <FONT SIZE=-1>
218 % if ( $curuser->access_right('Unsuspend customer package') ) { 
219
220             (&nbsp;<% pkg_unsuspend_link($cust_pkg) %>&nbsp;)
221 % } 
222 % if ( $curuser->access_right('Cancel customer package') ) { 
223
224             (&nbsp;<% pkg_cancel_link($cust_pkg) %>&nbsp;)
225 % } 
226
227         </FONT>
228       </TD>
229     </TR>
230 % } else { 
231  <!-- #status: active -->
232 % unless ( $cust_pkg->get('setup') ) { 
233  <!-- #not setup -->
234 % unless ( $part_pkg->freq ) { 
235
236
237         <TR>
238           <TD COLSPAN=<%$colspan%>>Not&nbsp;yet&nbsp;billed&nbsp;(one-time&nbsp;charge)</TD>
239         </TR>
240
241         <TR>
242           <TD COLSPAN=<%$colspan%>>
243             <FONT SIZE=-1>
244 % if ( $curuser->access_right('Cancel customer package immediately') ) { 
245
246                 (&nbsp;<% pkg_cancel_link($cust_pkg) %>&nbsp;)
247 % } 
248
249             </FONT>
250           </TD>
251         </TR>
252 % } else { 
253
254
255         <TR>
256           <TD COLSPAN=<%$colspan%>>Not&nbsp;yet&nbsp;billed&nbsp;(<% $billed_or_prepaid %>&nbsp;<% myfreq($part_pkg) %>)</TD>
257         </TR>
258 % } 
259 % } else { 
260  <!-- #setup -->
261 % unless ( $part_pkg->freq ) { 
262
263
264         <TR>
265           <TD COLSPAN=<%$colspan%>>One-time&nbsp;charge</TD>
266         </TR>
267
268         <TR>
269           <TD WIDTH="<%$width%>" ALIGN="right">Billed&nbsp;</TD>
270           <% pkg_datestr($cust_pkg, 'setup', $conf) %>
271         </TR>
272 % } else { 
273
274
275         <TR>
276           <TD COLSPAN=<%$colspan%>><FONT COLOR="#00CC00"><B>Active</B></FONT>,&nbsp;<% $billed_or_prepaid %>&nbsp;<% myfreq($part_pkg) %></TD>
277         </TR>
278
279         <TR>
280           <TD WIDTH="<%$width%>" ALIGN="right">Setup&nbsp;</TD>
281           <% pkg_datestr($cust_pkg, 'setup', $conf) %>
282         </TR>
283 % } 
284 % } 
285 % if ( $cust_pkg->get('last_bill') ) { 
286
287       <TR>
288         <TD WIDTH="<%$width%>" ALIGN="right"><% $last_bill_or_renewed %>&nbsp;</TD>
289         <% pkg_datestr($cust_pkg, 'last_bill', $conf) %>
290       </TR>
291 % } 
292 % if ( $cust_pkg->get('bill') ) { #next bill
293
294       <TR>
295         <TD WIDTH="<%$width%>" ALIGN="right"><% $next_bill_or_prepaid_until %>&nbsp;</TD>
296         <% pkg_datestr($cust_pkg, 'bill', $conf) %>
297       </TR>
298 % } 
299 % if ( $cust_pkg->get('expire') ) { 
300
301       <TR>
302         <TD WIDTH="<%$width%>" ALIGN="right">Expires&nbsp;</TD>
303         <% pkg_datestr($cust_pkg, 'expire', $conf) %>
304       </TR>
305 % } 
306 % if ( $part_pkg->freq ) { 
307
308       <TR>
309         <TD COLSPAN=<%$colspan%>>
310           <FONT SIZE=-1>
311 % if ( $curuser->access_right('Suspend customer package') ) { 
312
313               (&nbsp;<% pkg_suspend_link($cust_pkg) %>&nbsp;)
314 % } 
315 % if ( $curuser->access_right('Cancel customer package immediately') ) { 
316
317               (&nbsp;<% pkg_cancel_link($cust_pkg) %>&nbsp;)
318 % } 
319 % if ( $curuser->access_right('Cancel customer package later') ) { 
320
321               (&nbsp;<% pkg_expire_link($cust_pkg) %>&nbsp;)
322 % } 
323
324           <FONT>
325         </TD>
326       </TR>
327 % } 
328 % } 
329 % } 
330
331
332 </TABLE>
333 </TD>
334
335 <TD CLASS="inv" BGCOLOR="<% $bgcolor %>">
336   <TABLE CLASS="inv" BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH="100%">
337
338 %  #foreach my $svcpart (sort {$a->{svcpart} <=> $b->{svcpart}} @{$pkg->{svcparts}}) {
339 %  foreach my $part_svc ( $cust_pkg->part_svc ) {
340
341 %    #foreach my $service (@{$svcpart->{services}}) {
342 %    foreach my $cust_svc ( @{ $part_svc->cust_pkg_svc } ) {
343
344       <TR>
345         <TD ALIGN="right" VALIGN="top"><% FS::UI::Web::svc_link($m, $part_svc, $cust_svc) %></TD>
346         <TD STYLE="padding-bottom:0px"><B><% FS::UI::Web::svc_label_link($m, $part_svc, $cust_svc) %></B></TD>
347       </TR>
348
349       <TR>
350         <TD ALIGN="right" VALIGN="top" STYLE="padding-bottom:5px;padding-top:0px"><FONT SIZE="-2">
351
352 %         if ( $curuser->access_right('Recharge customer service')
353 %              && $cust_svc->svcdb eq 'svc_acct'
354 %              && (    $cust_svc->svc_x->seconds    ne ''
355 %                   || $cust_svc->svc_x->upbytes    ne ''
356 %                   || $cust_svc->svc_x->downbytes  ne ''
357 %                   || $cust_svc->svc_x->totalbytes ne ''
358 %                 )
359 %         ) { 
360             (&nbsp;<%svc_recharge_link($cust_svc)%>&nbsp;)
361 %         } 
362           </FONT></TD>
363
364           <TD ALIGN="right" VALIGN="top" STYLE="padding-bottom:5px;padding-top:0px"><FONT SIZE="-2">
365
366 %         if ( $curuser->access_right('Unprovision customer service') ) { 
367             (&nbsp;<%svc_unprovision_link($cust_svc)%>&nbsp;)
368 %         } 
369           </FONT></TD>
370         </TR>
371 %   } 
372
373 %   if (    ! $cust_pkg->get('cancel')
374 %        && $curuser->access_right('Provision customer service') 
375 %        && $part_svc->num_avail
376 %      ) {
377
378       <TR>
379         <TD COLSPAN=2 ALIGN="center" STYLE="padding-bottom:4px;padding-top:0px">
380           <B><% svc_provision_link($cust_pkg, $part_svc, $conf, $curuser) %></B>
381         </TD>
382       </TR>
383
384 %   } 
385
386 % } 
387
388 </TABLE>
389 </TD>
390 % } #end display packages
391 %
392
393
394 </TABLE>
395 % } else { 
396
397 <BR>
398 % } 
399 %
400 %#subroutines
401 %
402 %sub get_packages {
403 %  my $cust_main = shift or return undef;
404 %  my $conf = shift;
405 %  
406 %  my @packages = ();
407 %  my $method;
408 %  if (  $cgi->param('showcancelledpackages') eq '0' #see if it was set by me
409 %     || ( $conf->exists('hidecancelledpackages')
410 %           && ! $cgi->param('showcancelledpackages') )
411 %     )
412 %  {
413 %    $method = 'ncancelled_pkgs';
414 %  } else {
415 %    $method = 'all_pkgs';
416 %  }
417 %
418 %  [ $cust_main->$method() ];
419 %}
420 %  
421 %sub svc_provision_link {
422 %  my ($cust_pkg, $part_svc, $conf, $curuser) = @_;
423 %  ( my $svc_nbsp = $part_svc->svc ) =~ s/\s+/&nbsp;/g;
424 %  my $num_avail = $part_svc->num_avail;
425 %  my $pkgnum_svcpart = "pkgnum=". $cust_pkg->pkgnum. ';'.
426 %                       "svcpart=". $part_svc->svcpart;
427 %  my $url;
428 %  if ( $part_svc->svcdb eq 'svc_external' #could be generalized
429 %       && $conf->exists('svc_external-skip_manual')
430 %  ) {
431 %    $url = "${p}edit/process/". $part_svc->svcdb. ".cgi?$pkgnum_svcpart";
432 %  } else {
433 %    $url = FS::UI::Web::svc_url(
434 %                                 'm'        => $m,
435 %                                 'action'   => 'edit',
436 %                                 'part_svc' => $part_svc, 
437 %                                 'query'    => $pkgnum_svcpart,
438 %                               );
439 %    #$url = "${p}edit/$svcpart->{svcdb}.cgi?$pkgnum_svcpart";
440 %  }
441 %
442 %  my $link = qq!<A CLASS="provision" HREF="$url">!.
443 %             "Provision&nbsp;$svc_nbsp&nbsp;($num_avail)</A>";
444 %  if ( $conf->exists('legacy_link')
445 %       && $curuser->access_right('View/link unlinked services')
446 %     )
447 %  {
448 %    $link .= '<BR>'.
449 %             qq!<A CLASS="provision" HREF="${p}misc/link.cgi?!.
450 %             qq!$pkgnum_svcpart">!.
451 %            "Link&nbsp;to&nbsp;legacy&nbsp;$svc_nbsp&nbsp;($num_avail)</A>";
452 %  }
453 %  $link;
454 %}
455 %
456 %sub svc_unprovision_link {
457 %  my $cust_svc = shift or return '';
458 %  qq!<A HREF="javascript:areyousure('${p}misc/unprovision.cgi?!. $cust_svc->svcnum.
459 %  qq!', 'Permanently unprovision and delete this service?')">Unprovision</A>!;
460 %}
461 %
462 %sub pkg_datestr {
463 %  my($cust_pkg, $field, $conf) = @_ or return '';
464 %  return '&nbsp;' unless $cust_pkg->get($field);
465 %  my $format = '<TD align="left"><B>%b</B></TD>'.
466 %               '<TD align="right"><B>&nbsp;%o,</B></TD>'.
467 %               '<TD align="right"><B>&nbsp;%Y</B></TD>';
468 %  #$format .= '&nbsp;<FONT SIZE=-3>%l:%M:%S%P&nbsp;%z</FONT>'
469 %  $format .= '<TD ALIGN="right"><B>&nbsp;%l</TD>'.
470 %             '<TD ALIGN="center"><B>:</B></TD>'.
471 %             '<TD ALIGN="left"><B>%M</B></TD>'.
472 %             '<TD ALIGN="left"><B>&nbsp;%P</B></TD>'
473 %    if $conf->exists('cust_pkg-display_times');
474 %  my $strip = time2str($format, $cust_pkg->get($field) );
475 %  $strip =~ s/ (\d)/$1/g;
476 %  $strip;
477 %}
478 %
479 %sub pkg_change_link    { pkg_link('misc/change_pkg',    'Change&nbsp;package', @_ ); }
480 %
481 %sub pkg_suspend_link   { pkg_popup_link( 'misc/cancel_pkg/html?method=suspend',
482 %                                         'Suspend',
483 %                                         'Suspend',
484 %                                         @_
485 %                                       );
486 %                       }
487 %
488 %sub pkg_unsuspend_link { pkg_link('misc/unsusp_pkg',    'Unsuspend',           @_ ); }
489 %sub pkg_expire_link    { pkg_link('misc/expire_pkg',    'Cancel&nbsp;later',   @_ ); }
490 %sub pkg_dates_link     { pkg_link('edit/REAL_cust_pkg', 'Edit&nbsp;dates',     @_ ); }
491 %
492 %sub pkg_cancel_link    { pkg_popup_link( 'misc/cancel_pkg.html?method=cancel',
493 %                                         'Cancel&nbsp;now',
494 %                                         'Cancel',
495 %                                         @_
496 %                                       );
497 %                       }
498 %sub pkg_expire_link    { pkg_popup_link( 'misc/cancel_pkg.html?method=expire',
499 %                                         'Cancel&nbsp;later',
500 %                                         'Expire', #"Cancel package $num later"
501 %                                         @_
502 %                                       );
503 %                       }
504 %
505 %sub svc_recharge_link  { svc_popup_link( 'misc/recharge_svc.html',
506 %                                         'Recharge',
507 %                                         'Recharge',
508 %                                         @_
509 %                                       );
510 %                       }
511 %
512 %sub pkg_link {
513 %  my($action, $label, $cust_pkg) = @_;
514 %  return '' unless $cust_pkg;
515 %  qq!<a href="${p}$action.cgi?!. $cust_pkg->pkgnum. qq!">$label</a>!;
516 %}
517 %
518 %sub pkg_popup_link {
519 %  my($action, $label, $actionlabel, $cust_pkg) = @_;
520 %  $action .= '&pkgnum='. $cust_pkg->pkgnum;
521 %  $actionlabel .= ' package '. $cust_pkg->pkgnum;
522 %  popup_link($action, $label, $actionlabel, 392);
523 %}
524 %
525 %sub svc_popup_link {
526 %  my($action, $label, $actionlabel, $cust_svc) = @_;
527 %  $action .= '?svcnum='. $cust_svc->svcnum;
528 %  $actionlabel .= ' service '. $cust_svc->svcnum;
529 %  popup_link($action, $label, $actionlabel, 392);
530 %}
531 %
532 %sub popup_link {
533 %  my($action, $label, $actionlabel, $width) = @_;
534 %  qq!<A HREF="javascript:void(0);" onClick="overlib( OLiframeContent('$p$action', $width, 336, 'pkg_or_svc_action_popup' ), CAPTION, '$actionlabel', STICKY, AUTOSTATUSCAP, MIDX, 0, MIDY, 0, DRAGGABLE, CLOSECLICK ); return false;">$label</A>!;
535 %}
536 %
537 %sub pkg_customize_link {
538 %  my $cust_pkg = shift or return '';
539 %  my $custnum = $cust_pkg->custnum;
540 %  qq!<A HREF="${p}edit/part_pkg.cgi?!.
541 %    "keywords=$custnum;".
542 %    "clone=". $cust_pkg->part_pkg->pkgpart. ';'.
543 %    "pkgnum=". $cust_pkg->pkgnum.
544 %    qq!">Customize</A>!;
545 %}