[freeside-commits] branch FREESIDE_2_3_BRANCH updated. 8311e00fcc3cd65fa75c2911aae59803e2402466

Ivan ivan at 420.am
Wed Jan 15 14:41:37 PST 2014


The branch, FREESIDE_2_3_BRANCH has been updated
       via  8311e00fcc3cd65fa75c2911aae59803e2402466 (commit)
      from  dbd3c301113a4cfd77595afd7aecd6cb13d02d9d (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 8311e00fcc3cd65fa75c2911aae59803e2402466
Author: Ivan Kohler <ivan at freeside.biz>
Date:   Wed Jan 15 14:41:35 2014 -0800

    bulk credit import, RT#26319

diff --git a/FS/FS/cust_credit.pm b/FS/FS/cust_credit.pm
index f1d125c..24f7134 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.
diff --git a/httemplate/search/cust_credit.html b/httemplate/search/cust_credit.html
index 0fbc6fc..78bb1e4 100755
--- a/httemplate/search/cust_credit.html
+++ b/httemplate/search/cust_credit.html
@@ -96,6 +96,10 @@ if ( $cgi->param('agentnum') && $cgi->param('agentnum') =~ /^(\d+)$/ ) {
   $title = $agent->agent. " $title";
 }
 
+if ( $cgi->param('credbatch') =~ /^([\w\-\/\.\:]+)$/ ) {
+  push @search, "cust_credit.credbatch = '$1'";
+}
+
 if ( $cgi->param('refnum') && $cgi->param('refnum') =~ /^(\d+)$/ ) {
   push @search, "refnum = $1";
   my $part_referral = qsearchs('part_referral', { 'refnum' => $1 } );

-----------------------------------------------------------------------

Summary of changes:
 FS/FS/cust_credit.pm               |   52 ++++++++++++++++++++++++++++++++++++
 httemplate/search/cust_credit.html |    4 +++
 2 files changed, 56 insertions(+), 0 deletions(-)




More information about the freeside-commits mailing list