From: ivan Date: Mon, 18 Mar 2002 19:49:10 +0000 (+0000) Subject: fixes: bug #348 - adds the ability to email on deleted payments. X-Git-Tag: freeside_1_4_0_pre12~143 X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=commitdiff_plain;h=d4dabf21a2c9022dfb7023fb5df49f1536b2f29a fixes: bug #348 - adds the ability to email on deleted payments. --- diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm index 18725ced2..a3269b1c4 100644 --- a/FS/FS/Conf.pm +++ b/FS/FS/Conf.pm @@ -291,8 +291,8 @@ httemplate/docs/config.html { 'key' => 'deletepayments', 'section' => 'UI', - 'description' => 'Enable deletion of unclosed payments. Be very careful! Only delete payments that were data-entry errors, not adjustments.', - 'type' => 'checkbox', + 'description' => 'Enable deletion of unclosed payments. Be very careful! Only delete payments that were data-entry errors, not adjustments. Optionally specify one or more comma-separated email addresses to be notified when a payment is deleted.', + 'type' => [qw( checkbox text )], }, { diff --git a/FS/FS/Record.pm b/FS/FS/Record.pm index ea660d48a..0bd7aeda4 100644 --- a/FS/FS/Record.pm +++ b/FS/FS/Record.pm @@ -571,7 +571,8 @@ sub delete { $h_sth->execute or return $h_sth->errstr if $h_sth; dbh->commit or croak dbh->errstr if $FS::UID::AutoCommit; - undef $self; #no need to keep object! + #no need to needlessly destoy the data either + #undef $self; #no need to keep object! ''; } diff --git a/FS/FS/cust_bill.pm b/FS/FS/cust_bill.pm index c3524b984..092c174b4 100644 --- a/FS/FS/cust_bill.pm +++ b/FS/FS/cust_bill.pm @@ -388,6 +388,7 @@ sub send { #my @print_text = $cust_bill->print_text; #( date ) my @invoicing_list = $self->cust_main->invoicing_list; if ( grep { $_ ne 'POST' } @invoicing_list ) { #email invoice + #false laziness w/FS::cust_pay::delete #$ENV{SMTPHOSTS} = $smtpmachine; $ENV{MAILADDRESS} = $invoice_from; my $header = new Mail::Header ( [ @@ -882,7 +883,7 @@ sub print_text { =head1 VERSION -$Id: cust_bill.pm,v 1.22 2002-03-07 14:13:21 ivan Exp $ +$Id: cust_bill.pm,v 1.23 2002-03-18 19:49:10 ivan Exp $ =head1 BUGS diff --git a/FS/FS/cust_pay.pm b/FS/FS/cust_pay.pm index 6156eadeb..421f0200e 100644 --- a/FS/FS/cust_pay.pm +++ b/FS/FS/cust_pay.pm @@ -1,7 +1,10 @@ package FS::cust_pay; use strict; -use vars qw( @ISA $conf $unsuspendauto ); +use vars qw( @ISA $conf $unsuspendauto $smtpmachine $invoice_from ); +use Date::Format; +use Mail::Header; +use Mail::Internet; use Business::CreditCard; use FS::UID qw( dbh ); use FS::Record qw( dbh qsearch qsearchs dbh ); @@ -16,6 +19,8 @@ $FS::UID::callback{'FS::cust_pay'} = sub { $conf = new FS::Conf; $unsuspendauto = $conf->exists('unsuspendauto'); + $smtpmachine = $conf->config('smtpmachine'); + $invoice_from = $conf->config('invoice_from'); }; @@ -256,6 +261,47 @@ sub delete { return $error; } + if ( $conf->config('deletepayments') ne '' ) { + + my $cust_main = qsearchs('cust_main',{ 'custnum' => $self->custnum }); + #false laziness w/FS::cust_bill::send + $ENV{MAILADDRESS} = $conf->config('invoice_from'); #??? well as good as any + my $header = new Mail::Header ( [ + "From: $invoice_from", + "To: ". $conf->config('deletepayments'), + "Sender: $invoice_from", + "Reply-To: $invoice_from", + "Date: ". time2str("%a, %d %b %Y %X %z", time), + "Subject: FREESIDE NOTIFICATION: Payment deleted", + ] ); + my $message = new Mail::Internet ( + 'Header' => $header, + 'Body' => [ + "This is an automatic message from your Freeside installation\n", + "informing you that the following payment has been deleted:\n", + "\n", + 'paynum: '. $self->paynum. "\n", + 'custnum: '. $self->custnum. + " (". $cust_main->last. ", ". $cust_main->first. ")\n", + 'paid: $'. sprintf("%.2f", $self->paid). "\n", + 'date: '. time2str("%a %b %e %T %Y", $self->_date). "\n", + 'payby: '. $self->payby. "\n", + 'payinfo: '. $self->payinfo. "\n", + 'paybatch: '. $self->paybatch. "\n", + ], + ); + $!=0; + $message->smtpsend( Host => $smtpmachine ) + or $message->smtpsend( Host => $smtpmachine, Debug => 1 ) + or do { + $dbh->rollback if $oldAutoCommit; + return "(customer # ". $self->custnum. + ") can't send payment deletion email to ". + $conf->config('deletepayments'). + " via server $smtpmachine with SMTP: $!"; + }; + } + $dbh->commit or die $dbh->errstr if $oldAutoCommit; ''; @@ -359,7 +405,7 @@ sub unapplied { =head1 VERSION -$Id: cust_pay.pm,v 1.17 2002-02-10 18:56:49 ivan Exp $ +$Id: cust_pay.pm,v 1.18 2002-03-18 19:49:10 ivan Exp $ =head1 BUGS