summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormark <mark>2010-11-09 21:40:18 +0000
committermark <mark>2010-11-09 21:40:18 +0000
commit03c51a9f08159e2bdfec7839eb63514a087d6bdc (patch)
treeb4efa1926f596ff37ddf0d5206af1cd89ad06d48
parent9ab5259d95fafee083cd377b03f4ffdc37bd137a (diff)
fix sync_bill_date near the end of the month, RT#10503
-rw-r--r--FS/FS/part_pkg/flat.pm2
-rw-r--r--FS/FS/part_pkg/prorate_Mixin.pm15
2 files changed, 14 insertions, 3 deletions
diff --git a/FS/FS/part_pkg/flat.pm b/FS/FS/part_pkg/flat.pm
index a17813bd5..e8f54d124 100644
--- a/FS/FS/part_pkg/flat.pm
+++ b/FS/FS/part_pkg/flat.pm
@@ -198,7 +198,7 @@ sub calc_recur {
my $charge = $self->base_recur($cust_pkg);
if ( $self->option('sync_bill_date',1) ) {
my $next_bill = $cust_pkg->cust_main->next_bill_date;
- if ( defined($next_bill) and $next_bill != $$sdate ) {
+ if ( defined($next_bill) ) {
my $cutoff_day = (localtime($next_bill))[3];
$charge = $self->calc_prorate(@_, $cutoff_day);
}
diff --git a/FS/FS/part_pkg/prorate_Mixin.pm b/FS/FS/part_pkg/prorate_Mixin.pm
index 9c0c2669b..451690485 100644
--- a/FS/FS/part_pkg/prorate_Mixin.pm
+++ b/FS/FS/part_pkg/prorate_Mixin.pm
@@ -33,8 +33,8 @@ sub calc_recur {
=item calc_prorate CUST_PKG
Takes all the arguments of calc_recur, followed by a day of the month
-to prorate to. Calculates a prorated charge from the $sdate to that day,
-and sets the $sdate and $param->{months} accordingly.
+to prorate to (which must be <= 28). Calculates a prorated charge from
+the $sdate to that day, and sets the $sdate and $param->{months} accordingly.
Options:
- recur_fee: The charge to use for a complete billing period.
@@ -60,6 +60,17 @@ sub calc_prorate {
}
my $mend;
my $mstart;
+ # if cutoff day > 28, force it to the 1st of next month
+ if ( $cutoff_day > 28 ) {
+ $cutoff_day = 1;
+ # and if we are currently after the 28th, roll the current day
+ # forward to that day
+ if ( $mday > 28 ) {
+ $mday = 1;
+ #set $mnow = $mend so the amount billed will be zero
+ $mnow = timelocal(0,0,0,1,$mon == 11 ? 0 : $mon + 1,$year+($mon==11));
+ }
+ }
if ( $mday >= $cutoff_day ) {
$mend =
timelocal(0,0,0,$cutoff_day,$mon == 11 ? 0 : $mon + 1,$year+($mon==11));