ticket 1436, ACH export format, return processing and autopost
authorjeff <jeff>
Wed, 21 Mar 2007 04:01:52 +0000 (04:01 +0000)
committerjeff <jeff>
Wed, 21 Mar 2007 04:01:52 +0000 (04:01 +0000)
FS/FS/pay_batch.pm
httemplate/misc/download-batch.cgi
httemplate/search/cust_pay_batch.cgi

index add4da9..5a06ba6 100644 (file)
@@ -146,7 +146,7 @@ Options are:
 
 I<filehandle> - open filehandle of results file.
 
-I<format> - "csv-td_canada_trust-merchant_pc_batch", "csv-chase_canada-E-xactBatch" or "PAP"
+I<format> - "csv-td_canada_trust-merchant_pc_batch", "csv-chase_canada-E-xactBatch", "ach-spiritone", or "PAP"
 
 =cut
 
@@ -334,6 +334,40 @@ sub import_results {
       0;
     };
 
+  }elsif ( $format eq 'ach-spiritone' ) {
+
+    $filetype = "CSV";
+
+    @fields = (
+      '',            # Name
+      'paybatchnum', # ID:  Invoice number of the transaction
+      'aba',         # ABA Number for the transaction
+      'payinfo',     # Bank Account Number for the transaction
+      '',            # Transaction Type:  27 - debit
+      'paid',        # Amount:  Amount of the transaction.  Dollars and cents
+                     #          with decimal entered.
+      '',            # Default Transaction Type
+      '',            # Default Amount:  Dollars and cents with decimal entered.
+    );
+
+    $end_condition = sub {
+      '';
+    };
+
+    $hook = sub {
+      my $hash = shift;
+      $hash->{'_date'} = time;  # got a better one?
+      $hash->{'payinfo'} = $hash->{'payinfo'} . '@' . $hash->{'aba'};
+    };
+
+    $approved_condition = sub {
+      1;
+    };
+
+    $declined_condition = sub {
+      0;
+    };
+
 
   } else {
     return "Unknown format $format";
index 8d6c949..da97537 100644 (file)
@@ -23,6 +23,8 @@
 <% sprintf( '$$E-xactBatchFileV1.0$$%s:%03u$$%s',$sdate,$pay_batch->batchnum, $origid)
   %>
 %
+%}elsif ($format eq "ach-spiritone"){
+%#  1;
 %}else{
 %  die "Unknown format for batch in batchconfig. \n";
 %}
 <% $cust_pay_batch->paybatchnum %>,<% $cust_pay_batch->custnum %>,<% $cust_pay_batch->invnum %>,"<% $payname %>",00,<% $cust_pay_batch->payinfo %>,<% $cust_pay_batch->amount %>,<% $exp %>,,
 %
 %
+%  }elsif ($format eq "ach-spiritone"){
+%
+%  my( $account, $aba ) = split( '@', $cust_pay_batch->payinfo );
+%  my $payname=$cust_pay_batch->payname; $payname =~ tr/",/  /; #payinfo too?
+%  my $batchline = qq!"$payname","!.$cust_pay_batch->paybatchnum.
+%                  qq!","$aba","$account","27","!.$cust_pay_batch->amount.
+%                  qq!","27","0.00"!;
+%  push @batchlines, $batchline;
+<% $batchline %>
+%
 %  } else {
 %    die "I'm already dead, but you did not know that.\n";
 %  }
 %  #1;
 %} elsif ($format eq "csv-chase_canada-E-xactBatch"){
 %  #1;
+%} elsif ($format eq "ach-spiritone"){
+%  #1;
 %} else {
 %  die "I'm already dead (again), but you did not know that.\n";
 %}
 %
-%$dbh->commit or die $dbh->errstr if $oldAutoCommit;
 <%init>
 
 my $conf=new FS::Conf;
@@ -142,6 +155,13 @@ if ( $cgi->param('format') =~ /^([\w\- ]+)$/ ) {
   $format = $conf->config('batch-default_format');
 }
 
+my $autopost;
+if ( $format eq 'ach-spiritone' ) {
+  $autopost = 1;
+}else{
+  $autopost = 0;
+}
+
 my $oldAutoCommit = $FS::UID::AutoCommit;
 local $FS::UID::AutoCommit = 0;
 my $dbh = dbh;
@@ -168,4 +188,25 @@ my $cdate = sprintf("%02d", $date[3]).sprintf("%02d", $date[4] + 1).
 my $sdate = sprintf("%02d", $date[5] % 100).'/'.sprintf("%02d", $date[4] + 1).
             '/'.sprintf("%02d", $date[3]);
 
+my @batchlines = ();
 </%init>
+<%cleanup>
+if ($autopost) {
+  my $dir = $FS::UID::conf_dir. "cache.". $FS::UID::datasrc;
+  my $fh = new File::Temp(
+    TEMPLATE => 'paybatch.'. $batchnum .'.XXXXXXXX',
+    DIR      => $dir,
+  ) or die "can't open temp file: $!\n";
+
+  print $fh map{ "$_\n" } @batchlines;
+  seek $fh, 0, 0;
+
+  $error = $pay_batch->import_results( 'filehandle' => $fh,
+                                       'format'     => $format,
+                                     );
+  die $error if $error;
+}
+
+$dbh->commit or die $dbh->errstr if $oldAutoCommit;
+
+</%cleanup>
index e378ffa..c678feb 100755 (executable)
@@ -142,6 +142,7 @@ if ( $pay_batch ) {
                     qq!<OPTION VALUE="csv-chase_canada-E-xactBatch">CSV file for Chase Canada E-xactBatch</OPTION>!.
                     qq!<OPTION VALUE="PAP">80 byte file for TD Canada Trust PAP Batch</OPTION>!.
                     qq!<OPTION VALUE="BoM">Bank of Montreal ECA batch</OPTION>!.
+                    qq!<OPTION VALUE="ach-spiritone">Spiritone ACH batch</OPTION>!.
                     qq!</SELECT>!;
     }
     $html_init .= qq!<INPUT TYPE="hidden" NAME="batchnum" VALUE="$batchnum"><INPUT TYPE="submit" VALUE="Download"></FORM><BR>!;
@@ -165,6 +166,7 @@ if ( $pay_batch ) {
                     qq!<OPTION VALUE="csv-chase_canada-E-xactBatch">CSV file for Chase Canada E-xactBatch</OPTION>!.
                     qq!<OPTION VALUE="PAP">264 byte results for TD Canada Trust PAP Batch</OPTION>!.
                     qq!<OPTION VALUE="BoM">Bank of Montreal ECA results</OPTION>!.
+                    qq!<OPTION VALUE="ach-spiritone">Spiritone ACH batch</OPTION>!.
                     qq!</SELECT><BR>!;
     }
     $html_init .= qq!<INPUT TYPE="hidden" NAME="batchnum" VALUE="$batchnum">!;