- "emailinvoiceauto" implementation rewritten to work properly, stop
authorivan <ivan>
Tue, 17 Sep 2002 00:33:17 +0000 (00:33 +0000)
committerivan <ivan>
Tue, 17 Sep 2002 00:33:17 +0000 (00:33 +0000)
    overwriting existing invoice destinations

FS/FS/Conf.pm
FS/FS/cust_bill.pm
FS/FS/cust_main.pm
FS/FS/svc_acct.pm

index e93eaf3..e50cb29 100644 (file)
@@ -369,7 +369,7 @@ httemplate/docs/config.html
   {
     'key'         => 'emailinvoiceauto',
     'section'     => 'billing',
-    'description' => 'Automatically adds new accounts to the email invoice list upon customer creation',
+    'description' => 'Automatically adds new accounts to the email invoice list',
     'type'       => 'checkbox',
   },
 
index d49657e..65c41d5 100644 (file)
@@ -623,7 +623,7 @@ sub realtime_card {
   my @invoicing_list = grep { $_ ne 'POST' } $cust_main->invoicing_list;
   if ( $conf->exists('emailinvoiceauto')
        || ( $conf->exists('emailinvoiceonly') && ! @invoicing_list ) ) {
-    push @invoicing_list, $cust_main->default_invoicing_list;
+    push @invoicing_list, $cust_main->all_emails;
   }
   my $email = $invoicing_list[0];
 
@@ -1114,7 +1114,7 @@ sub print_text {
 
 =head1 VERSION
 
-$Id: cust_bill.pm,v 1.42 2002-09-10 03:31:00 ivan Exp $
+$Id: cust_bill.pm,v 1.43 2002-09-17 00:33:17 ivan Exp $
 
 =head1 BUGS
 
index cfa6b8b..84fd3d1 100644 (file)
@@ -1584,7 +1584,6 @@ sub invoicing_list {
     }
     my %seen = map { $_->address => 1 } @cust_main_invoice;
     foreach my $address ( @{$arrayref} ) {
-      #unless ( grep { $address eq $_->address } @cust_main_invoice ) {
       next if exists $seen{$address} && $seen{$address};
       $seen{$address} = 1;
       my $cust_main_invoice = new FS::cust_main_invoice ( {
@@ -1626,24 +1625,36 @@ sub check_invoicing_list {
   '';
 }
 
-=item default_invoicing_list
+=item set_default_invoicing_list
 
-Sets the invoicing list to all accounts associated with this customer.
+Sets the invoicing list to all accounts associated with this customer,
+overwriting any previous invoicing list.
 
 =cut
 
-sub default_invoicing_list {
+sub set_default_invoicing_list {
   my $self = shift;
-  my @list = ();
+  $self->invoicing_list($self->all_emails);
+}
+
+=item all_emails
+
+Returns the email addresses of all accounts provisioned for this customer.
+
+=cut
+
+sub all_emails {
+  my $self = shift;
+  my %list;
   foreach my $cust_pkg ( $self->all_pkgs ) {
     my @cust_svc = qsearch('cust_svc', { 'pkgnum' => $cust_pkg->pkgnum } );
     my @svc_acct =
       map { qsearchs('svc_acct', { 'svcnum' => $_->svcnum } ) }
         grep { qsearchs('svc_acct', { 'svcnum' => $_->svcnum } ) }
           @cust_svc;
-    push @list, map { $_->email } @svc_acct;
+    $list{$_}=1 foreach map { $_->email } @svc_acct;
   }
-  $self->invoicing_list(\@list);
+  keys %list;
 }
 
 =item invoicing_list_addpost
index 9032e20..f73ab82 100644 (file)
@@ -341,11 +341,20 @@ sub insert {
     return "queueing job (transaction rolled back): $error";
   }
 
-  #welcome email
   my $cust_pkg = $self->cust_svc->cust_pkg;
-  my( $cust_main, $to ) = ( '', '' );
+  my $cust_main = $cust_pkg->cust_main;
+
+  my $cust_pkg = $self->cust_svc->cust_pkg;
+
+  if ( $conf->exists('emailinvoiceauto') ) {
+    my @invoicing_list = $cust_main->invoicing_list;
+    push @invoicing_list, $self->email;
+    $cust_main->invoicing_list(@invoicing_list);
+  }
+
+  #welcome email
+  my $to = '';
   if ( $welcome_template && $cust_pkg ) {
-    my $cust_main = $cust_pkg->cust_main;
     my $to = join(', ', grep { $_ ne 'POST' } $cust_main->invoicing_list );
     if ( $to ) {
       my $wqueue = new FS::queue {