1 <& elements/search.html,
3 name_singular => 'contact',
4 query => { select => join(', ', @select),
6 addl_from => $addl_from,
8 extra_sql => $extra_sql,
10 count_query => "SELECT COUNT(*) FROM contact $addl_from $extra_sql", #XXX
18 unless $FS::CurrentUser::CurrentUser->access_right('List contacts');
20 my @select = 'contact.contactnum AS contact_contactnum'; #if we select it as bare contactnum, the multi-customer listings go away
21 push @select, map "contact.$_", qw( first last title );
27 #can't because contactnum is in the wrong field #my @contact_email = $contact->contact_email;
28 my @contact_email = qsearch('contact_email', { 'contactnum' => $contact->contact_contactnum } );
29 join(', ', map $_->emailaddress, @contact_email);
32 my $link; #for closure in this sub, we'll define it later
33 my $contact_classname_sub = sub {
35 my %hash = ( 'contactnum' => $contact->contact_contactnum );
37 if ( $link eq 'cust_main' ) {
38 $X_contact = qsearchs('cust_contact', { %hash, 'custnum' => $contact->custnum } );
39 } elsif ( $link eq 'prospect_main' ) {
40 $X_contact = qsearchs('prospect_contact', { %hash, 'prospectnum' => $contact->prospectnum } );
42 die 'guru meditation #5555';
44 $X_contact->contact_classname;
47 my @header = ( 'First', 'Last', 'Title', 'Email', 'Type' );
48 my @fields = ( 'first', 'last', 'title', $email_sub, $contact_classname_sub );
49 my @links = ( '', '', '', '', '', );
51 my $company_link = '';
53 if ( $cgi->param('selfservice_access') eq 'Y' ) {
54 $hash{'selfservice_access'} = 'Y';
58 $link = $cgi->param('link');
61 my $as = ') AS prospect_or_customer';
63 if ( $link eq 'cust_main' ) {
64 push @header, 'Customer';
66 "COALESCE( cust_main.company, cust_main.first||' '||cust_main.last $as",
67 map "cust_contact.$_", qw( custnum classnum comment selfservice_access );
69 ' LEFT JOIN cust_contact USING ( contactnum ) '.
70 ' LEFT JOIN cust_main ON ( cust_contact.custnum = cust_main.custnum )';
71 $extra_sql = ' cust_contact.custnum IS NOT NULL ';
72 $company_link = [ $p.'view/cust_main.cgi?', 'custnum' ];
73 } elsif ( $link eq 'prospect_main' ) {
74 push @header, 'Prospect';
76 "COALESCE( prospect_main.company, contact.first||' '||contact.last $as",
77 map "prospect_contact.$_", qw( prospectnum classnum comment );
79 ' LEFT JOIN prospect_contact USING ( contactnum ) '.
80 ' LEFT JOIN prospect_main ON ( prospect_contact.prospectnum = prospect_main.prospectnum )';
81 $extra_sql = ' prospect_contact.prospectnum IS NOT NULL ';
82 $company_link = [ $p.'view/prospect_main.html?', 'prospectnum' ];
84 die "don't know how to report on contacts linked to specified table";
87 #because right now its harder to show it for both kinds of contacts
88 push @fields, 'prospect_or_customer';
89 push @links, $company_link;
93 push @header, 'Self-service';
94 push @fields, 'selfservice_access';
96 push @header, 'Comment';
97 push @fields, 'comment';
99 $extra_sql = (keys(%hash) ? ' AND ' : ' WHERE '). $extra_sql