summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--FS/FS/cust_credit.pm37
-rw-r--r--httemplate/misc/cust_credit-import.html9
2 files changed, 41 insertions, 5 deletions
diff --git a/FS/FS/cust_credit.pm b/FS/FS/cust_credit.pm
index 094437e..8546372 100644
--- a/FS/FS/cust_credit.pm
+++ b/FS/FS/cust_credit.pm
@@ -1087,12 +1087,47 @@ use FS::cust_credit_bill;
sub process_batch_import {
my $job = shift;
+ # some false laziness with FS::cust_pay::process_batch_import
+ my $hashcb = sub {
+ my %hash = @_;
+ my $custnum = $hash{'custnum'};
+ my $agent_custid = $hash{'agent_custid'};
+ # translate agent_custid into regular custnum
+ if ($custnum && $agent_custid) {
+ die "can't specify both custnum and agent_custid\n";
+ } elsif ($agent_custid) {
+ # here is the agent virtualization
+ my $extra_sql = ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql;
+ my %search;
+ $search{'agent_custid'} = $agent_custid
+ if $agent_custid;
+ $search{'custnum'} = $custnum
+ if $custnum;
+ my $cust_main = qsearchs({
+ 'table' => 'cust_main',
+ 'hashref' => \%search,
+ 'extra_sql' => $extra_sql,
+ });
+ die "can't find customer with" .
+ ($custnum ? " custnum $custnum" : '') .
+ ($agent_custid ? " agent_custid $agent_custid" : '') . "\n"
+ unless $cust_main;
+ die "mismatched customer number\n"
+ if $custnum && ($custnum ne $cust_main->custnum);
+ $custnum = $cust_main->custnum;
+ }
+ $hash{'custnum'} = $custnum;
+ delete($hash{'agent_custid'});
+ return %hash;
+ };
+
my $opt = { 'table' => 'cust_credit',
'params' => [ '_date', 'credbatch' ],
'formats' => { 'simple' =>
- [ 'custnum', 'amount', 'reasonnum', 'invnum' ],
+ [ 'custnum', 'amount', 'reasonnum', 'invnum', 'agent_custid' ],
},
'default_csv' => 1,
+ 'format_hash_callbacks' => { 'simple' => $hashcb },
'postinsert_callback' => sub {
my $cust_credit = shift; #my ($cust_credit, $param ) = @_;
diff --git a/httemplate/misc/cust_credit-import.html b/httemplate/misc/cust_credit-import.html
index 937010d..d009d1e 100644
--- a/httemplate/misc/cust_credit-import.html
+++ b/httemplate/misc/cust_credit-import.html
@@ -67,10 +67,11 @@ Uploaded files can be CSV (comma-separated value) files or Excel spreadsheets.
Field information:
<ul>
- <li><i>custnum</i>: Customer number
- <li><i>amount</i>:
- <li><i>reasonnum</i>: <A HREF="<%$p%>browse/reason_type.html?class=R">Credit reason</A>
- <li><i>invnum</i>: Invoice number
+ <li><i>custnum</i>: This is the freeside customer number. It may be left blank. If specified, agent_custid must be blank.</li>
+ <li><i>amount</i>:</li>
+ <li><i>reasonnum</i>: <A HREF="<%$p%>browse/reason_type.html?class=R">Credit reason</A></li>
+ <li><i>invnum</i>: Invoice number</li>
+ <li><i>agent_custid</i>: This is the reseller's idea of the customer number or identifier. It may be left blank. If specified, custnum must be blank.</li>
</ul>
<BR><BR>