X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fcust_credit.pm;h=f8c13f9f016db31d78f194ed49a5732775913e13;hb=ab42a6d76c5a5905d223d214e409f0527b2c5b9e;hp=18f4a324676a76252456708016cbcaf9fd748e8c;hpb=6d1717a6efc1db987c309d149e679a5676a04e4a;p=freeside.git diff --git a/FS/FS/cust_credit.pm b/FS/FS/cust_credit.pm index 18f4a3246..f8c13f9f0 100644 --- a/FS/FS/cust_credit.pm +++ b/FS/FS/cust_credit.pm @@ -154,6 +154,10 @@ sub insert { my $dbh = dbh; my $cust_main = qsearchs( 'cust_main', { 'custnum' => $self->custnum } ); + unless ( $cust_main ) { + $dbh->rollback if $oldAutoCommit; + return "Unknown custnum ". $self->custnum; + } my $old_balance = $cust_main->balance; if (!$self->reasonnum) { @@ -743,10 +747,12 @@ sub calculate_tax_adjustment { if ($recur) { $recur -= $cust_bill_pkg->credited('', '', setuprecur => 'recur') || 0; } + # Skip line items that have been completely credited. + next if ($setup + $recur) == 0; my $setup_ratio = $setup / ($setup + $recur); - # Calculate the fraction of tax to credit: it's the fraction of this charge - # (either setup or recur) that's being credited. + # Calculate the fraction of tax to credit: it's the fraction of this + # charge (either setup or recur) that's being credited. my $charged = ($setuprecur eq 'setup') ? $setup : $recur; next if $charged == 0; # shouldn't happen, but still... @@ -911,7 +917,7 @@ sub credit_lineitems { my $invnum = $cust_bill_pkg->invnum; $need_to_unapply -= $cust_bill_pkg->owed($setuprecur); - next if $need_to_unapply < 0.005; + return if $need_to_unapply < 0.005; my $error; # then unapply payments one at a time (partially if need be) until the