[freeside-commits] freeside/FS/FS/part_pkg agent.pm, 1.5, 1.6 bulk.pm, 1.6, 1.7 flat_comission_cust.pm, 1.7, 1.8 flat_comission_pkg.pm, 1.6, 1.7 flat_comission.pm, 1.7, 1.8 flat.pm, 1.36, 1.37 prorate.pm, 1.17, 1.18 recur_Common.pm, 1.2, 1.3 rt_time.pm, 1.2, 1.3 sesmon_hour.pm, 1.8, 1.9 sesmon_minute.pm, 1.9, 1.10 sql_external.pm, 1.8, 1.9 sql_generic.pm, 1.8, 1.9 sqlradacct_hour.pm, 1.9, 1.10 subscription.pm, 1.15, 1.16 voip_sqlradacct.pm, 1.21, 1.22
Ivan,,,
ivan at wavetail.420.am
Sat Jan 30 18:57:16 PST 2010
Update of /home/cvs/cvsroot/freeside/FS/FS/part_pkg
In directory wavetail.420.am:/tmp/cvs-serv20011/FS/FS/part_pkg
Modified Files:
agent.pm bulk.pm flat_comission_cust.pm flat_comission_pkg.pm
flat_comission.pm flat.pm prorate.pm recur_Common.pm
rt_time.pm sesmon_hour.pm sesmon_minute.pm sql_external.pm
sql_generic.pm sqlradacct_hour.pm subscription.pm
voip_sqlradacct.pm
Log Message:
discounts, RT#6679
Index: flat_comission_pkg.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/part_pkg/flat_comission_pkg.pm,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- flat_comission_pkg.pm 13 Apr 2008 07:41:28 -0000 1.6
+++ flat_comission_pkg.pm 31 Jan 2010 02:57:14 -0000 1.7
@@ -55,4 +55,6 @@
$self->option('recur_fee');
}
+sub can_discount { 0; }
+
1;
Index: rt_time.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/part_pkg/rt_time.pm,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- rt_time.pm 30 Jan 2010 07:55:39 -0000 1.2
+++ rt_time.pm 31 Jan 2010 02:57:14 -0000 1.3
@@ -39,6 +39,8 @@
}
+sub can_discount { 0; }
+
sub calc_cancel {
my $self = shift;
my($cust_pkg, $sdate, $details, $param ) = @_;
Index: sesmon_hour.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/part_pkg/sesmon_hour.pm,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- sesmon_hour.pm 15 Apr 2008 19:43:53 -0000 1.8
+++ sesmon_hour.pm 31 Jan 2010 02:57:14 -0000 1.9
@@ -45,6 +45,8 @@
}
+sub can_discount { 0; }
+
sub is_free_options {
qw( setup_fee recur_fee recur_hourly_charge );
}
Index: flat_comission.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/part_pkg/flat_comission.pm,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- flat_comission.pm 13 Apr 2008 07:41:28 -0000 1.7
+++ flat_comission.pm 31 Jan 2010 02:57:14 -0000 1.8
@@ -64,4 +64,6 @@
$self->option('recur_fee');
}
+sub can_discount { 0; }
+
1;
Index: sql_external.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/part_pkg/sql_external.pm,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- sql_external.pm 15 Apr 2008 19:43:53 -0000 1.8
+++ sql_external.pm 31 Jan 2010 02:57:14 -0000 1.9
@@ -65,9 +65,9 @@
$price;
}
-sub is_free {
- 0;
-}
+sub can_discount { 0; }
+
+sub is_free { 0; }
sub base_recur {
my($self, $cust_pkg) = @_;
Index: agent.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/part_pkg/agent.pm,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- agent.pm 5 Aug 2009 23:32:34 -0000 1.5
+++ agent.pm 31 Jan 2010 02:57:13 -0000 1.6
@@ -163,6 +163,8 @@
}
+sub can_discount { 0; }
+
sub hide_svc_detail {
1;
}
Index: voip_sqlradacct.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/part_pkg/voip_sqlradacct.pm,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -d -r1.21 -r1.22
--- voip_sqlradacct.pm 24 Oct 2008 21:31:38 -0000 1.21
+++ voip_sqlradacct.pm 31 Jan 2010 02:57:14 -0000 1.22
@@ -181,9 +181,9 @@
}
-sub is_free {
- 0;
-}
+sub can_discount { 0; }
+
+sub is_free { 0; }
sub base_recur {
my($self, $cust_pkg) = @_;
Index: sesmon_minute.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/part_pkg/sesmon_minute.pm,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- sesmon_minute.pm 15 Apr 2008 19:43:53 -0000 1.9
+++ sesmon_minute.pm 31 Jan 2010 02:57:14 -0000 1.10
@@ -44,6 +44,8 @@
$self->option('recur_fee') + $min * $self->option('recur_minly_charge');
}
+sub can_discount { 0; }
+
sub is_free_options {
qw( setup_fee recur_fee recur_minly_charge );
}
Index: prorate.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/part_pkg/prorate.pm,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- prorate.pm 13 Apr 2008 07:41:28 -0000 1.17
+++ prorate.pm 31 Jan 2010 02:57:14 -0000 1.18
@@ -95,7 +95,7 @@
);
sub calc_recur {
- my($self, $cust_pkg, $sdate ) = @_;
+ my($self, $cust_pkg, $sdate, $details, $param ) = @_;
my $cutoff_day = $self->option('cutoff_day', 1) || 1;
my $mnow = $$sdate;
my ($sec,$min,$hour,$mday,$mon,$year) = (localtime($mnow) )[0,1,2,3,4,5];
@@ -117,7 +117,12 @@
$$sdate = $mstart;
my $permonth = $self->option('recur_fee') / $self->freq;
- $permonth * ( ( $self->freq - 1 ) + ($mend-$mnow) / ($mend-$mstart) );
+ my $months = ( ( $self->freq - 1 ) + ($mend-$mnow) / ($mend-$mstart) );
+
+ $param->{'months'} = $months;
+ my $discount = $self->calc_discount( $cust_pkg, $sdate, $details, $param);
+
+ sprintf('%.2f', $permonth * $months - $discount);
}
1;
Index: recur_Common.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/part_pkg/recur_Common.pm,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- recur_Common.pm 13 Jul 2009 10:12:22 -0000 1.2
+++ recur_Common.pm 31 Jan 2010 02:57:14 -0000 1.3
@@ -48,6 +48,8 @@
}#$recur_method eq 'subscription'
+ $charges -= $self->calc_discount( $cust_pkg, $sdate, $details, $param );
+
}#$recur_method eq 'prorate'
}#increment_next_bill
Index: sqlradacct_hour.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/part_pkg/sqlradacct_hour.pm,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- sqlradacct_hour.pm 15 Apr 2008 19:43:54 -0000 1.9
+++ sqlradacct_hour.pm 31 Jan 2010 02:57:14 -0000 1.10
@@ -158,6 +158,8 @@
$self->option('recur_fee') + $charges;
}
+sub can_discount { 0; }
+
sub is_free_options {
qw( setup_fee recur_fee recur_hourly_charge
recur_input_charge recur_output_charge recur_total_charge );
Index: flat.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/part_pkg/flat.pm,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -d -r1.36 -r1.37
--- flat.pm 30 Jan 2010 07:38:32 -0000 1.36
+++ flat.pm 31 Jan 2010 02:57:14 -0000 1.37
@@ -6,8 +6,10 @@
@usage_fieldorder @usage_recharge_fieldorder
);
use Tie::IxHash;
+use List::Util qw(min); # max);
#use FS::Record qw(qsearch);
use FS::UI::bytecount;
+use FS::Conf;
use FS::part_pkg;
@ISA = qw(FS::part_pkg);
@@ -153,7 +155,55 @@
return 0
if $self->option('recur_temporality', 1) eq 'preceding' && $last_bill == 0;
- $self->base_recur(@_);
+ my $br = $self->base_recur(@_);
+
+ my $discount = $self->calc_discount(@_);
+
+ sprintf('%.2f', $br - $discount);
+}
+
+sub calc_discount {
+ my $self = shift;
+ my($cust_pkg, $sdate, $details, $param ) = @_;
+
+ my $br = $self->base_recur(@_);
+
+ my $tot_discount = 0;
+ #UI enforces just 1 for now, will need ordering when they can be stacked
+ foreach my $cust_pkg_discount ( $cust_pkg->cust_pkg_discount_active ) {
+ my $discount = $cust_pkg_discount->discount;
+ #UI enforces one or the other (for now? probably for good)
+ my $amount = 0;
+ $amount += $discount->amount;
+ $amount += sprintf('%.2f', $discount->percent * $br / 100 );
+
+ my $chg_months = $param->{'months'} || $cust_pkg->part_pkg->freq;
+
+ my $months = $discount->months
+ ? min( $chg_months,
+ $discount->months - $cust_pkg->months_used )
+ : $chg_months;
+
+ my $error = $cust_pkg_discount->increment_months_used($months);
+ die "error discounting: $error" if $error;
+
+ $amount *= $months;
+
+ #add details on discount to invoice
+ my $conf = new FS::Conf;
+ my $money_char = $conf->config('money_char') || '$';
+
+ my $d = 'Includes ';
+ $d .= $discount->name. ' ' if $discount->name;
+ $d .= 'discount of '. $discount->description_short;
+ $d .= " for $months month". ( $months>1 ? 's' : '' );
+ $d .= ": $money_char$amount" if $months != 1 || $discount->percent;
+ push @$details, $d;
+
+ $tot_discount += $amount;
+ }
+
+ sprintf('%.2f', $tot_discount);
}
sub base_recur {
@@ -212,7 +262,11 @@
sub is_prepaid { 0; } #no, we're postpaid
-sub can_discount { 1; } #and anything that inherits from us
+#XXX discounts only on recurring fees for now (no setup/one-time or usage)
+sub can_discount {
+ my $self = shift;
+ $self->freq =~ /^\d+$/ && $self->freq > 0;
+}
sub usage_valuehash {
my $self = shift;
Index: flat_comission_cust.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/part_pkg/flat_comission_cust.pm,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- flat_comission_cust.pm 13 Apr 2008 07:41:28 -0000 1.7
+++ flat_comission_cust.pm 31 Jan 2010 02:57:14 -0000 1.8
@@ -62,4 +62,6 @@
$self->option('recur_fee');
}
+sub can_discount { 0; }
+
1;
Index: bulk.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/part_pkg/bulk.pm,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- bulk.pm 18 Jun 2009 11:07:04 -0000 1.6
+++ bulk.pm 31 Jan 2010 02:57:13 -0000 1.7
@@ -94,6 +94,8 @@
sprintf('%.2f', $self->base_recur($cust_pkg) + $total_svc_charge );
}
+sub can_discount { 0; }
+
sub hide_svc_detail {
1;
}
Index: sql_generic.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/part_pkg/sql_generic.pm,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- sql_generic.pm 15 Apr 2008 19:43:53 -0000 1.8
+++ sql_generic.pm 31 Jan 2010 02:57:14 -0000 1.9
@@ -76,6 +76,8 @@
$self->option('recur_fee') + $units * $self->option('recur_unit_charge');
}
+sub can_discount { 0; }
+
sub is_free_options {
qw( setup_fee recur_fee recur_unit_charge );
}
Index: subscription.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/part_pkg/subscription.pm,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- subscription.pm 13 Apr 2008 07:41:28 -0000 1.15
+++ subscription.pm 31 Jan 2010 02:57:14 -0000 1.16
@@ -103,7 +103,11 @@
$$sdate = timelocal(0,0,0,$cutoff_day,$mon,$year);
- $self->option('recur_fee');
+ my $br = $self->base_recur(@_);
+
+ my $discount = $self->calc_discount(@_);
+
+ sprintf('%.2f', $br - $discount);
}
1;
More information about the freeside-commits
mailing list