prorate option to round to full day, RT#7353
authormark <mark>
Fri, 29 Oct 2010 08:51:51 +0000 (08:51 +0000)
committermark <mark>
Fri, 29 Oct 2010 08:51:51 +0000 (08:51 +0000)
FS/FS/part_pkg/prorate.pm
FS/FS/part_pkg/prorate_Mixin.pm

index 22bb809..218f80f 100644 (file)
@@ -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,
 );
index ed532ee..b77d898 100644 (file)
@@ -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 ) {