diff options
Diffstat (limited to 'httemplate')
| -rw-r--r-- | httemplate/search/contact.html | 62 |
1 files changed, 22 insertions, 40 deletions
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 = ( |
