[freeside-commits] freeside/FS/FS cust_bill.pm, 1.160, 1.161 cust_main.pm, 1.267, 1.268 cust_pay.pm, 1.48, 1.49

Jeff Finucane,420,, jeff at wavetail.420.am
Tue Jan 30 20:30:51 PST 2007


Update of /home/cvs/cvsroot/freeside/FS/FS
In directory wavetail:/tmp/cvs-serv26306/FS/FS

Modified Files:
	cust_bill.pm cust_main.pm cust_pay.pm 
Log Message:
small change in payment receipt handling (ticket 1422)

Index: cust_pay.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_pay.pm,v
retrieving revision 1.48
retrieving revision 1.49
diff -u -d -r1.48 -r1.49
--- cust_pay.pm	23 Jan 2007 06:41:38 -0000	1.48
+++ cust_pay.pm	31 Jan 2007 04:30:49 -0000	1.49
@@ -99,12 +99,15 @@
 
 For backwards-compatibility and convenience, if the additional field invnum
 is defined, an FS::cust_bill_pay record for the full amount of the payment
-will be created.  In this case, custnum is optional.
+will be created.  In this case, custnum is optional.  An hash of optional
+arguments may be passed.  Currently "manual" is supported.  If true, a
+payment receipt is sent instead of a statement when 'payment_receipt_email'
+configuration option is set.
 
 =cut
 
 sub insert {
-  my $self = shift;
+  my ($self, %options) = @_;
 
   local $SIG{HUP} = 'IGNORE';
   local $SIG{INT} = 'IGNORE';
@@ -117,8 +120,9 @@
   local $FS::UID::AutoCommit = 0;
   my $dbh = dbh;
 
+  my $cust_bill;
   if ( $self->invnum ) {
-    my $cust_bill = qsearchs('cust_bill', { 'invnum' => $self->invnum } )
+    $cust_bill = qsearchs('cust_bill', { 'invnum' => $self->invnum } )
       or do {
         $dbh->rollback if $oldAutoCommit;
         return "Unknown cust_bill.invnum: ". $self->invnum;
@@ -188,28 +192,31 @@
   if ( $conf->exists('payment_receipt_email')
        && grep { $_ !~ /^(POST|FAX)$/ } $cust_main->invoicing_list
   ) {
+    my $error;
+    if ( exists($options{ 'manual' }) && $options{ 'manual' } ) {
 
-    my $receipt_template = new Text::Template (
-      TYPE   => 'ARRAY',
-      SOURCE => [ map "$_\n", $conf->config('payment_receipt_email') ],
-    ) or do {
-      warn "can't create payment receipt template: $Text::Template::ERROR";
-      return '';
-    };
+      my $receipt_template = new Text::Template (
+        TYPE   => 'ARRAY',
+        SOURCE => [ map "$_\n", $conf->config('payment_receipt_email') ],
+      ) or do {
+        warn "can't create payment receipt template: $Text::Template::ERROR";
+        return '';
+      };
 
-    my @invoicing_list = grep { $_ !~ /^(POST|FAX)$/ } $cust_main->invoicing_list;
+      my @invoicing_list = grep { $_ !~ /^(POST|FAX)$/ }
+                             $cust_main->invoicing_list;
 
-    my $payby = $self->payby;
-    my $payinfo = $self->payinfo;
-    $payby =~ s/^BILL$/Check/ if $payinfo;
-    $payinfo = $self->paymask if $payby eq 'CARD' || $payby eq 'CHEK';
-    $payby =~ s/^CHEK$/Electronic check/;
+      my $payby = $self->payby;
+      my $payinfo = $self->payinfo;
+      $payby =~ s/^BILL$/Check/ if $payinfo;
+      $payinfo = $self->paymask if $payby eq 'CARD' || $payby eq 'CHEK';
+      $payby =~ s/^CHEK$/Electronic check/;
 
-    my $error = send_email(
-      'from'    => $conf->config('invoice_from'), #??? well as good as any
-      'to'      => \@invoicing_list,
-      'subject' => 'Payment receipt',
-      'body'    => [ $receipt_template->fill_in( HASH => {
+      $error = send_email(
+        'from'    => $conf->config('invoice_from'), #??? well as good as any
+        'to'      => \@invoicing_list,
+        'subject' => 'Payment receipt',
+        'body'    => [ $receipt_template->fill_in( HASH => {
                        'date'    => time2str("%a %B %o, %Y", $self->_date),
                        'name'    => $cust_main->name,
                        'paynum'  => $self->paynum,
@@ -217,10 +224,25 @@
                        'payby'   => ucfirst(lc($payby)),
                        'payinfo' => $payinfo,
                        'balance' => $cust_main->balance,
-                   } ) ],
-    );
+                     } ) ],
+      );
+    }else{
+      unless($cust_bill){
+        $cust_bill = ($cust_main->cust_bill)[-1];
+      }
+      if ($cust_bill) {
+        my $queue = new FS::queue {
+           'paynum' => $self->paynum,
+           'job'    => 'FS::cust_bill::queueable_send',
+        };
+        $error = $queue->insert(
+          'invnum' => $cust_bill->invnum,
+          'template' => 'statement',
+        );
+      }
+    }
     if ( $error ) {
-      warn "can't send payment receipt: $error";
+      warn "can't send payment receipt/statement: $error";
     }
 
   }
@@ -428,7 +450,7 @@
   my $errors = 0;
   
   my @errors = map {
-    my $error = $_->insert;
+    my $error = $_->insert( 'manual' => 1 );
     if ( $error ) { 
       $errors++;
     } else {

Index: cust_bill.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_bill.pm,v
retrieving revision 1.160
retrieving revision 1.161
diff -u -d -r1.160 -r1.161
--- cust_bill.pm	30 Jan 2007 23:50:27 -0000	1.160
+++ cust_bill.pm	31 Jan 2007 04:30:49 -0000	1.161
@@ -571,8 +571,9 @@
       'Disposition' => 'inline',
     );
 
-    $args{'from'} =~ /\@([\w\.\-]+)/ or $1 = 'example.com';
-    my $content_id = join('.', rand()*(2**32), $$, time). "\@$1";
+    $args{'from'} =~ /\@([\w\.\-]+)/;
+    my $from = $1 || 'example.com';
+    my $content_id = join('.', rand()*(2**32), $$, time). "\@$from";
 
     my $path = "$FS::UID::conf_dir/conf.$FS::UID::datasrc";
     my $file;
@@ -728,6 +729,17 @@
 
 =cut
 
+sub queueable_send {
+  my %opt = @_;
+
+  my $self = qsearchs('cust_bill', { 'invnum' => $opt{invnum} } )
+    or die "invalid invoice number: " . $opt{invnum};
+
+  my $error = $self->send($opt{template}, $opt{agentnum}, $opt{invoice_from});
+
+  die $error if $error;
+}
+
 sub send {
   my $self = shift;
   my $template = scalar(@_) ? shift : '';

Index: cust_main.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_main.pm,v
retrieving revision 1.267
retrieving revision 1.268
diff -u -d -r1.267 -r1.268
--- cust_main.pm	30 Jan 2007 19:40:09 -0000	1.267
+++ cust_main.pm	31 Jan 2007 04:30:49 -0000	1.268
@@ -2739,10 +2739,12 @@
        'payinfo'  => $payinfo,
        'paybatch' => $paybatch,
     } );
-    my $error = $cust_pay->insert;
+    my $error = $cust_pay->insert($options{'manual'} ? ( 'manual' => 1 ) : () );
     if ( $error ) {
       $cust_pay->invnum(''); #try again with no specific invnum
-      my $error2 = $cust_pay->insert;
+      my $error2 = $cust_pay->insert( $options{'manual'} ?
+                                      ( 'manual' => 1 ) : ()
+                                    );
       if ( $error2 ) {
         # gah, even with transactions.
         my $e = 'WARNING: Card/ACH debited but database not updated - '.



More information about the freeside-commits mailing list