my $DEBUG = 0;
-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 $work_phone_sub = sub {
+ my $contact = shift;
+ #can't because contactnum is in the wrong field
+ my @contact_workphone = qsearch('contact_phone', { 'contactnum' => $contact->contact_contactnum, 'phonetypenum' => '1' } );
+ join(', ', map $_->phonenum, @contact_workphone);
};
+my $mobile_phone_sub = sub {
+ my $contact = shift;
+ #can't because contactnum is in the wrong field
+ my @contact_mobilephone = qsearch('contact_phone', { 'contactnum' => $contact->contact_contactnum, 'phonetypenum' => '3' } );
+ join(', ', map $_->phonenum, @contact_mobilephone);
+};
+
+my $home_phone_sub = sub {
+ my $contact = shift;
+ #can't because contactnum is in the wrong field
+ my @contact_homephone = qsearch('contact_phone', { 'contactnum' => $contact->contact_contactnum, 'phonetypenum' => '2' } );
+ 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 = (