summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--FS/FS/Conf.pm8
-rw-r--r--FS/FS/Schema.pm14
-rw-r--r--FS/FS/cust_main.pm1
-rw-r--r--FS/FS/pay_batch.pm6
-rwxr-xr-xFS/bin/freeside-eftca-upload35
-rwxr-xr-xhttemplate/search/pay_batch.cgi3
6 files changed, 39 insertions, 28 deletions
diff --git a/FS/FS/Conf.pm b/FS/FS/Conf.pm
index bee177052..590a5c3ec 100644
--- a/FS/FS/Conf.pm
+++ b/FS/FS/Conf.pm
@@ -3253,6 +3253,14 @@ and customer address. Include units.',
'section' => 'billing',
'description' => 'Configuration for EFT Canada batching, four lines: 1. SFTP username, 2. SFTP password, 3. Transaction code, 4. Number of days to delay process date.',
'type' => 'textarea',
+ 'per_agent' => 1,
+ },
+
+ {
+ 'key' => 'batch-spoolagent',
+ 'section' => 'billing',
+ 'description' => 'Store payment batches per-agent.',
+ 'type' => 'checkbox',
},
{
diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm
index 535999535..5c30a5e37 100644
--- a/FS/FS/Schema.pm
+++ b/FS/FS/Schema.pm
@@ -1382,19 +1382,19 @@ sub tables_hashref {
'pay_batch' => { #batches of payments to an external processor
'columns' => [
- 'batchnum', 'serial', '', '', '', '',
- 'payby', 'char', '', 4, '', '', # CARD/CHEK
- 'status', 'char', 'NULL', 1, '', '',
- 'download', @date_type, '', '',
- 'upload', @date_type, '', '',
+ 'batchnum', 'serial', '', '', '', '',
+ 'agentnum', 'int', 'NULL', '', '', '',
+ 'payby', 'char', '', 4, '', '', # CARD/CHEK
+ 'status', 'char', 'NULL', 1, '', '',
+ 'download', @date_type, '', '',
+ 'upload', @date_type, '', '',
],
'primary_key' => 'batchnum',
'unique' => [],
'index' => [],
},
- 'cust_pay_batch' => { #what's this used for again? list of customers
- #in current CARD batch? (necessarily CARD?)
+ 'cust_pay_batch' => { #list of customers in current CARD/CHEK batch
'columns' => [
'paybatchnum', 'serial', '', '', '', '',
'batchnum', 'int', '', '', '', '',
diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm
index f96a45aef..0788e15de 100644
--- a/FS/FS/cust_main.pm
+++ b/FS/FS/cust_main.pm
@@ -2481,6 +2481,7 @@ sub batch_card {
'status' => 'O',
'payby' => FS::payby->payby2payment($payby),
);
+ $pay_batch{agentnum} = $self->agentnum if $conf->exists('batch-spoolagent');
my $pay_batch = qsearchs( 'pay_batch', \%pay_batch );
diff --git a/FS/FS/pay_batch.pm b/FS/FS/pay_batch.pm
index 90b4eb8eb..bde8fdbf7 100644
--- a/FS/FS/pay_batch.pm
+++ b/FS/FS/pay_batch.pm
@@ -5,8 +5,9 @@ use vars qw( @ISA $DEBUG %import_info %export_info $conf );
use Time::Local;
use Text::CSV_XS;
use FS::Record qw( dbh qsearch qsearchs );
-use FS::cust_pay;
use FS::Conf;
+use FS::cust_pay;
+use FS::agent;
use Date::Parse qw(str2time);
use Business::CreditCard qw(cardtype);
@@ -40,6 +41,8 @@ from FS::Record. The following fields are currently supported:
=item batchnum - primary key
+=item agentnum - optional agent number for agent batches
+
=item payby - CARD or CHEK
=item status - O (Open), I (In-transit), or R (Resolved)
@@ -112,6 +115,7 @@ sub check {
$self->ut_numbern('batchnum')
|| $self->ut_enum('payby', [ 'CARD', 'CHEK' ])
|| $self->ut_enum('status', [ 'O', 'I', 'R' ])
+ || $self->ut_foreign_keyn('agentnum', 'agent', 'agentnum')
;
return $error if $error;
diff --git a/FS/bin/freeside-eftca-upload b/FS/bin/freeside-eftca-upload
index b50115365..45a358b23 100755
--- a/FS/bin/freeside-eftca-upload
+++ b/FS/bin/freeside-eftca-upload
@@ -38,15 +38,11 @@ else {
}
my $conf = new FS::Conf;
-my @batchconf = $conf->config('batchconfig-eft_canada');
-my $username = $batchconf[0] or die "no EFT Canada batch username configured\n";
-my $password = $batchconf[1] or die "no EFT Canada batch password configured\n";
my $tmpdir = tempdir( CLEANUP => 1 ); #DIR=>somewhere?
-my @filenames;
-
foreach my $pay_batch (@batches) {
+
my $batchnum = $pay_batch->batchnum;
my $filename = time2str('%Y%m%d', time) . '-' . sprintf('%06d.csv',$batchnum);
print STDERR "Exporting batch $batchnum to $filename...\n" if $opt_v;
@@ -54,27 +50,27 @@ foreach my $pay_batch (@batches) {
open OUT, ">$tmpdir/$filename";
print OUT $text;
close OUT;
- push @filenames, $filename;
-}
-my $host = 'ftp.eftcanada.com';
-print STDERR "Connecting to $username\@$host...\n" if $opt_v;
+ my @batchconf = $conf->config('batchconfig-eft_canada', $pay_batch->agentnum);
+ my $user = $batchconf[0] or die "no EFT Canada batch username configured\n";
+ my $pass = $batchconf[1] or die "no EFT Canada batch password configured\n";
+
+ my $host = 'ftp.eftcanada.com';
+ print STDERR "Connecting to $user\@$host...\n" if $opt_v;
-my $sftp = Net::SFTP::Foreign->new( host => $host,
- user => $username,
- password => $password,
- timeout => 30,
+ my $sftp = Net::SFTP::Foreign->new( host => $host,
+ user => $user,
+ password => $pass,
+ timeout => 30,
);
-die "failed to connect to '$username\@$host'\n(".$sftp->error.")\n"
- if $sftp->error;
+ die "failed to connect to '$user\@$host'\n(".$sftp->error.")\n"
+ if $sftp->error;
-foreach my $filename (@filenames) {
$sftp->put("$tmpdir/$filename", "$filename")
or die "failed to upload file (".$sftp->error.")\n";
-}
-$FS::UID::AutoCommit = 0;
-foreach my $pay_batch (@batches) {
+ undef $sftp; #$sftp->disconnect;
+
# Auto-approve and close the batch. Some false laziness with manual_approve.
my $batchnum = $pay_batch->batchnum;
my $error;
@@ -86,7 +82,6 @@ foreach my $pay_batch (@batches) {
$error ||= $pay_batch->set_status('R');
die "error closing batch $batchnum: $error\n\n" if $error;
}
-dbh->commit;
print STDERR "Finished!\n" if $opt_v;
diff --git a/httemplate/search/pay_batch.cgi b/httemplate/search/pay_batch.cgi
index 34297a500..b2a15ef3d 100755
--- a/httemplate/search/pay_batch.cgi
+++ b/httemplate/search/pay_batch.cgi
@@ -7,6 +7,9 @@
'order_by' => 'ORDER BY batchnum DESC',
},
'count_query' => "$count_query $extra_sql",
+ 'agent_virt' => 1,
+ 'agent_null_right' => 'Process batches', #'Process global batches',
+ 'agent_pos' => 1,
'header' => [ 'Batch',
'Type',
'First Download',