X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fcust_main.pm;h=dfe254c898b4147f03742f05ac92d5dd38b36cd5;hb=f13afe5e228a220311557e1ca6dacbf847c26baf;hp=33788f3b59e93673d7b7ba06e6a3a25d8e6385c8;hpb=c545a57d21341c49674defed65a4243f07b5ebaf;p=freeside.git diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm index 33788f3b5..dfe254c89 100644 --- a/FS/FS/cust_main.pm +++ b/FS/FS/cust_main.pm @@ -22,7 +22,7 @@ use Locale::Country; use Data::Dumper; use FS::UID qw( getotaker dbh driver_name ); use FS::Record qw( qsearchs qsearch dbdef ); -use FS::Misc qw( send_email generate_ps do_print ); +use FS::Misc qw( generate_email send_email generate_ps do_print ); use FS::Msgcat qw(gettext); use FS::cust_pkg; use FS::cust_svc; @@ -5007,7 +5007,7 @@ Returns a hex triplet color string for this customer's status. =cut use vars qw(%statuscolor); -tie my %statuscolor, 'Tie::IxHash', +tie %statuscolor, 'Tie::IxHash', 'prospect' => '7e0079', #'000000', #black? naw, purple 'active' => '00CC00', #green 'inactive' => '0000CC', #blue @@ -5470,6 +5470,122 @@ sub search_sql { } +=item email_search_sql HASHREF + +(Class method) + +Emails a notice to the specified customers. + +Valid parameters are those of the L method, plus the following: + +=over 4 + +=item from + +From: address + +=item subject + +Email Subject: + +=item html_body + +HTML body + +=item text_body + +Text body + +=item job + +Optional job queue job for status updates. + +=back + +Returns an error message, or false for success. + +If an error occurs during any email, stops the enture send and returns that +error. Presumably if you're getting SMTP errors aborting is better than +retrying everything. + +=cut + +sub email_search_sql { + my($class, $params) = @_; + + my $from = delete $params->{from}; + my $subject = delete $params->{subject}; + my $html_body = delete $params->{html_body}; + my $text_body = delete $params->{text_body}; + + my $job = delete $params->{'job'}; + + my $sql_query = $class->search_sql($params); + + my $count_query = delete($sql_query->{'count_query'}); + my $count_sth = dbh->prepare($count_query) + or die "Error preparing $count_query: ". dbh->errstr; + $count_sth->execute + or die "Error executing $count_query: ". $count_sth->errstr; + my $count_arrayref = $count_sth->fetchrow_arrayref; + my $num_cust = $count_arrayref->[0]; + + #my @extra_headers = @{ delete($sql_query->{'extra_headers'}) }; + #my @extra_fields = @{ delete($sql_query->{'extra_fields'}) }; + + + my( $num, $last, $min_sec ) = (0, time, 5); #progresbar foo + + #eventually order+limit magic to reduce memory use? + foreach my $cust_main ( qsearch($sql_query) ) { + + my $to = $cust_main->invoicing_list_emailonly_scalar; + next unless $to; + + my $error = send_email( + generate_email( + 'from' => $from, + 'to' => $to, + 'subject' => $subject, + 'html_body' => $html_body, + 'text_body' => $text_body, + ) + ); + return $error if $error; + + if ( $job ) { #progressbar foo + $num++; + if ( time - $min_sec > $last ) { + my $error = $job->update_statustext( + int( 100 * $num / $num_cust ) + ); + die $error if $error; + $last = time; + } + } + + } + + return ''; +} + +use Storable qw(thaw); +use Data::Dumper; +use MIME::Base64; +sub process_email_search_sql { + my $job = shift; + #warn "$me process_re_X $method for job $job\n" if $DEBUG; + + my $param = thaw(decode_base64(shift)); + warn Dumper($param) if $DEBUG; + + $param->{'job'} = $job; + + my $error = FS::cust_main->email_search_sql( $param ); + die $error if $error; + +} + =item fuzzy_search FUZZY_HASHREF [ HASHREF, SELECT, EXTRA_SQL, CACHE_OBJ ] Performs a fuzzy (approximate) search and returns the matching FS::cust_main