[freeside-commits] branch FREESIDE_2_3_BRANCH updated. 50c7d973c88a7ffb53bb74837420398e45d9ac88

Ivan ivan at 420.am
Sun Mar 17 19:11:37 PDT 2013


The branch, FREESIDE_2_3_BRANCH has been updated
       via  50c7d973c88a7ffb53bb74837420398e45d9ac88 (commit)
      from  562dc0428613576947db0504bf0a7faad1a075b4 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 50c7d973c88a7ffb53bb74837420398e45d9ac88
Author: Ivan Kohler <ivan at freeside.biz>
Date:   Sun Mar 17 19:11:35 2013 -0700

    fix report day selection on daylight savings boundaries, RT#21879

diff --git a/FS/FS/Cron/bill.pm b/FS/FS/Cron/bill.pm
index 46ef610..8dc2add 100644
--- a/FS/FS/Cron/bill.pm
+++ b/FS/FS/Cron/bill.pm
@@ -192,7 +192,8 @@ sub bill_where {
   # generate where_pkg/where_event search clause
   ###
 
-  my $billtime = day_end($time);
+  my $conf = new FS::Conf;
+  my $billtime = $conf->exists('next-bill-ignore-time') ? day_end($time) : $time;
 
   # select * from cust_main where
   my $where_pkg = <<"END";
diff --git a/FS/FS/Misc/DateTime.pm b/FS/FS/Misc/DateTime.pm
index e36f3a9..5ef760d 100644
--- a/FS/FS/Misc/DateTime.pm
+++ b/FS/FS/Misc/DateTime.pm
@@ -58,21 +58,14 @@ sub parse_datetime {
 
 =item day_end TIME
 
-If the next-bill-ignore-time configuration setting is turned off, just 
-returns the passed-in value.
-
-If the next-bill-ignore-time configuration setting is turned on, parses TIME
-as an integer UNIX timestamp and returns a new timestamp with the same date but
-23:59:59 for the time.
+Parses TIME as an integer UNIX timestamp and returns a new timestamp with the
+same date but 23:59:59 for the time.
 
 =cut
 
 sub day_end {
     my $time = shift;
 
-    my $conf = new FS::Conf;
-    return $time unless $conf->exists('next-bill-ignore-time');
-
     my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
         localtime($time);
     mktime(59,59,23,$mday,$mon,$year,$wday,$yday,$isdst);
diff --git a/FS/FS/UI/Web.pm b/FS/FS/UI/Web.pm
index 3778768..451c18e 100644
--- a/FS/FS/UI/Web.pm
+++ b/FS/FS/UI/Web.pm
@@ -6,7 +6,7 @@ use Exporter;
 use Carp qw( confess );
 use HTML::Entities;
 use FS::Conf;
-use FS::Misc::DateTime qw( parse_datetime );
+use FS::Misc::DateTime qw( parse_datetime day_end );
 use FS::Record qw(dbdef);
 use FS::cust_main;  # are sql_balance and sql_date_balance in the right module?
 
@@ -40,12 +40,7 @@ sub parse_beginning_ending {
   if ( $cgi->param($prefix.'end') =~ /^(\d+)$/ ) {
     $ending = $1 - 1;
   } elsif ( $cgi->param($prefix.'ending') =~ /^([ 0-9\-\/\:]{1,64})$/ ) {
-    #probably need an option to turn off the + 86399
-
-    #no, this should be add one day minus one second...
-    #  86399 is wrong twice a year when daylight savings time changes
-    #        and leap seconds too but only a second rather than an hour..
-    $ending = parse_datetime($1) + 86399;
+    $ending = day_end( parse_datetime($1) );
   }
 
   ( $beginning, $ending );
diff --git a/FS/FS/cust_main/Billing.pm b/FS/FS/cust_main/Billing.pm
index 395e629..8f7038f 100644
--- a/FS/FS/cust_main/Billing.pm
+++ b/FS/FS/cust_main/Billing.pm
@@ -116,8 +116,13 @@ sub bill_and_collect {
   $options{'actual_time'} ||= time;
   my $job = $options{'job'};
 
+  my $actual_time = ( $conf->exists('next-bill-ignore-time')
+                        ? day_end( $options{actual_time} )
+                        : $options{actual_time}
+                    );
+
   $job->update_statustext('0,cleaning expired packages') if $job;
-  $error = $self->cancel_expired_pkgs( day_end( $options{actual_time} ) );
+  $error = $self->cancel_expired_pkgs( $actual_time );
   if ( $error ) {
     $error = "Error expiring custnum ". $self->custnum. ": $error";
     if    ( $options{fatal} && $options{fatal} eq 'return' ) { return $error; }
@@ -125,7 +130,7 @@ sub bill_and_collect {
     else                                                     { warn   $error; }
   }
 
-  $error = $self->suspend_adjourned_pkgs( day_end( $options{actual_time} ) );
+  $error = $self->suspend_adjourned_pkgs( $actual_time );
   if ( $error ) {
     $error = "Error adjourning custnum ". $self->custnum. ": $error";
     if    ( $options{fatal} && $options{fatal} eq 'return' ) { return $error; }
@@ -133,7 +138,7 @@ sub bill_and_collect {
     else                                                     { warn   $error; }
   }
 
-  $error = $self->unsuspend_resumed_pkgs( day_end( $options{actual_time} ) );
+  $error = $self->unsuspend_resumed_pkgs( $actual_time );
   if ( $error ) {
     $error = "Error resuming custnum ".$self->custnum. ": $error";
     if    ( $options{fatal} && $options{fatal} eq 'return' ) { return $error; }
@@ -901,6 +906,11 @@ sub _make_lines {
 
   $cust_pkg->pkgpart($part_pkg->pkgpart);
 
+  my $cmp_time = ( $conf->exists('next-bill-ignore-time')
+                     ? day_end( $time )
+                     : $time
+                 );
+
   ###
   # bill setup
   ###
@@ -914,7 +924,7 @@ sub _make_lines {
        and ( $options{'resetup'}
              || ( ! $cust_pkg->setup
                   && ( ! $cust_pkg->start_date
-                       || $cust_pkg->start_date <= day_end($time)
+                       || $cust_pkg->start_date <= $cmp_time
                      )
                   && ( ! $conf->exists('disable_setup_suspended_pkgs')
                        || ( $conf->exists('disable_setup_suspended_pkgs') &&
@@ -963,7 +973,7 @@ sub _make_lines {
                                      && ! $cust_pkg->option('no_suspend_bill',1)
                                   )
        and
-            ( $part_pkg->freq ne '0' && ( $cust_pkg->bill || 0 ) <= day_end($time) )
+            ( $part_pkg->freq ne '0' && ( $cust_pkg->bill || 0 ) <= $cmp_time )
          || ( $part_pkg->plan eq 'voip_cdr'
                && $part_pkg->option('bill_every_call')
             )
@@ -987,7 +997,7 @@ sub _make_lines {
 
     #over two params!  lets at least switch to a hashref for the rest...
     my $increment_next_bill = ( $part_pkg->freq ne '0'
-                                && ( $cust_pkg->getfield('bill') || 0 ) <= day_end($time)
+                                && ( $cust_pkg->getfield('bill') || 0 ) <= $cmp_time
                                 && !$options{cancel}
                               );
     my %param = ( %setup_param,
diff --git a/httemplate/search/pay_batch.cgi b/httemplate/search/pay_batch.cgi
index 110d9c8..8326826 100755
--- a/httemplate/search/pay_batch.cgi
+++ b/httemplate/search/pay_batch.cgi
@@ -99,16 +99,10 @@ my $count_query = 'SELECT COUNT(*) FROM pay_batch';
 my($begin, $end) = ( '', '' );
 
 my @where;
-if ( $cgi->param('beginning')
-     && $cgi->param('beginning') =~ /^([ 0-9\-\/]{0,10})$/ ) {
-  $begin = parse_datetime($1);
-  push @where, "download >= $begin";
-}
-if ( $cgi->param('ending')
-      && $cgi->param('ending') =~ /^([ 0-9\-\/]{0,10})$/ ) {
-  $end = parse_datetime($1) + 86399;
-  push @where, "download < $end";
-}
+
+my($beginning,$ending) = FS::UI::Web::parse_beginning_ending($cgi);
+push @where, "download >= $beginning",
+             "download <= $ending";
 
 my @status;
 if ( $cgi->param('open') ) {

-----------------------------------------------------------------------

Summary of changes:
 FS/FS/Cron/bill.pm              |    3 ++-
 FS/FS/Misc/DateTime.pm          |   11 ++---------
 FS/FS/UI/Web.pm                 |    9 ++-------
 FS/FS/cust_main/Billing.pm      |   22 ++++++++++++++++------
 httemplate/search/pay_batch.cgi |   14 ++++----------
 5 files changed, 26 insertions(+), 33 deletions(-)




More information about the freeside-commits mailing list