From b75b481f255cbe08d8e6e6768924a68af4e15f82 Mon Sep 17 00:00:00 2001 From: Christopher Burger Date: Tue, 20 Nov 2018 19:02:02 -0500 Subject: [PATCH] RT# 77532 - V3 fix changing cust_contact to contact --- FS/FS/cust_main/Search.pm | 21 ++++++-------- httemplate/search/contact.html | 62 +++++++++++++++--------------------------- 2 files changed, 31 insertions(+), 52 deletions(-) diff --git a/FS/FS/cust_main/Search.pm b/FS/FS/cust_main/Search.pm index 1c7a64402..b1af41c2a 100644 --- a/FS/FS/cust_main/Search.pm +++ b/FS/FS/cust_main/Search.pm @@ -97,7 +97,7 @@ sub smart_search { push @cust_main, qsearch( { 'select' => 'cust_main.*', 'table' => 'cust_main', - 'addl_from' => ' left join cust_contact using (custnum) '. + 'addl_from' => ' left join contact using (custnum) '. ' left join contact_phone using (contactnum) ', 'hashref' => { %options }, 'extra_sql' => ( scalar(keys %options) ? ' AND ' : ' WHERE ' ). @@ -136,7 +136,7 @@ sub smart_search { 'select' => 'cust_main.*', 'table' => 'cust_main', 'addl_from' => ' left join cust_main_invoice using (custnum) '. - ' left join cust_contact using (custnum) '. + ' left join contact using (custnum) '. ' left join contact_email using (contactnum) ', 'hashref' => { %options }, 'extra_sql' => ( scalar(keys %options) ? ' AND ' : ' WHERE ' ). @@ -289,8 +289,7 @@ sub smart_search { push @cust_main, qsearch( { 'select' => 'cust_main.*', 'table' => 'cust_main', - 'addl_from' => ' left join cust_contact using (custnum) '. - ' left join contact using (contactnum) ', + 'addl_from' => ' left join contact using (custnum) ', 'hashref' => { %options }, 'extra_sql' => "$sql AND $agentnums_sql", #agent virtualization } ); @@ -322,8 +321,7 @@ sub smart_search { push @cust_main, qsearch( { 'select' => 'cust_main.*', 'table' => 'cust_main', - 'addl_from' => ' left join cust_contact using (custnum) '. - ' left join contact using (contactnum) ', + 'addl_from' => ' left join contact using (custnum) ', 'hashref' => { %options }, 'extra_sql' => "$sql AND $agentnums_sql", #agent virtualization } ); @@ -1094,8 +1092,6 @@ sub search { # (maybe we should be using FS::UI::Web::join_cust_main instead?) $addl_from .= ' LEFT JOIN (select refnum, referral from part_referral) AS part_referral_x ON (cust_main.refnum = part_referral_x.refnum) '; - my $count_query = "SELECT COUNT(*) FROM cust_main $addl_from $extra_sql"; - my @select = ( 'cust_main.custnum', 'cust_main.salesnum', @@ -1114,10 +1110,9 @@ sub search { my $contact_params = $params->{'contacts'}; $addl_from .= - ' LEFT JOIN cust_contact ON ( cust_main.custnum = cust_contact.custnum ) '; + ' LEFT JOIN contact ON ( cust_main.custnum = contact.custnum ) '; if ($contact_params->{'contacts_firstname'} || $contact_params->{'contacts_lastname'}) { - $addl_from .= ' LEFT JOIN contact ON ( cust_contact.contactnum = contact.contactnum ) '; my $first_query = " AND contact.first = '" . $contact_params->{'contacts_firstname'} . "'" unless !$contact_params->{'contacts_firstname'}; my $last_query = " AND contact.last = '" . $contact_params->{'contacts_lastname'} . "'" @@ -1126,12 +1121,12 @@ sub search { } if ($contact_params->{'contacts_email'}) { - $addl_from .= ' LEFT JOIN contact_email ON ( cust_contact.contactnum = contact_email.contactnum ) '; + $addl_from .= ' LEFT JOIN contact_email ON ( contact.contactnum = contact_email.contactnum ) '; $extra_sql .= " AND ( contact_email.emailaddress = '" . $contact_params->{'contacts_email'} . "' )"; } if ($contact_params->{'contacts_homephone'} || $contact_params->{'contacts_workphone'} || $contact_params->{'contacts_mobilephone'}) { - $addl_from .= ' LEFT JOIN contact_phone ON ( cust_contact.contactnum = contact_phone.contactnum ) '; + $addl_from .= ' LEFT JOIN contact_phone ON ( contact.contactnum = contact_phone.contactnum ) '; my $contacts_mobilephone; foreach my $phone (qw( contacts_homephone contacts_workphone contacts_mobilephone )) { (my $num = $contact_params->{$phone}) =~ s/\W//g; @@ -1148,6 +1143,8 @@ sub search { } + my $count_query = "SELECT COUNT(*) FROM cust_main $addl_from $extra_sql"; + if ($params->{'flattened_pkgs'}) { #my $pkg_join = ''; diff --git a/httemplate/search/contact.html b/httemplate/search/contact.html index 2121527a5..1ddfabb8b 100644 --- a/httemplate/search/contact.html +++ b/httemplate/search/contact.html @@ -44,48 +44,30 @@ my $dbh = dbh; my $DEBUG = 0; -my $work_phone_sub = sub { - my $contact = shift; - my $phone_type = qsearchs('phone_type', { 'typename' => 'Work' }); - #can't because contactnum is in the wrong field - my @contact_workphone = qsearch('contact_phone', { 'contactnum' => $contact->contact_contactnum, 'phonetypenum' => $phone_type->phonetypenum } ); - join(', ', map $_->phonenum, @contact_workphone); +my $format_phone_sub = sub { + + my $pn = $_[0] || return ''; + $pn =~ s/\D//g; + my @pn = split //, $pn; + + return sprintf( + '(%s) %s-%s', + join( '', @pn[0..2] ), + join( '', @pn[3..5] ), + join( '', @pn[6..9] ) + ) if @pn == 10; + + return sprintf( + '+%s (%s) %s-%s', + $pn[0], + join( '', @pn[1..3] ), + join( '', @pn[4..6] ), + join( '', @pn[7..10] ) + ) if @pn == 11 && $pn[0] == 1; + + encode_entities $_[0]; }; -my $mobile_phone_sub = sub { - my $contact = shift; - my $phone_type = qsearchs('phone_type', { 'typename' => 'Mobile' }); - #can't because contactnum is in the wrong field - my @contact_mobilephone = qsearch('contact_phone', { 'contactnum' => $contact->contact_contactnum, 'phonetypenum' => $phone_type->phonetypenum } ); - join(', ', map $_->phonenum, @contact_mobilephone); -}; - -my $home_phone_sub = sub { - my $contact = shift; - my $phone_type = qsearchs('phone_type', { 'typename' => 'Home' }); - #can't because contactnum is in the wrong field - my @contact_homephone = qsearch('contact_phone', { 'contactnum' => $contact->contact_contactnum, 'phonetypenum' => $phone_type->phonetypenum } ); - join(', ', map $_->phonenum, @contact_homephone); -}; - -my $link; #for closure in this sub, we'll define it later -my $contact_classname_sub = sub { - my $contact = shift; - my %hash = ( 'contactnum' => $contact->contact_contactnum ); - my $X_contact; - if ( $link eq 'cust_main' ) { - $X_contact = qsearchs('cust_contact', { %hash, 'custnum' => $contact->custnum } ); - } elsif ( $link eq 'prospect_main' ) { - $X_contact = qsearchs('prospect_contact', { %hash, 'prospectnum' => $contact->prospectnum } ); - } else { - die 'guru meditation #5555'; - } - $X_contact->contact_classname; -}; - -my @header = ( 'First', 'Last', 'Title', 'Email', 'Work Phone', 'Mobile Phone', 'Home Phone', 'Type' ); -my @fields = ( 'first', 'last', 'title', $email_sub, $work_phone_sub, $mobile_phone_sub, $home_phone_sub, $contact_classname_sub ); -my @links = ( '', '', '', '', '', '', '', '', ); my @report = ( -- 2.11.0