diff options
author | Ivan Kohler <ivan@freeside.biz> | 2014-01-15 14:41:16 -0800 |
---|---|---|
committer | Ivan Kohler <ivan@freeside.biz> | 2014-01-15 14:41:16 -0800 |
commit | 11171a2f45def9e2edc48d8e5c545a5005ed6bd0 (patch) | |
tree | 8be6219c1aa7877445668e56c9c78ae35eb1cac7 /FS | |
parent | b7c25d5e38e6459efe5d1c2f09f437b79798038e (diff) |
bulk credit import, RT#26319
Diffstat (limited to 'FS')
-rw-r--r-- | FS/FS/cust_credit.pm | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/FS/FS/cust_credit.pm b/FS/FS/cust_credit.pm index df59950ea..3f8d57c3c 100644 --- a/FS/FS/cust_credit.pm +++ b/FS/FS/cust_credit.pm @@ -1103,6 +1103,58 @@ sub credit_lineitems { =back +=head1 SUBROUTINES + +=over 4 + +=item process_batch_import + +=cut + +use List::Util qw( min ); +use FS::cust_bill; +use FS::cust_credit_bill; +sub process_batch_import { + my $job = shift; + + my $opt = { 'table' => 'cust_credit', + 'params' => [ 'credbatch' ], + 'formats' => { 'simple' => + [ 'custnum', 'amount', 'reasonnum', 'invnum' ], + }, + 'default_csv' => 1, + 'postinsert_callback' => sub { + my $cust_credit = shift; #my ($cust_credit, $param ) = @_; + + if ( $cust_credit->invnum ) { + + my $cust_bill = qsearchs('cust_bill', { invnum=>$cust_credit->invnum } ); + my $amount = min( $cust_credit->credited, $cust_bill->owed ); + + my $cust_credit_bill = new FS::cust_credit_bill ( { + 'crednum' => $cust_credit->crednum, + 'invnum' => $cust_bill->invnum, + 'amount' => $amount, + } ); + my $error = $cust_credit_bill->insert; + return '' unless $error; + + } + + #apply_payments_and_credits ? + $cust_credit->cust_main->apply_credits; + + return ''; + + }, + }; + + FS::Record::process_batch_import( $job, $opt, @_ ); + +} + +=back + =head1 BUGS The delete method. The replace method. |