From 4289a88d7ac580599e4af7242f6af90aa2653cb8 Mon Sep 17 00:00:00 2001 From: jeff Date: Mon, 23 Aug 2010 20:02:41 +0000 Subject: [PATCH] support importing charges by agent_custid --- FS/FS/cust_main.pm | 38 +++++++++++-- httemplate/misc/cust_main-import_charges.cgi | 63 +++++++++++++++++++--- .../misc/process/cust_main-import_charges.cgi | 3 +- 3 files changed, 92 insertions(+), 12 deletions(-) diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm index 520372360..355687820 100644 --- a/FS/FS/cust_main.pm +++ b/FS/FS/cust_main.pm @@ -8865,7 +8865,17 @@ sub batch_charge { my $param = shift; #warn join('-',keys %$param); my $fh = $param->{filehandle}; - my @fields = @{$param->{fields}}; + my $agentnum = $param->{agentnum}; + my $format = $param->{format}; + + my $extra_sql = ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql; + + my @fields; + if ( $format eq 'simple' ) { + @fields = qw( custnum agent_custid amount pkg ); + } else { + die "unknown format $format"; + } eval "use Text::CSV_XS;"; die $@ if $@; @@ -8905,10 +8915,32 @@ sub batch_charge { $row{$field} = shift @columns; } - my $cust_main = qsearchs('cust_main', { 'custnum' => $row{'custnum'} } ); + if ( $row{custnum} && $row{agent_custid} ) { + dbh->rollback if $oldAutoCommit; + return "can't specify custnum with agent_custid $row{agent_custid}"; + } + + my %hash = (); + if ( $row{agent_custid} && $agentnum ) { + %hash = ( 'agent_custid' => $row{agent_custid}, + 'agentnum' => $agentnum, + ); + } + + if ( $row{custnum} ) { + %hash = ( 'custnum' => $row{custnum} ); + } + + unless ( scalar(keys %hash) ) { + $dbh->rollback if $oldAutoCommit; + return "can't find customer without custnum or agent_custid and agentnum"; + } + + my $cust_main = qsearchs('cust_main', { %hash } ); unless ( $cust_main ) { $dbh->rollback if $oldAutoCommit; - return "unknown custnum $row{'custnum'}"; + my $custnum = $row{custnum} || $row{agent_custid}; + return "unknown custnum $custnum"; } if ( $row{'amount'} > 0 ) { diff --git a/httemplate/misc/cust_main-import_charges.cgi b/httemplate/misc/cust_main-import_charges.cgi index 3801929e8..c844e0ee4 100644 --- a/httemplate/misc/cust_main-import_charges.cgi +++ b/httemplate/misc/cust_main-import_charges.cgi @@ -1,22 +1,69 @@ -<% include('/elements/header.html', 'Batch Customer Charge') %> +<% include("/elements/header.html",'Batch Payment Charge') %> + +Import a CSV file containing customer payments. +

-Import a CSV file containing customer charges.

-Default file format is CSV, with the following field order: custnum, amount, description

-If amount is negative, a credit will be applied instead.

-

+<% &ntable("#cccccc", 2) %> + +<% include('/elements/tr-select-agent.html', + #'curr_value' => '', #$agentnum, + 'label' => "Agent", + 'empty_label' => 'Select agent', + ) +%> + + + Format + + + + + + + CSV filename + + -CSV Filename:

- + + +
-<% include('/elements/footer.html') %> +
+ +Simple file format is CSV, with the following field order: custnum, agent_custid, amount, description +

+ + +Field information: + + + +
+ +<% include('/elements/footer.html') %> <%init> die "access denied" unless $FS::CurrentUser::CurrentUser->access_right('Import'); + diff --git a/httemplate/misc/process/cust_main-import_charges.cgi b/httemplate/misc/process/cust_main-import_charges.cgi index 3ca68944a..bda3e3b70 100644 --- a/httemplate/misc/process/cust_main-import_charges.cgi +++ b/httemplate/misc/process/cust_main-import_charges.cgi @@ -16,7 +16,8 @@ my $fh = $cgi->upload('csvfile'); my $error = defined($fh) ? FS::cust_main::batch_charge( { filehandle => $fh, - 'fields' => [qw( custnum amount pkg )], + 'agentnum' => scalar($cgi->param('agentnum')), + 'format' => scalar($cgi->param('format')), } ) : 'No file'; -- 2.11.0