X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=httemplate%2Fsearch%2Felements%2Fcust_main_dayranges.html;h=91e039d285b0c513fcca778cb5a6151e0d85b554;hb=b1dacaef3f9773c72b4c6f525d2f1e584e1432fc;hp=476f138e9b748327ca9ae089918b7e2b31d95f9d;hpb=a81b07fba385be4599feec950d5b108e3c107d0d;p=freeside.git diff --git a/httemplate/search/elements/cust_main_dayranges.html b/httemplate/search/elements/cust_main_dayranges.html index 476f138e9..91e039d28 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 }; @@ -144,8 +145,12 @@ unless ( $cgi->param('all_customers') ) { $days = $1; } + # If this is set, allow cust_main records with nonzero balances + my $negative = $cgi->param('negative') || 0; + 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). + ($negative ? ' != 0' : ' > 0'); } if ( $cgi->param('agentnum') =~ /^(\d+)$/ ) { @@ -217,7 +222,7 @@ if($opt{'payment_links'} && $curuser->access_right('Process payment') && @payby) @pay_labels = (map { my $payby = $_; my $label = $label{$payby}; - sub {($payby eq $_[0]->payby) ? "$label" : $label} + sub {($payby eq $_[0]->payby) ? "$label (on file)" : $label} } @payby ); @pay_links = (map { [ "${p}misc/payment.cgi?payby=$_;custnum=", 'custnum' ] } @@ -248,11 +253,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_${startdays}_$enddays"; + + 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 $as = $opt{'no_as'} ? '' : " AS rangecol_${start}_$end"; + my $start = $cutoff->clone; + $start->subtract(days => $startdays); + + my $end = $cutoff->clone; + $end->subtract(days => $enddays); - my $sql = &{$range_sub}( $start, $end, $opt{'offset'} ); #%opt? + #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'};