X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=FS%2FFS%2Fcust_credit.pm;h=24f7134a1868d446c441f679fedb86058955fad9;hp=f1d125c5f24b49b3ba3e55af0bfb135e53e8f007;hb=8311e00fcc3cd65fa75c2911aae59803e2402466;hpb=dbd3c301113a4cfd77595afd7aecd6cb13d02d9d diff --git a/FS/FS/cust_credit.pm b/FS/FS/cust_credit.pm index f1d125c5f..24f7134a1 100644 --- a/FS/FS/cust_credit.pm +++ b/FS/FS/cust_credit.pm @@ -985,6 +985,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.