'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',
},
{
'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', '', '', '', '',
'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 );
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);
=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)
$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;
}
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;
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;
$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;
'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',