-if ( $cgi->param('cust_main') ) {
- $select .= ', cust_main.company';
- $addl_from = ' LEFT JOIN cust_main USING ( custnum )';
- $extra_sql = ' custnum IS NOT NULL ';
- $company_link = [ $p.'view/cust_main.cgi?', 'custnum' ];
-} elsif ( $cgi->param('prospect_main') ) {
- $select .= ', prospect_main.company';
- $addl_from = ' LEFT JOIN prospect_main USING ( prospectnum )';
- $extra_sql = ' prospectnum IS NOT NULL ';
- $company_link = [ $p.'view/prospect_main.html?', 'prospectnum' ];
+$link = $cgi->param('link');
+if ( $link ) {
+
+ my $as = ') AS prospect_or_customer';
+
+ if ( $link eq 'cust_main' ) {
+ push @header, 'Customer';
+ push @select,
+ "COALESCE( cust_main.company, cust_main.first||' '||cust_main.last $as",
+ map "cust_contact.$_", qw( custnum classnum comment selfservice_access );
+ $addl_from =
+ ' LEFT JOIN cust_contact USING ( contactnum ) '.
+ ' LEFT JOIN cust_main ON ( cust_contact.custnum = cust_main.custnum )';
+ $extra_sql = ' cust_contact.custnum IS NOT NULL ';
+ $company_link = [ $p.'view/cust_main.cgi?', 'custnum' ];
+ } elsif ( $link eq 'prospect_main' ) {
+ push @header, 'Prospect';
+ push @select,
+ "COALESCE( prospect_main.company, contact.first||' '||contact.last $as",
+ map "prospect_contact.$_", qw( prospectnum classnum comment );
+ $addl_from =
+ ' LEFT JOIN prospect_contact USING ( contactnum ) '.
+ ' LEFT JOIN prospect_main ON ( prospect_contact.prospectnum = prospect_main.prospectnum )';
+ $extra_sql = ' prospect_contact.prospectnum IS NOT NULL ';
+ $company_link = [ $p.'view/prospect_main.html?', 'prospectnum' ];
+ } else {
+ die "don't know how to report on contacts linked to specified table";
+ }
+
+ #because right now its harder to show it for both kinds of contacts
+ push @fields, 'prospect_or_customer';
+ push @links, $company_link;
+