From dc8a15535f28e96097a4f0fbf51b0aec2c7a7a5b Mon Sep 17 00:00:00 2001 From: Jonathan Prykop Date: Tue, 5 Jul 2016 16:51:34 -0500 Subject: [PATCH] RT#71563: Add agent_custid to credit import [v3 merge] --- FS/FS/cust_credit.pm | 37 ++++++++++++++++++++++++++++++++- httemplate/misc/cust_credit-import.html | 9 ++++---- 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/FS/FS/cust_credit.pm b/FS/FS/cust_credit.pm index 7cb79dff4..4286d3490 100644 --- a/FS/FS/cust_credit.pm +++ b/FS/FS/cust_credit.pm @@ -1103,12 +1103,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 9a63a04c5..68c566cf5 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:

-- 2.11.0