summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorMark Wells <mark@freeside.biz>2016-12-09 14:11:13 -0800
committerMark Wells <mark@freeside.biz>2016-12-09 14:11:13 -0800
commit7c22fd0aa3f0f251a16f5ad69cda8cf0d9256ba1 (patch)
tree500fb7b5d6dcf1cced46323d800920b03f079b9e /bin
parent5dd8c04f5d4d760b1e186e67123c9b7d9c5d58c8 (diff)
avoid creating contacts that duplicate other contact emails, #73708
Diffstat (limited to 'bin')
-rwxr-xr-xbin/create-billing-contacts-v318
1 files changed, 11 insertions, 7 deletions
diff --git a/bin/create-billing-contacts-v3 b/bin/create-billing-contacts-v3
index 35b81f859..a4e7e122b 100755
--- a/bin/create-billing-contacts-v3
+++ b/bin/create-billing-contacts-v3
@@ -25,19 +25,18 @@ if ( $opt{c} ) {
$classnum = $class->classnum;
}
-# Find all invoice destinations that are email addresses,
-# except those where the customer already has a contact with that
-# email address.
+# Find all invoice destinations that are email addresses, except those where
+# there is already a contact with that email address.
my @invoice_dests = qsearch({
select => 'cust_main_invoice.*',
table => 'cust_main_invoice',
hashref => { 'dest' => { op=>'!=', value=>'POST' } },
- addl_from => ' LEFT JOIN (contact JOIN contact_email USING (contactnum)) ON
- (cust_main_invoice.custnum = contact.custnum AND
- cust_main_invoice.dest = contact_email.emailaddress)',
- extra_sql => ' AND contact.contactnum IS NULL',
+ addl_from => ' LEFT JOIN contact_email ON
+ (cust_main_invoice.dest = contact_email.emailaddress)',
+ extra_sql => ' AND contact_email.contactnum IS NULL',
});
print "Found email destinations: ".scalar(@invoice_dests)."\n";
+my %email_used;
foreach my $invoice_dest (@invoice_dests) {
my $cust_main = $invoice_dest->cust_main;
@@ -45,6 +44,11 @@ foreach my $invoice_dest (@invoice_dests) {
my $first = $cust_main->get('first');
my $email = $invoice_dest->dest;
print "$first $last <$email>\n";
+ if (exists $email_used{$email}) {
+ print "-- in use by cust#$email_used{$email}\n";
+ next;
+ }
+ $email_used{$email} = $cust_main->custnum;
my $contact = qsearchs('contact', {
'custnum' => $invoice_dest->custnum,