add package invoice details & comments, RT#3810
[freeside.git] / httemplate / view / cust_main / packages.html
1 <A NAME="cust_pkg"><FONT SIZE="+2">Packages</FONT></A><BR>
2
3 % if ( $curuser->access_right('One-time charge') ) {
4
5 <SCRIPT TYPE="text/javascript">
6
7 function taxproductmagic(which) {
8   var str = '';
9   var elements = which.form.elements;
10   for (var i = 0; i<elements.length; i++) {
11     if (elements[i].name == 'taxproductnum'){
12       document.getElementById('taxproductnum').value = elements[i].value;
13       continue;
14     }
15     if (elements[i].name == 'taxproductnum_description'){
16       continue;
17     }
18     if (str.length){str += ';';}
19     str += elements[i].name + '=' + escape(elements[i].value);
20   }
21   document.getElementById('charge_storage').value = str;
22   cClick();
23   overlib( OLiframeContent('<% $p %>/browse/part_pkg_taxproduct.cgi?_type=select&id=taxproductnum&onclick=taxproductquickchargemagic&taxproductnum='+document.getElementById('taxproductnum').value, 1000, 400, 'tax_product_popup'), CAPTION, 'Select product', STICKY, AUTOSTATUSCAP, MIDX, 0, MIDY, 0, DRAGGABLE, CLOSECLICK);
24 }
25
26 function taxproductquickchargemagic() {
27   var str = document.getElementById('charge_storage').value;
28   if (str.length){str += ';';}
29   str += 'magic=taxproductnum;taxproductnum=';
30   str += escape(document.getElementById('taxproductnum').value);
31   cClick();
32   overlib( OLiframeContent('<% $p %>/edit/quick-charge.html?'+str, 545, 336, 'One-time charge'), CAPTION, 'One-time charge', STICKY, AUTOSTATUSCAP, MIDX, 0, MIDY, 0, DRAGGABLE, CLOSECLICK, BGCOLOR, '#333399', CGCOLOR, '#333399', CLOSETEXT, 'Close');
33
34 }
35
36 function taxoverridemagic(which) {
37   var str = '';
38   var elements = which.ownerDocument.QuickChargeForm.elements;
39   for (var i = 0; i<elements.length; i++) {
40     if (elements[i].name == 'tax_override'){
41       document.getElementById('tax_override').value = elements[i].value;
42       continue;
43     }
44     if (str.length){str += ';';}
45     str += elements[i].name + '=' + escape(elements[i].value);
46   }
47   document.getElementById('charge_storage').value = str;
48   cClick();
49   overlib( OLiframeContent('<% $p %>/edit/part_pkg_taxoverride.html?element_name=tax_override;onclick=taxoverridequickchargemagic;selected='+document.getElementById('tax_override').value, 1100, 600, 'tax_product_popup'), CAPTION, 'Edit product tax overrides', STICKY, AUTOSTATUSCAP, MIDX, 0, MIDY, 0, DRAGGABLE, CLOSECLICK);
50 }
51
52 function taxoverridequickchargemagic() {
53   var str = document.getElementById('charge_storage').value;
54   if (str.length){str += ';';}
55   str += 'magic=taxoverride;tax_override=';
56   str += document.getElementById('tax_override').value;
57   cClick();
58   overlib( OLiframeContent('<% $p %>/edit/quick-charge.html?'+str, 545, 336, 'One-time charge'), CAPTION, 'One-time charge', STICKY, AUTOSTATUSCAP, MIDX, 0, MIDY, 0, DRAGGABLE, CLOSECLICK, BGCOLOR, '#333399', CGCOLOR, '#333399', CLOSETEXT, 'Close');
59
60 }
61
62 </SCRIPT>
63 <FORM NAME='quickcharge'>
64   <INPUT NAME="taxproductnum"  ID="taxproductnum"  TYPE="hidden">
65   <INPUT NAME="tax_override"   ID="tax_override"   TYPE="hidden">
66   <INPUT NAME="charge_storage" ID="charge_storage" TYPE="hidden">
67   <INPUT NAME="taxproductnum_description"  ID="taxproductnum_description" TYPE="hidden">
68 </FORM>
69 % } 
70
71 % my $s = 0;
72 % if ( $curuser->access_right('Order customer package') ) { 
73   <% $s++ ? ' | ' : '' %>
74   <% order_pkg_link($cust_main) %>
75 % } 
76
77 % if ( $curuser->access_right('One-time charge')
78 %        && $conf->config('payby-default') ne 'HIDE'
79 %      ) {
80 %
81   <% $s++ ? ' | ' : '' %>
82   <% include('/elements/popup_link.html',
83      { 
84        'action'      => $p. 'edit/quick-charge.html?custnum='. $cust_main->custnum,
85        'label'       => 'One-time charge',
86        'actionlabel' => 'One-time charge',
87        'color'       => '#333399',
88        'width'       => 763,
89      })
90   %>
91 % } 
92
93 % if ( $curuser->access_right('Bulk change customer packages') ) { 
94   <% $s++ ? ' | ' : '' %>
95   <A HREF="<% $p %>edit/cust_pkg.cgi?<% $cust_main->custnum %>">Bulk order and cancel packages</A> (preserves services)
96 % } 
97
98
99 <BR><BR>
100 % if ( @$packages ) { 
101
102 Current packages
103 % } 
104 % if ( $cust_main->num_cancelled_pkgs ) {
105 %     if ( $cgi->param('showcancelledpackages') eq '0' #see if it was set by me
106 %          || ( $conf->exists('hidecancelledpackages')
107 %               && ! $cgi->param('showcancelledpackages')
108 %             )
109 %        )
110 %     {
111 %       $cgi->param('showcancelledpackages', 1);
112 %
113
114   ( <a href="<% $cgi->self_url %>">show
115 %   } else {
116 %       $cgi->param('showcancelledpackages', 0);
117 %
118
119   ( <a href="<% $cgi->self_url %>">hide
120 %   } 
121
122  cancelled packages</a> )
123 % } 
124 % if ( @$packages ) { 
125
126
127 <% include('/elements/table-grid.html') %>
128 % my $bgcolor1 = '#eeeeee';
129 %   my $bgcolor2 = '#ffffff';
130 %   my $bgcolor = '';
131
132 <TR>
133   <TH CLASS="grid" BGCOLOR="#cccccc">Package</TH>
134   <TH CLASS="grid" BGCOLOR="#cccccc">Status</TH>
135   <TH CLASS="grid" BGCOLOR="#cccccc">Services</TH>
136 </TR>
137
138 %foreach my $cust_pkg (@$packages) {
139 %
140 %  my $part_pkg = $cust_pkg->part_pkg;
141 %
142 %  if ( $bgcolor eq $bgcolor1 ) {
143 %    $bgcolor = $bgcolor2;
144 %  } else {
145 %    $bgcolor = $bgcolor1;
146 %  }
147
148
149 <!--pkgnum: <% $cust_pkg->pkgnum %>-->
150 <TR>
151
152   <TD CLASS="inv" BGCOLOR="<% $bgcolor %>">
153     <TABLE CLASS="inv" BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH="100%">
154       <TR>
155         <TD COLSPAN=2>
156           <A NAME="cust_pkg<% $cust_pkg->pkgnum %>"
157              ID  ="cust_pkg<% $cust_pkg->pkgnum %>"
158           ><% $curuser->option('show_pkgnum') ? $cust_pkg->pkgnum.': ' : '' %><% $part_pkg->pkg %></A>
159           - 
160           <% $part_pkg->comment %>
161         </TD>
162       </TR>
163
164 %   if ( $cust_pkg->quantity > 1 ) {
165       <TR>
166         <TD COLSPAN=2>
167           &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Quantity: 
168           <B><% $cust_pkg->quantity %></B>
169         </TD>
170       </TR>
171 %   }
172
173       <TR>
174         <TD COLSPAN=2>
175
176           <FONT SIZE=-1>
177
178 % unless ( $cust_pkg->get('cancel') ) { 
179 %   my $br = 0;
180 %   if ( $curuser->access_right('Change customer package') ) { $br=1;
181
182             (&nbsp;<%pkg_change_link($cust_pkg)%>&nbsp;)
183 %   } 
184 %   if ( $curuser->access_right('Edit customer package dates') ) { $br=1;
185
186             (&nbsp;<%pkg_dates_link($cust_pkg)%>&nbsp;)
187 %   } 
188 %   if ( $curuser->access_right('Customize customer package') ) { $br=1;
189
190             (&nbsp;<%pkg_customize_link($cust_pkg,$cust_main->custnum)%>&nbsp;)
191 %   } 
192     <% $br ? '<BR>' : '' %>
193 % } 
194
195 % if ( $cust_pkg->num_cust_event
196 %      && (    $curuser->access_right('Billing event reports')
197 %           || $curuser->access_right('View customer billing events')
198 %         )
199 %    ) {
200     (&nbsp;<%pkg_event_link($cust_pkg)%>&nbsp;)
201 % }
202
203           </FONT>
204
205         </TD>
206       </TR>
207
208 %   my $editi = $curuser->access_right('Edit customer package invoice details');
209 %   my $editc = $curuser->access_right('Edit customer package comments');
210 %
211 %   if ( $cust_pkg->cust_pkg_detail('I') || $cust_pkg->cust_pkg_detail('C')
212 %        || $editi || $editc                                                ) {
213 %
214 %     my $editlink = $p. 'edit/cust_pkg_detail?pkgnum='. $cust_pkg->pkgnum.
215 %                    ';detailtype=';
216
217       <TR>
218
219 %       if ( $cust_pkg->cust_pkg_detail('I') ) { 
220           <TD VALIGN="top">
221             <% include('/elements/table-grid.html') %>
222               <TR>
223                 <TH BGCOLOR="#dddddd" STYLE="border-bottom: dashed 1px black; padding-bottom: 1px">
224                   <FONT SIZE="-1">
225                     Invoice details
226 %                   if ( $editi && ! $cust_pkg->get('cancel') ) {
227                       (<% include('/elements/popup_link.html', { 
228                                     'action'      => $editlink. 'I',
229                                     'label'       => 'edit',
230                                     'actionlabel' => 'Edit invoice details',
231                                     'color'       => '#333399',
232                                     'width'       => 763,
233                                  })
234                        %>)
235 %                   }
236                   </FONT>
237                 </TH>
238               </TR>
239 %             foreach my $cust_pkg_detail ( $cust_pkg->cust_pkg_detail('I') ) {
240                 <TR>
241                   <TD><FONT SIZE="-1">&nbsp;-&nbsp;<% $cust_pkg_detail->detail |h %></FONT></TD>
242                 </TR>
243 %             }
244             </TABLE>
245           </TD>
246 %       } else {
247           <TD>
248 %           if ( $editi && ! $cust_pkg->get('cancel') ) {
249               <FONT SIZE="-1">
250                 (&nbsp;<% include('/elements/popup_link.html', { 
251                                'action'      => $editlink. 'I',
252                                'label'       => 'Add&nbsp;invoice&nbsp;details',
253                                'actionlabel' => 'Add invoice details',
254                                'color'       => '#333399',
255                                'width'       => 763,
256                             })
257                   %>&nbsp;)
258               </FONT>
259 %           }
260           </TD>
261 %       }
262
263 %       if ( $cust_pkg->cust_pkg_detail('C') ) { 
264           <TD VALIGN="top">
265             <% include('/elements/table-grid.html') %>
266               <TR>
267                 <TH BGCOLOR="#dddddd" STYLE="border-bottom: dashed 1px black; padding-bottom: 1px">
268                   <FONT SIZE="-1">
269                     Comments
270 %                   if ( $editc ) {
271                       (<% include('/elements/popup_link.html', { 
272                                     'action'      => $editlink. 'C',
273                                     'label'       => 'edit',
274                                     'actionlabel' => 'Edit comments',
275                                     'color'       => '#333399',
276                                     'width'       => 763,
277                                  })
278                        %>)
279 %                   }
280                   </FONT>
281                 </TH>
282               </TR>
283 %             foreach my $cust_pkg_detail ( $cust_pkg->cust_pkg_detail('C') ) {
284                 <TR>
285                   <TD><FONT SIZE="-1">&nbsp;-&nbsp;<% $cust_pkg_detail->detail |h %></FONT></TD>
286                 </TR>
287 %             }
288             </TABLE>
289           </TD>
290 %       } else {
291           <TD>
292 %           if ( $editc ) {
293               <FONT SIZE="-1">
294                 (&nbsp;<% include('/elements/popup_link.html', { 
295                                'action'      => $editlink. 'C',
296                                'label'       => 'Add&nbsp;comments',
297                                'actionlabel' => 'Add comments',
298                                'color'       => '#333399',
299                                'width'       => 763,
300                             })
301                   %>&nbsp;)
302               </FONT>
303 %           }
304           </TD>
305 %       }
306
307       </TR>
308 %   }
309
310     </TABLE>
311
312   </TD>
313
314   <TD CLASS="inv" BGCOLOR="<% $bgcolor %>">
315     <TABLE CLASS="inv" BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH="100%">
316 %
317 %  sub myfreq {
318 %    my $part_pkg = shift;
319 %    my $freq = $part_pkg->freq_pretty;
320 %    $freq =~ s/ /&nbsp;/g;
321 %    $freq;
322 %  }
323 %
324 %  #this should use cust_pkg->status and cust_pkg->statuscolor eventually
325 %  #my $colspan = $conf->exists('cust_pkg-display_times') ? 8 : 4;
326 %  #my $width = $conf->exists('cust_pkg-display_times') ? '38%' : '56%';
327 %
328 %  #false laziness w/edit/REAL_cust_pkg.cgi
329 %  my( $billed_or_prepaid, $last_bill_or_renewed, $next_bill_or_prepaid_until );
330 %  unless ( $part_pkg->is_prepaid ) {
331 %    $billed_or_prepaid = 'billed';
332 %    $last_bill_or_renewed = 'Last&nbsp;bill';
333 %    $next_bill_or_prepaid_until = 'Next&nbsp;bill';
334 %  } else {
335 %    $billed_or_prepaid = 'prepaid';
336 %    $last_bill_or_renewed = 'Renewed';
337 %    $next_bill_or_prepaid_until = 'Prepaid&nbsp;until';
338 %  }
339 %
340 %
341 % if ( $cust_pkg->get('cancel') ) { #status: cancelled
342 %   my $cpr = $cust_pkg->last_cust_pkg_reason('cancel');
343
344     <% pkg_status_row($cust_pkg, 'Cancelled', 'cancel', 'color'=>'FF0000', conf=>$conf ) %>
345
346     <% pkg_status_row_colspan(
347          ( $cpr ? $cpr->reasontext. ' by '. $cpr->otaker : '' ), '',
348          'align' => 'right', 'color' => 'ff0000', 'size' => '-2',
349        )
350     %>
351
352 %   unless ( $cust_pkg->get('setup') ) { 
353
354         <% pkg_status_row_colspan('Never billed') %>
355
356 %   } else { 
357
358        <% pkg_status_row( $cust_pkg, 'Setup', 'setup', conf=>$conf ) %>
359        <% pkg_status_row_changed( $cust_pkg, conf=>$conf ) %>
360        <% pkg_status_row_if( $cust_pkg, $last_bill_or_renewed, 'last_bill', conf=>$conf, curuser=>$curuser ) %>
361        <% pkg_status_row_if( $cust_pkg, 'Suspended', 'susp', conf=>$conf, curuser=>$curuser ) %>
362
363 %   } 
364 %
365 % } else { 
366 %
367 %   if ( $cust_pkg->get('susp') ) { #status: suspended
368 %     my $cpr = $cust_pkg->last_cust_pkg_reason('susp');
369
370     <% pkg_status_row( $cust_pkg, 'Suspended', 'susp', 'color'=>'FF9900', conf=>$conf ) %>
371
372     <% pkg_status_row_colspan(
373          ( $cpr ? $cpr->reasontext. ' by '. $cpr->otaker : '' ), '',
374          'align' => 'right', 'color' => 'FF9900', 'size' => '-2',
375        )
376     %>
377
378 %   unless ( $cust_pkg->get('setup') ) { 
379       <% pkg_status_row_colspan('Never billed') %>
380 %   } else { 
381       <% pkg_status_row($cust_pkg, 'Setup', 'setup', conf=>$conf ) %>
382 %   } 
383
384     <% pkg_status_row_changed( $cust_pkg, conf=>$conf ) %>
385     <% pkg_status_row_if( $cust_pkg, $last_bill_or_renewed, 'last_bill', conf=>$conf, curuser=>$curuser ) %>
386 %   # pkg_status_row($cust_pkg, 'Next bill', 'bill', conf=>$conf)
387     <% pkg_status_row_if( $cust_pkg, 'Expires', 'expire', conf=>$conf, curuser=>$curuser ) %>
388
389     <TR>
390       <TD COLSPAN=<%$colspan%>>
391         <FONT SIZE=-1>
392 %         if ( $curuser->access_right('Unsuspend customer package') ) { 
393             (&nbsp;<% pkg_unsuspend_link($cust_pkg) %>&nbsp;)
394 %         } 
395 %         if ( $curuser->access_right('Cancel customer package immediately') ) {
396             (&nbsp;<% pkg_cancel_link($cust_pkg) %>&nbsp;)
397 %         } 
398         </FONT>
399       </TD>
400     </TR>
401
402 %   } else { #status: active
403 %
404 %     unless ( $cust_pkg->get('setup') ) { #not setup
405 %
406 %       unless ( $part_pkg->freq ) { 
407
408           <% pkg_status_row_colspan('Not&nbsp;yet&nbsp;billed&nbsp;(one-time&nbsp;charge)') %>
409
410           <TR>
411             <TD COLSPAN=<%$colspan%>>
412               <FONT SIZE=-1>
413 %               if ( $curuser->access_right('Cancel customer package immediately') ) { 
414                   (&nbsp;<% pkg_cancel_link($cust_pkg) %>&nbsp;)
415 %               } 
416               </FONT>
417             </TD>
418           </TR>
419
420 %       } else { 
421
422          <% pkg_status_row_colspan("Not&nbsp;yet&nbsp;billed&nbsp;($billed_or_prepaid&nbsp;". myfreq($part_pkg). ')' ) %>
423
424 %       } 
425 %
426 %     } else { #setup
427 %
428 %       unless ( $part_pkg->freq ) { 
429
430           <% pkg_status_row_colspan('One-time&nbsp;charge') %>
431
432           <% pkg_status_row($cust_pkg, 'Billed', 'setup', conf=>$conf) %>
433
434 %       } else { 
435 %
436 %         if (scalar($cust_pkg->overlimit)) {
437
438             <% pkg_status_row_colspan(
439                  'Overlimit',
440                  $billed_or_prepaid. '&nbsp;'. myfreq($part_pkg),
441                  'color' => 'FFD000',
442                )
443             %>
444
445 %         } else {
446             <% pkg_status_row_colspan(
447                  'Active',
448                  $billed_or_prepaid. '&nbsp;'. myfreq($part_pkg),
449                  'color' => '00CC00',
450                )
451             %>
452 %         } 
453
454           <% pkg_status_row($cust_pkg, 'Setup', 'setup', conf=>$conf) %>
455
456 %       } 
457 %
458 %     } 
459
460       <% pkg_status_row_changed( $cust_pkg, conf=>$conf ) %>
461       <% pkg_status_row_if( $cust_pkg, $last_bill_or_renewed, 'last_bill', conf=>$conf, curuser=>$curuser ) %>
462       <% pkg_status_row_if( $cust_pkg, $next_bill_or_prepaid_until, 'bill', conf=>$conf, curuser=>$curuser ) %>
463       <% pkg_status_row_if( $cust_pkg, 'Will suspend on', 'adjourn', conf=>$conf, curuser=>$curuser ) %>
464       <% pkg_status_row_if( $cust_pkg, 'Expires', 'expire', conf=>$conf, curuser=>$curuser ) %>
465
466 %     if ( $part_pkg->freq ) { 
467
468         <TR>
469           <TD COLSPAN=<%$colspan%>>
470             <FONT SIZE=-1>
471 %             if ( $curuser->access_right('Suspend customer package') ) { 
472                 (&nbsp;<% pkg_suspend_link($cust_pkg) %>&nbsp;)
473 %             } 
474 %             if ( $curuser->access_right('Suspend customer package later') ) { 
475                 (&nbsp;<% pkg_adjourn_link($cust_pkg) %>&nbsp;)
476 %             } 
477 %             if ( $curuser->access_right('Cancel customer package immediately') ) { 
478                 (&nbsp;<% pkg_cancel_link($cust_pkg) %>&nbsp;)
479 %             } 
480 %             if ( $curuser->access_right('Cancel customer package later') ) { 
481                 (&nbsp;<% pkg_expire_link($cust_pkg) %>&nbsp;)
482 %             } 
483
484             <FONT>
485           </TD>
486         </TR>
487 %     }
488 %
489 %   } 
490 % } 
491
492 </TABLE>
493 </TD>
494
495 <TD CLASS="inv" BGCOLOR="<% $bgcolor %>">
496   <TABLE CLASS="inv" BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH="100%">
497
498 %  #foreach my $svcpart (sort {$a->{svcpart} <=> $b->{svcpart}} @{$pkg->{svcparts}}) {
499 %  foreach my $part_svc ( $cust_pkg->part_svc ) {
500
501 %    #foreach my $service (@{$svcpart->{services}}) {
502 %    foreach my $cust_svc ( @{ $part_svc->cust_pkg_svc } ) {
503
504       <TR>
505         <TD ALIGN="right" VALIGN="top"><% FS::UI::Web::svc_link($m, $part_svc, $cust_svc) %></TD>
506         <TD STYLE="padding-bottom:0px"><B><% FS::UI::Web::svc_label_link($m, $part_svc, $cust_svc) %></B></TD>
507         <TD><% FS::UI::Web::svc_export_links($m, $part_svc, $cust_svc) %></TD>
508       </TR>
509
510       <TR>
511         <TD ALIGN="right" COLSPAN="3" VALIGN="top" STYLE="padding-bottom:1px;padding-top:0px"><FONT SIZE="-2" COLOR="#FFD000">
512
513             <% $cust_svc->overlimit ? "Overlimit: ". time2str('%b %o %Y' . ($conf->exists('cust_pkg-display_times') ? ' %l:%M %P' : ''), $cust_svc->overlimit) : '' %>
514           </FONT></TD>
515       </TR>
516
517       <TR>
518         <TD ALIGN="right" VALIGN="top" STYLE="padding-bottom:5px;padding-top:0px"><FONT SIZE="-2">
519
520 %         if ( $curuser->access_right('Recharge customer service')
521 %              && $part_svc->svcdb eq 'svc_acct'
522 %              && (    $cust_svc->svc_x->seconds    ne ''
523 %                   || $cust_svc->svc_x->upbytes    ne ''
524 %                   || $cust_svc->svc_x->downbytes  ne ''
525 %                   || $cust_svc->svc_x->totalbytes ne ''
526 %                 )
527 %         ) { 
528             (&nbsp;<%svc_recharge_link($cust_svc)%>&nbsp;)
529 %         } 
530           </FONT></TD>
531
532           <TD ALIGN="right" VALIGN="top" STYLE="padding-bottom:5px;padding-top:0px"><FONT SIZE="-2">
533
534 %         if ( $curuser->access_right('Unprovision customer service') ) { 
535             (&nbsp;<%svc_unprovision_link($cust_svc)%>&nbsp;)
536 %         } 
537           </FONT></TD>
538         </TR>
539 %   } 
540
541 %   if (    ! $cust_pkg->get('cancel')
542 %        && $curuser->access_right('Provision customer service') 
543 %        && $part_svc->num_avail
544 %      ) {
545
546       <TR>
547         <TD COLSPAN=3 ALIGN="center" STYLE="padding-bottom:4px;padding-top:0px">
548           <B><% svc_provision_link($cust_pkg, $part_svc, $conf, $curuser) %></B>
549         </TD>
550       </TR>
551
552 %   } 
553
554 % } 
555
556 </TABLE>
557 </TD>
558 % } #end display packages
559 %
560
561
562 </TABLE>
563 % } else { 
564
565 <BR>
566 % } 
567 % if ( $cgi->param('fragment') =~ /^cust_pkg(\d+)$/ ) {
568   <SCRIPT>
569     // IE-specific hack.  other browsers listen to #fragments
570     // is this even working?  or is the #target redirection just working cause
571     // we set the URL params differently?
572     var el = document.getElementById( 'cust_pkg<% $1 %>' );
573     if ( el ) el.scrollIntoView(true);
574   </SCRIPT>
575 % }
576 <%init>
577
578 my( $cust_main ) = @_;
579 my $conf = new FS::Conf;
580
581 my $curuser = $FS::CurrentUser::CurrentUser;
582
583 my $packages = get_packages($cust_main, $conf);
584
585 my $colspan = $conf->exists('cust_pkg-display_times') ? 8 : 4;
586 my $width = $conf->exists('cust_pkg-display_times') ? '38%' : '56%';
587
588 sub pkg_status_row {
589   my( $cust_pkg, $title, $field, %opt ) = @_;
590
591   my $color = $opt{'color'};
592
593   my $html = qq(<TR><TD WIDTH="<%$width%>" ALIGN="right">);
594   $html   .= qq(<FONT COLOR="#$color"><B>) if length($color);
595   $html   .= qq($title&nbsp;);
596   $html   .= qq(</B></FONT>) if length($color);
597   $html   .= qq(</TD>);
598   $html   .= pkg_datestr($cust_pkg, $field, $opt{conf}).'</TR>';
599
600   $html;
601 }
602
603 sub pkg_status_row_if {
604   my( $cust_pkg, $title, $field, %opt ) = @_;
605   
606   $title = '<FONT SIZE=-1>(&nbsp;'. pkg_unadjourn_link($cust_pkg). '&nbsp;)&nbsp;</FONT>'. $title
607     if ( $field eq 'adjourn' &&
608          $opt{curuser}->access_right('Suspend customer package later')
609        );
610
611   $title = '<FONT SIZE=-1>(&nbsp;'. pkg_unexpire_link($cust_pkg). '&nbsp;)&nbsp;</FONT>'. $title
612     if ( $field eq 'expire' &&
613          $opt{curuser}->access_right('Cancel customer package later')
614        );
615
616   $cust_pkg->get($field) ? pkg_status_row($cust_pkg, $title, $field, %opt) : '';
617 }
618
619 sub pkg_status_row_changed {
620   my( $cust_pkg, %opt ) = @_;
621   return '' unless $cust_pkg->change_date;
622   my $html = pkg_status_row( $cust_pkg, 'Package&nbsp;changed', 'change_date', conf=>$opt{'conf'} );
623   my $old = $cust_pkg->old_cust_pkg;
624   if ( $old ) {
625     my $part_pkg = $old->part_pkg;
626     my $label = 'Changed from '. $cust_pkg->change_pkgnum. ': '.
627                 $part_pkg->pkg. ' - '. $part_pkg->comment;
628     $html .= pkg_status_row_colspan( $label, '', size=>'-1', align=>'right' );
629   }
630   $html;
631 }
632
633 sub pkg_status_row_colspan {
634   my($title, $addl, %opt) = @_;
635
636   my $align = $opt{'align'} ? 'ALIGN="'. $opt{'align'}.'"' : '';
637   my $color = $opt{'color'} ? 'COLOR="#'.$opt{'color'}.'"' : '';
638   my $size  = $opt{'size'}  ? 'SIZE="'.  $opt{'size'}. '"' : '';
639
640   my $html = qq(<TR><TD COLSPAN=$colspan $align>);
641   $html   .= qq(<FONT $color $size>) if length($color) || $size;
642   $html   .= qq(<B>) if $color && !$size;
643   $html   .= $title;
644   $html   .= qq(</B>) if $color && !$size;
645   $html   .= qq(</FONT>) if length($color) || $size;
646   $html   .= ",&nbsp;$addl" if length($addl);
647   $html   .= qq(</TD></TR>);
648
649   $html;
650
651 }
652
653 #subroutines
654
655 sub get_packages {
656   my $cust_main = shift or return undef;
657   my $conf = shift;
658   
659   my @packages = ();
660   my $method;
661   if (  $cgi->param('showcancelledpackages') eq '0' #see if it was set by me
662      || ( $conf->exists('hidecancelledpackages')
663            && ! $cgi->param('showcancelledpackages') )
664      )
665   {
666     $method = 'ncancelled_pkgs';
667   } else {
668     $method = 'all_pkgs';
669   }
670
671   [ $cust_main->$method() ];
672 }
673
674 sub svc_provision_link {
675   my ($cust_pkg, $part_svc, $conf, $curuser) = @_;
676   ( my $svc_nbsp = $part_svc->svc ) =~ s/\s+/&nbsp;/g;
677   my $num_avail = $part_svc->num_avail;
678   my $pkgnum_svcpart = "pkgnum=". $cust_pkg->pkgnum. ';'.
679                        "svcpart=". $part_svc->svcpart;
680   my $url;
681   if ( $part_svc->svcdb eq 'svc_external' #could be generalized
682        && $conf->exists('svc_external-skip_manual')
683   ) {
684     $url = "${p}edit/process/". $part_svc->svcdb. ".cgi?$pkgnum_svcpart";
685   } else {
686     $url = svc_url(
687                     'm'        => $m,
688                     'action'   => 'edit',
689                     'part_svc' => $part_svc, 
690                     'query'    => $pkgnum_svcpart,
691                   );
692     #$url = "${p}edit/$svcpart->{svcdb}.cgi?$pkgnum_svcpart";
693   }
694
695   my $link = qq!<A CLASS="provision" HREF="$url">!.
696              "Provision&nbsp;$svc_nbsp&nbsp;($num_avail)</A>";
697   if ( $conf->exists('legacy_link')
698        && $curuser->access_right('View/link unlinked services')
699      )
700   {
701     $link .= '<BR>'.
702              qq!<A CLASS="provision" HREF="${p}misc/link.cgi?!.
703              qq!$pkgnum_svcpart">!.
704             "Link&nbsp;to&nbsp;legacy&nbsp;$svc_nbsp&nbsp;($num_avail)</A>";
705   }
706   $link;
707 }
708
709 sub svc_unprovision_link {
710   my $cust_svc = shift or return '';
711   qq!<A HREF="javascript:areyousure('${p}misc/unprovision.cgi?!. $cust_svc->svcnum.
712   qq!', 'Permanently unprovision and delete this service?')">Unprovision</A>!;
713 }
714
715 sub pkg_datestr {
716   my($cust_pkg, $field, $conf) = @_ or return '';
717   return '&nbsp;' unless $cust_pkg->get($field);
718   my $format = '<TD align="left"><B>%b</B></TD>'.
719                '<TD align="right"><B>&nbsp;%o,</B></TD>'.
720                '<TD align="right"><B>&nbsp;%Y</B></TD>';
721   #$format .= '&nbsp;<FONT SIZE=-3>%l:%M:%S%P&nbsp;%z</FONT>'
722   $format .= '<TD ALIGN="right"><B>&nbsp;%l</TD>'.
723              '<TD ALIGN="center"><B>:</B></TD>'.
724              '<TD ALIGN="left"><B>%M</B></TD>'.
725              '<TD ALIGN="left"><B>&nbsp;%P</B></TD>'
726     if $conf->exists('cust_pkg-display_times');
727   my $strip = time2str($format, $cust_pkg->get($field) );
728   $strip =~ s/ (\d)/$1/g;
729   $strip;
730 }
731
732 sub pkg_change_link { include( '/elements/popup_link-cust_pkg.html',
733                                { 'action'      => $p. 'misc/change_pkg.cgi?dummy=value',
734                                  'label'       => 'Change&nbsp;package',
735                                  'actionlabel' => 'Change',
736                                  'cust_pkg'    => shift,
737                                }
738                              )
739                      }
740
741 sub pkg_suspend_link { include( '/elements/popup_link-cust_pkg.html',
742                                 { 'action'      => $p. 'misc/cancel_pkg.html?method=suspend',
743                                   'label'       => 'Suspend&nbsp;now',
744                                   'actionlabel' => 'Suspend',
745                                   'color'       => '#FF9900',
746                                   'cust_pkg'    => shift,
747                                 }
748                               )
749                      }
750
751
752 sub pkg_adjourn_link { include( '/elements/popup_link-cust_pkg.html',
753                                 { 'action'      => $p. 'misc/cancel_pkg.html?method=adjourn',
754                                   'label'       => 'Suspend&nbsp;later',
755                                   'actionlabel' => 'Adjourn',
756                                   'color'       => '#CC6600',
757                                   'cust_pkg'    => shift,
758                                 }
759                               )
760                      }
761
762 sub pkg_unsuspend_link { pkg_link('misc/unsusp_pkg',    'Unsuspend',           @_ ); }
763 sub pkg_dates_link     { pkg_link('edit/REAL_cust_pkg', 'Edit&nbsp;dates',     @_ ); }
764 sub pkg_unadjourn_link     { pkg_link('misc/unadjourn_pkg', 'Abort',               @_ ); }
765 sub pkg_unexpire_link      { pkg_link('misc/unexpire_pkg',  'Abort',               @_ ); }
766
767 sub pkg_cancel_link { include( '/elements/popup_link-cust_pkg.html',
768                                { 'action'      => $p. 'misc/cancel_pkg.html?method=cancel',
769                                  'label'       => 'Cancel&nbsp;now',
770                                  'actionlabel' => 'Cancel',
771                                  'color'       => '#ff0000',
772                                  'cust_pkg'    => shift,
773                                }
774                              )
775                     }
776
777 sub pkg_expire_link { include( '/elements/popup_link-cust_pkg.html',
778                                { 'action'      => $p. 'misc/cancel_pkg.html?method=expire',
779                                  'label'       => 'Cancel&nbsp;later',
780                                  'actionlabel' => 'Expire', #"Cancel package $num later"
781                                  'color'       => '#CC0000',
782                                  'cust_pkg'    => shift,
783                                }
784                              )
785                     }
786
787 sub svc_recharge_link { include( '/elements/popup_link-cust_svc.html',
788                                  { 'action'      => $p. 'misc/recharge_svc.html',
789                                    'label'       => 'Recharge',
790                                    'actionlabel' => 'Recharge',
791                                    'color'       => '#333399',
792                                    'cust_svc'    => shift,
793                                  }
794                                )
795                       }
796
797 sub order_pkg_link { include( '/elements/popup_link-cust_main.html',
798                               { 'action'      => $p. 'misc/order_pkg.html',
799                                 'label'       => 'Order&nbsp;new&nbsp;package',
800                                 'actionlabel' => 'Order new package',
801                                 'color'       => '#333399',
802                                 'cust_main'   => shift,
803                                 'closetext'   => 'Close',
804                               }
805                             )
806                    }
807
808 sub pkg_event_link {
809   my($cust_pkg) = @_;
810   qq!<a href="${p}search/cust_event.html?pkgnum=!. $cust_pkg->pkgnum. qq!">!.
811   'View package events'.
812   '</a>';
813 }
814
815 sub pkg_link {
816   my($action, $label, $cust_pkg) = @_;
817   return '' unless $cust_pkg;
818   qq!<a href="$p$action.cgi?!. $cust_pkg->pkgnum. qq!">$label</a>!;
819 }
820
821 sub pkg_customize_link {
822   my $cust_pkg = shift or return '';
823   my $custnum = $cust_pkg->custnum;
824   qq!<A HREF="${p}edit/part_pkg.cgi?!.
825     "clone=". $cust_pkg->part_pkg->pkgpart. ';'.
826     "pkgnum=". $cust_pkg->pkgnum.
827     qq!">Customize</A>!;
828 }
829
830 </%init>