[freeside-commits] freeside/FS/FS/part_pkg discount_Mixin.pm, 1.3, 1.4

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


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

Modified Files:
	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.3
retrieving revision 1.4
diff -u -w -d -r1.3 -r1.4
--- discount_Mixin.pm	20 Jan 2011 00:38:15 -0000	1.3
+++ discount_Mixin.pm	29 Apr 2011 12:10:18 -0000	1.4
@@ -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