X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=httemplate%2Fsearch%2Felements%2Fcust_pay_or_refund.html;h=8c32b79bdf89ec1f437b3d5d21d6ff7beeb13771;hb=8dba5cb96454bf8ec81333ebac381180731396f1;hp=75493f409c9385b15dc6e9aeaef98cf2565141a8;hpb=f48936de00e81e89ea0f84b28e9c7b213fe898a8;p=freeside.git diff --git a/httemplate/search/elements/cust_pay_or_refund.html b/httemplate/search/elements/cust_pay_or_refund.html index 75493f409..8c32b79bd 100755 --- a/httemplate/search/elements/cust_pay_or_refund.html +++ b/httemplate/search/elements/cust_pay_or_refund.html @@ -39,21 +39,21 @@ Examples: ) -<% include( 'search.html', - 'title' => $title, +<& search.html, + 'title' => $title, # XXX: translate 'name_singular' => $name_singular, 'query' => $sql_query, 'count_query' => $count_query, - 'count_addl' => [ '$%.2f total '.$opt{name_verb}, ], + 'count_addl' => \@count_addl, 'redirect_empty' => $opt{'redirect_empty'}, 'header' => \@header, 'fields' => \@fields, + 'sort_fields' => \@sort_fields, 'align' => $align, 'links' => \@links, 'color' => \@color, 'style' => \@style, - ) -%> +&> <%init> my %opt = @_; @@ -68,7 +68,10 @@ my $table = $opt{'table'} || 'cust_'.$opt{'thing'}; my $amount_field = $opt{'amount_field'}; my $name_singular = $opt{'name_singular'}; -my $title = "\u$name_singular Search Results"; +my $unapplied = $cgi->param('unapplied'); +my $title = ''; +$title = 'Unapplied ' if $unapplied; +$title .= "\u$name_singular Search Results"; my $link = ''; if ( ( $curuser->access_right('View invoices') #XXX for now @@ -132,6 +135,7 @@ if ( $cgi->param('tax_names') ) { my @header = (); my @fields = (); +my @sort_fields = (); my $align = ''; my @links = (); if ( $opt{'pre_header'} ) { @@ -139,21 +143,35 @@ if ( $opt{'pre_header'} ) { $align .= 'c' x scalar(@{ $opt{'pre_header'} }); push @links, map '', @{ $opt{'pre_header'} }; push @fields, @{ $opt{'pre_fields'} }; + push @sort_fields, @{ $opt{'pre_fields'} }; } push @header, "\u$name_singular", 'Amount', - 'Date', ; -$align .= 'rrr'; -push @links, '', '', ''; +$align .= 'rr'; +push @links, '', ''; push @fields, 'payby_payinfo_pretty', sub { sprintf('$%.2f', shift->$amount_field() ) }, - sub { time2str('%b %d %Y', shift->_date ) }, ; +push @sort_fields, '', $amount_field; + +if ( $unapplied ) { + push @header, emt('Unapplied'); + $align .= 'r'; + push @links, ''; + push @fields, sub { sprintf('$%.2f', shift->unapplied_amount) }; + push @sort_fields, ''; +} + +push @header, emt('Date'); +$align .= 'r'; +push @links, ''; +push @fields, sub { time2str('%b %d %Y', shift->_date ) }; +push @sort_fields, '_date'; unless ( $opt{'disable_by'} ) { - push @header, 'By'; + push @header, emt('By'); $align .= 'c'; push @links, ''; push @fields, sub { my $o = shift->otaker; @@ -164,7 +182,7 @@ unless ( $opt{'disable_by'} ) { } if ( $tax_names ) { - push @header, ('Tax names', 'Tax province'); + push @header, (emt('Tax names'), emt('Tax province')); $align .= 'cc'; push @links, ('',''); push @fields, sub { join (' + ', map { /^(.*?)(, \w\w)?$/; $1 } @@ -192,10 +210,17 @@ push @header, @{ $opt{'addl_header'} } push @fields, @{ $opt{'addl_fields'} } if $opt{'addl_fields'}; -my( $count_query, $sql_query ); +my( $count_query, $sql_query, @count_addl ); if ( $cgi->param('magic') ) { my @search = (); + my @select = ( + "$table.*", + FS::UI::Web::cust_sql_fields(), + 'cust_main.custnum AS cust_main_custnum', + ); + push @select, $tax_names if $tax_names; + my $orderby; if ( $cgi->param('magic') eq '_date' ) { @@ -328,6 +353,13 @@ if ( $cgi->param('magic') ) { die "unknown search magic: ". $cgi->param('magic'); } + #unapplied payment/refund + if ( $unapplied ) { + push @select, '(' . "FS::$table"->unapplied_sql . ') AS unapplied_amount'; + push @search, "FS::$table"->unapplied_sql . ' > 0'; + + } + #for the history search if ( $cgi->param('history_action') =~ /^([\w,]+)$/ ) { my @history_action = split(/,/, $1); @@ -374,20 +406,21 @@ if ( $cgi->param('magic') ) { my $search = ' WHERE '. join(' AND ', @search); - $count_query = "SELECT COUNT(*), SUM($amount_field) ". - "FROM $table $addl_from". - "$search $group_by"; + $count_query = "SELECT COUNT(*), SUM($amount_field) "; + $count_query .= ', SUM(' . "FS::$table"->unapplied_sql . ') ' + if $unapplied; + $count_query .= "FROM $table $addl_from". + "$search $group_by"; + + @count_addl = ( '$%.2f total '.$opt{name_verb} ); + push @count_addl, '$%.2f unapplied' if $unapplied; $sql_query = { 'table' => $table, - 'select' => join(', ', - "$table.*", - ( $tax_names ? $tax_names : () ), - 'cust_main.custnum as cust_main_custnum', - FS::UI::Web::cust_sql_fields(), - ), + 'select' => join(', ', @select), 'hashref' => {}, - 'extra_sql' => "$search $group_by ORDER BY $orderby", + 'extra_sql' => "$search $group_by", + 'order_by' => "ORDER BY $orderby", 'addl_from' => $addl_from, }; @@ -404,6 +437,7 @@ if ( $cgi->param('magic') ) { $count_query = "SELECT COUNT(*), SUM($amount_field) FROM $table". " WHERE payinfo = '$payinfo' AND payby = '$payby'". " AND ". $curuser->agentnums_sql; + @count_addl = ( '$%.2f total '.$opt{name_verb} ); $sql_query = { 'table' => $table, @@ -415,4 +449,7 @@ if ( $cgi->param('magic') ) { } +# for consistency +$title = join('',map {ucfirst} split(/\b/,$title)); +