From: mark Date: Wed, 31 Mar 2010 07:41:29 +0000 (+0000) Subject: RT#7266: aging reports as of a past date X-Git-Tag: root_of_svc_elec_features~336 X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=commitdiff_plain;h=4ca83488cafd75e2612358672e0f416918d951cf RT#7266: aging reports as of a past date --- diff --git a/httemplate/search/elements/cust_main_dayranges.html b/httemplate/search/elements/cust_main_dayranges.html index cc014923f..f75927855 100644 --- a/httemplate/search/elements/cust_main_dayranges.html +++ b/httemplate/search/elements/cust_main_dayranges.html @@ -98,8 +98,14 @@ my $ranges = $opt{'ranges'} ? delete($opt{'ranges'}) : [ my $range_sub = delete($opt{'range_sub'}); #or die +my $offset = 0; +if($cgi->param('as_of')) { + $offset = int((time - str2time($cgi->param('as_of'))) / 86400); + $opt{'title'} .= ' ('.$cgi->param('as_of').')' if $offset > 0; +} + #my $range_cols = join(',', map &{$range_sub}( @$_ ), @ranges ); -my $range_cols = join(',', map call_range_sub($range_sub, @$_ ), @$ranges ); +my $range_cols = join(',', map call_range_sub($range_sub, @$_, 'offset' => $offset ), @$ranges ); my $select_count_pkgs = FS::cust_main->select_count_pkgs_sql; @@ -119,14 +125,14 @@ END my @where = (); unless ( $cgi->param('all_customers') ) { - +# Exclude entire cust_main records where the balance is >0 my $days = 0; if ( $cgi->param('days') =~ /^\s*(\d+)\s*$/ ) { $days = $1; } push @where, - call_range_sub($range_sub, $days, 0, 'no_as'=>1). ' > 0'; # != 0'; + call_range_sub($range_sub, $days + $offset, 0, 'no_as'=>1). ' > 0'; # != 0'; } if ( $cgi->param('agentnum') =~ /^(\d+)$/ ) { @@ -167,7 +173,7 @@ my $sql_query = { my $total_sql = "SELECT ". - join(',', map call_range_sub( $range_sub, @$_, 'sum'=>1 ), @$ranges). + join(',', map call_range_sub( $range_sub, @$_, 'offset' => $offset, 'sum'=>1 ), @$ranges). " FROM cust_main $where"; my $total_sth = dbh->prepare($total_sql) or die dbh->errstr; @@ -203,7 +209,7 @@ sub call_range_sub { my $as = $opt{'no_as'} ? '' : " AS rangecol_${start}_$end"; - my $sql = &{$range_sub}( $start, $end ); #%opt? + my $sql = &{$range_sub}( $start, $end, $opt{'offset'} ); #%opt? $sql = "SUM($sql)" if $opt{'sum'}; diff --git a/httemplate/search/report_receivables.cgi b/httemplate/search/report_receivables.cgi index 6df016134..53261849a 100755 --- a/httemplate/search/report_receivables.cgi +++ b/httemplate/search/report_receivables.cgi @@ -28,13 +28,18 @@ die "access denied" # ) sub balance { - my($start, $end) = @_; #, %opt ? - + my($start, $end, $offset) = @_; #, %opt ? #handle start and end ranges (86400 = 24h * 60m * 60s) my $str2time = str2time_sql; my $closing = str2time_sql_closing; - $start = $start ? "( $str2time now() $closing - ".($start * 86400). ' )' : ''; - $end = $end ? "( $str2time now() $closing - ".($end * 86400). ' )' : ''; + + # $end == 0 means "+infinity", while $start == 0 really means 0 + # so we should always include a start condition + $start = "( $str2time now() $closing - ". ($start + $offset) * 86400 . ' )'; + # but only include an end condition if $end != 0 + $end = $end ? + "( $str2time now() $closing - ". ($end + $offset) * 86400 . ' )' + : ''; #$opt{'unapplied_date'} = 1; diff --git a/httemplate/search/report_receivables.html b/httemplate/search/report_receivables.html index bfb016945..b7c84f0de 100755 --- a/httemplate/search/report_receivables.html +++ b/httemplate/search/report_receivables.html @@ -24,6 +24,12 @@ Customers with a balance over days old + <% include( '/elements/tr-input-date-field.html', { + 'name' => 'as_of', + 'value' => time, + 'label' => 'As of date ', + 'format' => FS::Conf->new->config('date_format') || '%m/%d/%Y', + } ) %> diff --git a/httemplate/search/report_unapplied_cust_pay.html b/httemplate/search/report_unapplied_cust_pay.html index 10093e576..65e064ccb 100755 --- a/httemplate/search/report_unapplied_cust_pay.html +++ b/httemplate/search/report_unapplied_cust_pay.html @@ -25,6 +25,12 @@ Customers with unapplied payments over days old + <% include( '/elements/tr-input-date-field.html', { + 'name' => 'as_of', + 'value' => time, + 'label' => 'As of date ', + 'format' => FS::Conf->new->config('date_format') || '%m/%d/%Y', + } ) %> diff --git a/httemplate/search/unapplied_cust_pay.html b/httemplate/search/unapplied_cust_pay.html index 8d064d174..73361c00b 100755 --- a/httemplate/search/unapplied_cust_pay.html +++ b/httemplate/search/unapplied_cust_pay.html @@ -13,13 +13,15 @@ die "access denied" <%once> sub unapplied_payments { - my($start, $end, %opt) = @_; + my($start, $end, $offset) = @_; #handle start and end ranges (86400 = 24h * 60m * 60s) my $str2time = str2time_sql; my $closing = str2time_sql_closing; - $start = $start ? "( $str2time now() $closing - ".($start * 86400). ' )' : ''; - $end = $end ? "( $str2time now() $closing - ".($end * 86400). ' )' : ''; + $start = "( $str2time now() $closing - ".($start + $offset) * 86400 . ' )'; + $end = $end ? + "( $str2time now() $closing - ".($end + $offset) * 86400 . ' )' + : ''; FS::cust_main->unapplied_payments_date_sql( $start, $end );