RT 82999 - fixed issue where payment receipt only sent when one email present.
[freeside.git] / FS / FS / cust_pay.pm
index 67f4b29..3e368f6 100644 (file)
@@ -227,6 +227,8 @@ sub insert {
   local $FS::UID::AutoCommit = 0;
   my $dbh = dbh;
 
+  my $conf = new FS::Conf;
+
   my $cust_bill;
   if ( $self->invnum ) {
     $cust_bill = qsearchs('cust_bill', { 'invnum' => $self->invnum } )
@@ -652,6 +654,8 @@ sub send_receipt {
 
   return '' unless $conf->config_bool('payment_receipt', $cust_main->agentnum);
 
+  return '' if ($conf->config_bool('allow_payment_receipt_noemail', $cust_main->agentnum) && $cust_main->paymentreceipt_noemail);
+
   my @invoicing_list = $cust_main->invoicing_list_emailonly;
   return '' unless @invoicing_list;
 
@@ -669,7 +673,7 @@ sub send_receipt {
         'cust_main'      => $cust_main,
         'cust_bill'      => $opt->{cust_bill},
         'cust_pkg'       => $opt->{cust_pkg},
-        'invoicing_list' => @invoicing_list,
+        'invoicing_list' => \@invoicing_list,
         'msgnum'         => $conf->config('payment_receipt_msgnum', $cust_main->agentnum)
     );
 
@@ -706,9 +710,6 @@ sub send_receipt {
 
       $error = $queue->insert(%opt);
     }
-
-
-
   }
 
   warn "send_receipt: $error\n" if $error;
@@ -721,7 +722,7 @@ $error = $self->send_message_receipt(
         'cust_main'      => $cust_main,
         'cust_bill'      => $opt->{cust_bill},
         'cust_pkg'       => $opt->{cust_pkg},
-        'invoicing_list' => @invoicing_list,
+        'invoicing_list' => \@invoicing_list,
         'msgnum'         => $conf->config('payment_receipt_msgnum', $cust_main->agentnum)
       );
 
@@ -732,7 +733,7 @@ sub send_message_receipt {
   my $cust_main      = $opt{'cust_main'};
   my $cust_bill      = $opt{'cust_bill'};
   my $cust_pkg       = $opt{'cust_pkg'};
-  my @invoicing_list = $opt{'invoicing_list'};
+  my @invoicing_list = ref($opt{'invoicing_list'}) ? @{ $opt{'invoicing_list'} } : ( $opt{'invoicing_list'} );
   my $msgnum         = $opt{'msgnum'};
   my $error = '';