X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=httemplate%2Fsearch%2Felements%2Fcust_pay_or_refund.html;h=c272a16140d6d544b624776bc06e95c52e6a9785;hb=17ca8b897e82cffb3731a63ccae1fb12494a7246;hp=fccb9eef7f5598a25f4305f969876f9e75ddcf6d;hpb=b5c4237a34aef94976bc343c8d9e138664fc3984;p=freeside.git diff --git a/httemplate/search/elements/cust_pay_or_refund.html b/httemplate/search/elements/cust_pay_or_refund.html index fccb9eef7..c272a1614 100755 --- a/httemplate/search/elements/cust_pay_or_refund.html +++ b/httemplate/search/elements/cust_pay_or_refund.html @@ -39,8 +39,8 @@ Examples: ) -<% include( 'search.html', - 'title' => $title, +<& search.html, + 'title' => $title, # XXX: translate 'name_singular' => $name_singular, 'query' => $sql_query, 'count_query' => $count_query, @@ -51,10 +51,10 @@ Examples: 'sort_fields' => \@sort_fields, 'align' => $align, 'links' => \@links, + 'link_onclicks' => \@link_onclicks, 'color' => \@color, 'style' => \@style, - ) -%> +&> <%init> my %opt = @_; @@ -75,8 +75,9 @@ $title = 'Unapplied ' if $unapplied; $title .= "\u$name_singular Search Results"; my $link = ''; -if ( ( $curuser->access_right('View invoices') #XXX for now - || $curuser->access_right('View customer payments') +if ( ( $curuser->access_right('View invoices') #remove in 2.5 (2.7?) + || ($curuser->access_right('View payments') && $table =~ /^cust_pay/) + || ($curuser->access_right('View refunds') && $table eq 'cust_refund') ) && ! $opt{'disable_link'} ) @@ -134,11 +135,12 @@ if ( $cgi->param('tax_names') ) { } } -my @header = (); -my @fields = (); -my @sort_fields = (); +my @header; +my @fields; +my @sort_fields; my $align = ''; -my @links = (); +my @links; +my @link_onclicks; if ( $opt{'pre_header'} ) { push @header, @{ $opt{'pre_header'} }; $align .= 'c' x scalar(@{ $opt{'pre_header'} }); @@ -147,6 +149,16 @@ if ( $opt{'pre_header'} ) { push @sort_fields, @{ $opt{'pre_fields'} }; } +my $sub_receipt = sub { + my $obj = shift; + my $objnum = $obj->primary_key . '=' . $obj->get($obj->primary_key); + + include('/elements/popup_link_onclick.html', + 'action' => $p.'view/cust_pay.html?link=popup;'.$objnum, + 'actionlabel' => emt('Payment Receipt'), + ); +}; + push @header, "\u$name_singular", 'Amount', ; @@ -155,24 +167,25 @@ push @links, '', ''; push @fields, 'payby_payinfo_pretty', sub { sprintf('$%.2f', shift->$amount_field() ) }, ; +push @link_onclicks, $sub_receipt, '', push @sort_fields, '', $amount_field; if ( $unapplied ) { - push @header, 'Unapplied'; + push @header, emt('Unapplied'); $align .= 'r'; push @links, ''; push @fields, sub { sprintf('$%.2f', shift->unapplied_amount) }; push @sort_fields, ''; } -push @header, 'Date'; +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; @@ -183,7 +196,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 } @@ -232,83 +245,153 @@ if ( $cgi->param('magic') ) { $title = $agent->agent. " $title"; } + if ( $cgi->param('refnum') && $cgi->param('refnum') =~ /^(\d+)$/ ) { + push @search, "refnum = $1"; + my $part_referral = qsearchs('part_referral', { 'refnum' => $1 } ); + die "unknown refnum $1" unless $part_referral; + $title = $part_referral->referral. " $title"; + } + + # cust_classnum (false laziness w/ elements/cust_main_dayranges.html, prepaid_income.html, cust_bill_pay.html, cust_bill_pkg.html cust_bill_pkg_referral.html, unearned_detail.html, cust_credit.html, cust_credit_refund.html, cust_main::Search::search_sql) + if ( grep { $_ eq 'cust_classnum' } $cgi->param ) { + my @classnums = grep /^\d*$/, $cgi->param('cust_classnum'); + push @search, 'COALESCE( cust_main.classnum, 0) IN ( '. + join(',', map { $_ || '0' } @classnums ). + ' )' + if @classnums; + } + if ( $cgi->param('custnum') =~ /^(\d+)$/ ) { push @search, "custnum = $1"; } if ( $cgi->param('payby') ) { - $cgi->param('payby') =~ - /^(CARD|CHEK|BILL|PREP|CASH|WEST|MCRD)(-(VisaMC|Amex|Discover|Maestro))?$/ - or die "illegal payby ". $cgi->param('payby'); - push @search, "$table.payby = '$1'"; - if ( $3 ) { - - my $cardtype = $3; - - my $search; - if ( $cardtype eq 'VisaMC' ) { - #avoid posix regexes for portability - $search = - " ( ( substring($table.payinfo from 1 for 1) = '4' ". - " AND substring($table.payinfo from 1 for 4) != '4936' ". - " AND substring($table.payinfo from 1 for 6) ". - " NOT SIMILAR TO '49030[2-9]' ". - " AND substring($table.payinfo from 1 for 6) ". - " NOT SIMILAR TO '49033[5-9]' ". - " AND substring($table.payinfo from 1 for 6) ". - " NOT SIMILAR TO '49110[1-2]' ". - " AND substring($table.payinfo from 1 for 6) ". - " NOT SIMILAR TO '49117[4-9]' ". - " AND substring($table.payinfo from 1 for 6) ". - " NOT SIMILAR TO '49118[1-2]' ". - " )". - " OR substring($table.payinfo from 1 for 2) = '51' ". - " OR substring($table.payinfo from 1 for 2) = '52' ". - " OR substring($table.payinfo from 1 for 2) = '53' ". - " OR substring($table.payinfo from 1 for 2) = '54' ". - " OR substring($table.payinfo from 1 for 2) = '54' ". - " OR substring($table.payinfo from 1 for 2) = '55' ". - " OR substring($table.payinfo from 1 for 2) = '36' ". #Diner's int'l processed as Visa/MC inside US - " ) "; - } elsif ( $cardtype eq 'Amex' ) { - $search = - " ( substring($table.payinfo from 1 for 2 ) = '34' ". - " OR substring($table.payinfo from 1 for 2 ) = '37' ". - " ) "; - } elsif ( $cardtype eq 'Discover' ) { - $search = - " ( substring($table.payinfo from 1 for 4 ) = '6011' ". - " OR substring($table.payinfo from 1 for 2 ) = '65' ". - " OR substring($table.payinfo from 1 for 3 ) = '622' ". #China Union Pay processed as Discover outside CN - " ) "; - } elsif ( $cardtype eq 'Maestro' ) { - $search = - " ( substring($table.payinfo from 1 for 2 ) = '63' ". - " OR substring($table.payinfo from 1 for 2 ) = '67' ". - " OR substring($table.payinfo from 1 for 6 ) = '564182' ". - " OR substring($table.payinfo from 1 for 4 ) = '4936' ". - " OR substring($table.payinfo from 1 for 6 ) ". - " SIMILAR TO '49030[2-9]' ". - " OR substring($table.payinfo from 1 for 6 ) ". - " SIMILAR TO '49033[5-9]' ". - " OR substring($table.payinfo from 1 for 6 ) ". - " SIMILAR TO '49110[1-2]' ". - " OR substring($table.payinfo from 1 for 6 ) ". - " SIMILAR TO '49117[4-9]' ". - " OR substring($table.payinfo from 1 for 6 ) ". - " SIMILAR TO '49118[1-2]' ". - " ) "; - } else { - die "unknown card type $cardtype"; - } - my $masksearch = $search; - $masksearch =~ s/$table\.payinfo/$table.paymask/gi; + my @all_payby_search = (); + foreach my $payby ( $cgi->param('payby') ) { + + $payby =~ + /^(CARD|CHEK|BILL|PREP|CASH|WEST|MCRD)(-(VisaMC|Amex|Discover|Maestro|Tokenized))?$/ + or die "illegal payby $payby"; + + my $payby_search = "$table.payby = '$1'"; + + if ( $3 ) { + + my $cardtype = $3; + + my $search; + if ( $cardtype eq 'VisaMC' ) { + + #avoid posix regexes for portability + $search = + " ( ( substring($table.payinfo from 1 for 1) = '4' ". + " AND substring($table.payinfo from 1 for 4) != '4936' ". + " AND substring($table.payinfo from 1 for 6) ". + " NOT SIMILAR TO '49030[2-9]' ". + " AND substring($table.payinfo from 1 for 6) ". + " NOT SIMILAR TO '49033[5-9]' ". + " AND substring($table.payinfo from 1 for 6) ". + " NOT SIMILAR TO '49110[1-2]' ". + " AND substring($table.payinfo from 1 for 6) ". + " NOT SIMILAR TO '49117[4-9]' ". + " AND substring($table.payinfo from 1 for 6) ". + " NOT SIMILAR TO '49118[1-2]' ". + " )". + " OR substring($table.payinfo from 1 for 2) = '51' ". + " OR substring($table.payinfo from 1 for 2) = '52' ". + " OR substring($table.payinfo from 1 for 2) = '53' ". + " OR substring($table.payinfo from 1 for 2) = '54' ". + " OR substring($table.payinfo from 1 for 2) = '54' ". + " OR substring($table.payinfo from 1 for 2) = '55' ". +# " OR substring($table.payinfo from 1 for 2) = '36' ". #Diner's int'l was processed as Visa/MC inside US, now Discover + " ) "; + + } elsif ( $cardtype eq 'Amex' ) { + + $search = + " ( substring($table.payinfo from 1 for 2 ) = '34' ". + " OR substring($table.payinfo from 1 for 2 ) = '37' ". + " ) "; + + } elsif ( $cardtype eq 'Discover' ) { + + my $conf = new FS::Conf; + my $country = $conf->config('countrydefault') || 'US'; + + $search = + " ( substring($table.payinfo from 1 for 4 ) = '6011' ". + " OR substring($table.payinfo from 1 for 2 ) = '65' ". + " OR substring($table.payinfo from 1 for 3 ) = '300' ". + " OR substring($table.payinfo from 1 for 3 ) = '301' ". + " OR substring($table.payinfo from 1 for 3 ) = '302' ". + " OR substring($table.payinfo from 1 for 3 ) = '303' ". + " OR substring($table.payinfo from 1 for 3 ) = '304' ". + " OR substring($table.payinfo from 1 for 3 ) = '305' ". + " OR substring($table.payinfo from 1 for 4 ) = '3095' ". + " OR substring($table.payinfo from 1 for 2 ) = '36' ". + " OR substring($table.payinfo from 1 for 2 ) = '38' ". + " OR substring($table.payinfo from 1 for 2 ) = '39' ". + " OR substring($table.payinfo from 1 for 3 ) = '644' ". + " OR substring($table.payinfo from 1 for 3 ) = '645' ". + " OR substring($table.payinfo from 1 for 3 ) = '646' ". + " OR substring($table.payinfo from 1 for 3 ) = '647' ". + " OR substring($table.payinfo from 1 for 3 ) = '648' ". + " OR substring($table.payinfo from 1 for 3 ) = '649' ". + ( $country =~ /^(US|CA)$/ + ?" OR substring($table.payinfo from 1 for 4 ) = '3528' ". # JCB cards in the 3528-3589 range identified as Discover inside US/CA + " OR substring($table.payinfo from 1 for 4 ) = '3529' ". + " OR substring($table.payinfo from 1 for 3 ) = '353' ". + " OR substring($table.payinfo from 1 for 3 ) = '354' ". + " OR substring($table.payinfo from 1 for 3 ) = '355' ". + " OR substring($table.payinfo from 1 for 3 ) = '356' ". + " OR substring($table.payinfo from 1 for 3 ) = '357' ". + " OR substring($table.payinfo from 1 for 3 ) = '358' " + :"" + ). + " OR substring($table.payinfo from 1 for 3 ) = '622' ". #China Union Pay processed as Discover outside CN + " ) "; + + } elsif ( $cardtype eq 'Maestro' ) { + + $search = + " ( substring($table.payinfo from 1 for 2 ) = '63' ". + " OR substring($table.payinfo from 1 for 2 ) = '67' ". + " OR substring($table.payinfo from 1 for 6 ) = '564182' ". + " OR substring($table.payinfo from 1 for 4 ) = '4936' ". + " OR substring($table.payinfo from 1 for 6 ) ". + " SIMILAR TO '49030[2-9]' ". + " OR substring($table.payinfo from 1 for 6 ) ". + " SIMILAR TO '49033[5-9]' ". + " OR substring($table.payinfo from 1 for 6 ) ". + " SIMILAR TO '49110[1-2]' ". + " OR substring($table.payinfo from 1 for 6 ) ". + " SIMILAR TO '49117[4-9]' ". + " OR substring($table.payinfo from 1 for 6 ) ". + " SIMILAR TO '49118[1-2]' ". + " ) "; + + } elsif ( $cardtype eq 'Tokenized' ) { + + $search = " substring($table.payinfo from 1 for 2 ) = '99' "; + + } else { + die "unknown card type $cardtype"; + } + + my $masksearch = $search; + $masksearch =~ s/$table\.payinfo/$table.paymask/gi; + + $payby_search = "( $payby_search AND ( $search OR ( $table.paymask IS NOT NULL AND $masksearch ) ) )"; - push @search, - "( $search OR ( $table.paymask IS NOT NULL AND $masksearch ) )"; + } + + push @all_payby_search, $payby_search; } + + push @search, ' ( '. join(' OR ', @all_payby_search). ' ) ' if @all_payby_search; + } if ( $cgi->param('payinfo') ) { @@ -317,6 +400,16 @@ if ( $cgi->param('magic') ) { push @search, "$table.payinfo = '$1'"; } + if ( $cgi->param('ccpay') =~ /^([\w-:]+)$/ ) { + # I think that's all the characters we need to allow. + # To avoid confusion, this parameter searches both auth and order_number. + push @search, "($table.auth LIKE '$1%') OR ($table.order_number LIKE '$1%')"; + push @fields, 'auth', 'order_number'; + push @header, 'Auth #', 'Transaction #'; + $align .= 'rr'; + + } + if ( $cgi->param('usernum') =~ /^(\d+)$/ ) { push @search, "$table.usernum = $1"; } @@ -327,6 +420,7 @@ if ( $cgi->param('magic') ) { } my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi); + push @search, "_date >= $beginning ", "_date <= $ending"; @@ -346,7 +440,14 @@ if ( $cgi->param('magic') ) { $cgi->param('paybatch') =~ /^([\w\/\:\-\.]+)$/ or die "illegal paybatch: ". $cgi->param('paybatch'); - push @search, "paybatch = '$1'"; + $orderby = "LOWER(company || ' ' || last || ' ' || first )"; + + } elsif ( $cgi->param('magic') eq 'batchnum' ) { + + $cgi->param('batchnum') =~ /^(\d+)$/ + or die "illegal batchnum: ".$cgi->param('batchnum'); + + push @search, "batchnum = $1"; $orderby = "LOWER(company || ' ' || last || ' ' || first )"; @@ -354,6 +455,10 @@ if ( $cgi->param('magic') ) { die "unknown search magic: ". $cgi->param('magic'); } + if ( $cgi->param('paybatch') =~ /^([\w\/\:\-\.]+)$/ ) { + push @search, "paybatch = '$1'"; + } + #unapplied payment/refund if ( $unapplied ) { push @select, '(' . "FS::$table"->unapplied_sql . ') AS unapplied_amount'; @@ -379,7 +484,7 @@ if ( $cgi->param('magic') ) { #here is the agent virtualization push @search, $curuser->agentnums_sql; - my $addl_from = ' LEFT JOIN cust_main USING ( custnum ) '; + my $addl_from = FS::UI::Web::join_cust_main($table); my $group_by = ''; if ( $cgi->param('tax_names') ) {