X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fcust_main_Mixin.pm;h=d493060f0c7cf445b4b0ccaaa35994ffda8f8426;hb=72deba42ac5847c2a6bdeea20157035b8f9df7ae;hp=b446d69651348ed0972525ddb1ab547a1e9cc6cf;hpb=6c9cd1c36adbb9fc950fcf0a0b269fa6f16838a1;p=freeside.git diff --git a/FS/FS/cust_main_Mixin.pm b/FS/FS/cust_main_Mixin.pm index b446d6965..d493060f0 100644 --- a/FS/FS/cust_main_Mixin.pm +++ b/FS/FS/cust_main_Mixin.pm @@ -408,9 +408,6 @@ sub email_search_result { or die "msgnum $msgnum not found\n"; } - $param->{'payby'} = [ split(/\0/, $param->{'payby'}) ] - unless ref($param->{'payby'}); - my $sql_query = $class->search($param->{'search'}); my $count_query = delete($sql_query->{'count_query'}); @@ -423,7 +420,9 @@ sub email_search_result { my( $num, $last, $min_sec ) = (0, time, 5); #progresbar foo my @retry_jobs = (); + my $dups = 0; my $success = 0; + my %sent_to = (); #eventually order+limit magic to reduce memory use? foreach my $obj ( qsearch($sql_query) ) { @@ -443,21 +442,34 @@ sub email_search_result { if ( !$cust_main ) { next; # unlinked object; nothing else we can do } + + if( $sent_to{$cust_main->custnum} ) { + # avoid duplicates + $dups++; + next; + } + + $sent_to{$cust_main->custnum} = 1; if ( $msg_template ) { # XXX add support for other context objects? + # If we do that, handling of "duplicates" will + # have to be smarter. Currently we limit to + # one message per custnum because they'd all + # be identical. @message = $msg_template->prepare( 'cust_main' => $cust_main ); } else { - my $to = $cust_main->invoicing_list_emailonly_scalar; - next if !$to; + my @to = $cust_main->invoicing_list_emailonly; + next if !@to; @message = ( 'from' => $from, - 'to' => $to, + 'to' => \@to, 'subject' => $subject, 'html_body' => $html_body, 'text_body' => $text_body, + 'custnum' => $cust_main->custnum, ); } #if $msg_template @@ -494,7 +506,7 @@ sub email_search_result { if(@retry_jobs) { # fail the job, but with a status message that makes it clear # something was sent. - return "Sent $success, failed ".scalar(@retry_jobs).". Failed attempts placed in job queue.\n"; + return "Sent $success, skipped $dups duplicate(s), failed ".scalar(@retry_jobs).". Failed attempts placed in job queue.\n"; } return ''; @@ -526,6 +538,41 @@ sub process_email_search_result { } +=item conf + +Returns a configuration handle (L) set to the customer's locale, +if they have one. If not, returns an FS::Conf with no locale. + +=cut + +sub conf { + my $self = shift; + return $self->{_conf} if (ref $self and $self->{_conf}); + my $cust_main = $self->cust_main; + my $conf = new FS::Conf { + 'locale' => ($cust_main ? $cust_main->locale : '') + }; + $self->{_conf} = $conf if ref $self; + return $conf; +} + +=item mt TEXT [, ARGS ] + +Localizes a text string (see L) for the customer's locale, +if they have one. + +=cut + +sub mt { + my $self = shift; + return $self->{_lh}->maketext(@_) if (ref $self and $self->{_lh}); + my $cust_main = $self->cust_main; + my $locale = $cust_main ? $cust_main->locale : ''; + my $lh = FS::L10N->get_handle($locale); + $self->{_lh} = $lh if ref $self; + return $lh->maketext(@_); +} + =back =head1 BUGS