input and output on data volume fields specified with k,m,g,or t
[freeside.git] / FS / FS / pay_batch.pm
index 069105a..5a06ba6 100644 (file)
@@ -6,6 +6,7 @@ use Time::Local;
 use Text::CSV_XS;
 use FS::Record qw( dbh qsearch qsearchs );
 use FS::cust_pay;
+use FS::part_bill_event qw(due_events);
 
 @ISA = qw(FS::Record);
 
@@ -145,14 +146,14 @@ 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
 
 sub import_results {
   my $self = shift;
 
-  my $param = @_;
+  my $param = ref($_[0]) ? shift : { @_ };
   my $fh = $param->{'filehandle'};
   my $format = $param->{'format'};
 
@@ -333,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";
@@ -359,11 +394,6 @@ sub import_results {
   };
 
   my $error = $self->set_status('R');
-
-  my $newbatch = new FS::pay_batch { $self->hash };
-  $newbatch->status('R');   # Resolved
-  $newbatch->upload(time);
-  my $error = $newbatch->replace($self);
   if ( $error ) {
     $dbh->rollback if $oldAutoCommit;
     return $error