9fed5b581954144decb1735424b754de9ebf5192
[freeside.git] / httemplate / view / cust_main / packages / package.html
1 <TD CLASS="inv package" BGCOLOR="<% $bgcolor %>" VALIGN="top">
2   <% join('', @marker ) %>
3   <TABLE CLASS="inv package"> 
4     <TR>
5       <TD COLSPAN=2>
6         <% $opt{before_pkg_callback}
7              ? &{ $opt{before_pkg_callback} }( $cust_pkg )
8              : ''
9         %>
10
11 % ###
12 % # Package
13 % ###
14         <A NAME="cust_pkg<% $cust_pkg->pkgnum %>"
15            ID  ="cust_pkg<% $cust_pkg->pkgnum %>"
16         ><% $opt{show_pkgnum} ? $cust_pkg->pkgnum.': ' : '' %><B><% $part_pkg->pkg |h %></B></A>
17 %
18 %       my $custom_comment;
19 %       if ( 0 && FS::part_pkg::flat->can('price_info') eq $part_pkg->can('price_info') ) {
20 %         #perf hack / disabled in 4.x (feature pricing / cust_pkg_usageprice incompatible, well, harder)
21 %
22 %         $part_pkg->{"_$_"} = $part_pkg->option($_) || 0
23 %           foreach grep !defined($part_pkg->{"_$_"} ), qw(setup_fee recur_fee);
24 %           
25 %         my $str = '';
26 %         $str = $opt{money_char} . $part_pkg->{_setup_fee}.
27 %                ($part_pkg->{_recur_fee} ? ' setup' : ' one-time')
28 %           if $part_pkg->{_setup_fee};
29 %         $str .= ', ' if $part_pkg->{_setup_fee} && $part_pkg->{_recur_fee};
30 %         $str .= $opt{money_char}. $part_pkg->{_recur_fee}.
31 %                 '/'. $part_pkg->freq_pretty
32 %           if $part_pkg->{_recur_fee};
33 %         $str;
34 %
35 %         $custom_comment = 
36 %           ( $part_pkg->custom ? '(CUSTOM) ' : '' ).
37 %           $part_pkg->comment.
38 %           ( ($part_pkg->custom || $part_pkg->comment) ? ' - ' : '' ).
39 %           ($str || 'No charge');
40 %
41 %       } else {
42 %         $custom_comment = $part_pkg->custom_comment('cust_pkg'=>$cust_pkg);
43 %       }
44         <% $custom_comment ? ' - ' : '' %>
45         <% $custom_comment |h %>
46       </TD>
47     </TR>
48
49 % ###
50 % # Quantity
51 % ###
52 % if ( $cust_pkg->quantity > 1 ) {
53     <TR>
54       <TD COLSPAN=2>
55           &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<% mt('Quantity:') |h %> 
56           <B><% $cust_pkg->quantity %></B>
57
58 %       if ( $curuser->access_right('Change customer package')
59 %              && ! $cust_pkg->get('cancel')
60 %              && ! $change_from
61 %              && ! $supplemental
62 %              && $part_pkg->freq ne '0'
63 %              && ! $opt{no_links}
64 %              && $opt{'invoice-unitprice'}
65 %          )
66 %       {
67           <FONT SIZE="-1">
68             (&nbsp;<% pkg_change_quantity_link($cust_pkg, 'change') %>&nbsp;)
69           </FONT>
70 %       }
71       </TD>
72     </TR>
73 % }
74
75 % ###
76 % # Sales person
77 % ###
78 % if ( $cust_pkg->salesnum ) {
79     <TR>
80       <TD COLSPAN=2>
81           &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<% mt('Sales Person:') |h %> 
82           <B><% $cust_pkg->salesperson |h %></B>
83 %       if ( $curuser->access_right('Change customer package')
84 %              && ! $cust_pkg->get('cancel')
85 %              && ! $change_from
86 %              && ! $supplemental
87 %              #&& $part_pkg->freq ne '0'
88 %              && ! $opt{no_links}
89 %          )
90 %       {
91         <FONT SIZE="-1">
92           (&nbsp;<% pkg_change_salesnum_link($cust_pkg, 'change') %>&nbsp;)
93         </FONT>
94 %     }
95       </TD>
96     </TR>
97 % }
98
99
100 % ###
101 % # Invoice details & comments
102 % ###
103 %   my $editi = $curuser->access_right('Edit customer package invoice details');
104 %   my $editc = $curuser->access_right('Edit customer package comments');
105 %   my @cust_pkg_detail = $cust_pkg->cust_pkg_detail;
106 %   my @invoice_detail = grep { $_->detailtype eq 'I' } @cust_pkg_detail;
107 %   my @comments       = grep { $_->detailtype eq 'C' } @cust_pkg_detail;
108 %
109 %   if ( scalar(@invoice_detail) || scalar(@comments) || $editi || $editc ) {
110 %
111 %     my $editlink = $p. 'edit/cust_pkg_detail.html?pkgnum='. $cust_pkg->pkgnum.
112 %                    ';detailtype=';
113
114       <TR>
115
116 %       if ( @invoice_detail ) {
117           <TD VALIGN="top">
118             <& /elements/table-grid.html &>
119               <TR>
120                 <TH BGCOLOR="#dddddd" STYLE="border-bottom: dashed 1px black; padding-bottom: 1px">
121                   <FONT SIZE="-1">
122                     <% mt('Invoice details') |h %> 
123 %                   if ( $editi && ! $cust_pkg->get('cancel') && ! $opt{no_links} ) {
124                       (<& /elements/popup_link.html, { 
125                                     'action'      => $editlink. 'I',
126                                     'label'       => emt('edit'),
127                                     'actionlabel' => emt('Edit invoice details'),
128                                     'color'       => '#333399',
129                                     'width'       => 763,
130                                  }
131                        &>)
132 %                   }
133                   </FONT>
134                 </TH>
135               </TR>
136 %             foreach my $cust_pkg_detail ( @invoice_detail ) {
137                 <TR>
138                   <TD><FONT SIZE="-1">&nbsp;-&nbsp;<% $cust_pkg_detail->detail |h %></FONT></TD>
139                 </TR>
140 %             }
141             </TABLE>
142           </TD>
143 %       } else {
144           <TD>
145           </TD>
146 %       }
147
148 %       if ( @comments ) { 
149           <TD VALIGN="top">
150             <& /elements/table-grid.html &>
151               <TR>
152                 <TH BGCOLOR="#dddddd" STYLE="border-bottom: dashed 1px black; padding-bottom: 1px">
153                   <FONT SIZE="-1">
154                     <% mt('Comments') |h %> 
155 %                   if ( $editc && ! $opt{no_links} ) {
156                       (<& /elements/popup_link.html, { 
157                                     'action'      => $editlink. 'C',
158                                     'label'       => emt('edit'),
159                                     'actionlabel' => emt('Edit comments'),
160                                     'color'       => '#333399',
161                                     'width'       => 763,
162                                  }
163                        &>)
164 %                   }
165                   </FONT>
166                 </TH>
167               </TR>
168 %             foreach my $cust_pkg_detail ( @comments ) {
169                 <TR>
170                   <TD><FONT SIZE="-1">&nbsp;-&nbsp;<% $cust_pkg_detail->detail |h %></FONT></TD>
171                 </TR>
172 %             }
173             </TABLE>
174           </TD>
175 %       } else {
176           <TD>
177           </TD>
178 %       }
179
180       </TR>
181
182
183 %   }
184   </TABLE>
185
186 % if ( @cust_pkg_usage ) {
187   <TABLE CLASS="usage inv">
188     <TR><TH COLSPAN=4><% emt('Included usage') %></TH></TR>
189 %   foreach my $usage (@cust_pkg_usage) {
190 %     my $part = $usage->part_pkg_usage;
191 %     my $ratio = 255 * ($usage->minutes / $part->minutes);
192 %     $ratio = 255 if $ratio > 255; # because rollover
193 %     my $color = sprintf('STYLE="font-weight: bold; color: #%02x%02x00"', 255 - $ratio, $ratio);
194 %     my $trstyle = '';
195 %     $trstyle = ' CLASS="shared"' if $part->shared;
196     <TR<%$trstyle%>>
197       <TD ALIGN="right"><% $part->description %>: </TD>
198       <TD <%$color%> ALIGN="right"><% sprintf('%.1f', $usage->minutes) %></TD>
199       <TD <%$color%>> / </TD>
200       <TD <%$color%>><% $part->minutes %></TD>
201 %     if ( $part->shared ) {
202       <TD><I>(shared)</I></TD>
203 %     }
204     </TR>
205 %   }
206   </TABLE>
207 % }
208
209
210 % ###
211 % # Package actions dropdown
212 % ###
213 % unless ( $opt{no_links} ) {
214
215   <TABLE CLASS="inv package"> 
216     <TR>
217       <TD COLSPAN=2>
218
219 %       my $plink = "pkgnum=$pkgnum";
220 %       my $reg_recur_cond =  sub { $part_pkg->freq ne '0'
221 %                                       && ! $change_from
222 %                                       && ! $supplemental
223 %                                       && ! $cust_pkg->get('cancel')
224 %                                 };
225 %       my $change_cond = sub { $part_pkg->freq ne '0'
226 %                                 && ! $change_from
227 %                                 && ! $supplemental
228 %                                 && ! $cust_pkg->get('cancel')
229 %                                 && $cust_pkg->change_to_pkgnum,
230 %                             };
231
232         <& /elements/dropdown-menu.html,
233              id      => 'cust_pkg'. $cust_pkg->pkgnum. '_menu',
234              bgcolor => $opt{row} % 2 ? '#ffffff' : '#eeeeee',
235              menu    => [
236                [ 
237
238                  #TODO: order/group these better
239
240                  { label => 'Package actions',
241                    content =>
242                     '<FONT STYLE="text-decoration:underline;font-weight:bold">'.
243                     'Package actions</FONT>'.
244                     ' <IMG SRC="'.$p.'images/arrow.down.black.png">',
245                  },
246
247                  { label       => 'Modify one-time charge',
248                    acl         => 'Modify one-time charge',
249                    condition   => sub { $part_pkg->freq eq '0' },
250                    url         => "edit/quick-charge.html?change_$plink",
251                  },
252
253                  { label       => 'Change package',
254                    acl         => 'Change customer package',
255                    condition   => $reg_recur_cond,
256                    popup       => "misc/change_pkg.cgi?$plink".
257                                     ';locationnum='. $cust_pkg->locationnum.
258                    actionlabel => emt('Change package'),
259                    #width       => 768,
260                    width       => 960,
261                    height      => 538,
262                  },
263
264                  { label       => 'Discount package',
265                    condition   => sub { $part_pkg->freq ne '0'
266                                          && ! $change_from
267                                          && ! $supplemental
268                                          && ! $cust_pkg->get('cancel')
269                                          && $can_discount_pkg
270                                       },
271                    popup       => "edit/cust_pkg_discount.html?$plink".
272                    actionlabel => emt('Discount package'),
273                    width       => 616,
274                  },
275
276                  { label       => 'Customize package',
277                    acl         => 'Customize customer package',
278                    condition   => $reg_recur_cond,
279                    url         => "edit/part_pkg.cgi?$plink".
280                                     ';clone='. $part_pkg->pkgpart,
281                  },
282
283                  { label       => 'View package events',
284                    acl         => [ 'Billing event reports',
285                                     'View customer billing events', ],
286                    condition   => sub { $cust_pkg->exists_cust_event },
287                    url         => "search/cust_event.html?$plink",
288                  },
289
290                  { label       => 'Change quantity',
291                    acl         => 'Change customer package',
292                    condition   => sub { $part_pkg->freq ne '0'
293                                         && ! $change_from
294                                         && ! $supplemental
295                                         && ! $cust_pkg->get('cancel')
296                                         && $opt{'invoice-unitprice'}
297                                   },
298                    popup       => "edit/cust_pkg_quantity.html?$plink",
299
300                    actionlabel => emt('Change quantity'),
301                    width       => 390,
302                    height      => 220,
303                  },
304
305                  { label       => 'Change sales person',
306                    acl         => 'Change customer package',
307                    condition   => sub { ! $change_from
308                                         && ! $supplemental
309                                         && ! $cust_pkg->get('cancel')
310                                   },
311                    popup       => "edit/cust_pkg_salesnum.html?$plink",
312                    actionlabel => emt('Change sales persion'),
313                    width       => 390,
314                    height      => 220,
315                  },
316
317                  { label       => (@invoice_detail ? 'Edit' : 'Add').
318                                     ' invoice details',
319                    acl         => 'Edit customer package invoice details',
320                    condition   => sub { ! $cust_pkg->get('cancel') },
321                    popup       => "edit/cust_pkg_detail.html?$plink".
322                                     ';detailtype=I',
323                    actionlabel => emt( (@invoice_detail ? 'Edit' : 'Add').
324                                        ' invoice details'
325                                      ),
326                    width       => 768,
327                  },
328
329                  { label        => (@comments ? 'Edit' : 'Add'). ' comments',
330                    acl         => 'Edit customer package comments',
331                    popup       => "edit/cust_pkg_detail.html?$plink".
332                                     ';detailtype=C',
333                    actionlabel => emt( (@comments ? 'Edit' : 'Add').
334                                        ' comments'
335                                      ),
336                    width       => 768,
337                  },
338
339                  { label       => '-',
340                    condition   => sub { $part_pkg->freq ne '0' },
341                    content     => '-',
342                  },
343
344                  { label       => 'Set start date',
345                    acl         => 'Change package start date',
346                    condition   => sub { $part_pkg->freq ne '0'
347                                           && ! $change_from
348                                           && ! $supplemental
349                                           && ! $cust_pkg->get('cancel')
350                                           && ! $cust_pkg->get('setup')
351                                       },
352                   popup       => "misc/change_pkg_date.html?$plink".
353                                    ';field=start_date',
354                   actionlabel => emt('Set start of billing for'),
355                   width       => 510,
356                   height      => 310,
357                  },
358
359                  { label       => 'Set contract end',
360                    acl         => 'Change package contract end date',
361                    condition   => sub { $part_pkg->freq ne '0'
362                                           && ! $change_from
363                                           && ! $supplemental
364                                           && ! $cust_pkg->get('cancel')
365                                           && ! $cust_pkg->change_to_pkgnum
366                                       },
367                    popup       => "misc/change_pkg_date.html?$plink".
368                                    ';field=contract_end',
369                    actionlabel => emt('Set contract end for'),
370                    width       => 510,
371                    height      => 310,
372                  },
373
374                  { label       => '-',
375                    condition   => sub { $part_pkg->freq ne '0' },
376                    content     => '-',
377                  },
378
379                  { label       => 'Change now',
380                    acl         => 'Change customer package',
381                    condition   => $change_cond,
382                    url         => "misc/change_pkg_now.cgi?$pkgnum",
383                  },
384
385                  { label       => 'Reschedule',
386                    acl         => 'Change customer package',
387                    condition   => sub { $part_pkg->freq ne '0'
388                                           && ! $change_from
389                                           && ! $supplemental
390                                           && ! $cust_pkg->get('cancel')
391                                           && $cust_pkg->change_to_pkgnum,
392                                       },
393                    popup       => "misc/change_pkg.html?$plink",
394                    actionlabel => emt('Edit scheduled change for'),
395                    url         => "misc/change_pkg_now.cgi?$pkgnum",
396                    width       => 960,
397                    height      => 490,
398     
399                  },
400
401                  { label       => 'Abort change',
402                    acl         => 'Change customer package',
403                    condition   => $change_cond,
404                    url         => "misc/do_not_change_pkg.cgi?$pkgnum",
405                  },
406
407                  { label       => '-',
408                    acl         => 'Change customer package',
409                    condition   => $change_cond,
410                    content     => '-',
411                  },
412
413                  { label       => 'Suspend now',
414                    acl         => 'Suspend customer package',
415                    condition   => sub { $part_pkg->freq ne '0'
416                                           && ! $change_from
417                                           && ! $supplemental
418                                           && ! $cust_pkg->get('cancel')
419                                           && ! $cust_pkg->get('susp')
420                                       },
421                    popup       => "misc/cancel_pkg.html?method=suspend;$plink",
422                    actionlabel => emt('Suspend now'),
423                    color       => '#FF9900',
424                    width       => 768,
425                    height      => 420,
426                  },
427
428                  { label       => 'Suspend later',
429                    acl         => 'Suspend customer package later',
430                    condition   => sub { $part_pkg->freq ne '0'
431                                           && ! $change_from
432                                           && ! $supplemental
433                                           && ! $cust_pkg->get('cancel')
434                                           && ! $cust_pkg->get('susp')
435                                       },
436                    popup       => "misc/cancel_pkg.html?method=adjourn;$plink",
437                    actionlabel => emt('Suspend later'),
438                    color       => '#CC6600',
439                    width       => 768,
440                    height      => 445,
441                  },
442
443                  { label       => $cust_pkg->dundate
444                                     ? 'Edit suspension delay'
445                                     : 'Delay suspend',
446
447                    acl         => 'Delay suspension events',
448                    condition   => sub { $part_pkg->freq ne '0'
449                                           && ! $change_from
450                                           && ! $supplemental
451                                           && ! $cust_pkg->get('cancel')
452                                           && ! $cust_pkg->get('susp')
453                                       },
454                    popup       => "misc/delay_susp_pkg.html?$plink",
455                    actionlabel => emt('Delay suspend for'),
456                    width       => 768,
457                  },
458
459                  { label       => 'Start billing',
460                    acl         => 'Unsuspend customer package',
461                    condition   => sub { $part_pkg->freq ne '0'
462                                           && ! $change_from
463                                           && ! $supplemental
464                                           && ! $cust_pkg->get('cancel')
465                                           && $cust_pkg->get('susp')
466                                           && $cust_pkg->order_date == $cust_pkg->get('susp')
467                                       },
468                    popup        => "misc/unhold_pkg.html?$plink",
469                    actionlabel  => emt('Start billing'),
470                    color       => '#00CC00',
471                    width       => 510,
472                    height      => 310,
473                  },
474
475                  { label       => 'Unsuspend now',
476                    acl         => 'Unsuspend customer package',
477                    condition   => sub { $part_pkg->freq ne '0'
478                                           && ! $change_from
479                                           && ! $supplemental
480                                           && ! $cust_pkg->get('cancel')
481                                           && $cust_pkg->get('susp')
482                                           && $cust_pkg->order_date != $cust_pkg->get('susp')
483                                       },
484                    'url'       => "misc/unsusp_pkg.cgi?$pkgnum",
485                  },
486
487                  { label       => 'Unsuspend later',
488                    acl         => 'Unsuspend customer package',
489                    condition   => sub { $part_pkg->freq ne '0'
490                                           && ! $change_from
491                                           && ! $supplemental
492                                           && ! $cust_pkg->get('cancel')
493                                           && $cust_pkg->get('susp')
494                                           && $cust_pkg->order_date != $cust_pkg->get('susp')
495                                       },
496                    popup       => "misc/cancel_pkg.html?method=resume;$plink",
497                    actionlabel => emt('Unsuspend later'),
498                    color       => '#00CC00',
499                    width       => 768,
500                  },
501
502                  { label       => '-',
503                    condition   => sub { $part_pkg->freq ne '0'
504                                           && ! $change_from
505                                           && ! $supplemental
506                                           && ! $cust_pkg->get('cancel')
507                                           && ! $cust_pkg->get('susp')
508                                       },
509                    content     => '-',
510                  },
511
512                  { label       => 'Cancel now',
513                    acl         => 'Cancel customer package immediately',
514                    condition   => sub { $part_pkg->freq ne '0'
515                                           && ! $change_from
516                                           && ! $supplemental
517                                           && ! $cust_pkg->change_to_pkgnum
518                                           && ! $cust_pkg->get('cancel')
519                                       },
520                    popup       => "misc/cancel_pkg.html?method=cancel;$plink",
521                    actionlabel => emt('Cancel now'),
522                    color       => '#FF0000',
523                    width       => 768,
524                  },
525
526                  { label       => 'Cancel later',
527                    acl         => 'Cancel customer package later',
528                    condition   => sub { $part_pkg->freq ne '0'
529                                           && ! $change_from
530                                           && ! $supplemental
531                                           && ! $cust_pkg->change_to_pkgnum
532                                           && ! $cust_pkg->get('cancel')
533                                       },
534                    popup       => "misc/cancel_pkg.html?method=expire;$plink",
535                    actionlabel => emt('Cancel later'),
536                    color       => '#CC0000',
537                    width       => 768,
538                  },
539
540                  { label       => 'Un-cancel',
541                    acl         => 'Un-cancel customer package',
542                    condition   => sub { $part_pkg->freq ne '0'
543                                           && ! $supplemental
544                                           && ! $cust_pkg->change_custnum
545                                           && $cust_pkg->get('cancel')
546                                       },
547                    popup       => "misc/cancel_pkg.html?method=uncancel;$plink",
548                    actionlabel => emt('Un-cancel'),
549                    width       => 960,
550                    height      => 740,
551
552                  },
553
554                ],
555              ],
556         &>
557
558       </TD>
559     </TR>
560   </TABLE>
561
562 % }
563
564   <% join('', map '</DIV>', @marker ) %>
565
566 </TD>
567
568 <%init>
569
570 my %opt = @_;
571
572 my $bgcolor  = $opt{'bgcolor'};
573 my $cust_pkg = $opt{'cust_pkg'};
574 my $part_pkg = $opt{'part_pkg'};
575
576 my $curuser = $FS::CurrentUser::CurrentUser;
577
578 my $countrydefault = $opt{'countrydefault'} || 'US';
579 my $statedefault   = $opt{'statedefault'}
580                      || ($countrydefault eq 'US' ? 'CA' : '');
581
582 # put a marker on the left edge of this column
583 # if this package is somehow special
584 my $supplemental = $opt{'supplemental'} || 0;
585 my $change_from = $opt{'change_from'} || 0;
586 my @marker;
587 if ( $supplemental ) {
588   push @marker, '<DIV CLASS="package-marker-supplemental">';
589 }
590 if ( $change_from ) {
591   push @marker, '<DIV CLASS="package-marker-change_from">';
592 }
593
594 $cust_pkg->pkgnum =~ /^(\d+)$/;
595 my $pkgnum = $1;
596 my @cust_pkg_usage = qsearch({
597   'select'    => 'cust_pkg_usage.*',
598   'table'     => 'cust_pkg_usage',
599   'addl_from' => ' JOIN part_pkg_usage USING (pkgusagepart)',
600   'extra_sql' => " WHERE pkgnum = $1",
601   'order_by'  => ' ORDER BY priority ASC, description ASC',
602 });
603
604 #subroutines
605
606 #false laziness w/status.html
607 sub pkg_link {
608   my($action, $label, $cust_pkg) = @_;
609   return '' unless $cust_pkg;
610   qq!<a href="$p$action.cgi?!. $cust_pkg->pkgnum. qq!">$label</a>!;
611 }
612
613 sub pkg_change_location_link {
614   my $cust_pkg = shift;
615   my $pkgpart = $cust_pkg->pkgpart;
616   include( '/elements/popup_link-cust_pkg.html',
617     'action'      => $p. "misc/change_pkg.cgi?locationnum=-1;pkgpart=$pkgpart;".
618                      "address1=;address2=;city=;county=;state=$statedefault;".
619                      "zip=;country=$countrydefault",
620     'label'       => emt('Change location'),
621     'actionlabel' => emt('Change'),
622     'cust_pkg'    => $cust_pkg,
623     'width'       => 960,
624     'height'      => 530,
625   );
626 }
627
628 sub pkg_change_quantity_link {
629   my( $cust_pkg, $label ) = @_;
630   include( '/elements/popup_link-cust_pkg.html',
631     'action'      => $p. 'edit/cust_pkg_quantity.html?',
632     'label'       => emt($label),
633     'actionlabel' => emt('Change'),
634     'cust_pkg'    => $cust_pkg,
635     'width'       => 390,
636     'height'      => 220,
637   );
638 }
639
640 sub pkg_change_salesnum_link {
641   my( $cust_pkg, $label ) = @_;
642   include( '/elements/popup_link-cust_pkg.html',
643     'action'      => $p. 'edit/cust_pkg_salesnum.html?',
644     'label'       => emt($label),
645     'actionlabel' => emt('Change'),
646     'cust_pkg'    => $cust_pkg,
647     'width'       => 390,
648     'height'      => 220,
649   );
650 }
651
652 # figure out if this user will be able to edit either the setup or recurring
653 # discounts for this package
654 my $can_discount_pkg = 0;
655
656 if ( $part_pkg->can_discount ) {
657   #looking these up individually uses the ACL cache and is a big win for lots
658   # of packages
659   my $discount = $curuser->access_right('Discount customer package');
660   my $waive    = $curuser->access_right('Waive setup fee');
661
662   $can_discount_pkg = 
663     (   ($discount || $waive) 
664           && $cust_pkg->base_setup > 0
665           && !$cust_pkg->setup
666      or
667         ( $discount
668           && $cust_pkg->base_recur > 0
669           && $cust_pkg->freq ne '0'
670         )
671     );
672
673 }
674
675 </%init>