[freeside-commits] freeside/FS/FS/part_pkg discount_Mixin.pm, 1.1.2.2, 1.1.2.3

Erik Levinson levinse at wavetail.420.am
Fri Apr 29 05:10:51 PDT 2011


Update of /home/cvs/cvsroot/freeside/FS/FS/part_pkg
In directory wavetail.420.am:/tmp/cvs-serv24952/FS/FS/part_pkg

Modified Files:
      Tag: FREESIDE_2_1_BRANCH
	discount_Mixin.pm 
Log Message:
apply discount to setup fees, part 1 of 2, RT11512

Index: discount_Mixin.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/part_pkg/discount_Mixin.pm,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -u -w -d -r1.1.2.2 -r1.1.2.3
--- discount_Mixin.pm	19 Jan 2011 00:30:41 -0000	1.1.2.2
+++ discount_Mixin.pm	29 Apr 2011 12:10:48 -0000	1.1.2.3
@@ -44,6 +44,8 @@
   my $br = $self->base_recur($cust_pkg, $sdate);
   $br += $param->{'override_charges'} if $param->{'override_charges'};
 
+  return 0 if defined $param->{'setup_charge'} && $param->{'setup_charge'} == 0;
+
   my $tot_discount = 0;
   #UI enforces just 1 for now, will need ordering when they can be stacked
 
@@ -91,8 +93,18 @@
       $discount->months - $cust_pkg_discount->months_used )
     : $chg_months;
 
+    if(defined $param->{'setup_charge'}) {
+        next unless $discount->setup;
+
+        if ( $discount->percent ) {
+            $amount = sprintf('%.2f', $discount->percent * $param->{'setup_charge'} / 100 );
+            $months = 1;
+        }
+    }
+
     my $error = $cust_pkg_discount->increment_months_used($months)
-    if $cust_pkg->pkgpart == $param->{real_pkgpart};
+        if ($cust_pkg->pkgpart == $param->{real_pkgpart} 
+            && ! defined $param->{'setup_charge'});
     die "error discounting: $error" if $error;
 
     $amount *= $months;
@@ -114,9 +126,9 @@
     $months = sprintf('%.2f', $months) if $months =~ /\./;
 
     my $d = 'Includes ';
-    $d .= $discount->name. ' ' if $discount->name;
+    $d .= 'setup ' if defined $param->{'setup_charge'};
     $d .= 'discount of '. $discount->description_short;
-    $d .= " for $months month". ( $months!=1 ? 's' : '' );
+    $d .= " for $months month". ( $months!=1 ? 's' : '' ) unless defined $param->{'setup_charge'};
     $d .= ": $money_char$amount" if $months != 1 || $discount->percent;
     push @$details, $d;
 



More information about the freeside-commits mailing list