From: mark <mark>
Date: Fri, 29 Oct 2010 08:51:51 +0000 (+0000)
Subject: prorate option to round to full day, RT#7353
X-Git-Tag: freeside_2_1_1~1^2~45
X-Git-Url: http://git.freeside.biz/gitweb/?a=commitdiff_plain;ds=sidebyside;h=4ad8b72c0dde10d4907298277181ddfaa99dafb6;p=freeside.git

prorate option to round to full day, RT#7353
---

diff --git a/FS/FS/part_pkg/prorate.pm b/FS/FS/part_pkg/prorate.pm
index 22bb80901..218f80f6a 100644
--- a/FS/FS/part_pkg/prorate.pm
+++ b/FS/FS/part_pkg/prorate.pm
@@ -83,7 +83,11 @@ use FS::part_pkg::flat;
                                     'for one full period after that',
                           'type' => 'checkbox',
                         },
-
+    'prorate_round_day'=> {
+                          'name' => 'When prorating first month, round to '.
+                                    'the nearest full day',
+                          'type' => 'checkbox',
+                        },
 
     #it would be better if this had to be turned on, its confusing
     'externalid' => { 'name'   => 'Optional External ID',
@@ -95,7 +99,7 @@ use FS::part_pkg::flat;
                     'recharge_amount', 'recharge_seconds', 'recharge_upbytes',
                     'recharge_downbytes', 'recharge_totalbytes',
                     'usage_rollover', 'recharge_reset', 'add_full_period',
-                    'externalid', ],
+                    'prorate_round_day', 'externalid', ],
   'freq' => 'm',
   'weight' => 20,
 );
diff --git a/FS/FS/part_pkg/prorate_Mixin.pm b/FS/FS/part_pkg/prorate_Mixin.pm
index ed532ee12..b77d898c4 100644
--- a/FS/FS/part_pkg/prorate_Mixin.pm
+++ b/FS/FS/part_pkg/prorate_Mixin.pm
@@ -66,6 +66,10 @@ sub calc_prorate {
     # only works for freq >= 1 month; probably can't be fixed
     my $mnow = $$sdate;
     my ($sec, $min, $hour, $mday, $mon, $year) = (localtime($mnow))[0..5];
+    if ( $self->option('prorate_round_day',1) ) {
+      $mday++ if $hour >= 12;
+      $mnow = timelocal(0,0,0,$mday,$mon,$year);
+    }
     my $mend;
     my $mstart;
     if ( $mday >= $cutoff_day ) {