From: ivan <ivan>
Date: Fri, 4 Mar 2005 22:24:27 +0000 (+0000)
Subject: fix "Column reference "payby" is ambiguous" error when selecting by payment type... 
X-Git-Tag: SQL_LEDGER_2_4_4~1^2~443
X-Git-Url: http://git.freeside.biz/gitweb/?a=commitdiff_plain;h=f34557b8890dcc63db6c5588233dc7bfa9d39f22;p=freeside.git

fix "Column reference "payby" is ambiguous" error when selecting by payment type, fix missing check #s caused by cust_main.payinfo masking cust_pay.payinfo, closes (really this time): Bug#1105
---

diff --git a/httemplate/search/cust_credit.html b/httemplate/search/cust_credit.html
index 85128bca2..8f6258e4e 100755
--- a/httemplate/search/cust_credit.html
+++ b/httemplate/search/cust_credit.html
@@ -9,7 +9,7 @@
    }
 
    if ( $cgi->param('agentnum') && $cgi->param('agentnum') =~ /^(\d+)$/ ) {
-     push @search, "agentnum = $1"; # $search{'agentnum'} = $1;
+     push @search, "agentnum = $1";
      my $agent = qsearchs('agent', { 'agentnum' => $1 } );
      die "unknown agentnum $1" unless $agent;
      $title = $agent->agent. " $title";
@@ -46,6 +46,7 @@
 
    my $sql_query   = {
      'table'     => 'cust_credit',
+     'select'    => 'cust_credit.*, cust_main.last, cust_main.first, cust_main.company',
      'hashref'   => {},
      'extra_sql' => $where,
      'addl_from' => 'LEFT JOIN cust_main USING ( custnum )',
diff --git a/httemplate/search/cust_pay.cgi b/httemplate/search/cust_pay.cgi
index 64fe1f93a..d4aaaa89c 100755
--- a/httemplate/search/cust_pay.cgi
+++ b/httemplate/search/cust_pay.cgi
@@ -3,7 +3,6 @@
    my( $count_query, $sql_query );
    if ( $cgi->param('magic') && $cgi->param('magic') eq '_date' ) {
    
-     my %search = ();
      my @search = ();
 
      if ( $cgi->param('agentnum') && $cgi->param('agentnum') =~ /^(\d+)$/ ) {
@@ -16,7 +15,7 @@
      if ( $cgi->param('payby') ) {
        $cgi->param('payby') =~ /^(CARD|CHEK|BILL)(-(VisaMC|Amex|Discover))?$/
          or die "illegal payby ". $cgi->param('payby');
-       $search{'payby'} = $1;
+       push @search, "cust_pay.payby = '$1'";
        if ( $3 ) {
          if ( $3 eq 'VisaMC' ) {
            #avoid posix regexes for portability
@@ -60,22 +59,19 @@
        push @search, " _date < $1 ";
      }
    
-     my $search;
+     my $search = '';
      if ( @search ) {
-       $search = ( scalar(keys %search) ? ' AND ' : ' WHERE ' ).
-                 join(' AND ', @search);
+       $search = ' WHERE '. join(' AND ', @search);
      }
 
-     my $hsearch = join(' AND ', map { "$_ = '$search{$_}'" } keys %search );
      $count_query = "SELECT COUNT(*), SUM(paid) ".
                     "FROM cust_pay LEFT JOIN cust_main USING ( custnum )".
-                    ( $hsearch ? " WHERE $hsearch " : '' ).
                     $search;
    
-     warn join('-', keys %search);
      $sql_query = {
        'table'     => 'cust_pay',
-       'hashref'   => \%search,
+       'select'    => 'cust_pay.*, cust_main.last, cust_main.first, cust_main.company',
+       'hashref'   => {},
        'extra_sql' => "$search ORDER BY _date",
        'addl_from' => 'LEFT JOIN cust_main USING ( custnum )',
      };