X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=httemplate%2Fsearch%2Felements%2Fcust_main_dayranges.html;h=d5ef62540e72e2f21a8db0a2611efad8f4e2e754;hb=64808a397a0a0935069d65c48aba9afaeb4fafd2;hp=aa133883b464d8a827f15020db1a51c92fb5e7d8;hpb=152d5357089a71f637530054b71f21c36fdfe01b;p=freeside.git diff --git a/httemplate/search/elements/cust_main_dayranges.html b/httemplate/search/elements/cust_main_dayranges.html index aa133883b..d5ef62540 100644 --- a/httemplate/search/elements/cust_main_dayranges.html +++ b/httemplate/search/elements/cust_main_dayranges.html @@ -11,6 +11,7 @@ Example: my( $start, $end ) = @_; "SQL EXPRESSION BASED ON $start AND $end"; + # where $start and $end are unix timestamps }; @@ -252,7 +253,16 @@ sub call_range_sub { my $as = $opt{'no_as'} ? '' : " AS rangecol_${start}_$end"; - my $sql = &{$range_sub}( $start, $end, $opt{'offset'} ); #%opt? + my $offset = $opt{'offset'} || 0; + # Time::ParseDate for excruciating correctness + # Always use $offset - 1day + 1sec = the last second of that day + $start = parsedate('00:00 '.($start + $offset - 1).' days ago') - 1; + $end = $end ? + parsedate('00:00 '.($end + $offset - 1).' days ago') - 1 : + ''; + my $cutoff = parsedate('00:00 '.($offset - 1).' days ago') - 1; + + my $sql = &{$range_sub}( $start, $end, $cutoff ); #%opt? $sql = "SUM($sql)" if $opt{'sum'};