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 ' ).
'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 ' ).
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
} );
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
} );
# (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',
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'} . "'"
}
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;
}
+ my $count_query = "SELECT COUNT(*) FROM cust_main $addl_from $extra_sql";
+
if ($params->{'flattened_pkgs'}) {
#my $pkg_join = '';
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 = (