[freeside-commits] branch master updated. 2be0687ad93376100101bb270d7ff838b91a869a

Mark Wells mark at 420.am
Mon Jan 7 17:17:59 PST 2013


The branch, master has been updated
       via  2be0687ad93376100101bb270d7ff838b91a869a (commit)
      from  eb70a0b5a299e8e77e64cd10ee515270fbe14044 (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 2be0687ad93376100101bb270d7ff838b91a869a
Author: Mark Wells <mark at freeside.biz>
Date:   Mon Jan 7 17:14:32 2013 -0800

    application of line item credits, #20629

diff --git a/FS/FS/cust_credit.pm b/FS/FS/cust_credit.pm
index c716602..082b0f2 100644
--- a/FS/FS/cust_credit.pm
+++ b/FS/FS/cust_credit.pm
@@ -646,6 +646,7 @@ Example:
 use FS::cust_bill_pkg;
 sub credit_lineitems {
   my( $class, %arg ) = @_;
+  warn Data::Dumper::Dumper \%arg;
   my $curuser = $FS::CurrentUser::CurrentUser;
 
   #some false laziness w/misc/xmlhttp-cust_bill_pkg-calculate_taxes.html
@@ -717,8 +718,7 @@ sub credit_lineitems {
   my %cust_bill_pkg = ();
   my %cust_credit_bill_pkg = ();
   my %taxlisthash = ();
-  # except here they're billpaynums
-  my %unapplied_payments;
+  my %unapplied_payments; #invoice numbers, and then billpaynums
   foreach my $billpkgnum ( @{$arg{billpkgnums}} ) {
     my $setuprecur = shift @{$arg{setuprecurs}};
     my $amount = shift @{$arg{amounts}};
@@ -753,7 +753,7 @@ sub credit_lineitems {
         $dbh->rollback if $oldAutoCommit;
         return "Error unapplying payment: $error";
       }
-      $unapplied_payments{$cust_bill_pay_pkg->billpaynum}
+      $unapplied_payments{$invnum}{$cust_bill_pay_pkg->billpaynum}
         += $cust_bill_pay_pkg->amount;
     }
 
@@ -893,27 +893,37 @@ sub credit_lineitems {
           $dbh->rollback if $oldAutoCommit;
           return "Error unapplying payment: $error";
         }
-        $unapplied_payments{$cust_bill_pay_pkg->billpaynum}
+        $unapplied_payments{$invnum}{$cust_bill_pay_pkg->billpaynum}
           += $cust_bill_pay_pkg->amount;
       }
     } #foreach $taxline
 
     # if we unapplied any payments from line items, also unapply that 
     # amount from the invoice
-    foreach my $billpaynum (keys %unapplied_payments) {
+    foreach my $billpaynum (keys %{$unapplied_payments{$invnum}}) {
       my $cust_bill_pay = FS::cust_bill_pay->by_key($billpaynum)
         or die "broken payment application $billpaynum";
+      my @subapps = $cust_bill_pay->lineitem_applications;
       $error = $cust_bill_pay->delete; # can't replace
 
       my $new_cust_bill_pay = FS::cust_bill_pay->new({
           $cust_bill_pay->hash,
           billpaynum => '',
           amount => sprintf('%.2f', 
-              $cust_bill_pay->amount - $unapplied_payments{$billpaynum}),
+              $cust_bill_pay->amount 
+              - $unapplied_payments{$invnum}{$billpaynum}),
       });
 
       if ( $new_cust_bill_pay->amount > 0 ) {
         $error ||= $new_cust_bill_pay->insert;
+        # Also reapply it to everything it was applied to before.
+        # Note that we've already deleted cust_bill_pay_pkg records for the
+        # items we're crediting, so they aren't on this list.
+        foreach my $cust_bill_pay_pkg (@subapps) {
+          $cust_bill_pay_pkg->billpaypkgnum('');
+          $cust_bill_pay_pkg->billpaynum($new_cust_bill_pay->billpaynum);
+          $error ||= $cust_bill_pay_pkg->insert;
+        }
       }
       if ( $error ) {
         $dbh->rollback if $oldAutoCommit;
diff --git a/FS/FS/cust_main_county.pm b/FS/FS/cust_main_county.pm
index db6be75..5733595 100644
--- a/FS/FS/cust_main_county.pm
+++ b/FS/FS/cust_main_county.pm
@@ -498,6 +498,8 @@ sub taxline {
         'taxnum'      => $self->taxnum,
         'taxtype'     => ref($self),
         'cents'       => $this_tax_cents,
+        'pkgnum'      => $cust_bill_pkg->pkgnum,
+        'locationnum' => $cust_bill_pkg->cust_pkg->tax_locationnum,
         'taxable_cust_bill_pkg' => $cust_bill_pkg,
         'tax_cust_bill_pkg'     => $tax_item,
     });

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

Summary of changes:
 FS/FS/cust_credit.pm      |   22 ++++++++++++++++------
 FS/FS/cust_main_county.pm |    2 ++
 2 files changed, 18 insertions(+), 6 deletions(-)




More information about the freeside-commits mailing list