X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2FFS%2Fsvc_acct.pm;h=e7ec4a2317d03fdd482b4171bad4c61877221f06;hp=d3e23f237037b8846f4e4a173250bfc9e837099a;hb=45d0f6c6325fb8ab5fdc478a7dc278872defa479;hpb=c44432a5f0f1c1841ff8b50e734a30bd9aeef945 diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm index d3e23f237..e7ec4a231 100644 --- a/FS/FS/svc_acct.pm +++ b/FS/FS/svc_acct.pm @@ -44,7 +44,6 @@ use FS::PagedSearch qw( psearch ); # XXX in v4, replace with FS::Cursor use FS::part_pkg; use FS::part_svc; use FS::svc_acct_pop; -use FS::cust_main_invoice; use FS::svc_domain; use FS::svc_pbx; use FS::raddb; @@ -711,9 +710,37 @@ sub insert { || $conf->exists('emailinvoiceauto') && ! $cust_main->invoicing_list_emailonly ) { - my @invoicing_list = $cust_main->invoicing_list; - push @invoicing_list, $self->email; - $cust_main->invoicing_list(\@invoicing_list); + + # slight false laziness w/ edit/process/cust_main.cgi... + # and also slightly arbitrary behavior. + # if the "real name" of this account matches the first + last name + # of a contact, attach the email address to that person. + my @contacts = map { $_->contact } $cust_main->cust_contact; + my $myname = $self->get('finger'); + my ($contact) = + grep { $_->get('first') . ' ' . $_->get('last') eq $myname } @contacts; + # otherwise just pick the first one + $contact ||= $contacts[0]; + # if there is one + $contact ||= FS::contact->new({ + 'custnum' => $cust_main->get('custnum'), + 'locationnum' => $cust_main->get('bill_locationnum'), + 'last' => $cust_main->get('last'), + 'first' => $cust_main->get('first'), + }); + $contact->set('emailaddress', $self->email); + $contact->set('invoice_dest', 'Y'); + + if ( $contact->get('contactnum') ) { + $error = $contact->replace; + } else { + $error = $contact->insert; + } + + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return "creating invoice destination contact: $error"; + } } #welcome email @@ -800,23 +827,6 @@ sub delete { local $FS::UID::AutoCommit = 0; my $dbh = dbh; - foreach my $cust_main_invoice ( - qsearch( 'cust_main_invoice', { 'dest' => $self->svcnum } ) - ) { - unless ( defined($cust_main_invoice) ) { - warn "WARNING: something's wrong with qsearch"; - next; - } - my %hash = $cust_main_invoice->hash; - $hash{'dest'} = $self->email; - my $new = new FS::cust_main_invoice \%hash; - my $error = $new->replace($cust_main_invoice); - if ( $error ) { - $dbh->rollback if $oldAutoCommit; - return $error; - } - } - foreach my $svc_domain ( qsearch( 'svc_domain', { 'catchall' => $self->svcnum } ) ) { @@ -2666,6 +2676,31 @@ sub virtual_maildir { $self->domain. '/maildirs/'. $self->username. '/'; } +=item password_disallowed_names + +Override, for L. Not really intended for other use. + +=cut + +sub password_disallowed_names { + my $self = shift; + my $dbh = dbh; + my $results = {}; + foreach my $field ( qw( username finger ) ) { + my $sql = 'SELECT DISTINCT '.$field.' FROM svc_acct'; + my $sth = $dbh->prepare($sql) + or die "Error preparing $sql: ". $dbh->errstr; + $sth->execute() + or die "Error executing $sql: ". $sth->errstr; + foreach my $row (@{$sth->fetchall_arrayref}, $self->get($field)) { + foreach my $word (split(/\s+/,$$row[0])) { + $results->{lc($word)} = 1; + } + } + } + return keys %$results; +} + =back =head1 CLASS METHODS