diff options
| author | levinse <levinse> | 2011-05-03 23:26:08 +0000 | 
|---|---|---|
| committer | levinse <levinse> | 2011-05-03 23:26:08 +0000 | 
| commit | 3e4c6bf062b39d8030dc3afb45fec35da6593ac5 (patch) | |
| tree | c0e7cd95e5d5429595d8376fe04ac72221fb2ef4 /FS | |
| parent | ccb341fa032dc2e57a12d69ae1b06198a6731286 (diff) | |
configurable ignore time portion of billing timestamp when billing
Diffstat (limited to 'FS')
| -rw-r--r-- | FS/FS/Conf.pm | 9 | ||||
| -rw-r--r-- | FS/FS/cust_main/Billing.pm | 28 | 
2 files changed, 29 insertions, 8 deletions
| diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm index 02133b06a..2862e1810 100644 --- a/FS/FS/Conf.pm +++ b/FS/FS/Conf.pm @@ -750,7 +750,14 @@ my %payment_gateway_options = (      'type'        => 'text',      'per_agent'   => 1,    }, - +   +  { +    'key'         => 'next-bill-ignore-time', +    'section'     => 'billing', +    'description' => 'Ignore the time portion of next bill dates when billing, matching anything from 00:00:00 to 23:59:59 on the billing day.', +    'type'        => 'checkbox', +  }, +      {      'key'         => 'business-onlinepayment',      'section'     => 'billing', diff --git a/FS/FS/cust_main/Billing.pm b/FS/FS/cust_main/Billing.pm index 1bf7b02a7..5647ef014 100644 --- a/FS/FS/cust_main/Billing.pm +++ b/FS/FS/cust_main/Billing.pm @@ -20,6 +20,7 @@ use FS::cust_bill_pkg_tax_rate_location;  use FS::part_event;  use FS::part_event_condition;  use FS::pkg_category; +use POSIX;  # 1 is mostly method/subroutine entry and options  # 2 traces progress of some operations @@ -112,7 +113,7 @@ sub bill_and_collect {    my $job = $options{'job'};    $job->update_statustext('0,cleaning expired packages') if $job; -  $error = $self->cancel_expired_pkgs( $options{actual_time} ); +  $error = $self->cancel_expired_pkgs( $self->day_end( $options{actual_time} ) );    if ( $error ) {      $error = "Error expiring custnum ". $self->custnum. ": $error";      if    ( $options{fatal} && $options{fatal} eq 'return' ) { return $error; } @@ -120,7 +121,7 @@ sub bill_and_collect {      else                                                     { warn   $error; }    } -  $error = $self->suspend_adjourned_pkgs( $options{actual_time} ); +  $error = $self->suspend_adjourned_pkgs( $self->day_end( $options{actual_time} ) );    if ( $error ) {      $error = "Error adjourning custnum ". $self->custnum. ": $error";      if    ( $options{fatal} && $options{fatal} eq 'return' ) { return $error; } @@ -164,9 +165,22 @@ sub bill_and_collect {  } +sub day_end { +    # XXX: sometimes "incorrect" if crossing DST boundaries? + +    my $self = shift; +    my $time = shift; + +    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); +} +  sub cancel_expired_pkgs {    my ( $self, $time, %options ) = @_; - +      my @cancel_pkgs = $self->ncancelled_pkgs( {       'extra_sql' => " AND expire IS NOT NULL AND expire > 0 AND expire <= $time "    } ); @@ -189,7 +203,7 @@ sub cancel_expired_pkgs {  sub suspend_adjourned_pkgs {    my ( $self, $time, %options ) = @_; - +      my @susp_pkgs = $self->ncancelled_pkgs( {      'extra_sql' =>        " AND ( susp IS NULL OR susp = 0 ) @@ -833,7 +847,7 @@ sub _make_lines {         and ( $options{'resetup'}               || ( ! $cust_pkg->setup                    && ( ! $cust_pkg->start_date -                       || $cust_pkg->start_date <= $time +                       || $cust_pkg->start_date <= $self->day_end($time)                       )                    && ( ! $conf->exists('disable_setup_suspended_pkgs')                         || ( $conf->exists('disable_setup_suspended_pkgs') && @@ -878,7 +892,7 @@ sub _make_lines {    if (     ! $cust_pkg->start_date         and ( ! $cust_pkg->susp || $part_pkg->option('suspend_bill', 1) )         and -            ( $part_pkg->freq ne '0' && ( $cust_pkg->bill || 0 ) <= $time ) +            ( $part_pkg->freq ne '0' && ( $cust_pkg->bill || 0 ) <= $self->day_end($time) )           || ( $part_pkg->plan eq 'voip_cdr'                 && $part_pkg->option('bill_every_call')              ) @@ -902,7 +916,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 ) <= $time +                                && ( $cust_pkg->getfield('bill') || 0 ) <= $self->day_end($time)                                  && !$options{cancel}                                );      my %param = ( 'precommit_hooks'     => $precommit_hooks, | 
