[freeside-commits] freeside/FS/FS cust_main.pm, 1.464.2.1, 1.464.2.2 Conf.pm, 1.324.2.2, 1.324.2.3
Ivan,,,
ivan at wavetail.420.am
Tue Oct 27 11:11:47 PDT 2009
Update of /home/cvs/cvsroot/freeside/FS/FS
In directory wavetail.420.am:/tmp/cvs-serv10856/FS/FS
Modified Files:
Tag: FREESIDE_1_9_BRANCH
cust_main.pm Conf.pm
Log Message:
address1 search, RT#5060
Index: Conf.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/Conf.pm,v
retrieving revision 1.324.2.2
retrieving revision 1.324.2.3
diff -u -d -r1.324.2.2 -r1.324.2.3
--- Conf.pm 24 Oct 2009 00:34:39 -0000 1.324.2.2
+++ Conf.pm 27 Oct 2009 18:11:44 -0000 1.324.2.3
@@ -2112,6 +2112,13 @@
},
{
+ 'key' => 'address1-search',
+ 'section' => 'UI',
+ 'description' => 'Enable the ability to search the address1 field from customer search.',
+ 'type' => 'checkbox',
+ },
+
+ {
'key' => 'address2-search',
'section' => 'UI',
'description' => 'Enable a "Unit" search box which searches the second address field. Useful for multi-tenant applications. See also: cust_main-require_address2',
Index: cust_main.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_main.pm,v
retrieving revision 1.464.2.1
retrieving revision 1.464.2.2
diff -u -d -r1.464.2.1 -r1.464.2.2
--- cust_main.pm 25 Oct 2009 23:30:02 -0000 1.464.2.1
+++ cust_main.pm 27 Oct 2009 18:11:44 -0000 1.464.2.2
@@ -2,8 +2,12 @@
require 5.006;
use strict;
-use vars qw( @ISA @EXPORT_OK $DEBUG $me $conf @encrypted_fields
- $import $skip_fuzzyfiles $ignore_expired_card @paytypes);
+use vars qw( @ISA @EXPORT_OK $DEBUG $me $conf
+ @encrypted_fields
+ $import $ignore_expired_card
+ $skip_fuzzyfiles @fuzzyfields
+ @paytypes
+ );
use vars qw( $realtime_bop_decline_quiet ); #ugh
use Safe;
use Carp;
@@ -77,9 +81,11 @@
$me = '[FS::cust_main]';
$import = 0;
-$skip_fuzzyfiles = 0;
$ignore_expired_card = 0;
+$skip_fuzzyfiles = 0;
+ at fuzzyfields = ( 'first', 'last', 'company', 'address1' );
+
@encrypted_fields = ('payinfo', 'paycvv');
sub nohistory_fields { ('paycvv'); }
@@ -1492,9 +1498,7 @@
my $dbh = dbh;
my $queue = new FS::queue { 'job' => 'FS::cust_main::append_fuzzyfiles' };
- my $error = $queue->insert( map $self->getfield($_),
- qw(first last company)
- );
+ my $error = $queue->insert( map $self->getfield($_), @fuzzyfields );
if ( $error ) {
$dbh->rollback if $oldAutoCommit;
return "queueing job (transaction rolled back): $error";
@@ -1502,9 +1506,7 @@
if ( $self->ship_last ) {
$queue = new FS::queue { 'job' => 'FS::cust_main::append_fuzzyfiles' };
- $error = $queue->insert( map $self->getfield("ship_$_"),
- qw(first last company)
- );
+ $error = $queue->insert( map $self->getfield("ship_$_"), @fuzzyfields );
if ( $error ) {
$dbh->rollback if $oldAutoCommit;
return "queueing job (transaction rolled back): $error";
@@ -4457,9 +4459,9 @@
sub _bop_recurring_billing {
my( $self, %opt ) = @_;
- my $method = $conf->config('credit_card-recurring_billing_flag');
+ my $method = scalar($conf->config('credit_card-recurring_billing_flag'));
- if ( $method eq 'transaction_is_recur' ) {
+ if ( defined($method) && $method eq 'transaction_is_recur' ) {
return 1 if $opt{'trans_is_recur'};
@@ -8443,8 +8445,8 @@
=item fuzzy_search FUZZY_HASHREF [ HASHREF, SELECT, EXTRA_SQL, CACHE_OBJ ]
Performs a fuzzy (approximate) search and returns the matching FS::cust_main
-records. Currently, I<first>, I<last> and/or I<company> may be specified (the
-appropriate ship_ field is also searched).
+records. Currently, I<first>, I<last>, I<company> and/or I<address1> may be
+specified (the appropriate ship_ field is also searched).
Additional options are the same as FS::Record::qsearch
@@ -8573,15 +8575,18 @@
}
if ( $search =~ /^\s*(\d+)\s*$/
- || ( $conf->config('cust_main-agent_custid-format') eq 'ww?d+'
- && $search =~ /^\s*(\w\w?\d+)\s*$/
- )
- )
+ || ( $conf->config('cust_main-agent_custid-format') eq 'ww?d+'
+ && $search =~ /^\s*(\w\w?\d+)\s*$/
+ )
+ || ( $conf->exists('address1-search' )
+ && $search =~ /^\s*(\d+\-?\w*)\s*$/ #i.e. 1234A or 9432-D
+ )
+ )
{
my $num = $1;
- if ( $num <= 2147483647 ) { #need a bigint custnum? wow.
+ if ( $num =~ /^(\d+)$/ && $num <= 2147483647 ) { #need a bigint custnum? wow
push @cust_main, qsearch( {
'table' => 'cust_main',
'hashref' => { 'custnum' => $num, %options },
@@ -8595,13 +8600,28 @@
'extra_sql' => " AND $agentnums_sql", #agent virtualization
} );
+ if ( $conf->exists('address1-search') ) {
+ my $len = length($num);
+ $num = lc($num);
+ foreach my $prefix ( '', 'ship_' ) {
+ push @cust_main, qsearch( {
+ 'table' => 'cust_main',
+ 'hashref' => { %options, },
+ 'extra_sql' =>
+ ( keys(%options) ? ' AND ' : ' WHERE ' ).
+ " LOWER(SUBSTRING(${prefix}address1 FROM 1 FOR $len)) = '$num' ".
+ " AND $agentnums_sql",
+ } );
+ }
+ }
+
} elsif ( $search =~ /^\s*(\S.*\S)\s+\((.+), ([^,]+)\)\s*$/ ) {
my($company, $last, $first) = ( $1, $2, $3 );
# "Company (Last, First)"
#this is probably something a browser remembered,
- #so just do an exact search
+ #so just do an exact (but case-insensitive) search
foreach my $prefix ( '', 'ship_' ) {
push @cust_main, qsearch( {
@@ -8670,11 +8690,16 @@
#exact
my $sql = scalar(keys %options) ? ' AND ' : ' WHERE ';
- $sql .= " ( LOWER(last) = $q_value
- OR LOWER(company) = $q_value
- OR LOWER(ship_last) = $q_value
- OR LOWER(ship_company) = $q_value
- )";
+ $sql .= " ( LOWER(last) = $q_value
+ OR LOWER(company) = $q_value
+ OR LOWER(ship_last) = $q_value
+ OR LOWER(ship_company) = $q_value
+ ";
+ $sql .= " OR LOWER(address1) = $q_value
+ OR LOWER(ship_address1) = $q_value
+ "
+ if $conf->exists('address1-search');
+ $sql .= " )";
push @cust_main, qsearch( {
'table' => 'cust_main',
@@ -8715,6 +8740,13 @@
;
}
+ if ( $conf->exists('address1-search') ) {
+ push @hashrefs,
+ { 'address1' => { op=>'ILIKE', value=>"%$value%" }, },
+ { 'ship_address1' => { op=>'ILIKE', value=>"%$value%" }, },
+ ;
+ }
+
foreach my $hashref ( @hashrefs ) {
push @cust_main, qsearch( {
@@ -8745,6 +8777,10 @@
push @cust_main,
FS::cust_main->fuzzy_search( { $field => $value }, @fuzopts );
}
+ if ( $conf->exists('address1-search') ) {
+ push @cust_main,
+ FS::cust_main->fuzzy_search( { 'address1' => $value }, @fuzopts );
+ }
}
@@ -8828,9 +8864,6 @@
=cut
-use vars qw(@fuzzyfields);
- at fuzzyfields = ( 'last', 'first', 'company' );
-
sub check_and_rebuild_fuzzyfiles {
my $dir = $FS::UID::conf_dir. "/cache.". $FS::UID::datasrc;
rebuild_fuzzyfiles() if grep { ! -e "$dir/cust_main.$_" } @fuzzyfields
@@ -8890,7 +8923,7 @@
\@array;
}
-=item append_fuzzyfiles LASTNAME COMPANY
+=item append_fuzzyfiles FIRSTNAME LASTNAME COMPANY ADDRESS1
=cut
@@ -8903,7 +8936,7 @@
my $dir = $FS::UID::conf_dir. "/cache.". $FS::UID::datasrc;
- foreach my $field (qw( first last company )) {
+ foreach my $field (@fuzzyfields) {
my $value = shift;
if ( $value ) {
More information about the freeside-commits
mailing list