summaryrefslogtreecommitdiff
path: root/FS/FS/cust_credit.pm
diff options
context:
space:
mode:
authorJonathan Prykop <jonathan@freeside.biz>2016-07-05 16:51:34 -0500
committerJonathan Prykop <jonathan@freeside.biz>2016-07-05 16:55:43 -0500
commitcd87a18951c8fc681feb01a36c1b6956c3853909 (patch)
treef0a2c42d5c5b29ee005758c2a519be8842620c98 /FS/FS/cust_credit.pm
parenta93e3b32a69b75701b717175011894265b37f959 (diff)
RT#71563: Add agent_custid to credit import
Diffstat (limited to 'FS/FS/cust_credit.pm')
-rw-r--r--FS/FS/cust_credit.pm37
1 files changed, 36 insertions, 1 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 ) = @_;