X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=httemplate%2Fsearch%2Felements%2Fcust_main_dayranges.html;h=9b8b08f4752b574ef373b41f9e687af493e7f077;hb=f48936de00e81e89ea0f84b28e9c7b213fe898a8;hp=c53e68016770830294c45f487a291ff027a921eb;hpb=f22b714f2b7a38c8a930d8248ccb32751db82b5e;p=freeside.git diff --git a/httemplate/search/elements/cust_main_dayranges.html b/httemplate/search/elements/cust_main_dayranges.html index c53e68016..9b8b08f47 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 }; @@ -145,7 +146,7 @@ unless ( $cgi->param('all_customers') ) { } push @where, - call_range_sub($range_sub, $days + $offset, 0, 'no_as'=>1). ' > 0'; # != 0'; + call_range_sub($range_sub, $days, 0, 'offset' => $offset, 'no_as'=>1). ' > 0'; # != 0'; } if ( $cgi->param('agentnum') =~ /^(\d+)$/ ) { @@ -248,11 +249,25 @@ my $money_char = $conf->config('money_char') || '$'; # ) sub call_range_sub { - my($range_sub, $start, $end, %opt) = @_; + my($range_sub, $startdays, $enddays, %opt) = @_; - my $as = $opt{'no_as'} ? '' : " AS rangecol_${start}_$end"; + my $as = $opt{'no_as'} ? '' : " AS rangecol_${startdays}_$enddays"; - my $sql = &{$range_sub}( $start, $end, $opt{'offset'} ); #%opt? + my $offset = $opt{'offset'} || 0; + # Always use $offset - 1day + 1sec = the last second of that day + my $cutoff = DateTime->now->set(hour => 23, minute => 59, second => 59); + $cutoff->subtract(days => $offset); + + my $start = $cutoff->clone; + $start->subtract(days => $startdays); + + my $end = $cutoff->clone; + $end->subtract(days => $enddays); + + #warn "offset $offset (".$cutoff->epoch."), range $startdays-$enddays (".$start->epoch . '-' . ($enddays ? $end->epoch : '').")\n"; + my $sql = &{$range_sub}( $start->epoch, + $enddays ? $end->epoch : '', + $cutoff->epoch ); #%opt? $sql = "SUM($sql)" if $opt{'sum'};