fixes: bug #348 - adds the ability to email on deleted payments.
authorivan <ivan>
Mon, 18 Mar 2002 19:49:10 +0000 (19:49 +0000)
committerivan <ivan>
Mon, 18 Mar 2002 19:49:10 +0000 (19:49 +0000)
FS/FS/Conf.pm
FS/FS/Record.pm
FS/FS/cust_bill.pm
FS/FS/cust_pay.pm

index 18725ce..a3269b1 100644 (file)
@@ -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 )],
   },
 
   {
index ea660d4..0bd7aed 100644 (file)
@@ -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!
 
   '';
 }
index c3524b9..092c174 100644 (file)
@@ -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
 
index 6156ead..421f020 100644 (file)
@@ -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