separate setup and recur discounts, #14092
[freeside.git] / httemplate / view / cust_main / packages / package.html
index 8aa6403..e98b95e 100644 (file)
                 (&nbsp;<%onetime_change_link($cust_pkg)%>&nbsp;)
 %           }
 %           # also, you can discount it
-%           if ( $curuser->access_right('Discount customer package')
-%                && ! scalar($cust_pkg->cust_pkg_discount_active)
-%                && ! scalar($cust_pkg->part_pkg->part_pkg_discount)
-%              ) {
+%           if ( $can_discount_pkg ) {
               (&nbsp;<%pkg_discount_link($cust_pkg)%>&nbsp;)
 %           }
           <BR>
                 (&nbsp;<%pkg_change_link($cust_pkg)%>&nbsp;)
 %             } 
 %
-%             if ( $curuser->access_right('Discount customer package')
-%                  && $part_pkg->can_discount
-%                  && ! scalar( @{ $cust_pkg->{_cust_pkg_discount_active} } )
-%                  && (    ! $opt{'term_discounts'}
-%                       || ! scalar($cust_pkg->part_pkg->part_pkg_discount)
-%                     )
-%                )
-%             {
+%             if ( $can_discount_pkg ) {
 %               $br=1;
                 (&nbsp;<%pkg_discount_link($cust_pkg)%>&nbsp;)
 %             }
@@ -437,4 +427,21 @@ sub pkg_event_link {
   '</a>';
 }
 
+# figure out if this user will be able to edit either the setup or recurring
+# discounts for this package
+my $can_discount_pkg = (
+  $part_pkg->can_discount
+  and
+  ( ( $curuser->access_right(['Discount customer package', 'Waive setup fee'])
+      and $cust_pkg->base_setup > 0
+      and !$cust_pkg->setup
+    )
+   or
+    ( $curuser->access_right('Discount customer package')
+      and $cust_pkg->base_recur > 0
+      and $cust_pkg->freq ne '0'
+    )
+  )
+);
+
 </%init>