fix customer-specific pending payment search, RT#32962
authorIvan Kohler <ivan@freeside.biz>
Wed, 14 Jan 2015 04:10:09 +0000 (20:10 -0800)
committerIvan Kohler <ivan@freeside.biz>
Wed, 14 Jan 2015 04:10:09 +0000 (20:10 -0800)
httemplate/search/elements/cust_pay_or_refund.html

index 8aece0c..b5172fb 100755 (executable)
@@ -239,14 +239,14 @@ if ( $cgi->param('magic') ) {
   if ( $cgi->param('magic') eq '_date' ) {
 
     if ( $cgi->param('agentnum') && $cgi->param('agentnum') =~ /^(\d+)$/ ) {
-      push @search, "agentnum = $1"; # $search{'agentnum'} = $1;
+      push @search, "cust_main.agentnum = $1"; # $search{'agentnum'} = $1;
       my $agent = qsearchs('agent', { 'agentnum' => $1 } );
       die "unknown agentnum $1" unless $agent;
       $title = $agent->agent. " $title";
     }
 
     if ( $cgi->param('refnum') && $cgi->param('refnum') =~ /^(\d+)$/ ) {
-      push @search, "refnum = $1";
+      push @search, "cust_main.refnum = $1";
       my $part_referral = qsearchs('part_referral', { 'refnum' => $1 } );
       die "unknown refnum $1" unless $part_referral;
       $title = $part_referral->referral. " $title";
@@ -262,7 +262,7 @@ if ( $cgi->param('magic') ) {
     }
 
     if ( $cgi->param('custnum') =~ /^(\d+)$/ ) {
-      push @search, "custnum = $1";
+      push @search, "$table.custnum = $1";
     }
 
     if ( $cgi->param('payby') ) {
@@ -421,22 +421,22 @@ if ( $cgi->param('magic') ) {
 
     #for cust_pay_pending...  statusNOT=done
     if ( $cgi->param('statusNOT') =~ /^(\w+)$/ ) {
-      push @search, "status != '$1'";
+      push @search, "$table.status != '$1'";
     }
 
     my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi);
 
-    push @search, "_date >= $beginning ",
-                  "_date <= $ending";
+    push @search, "$table._date >= $beginning ",
+                  "$table._date <= $ending";
 
     if ( $table eq 'cust_pay_void' ) {
       my($v_beginning, $v_ending) =
         FS::UI::Web::parse_beginning_ending($cgi, 'void');
-      push @search, "void_date >= $v_beginning ",
-                    "void_date <= $v_ending";
+      push @search, "$table.void_date >= $v_beginning ",
+                    "$table.void_date <= $v_ending";
     }
 
-    push @search, FS::UI::Web::parse_lt_gt($cgi, $amount_field );
+    push @search, FS::UI::Web::parse_lt_gt($cgi, "$table.$amount_field" );
 
     $orderby = '_date';
 
@@ -517,7 +517,7 @@ if ( $cgi->param('magic') ) {
 
   my $search = ' WHERE '. join(' AND ', @search);
 
-  $count_query = "SELECT COUNT(*), SUM($amount_field) ";
+  $count_query = "SELECT COUNT(*), SUM($table.$amount_field) ";
   $count_query .= ', SUM(' . "FS::$table"->unapplied_sql . ') ' 
     if $unapplied;
   $count_query .= "FROM $table $addl_from".
@@ -545,7 +545,7 @@ if ( $cgi->param('magic') ) {
   $cgi->param('payby') =~ /^(\w+)$/ or die "illegal payby";
   my $payby = $1;
 
-  $count_query = "SELECT COUNT(*), SUM($amount_field) FROM $table".
+  $count_query = "SELECT COUNT(*), SUM($table.$amount_field) FROM $table".
                  "  WHERE payinfo = '$payinfo' AND payby = '$payby'".
                  "  AND ". $curuser->agentnums_sql;
   @count_addl = ( '$%.2f total '.$opt{name_verb} );