diff options
author | ivan <ivan> | 2003-12-15 06:42:51 +0000 |
---|---|---|
committer | ivan <ivan> | 2003-12-15 06:42:51 +0000 |
commit | 80647ef08f5ef074f318329c6353e7b35f443def (patch) | |
tree | 430786da7643b194c690810fd47391428a00fdd0 | |
parent | 3069f4a1173f9d20815e682d54e2aabdd0d399ce (diff) |
fix bug that charged full amounts of all open invoices as soon as balance went positive (only manifests when any cust_bill->owed somehow got to be negative)
-rw-r--r-- | FS/FS/cust_bill.pm | 5 | ||||
-rw-r--r-- | FS/FS/cust_main.pm | 20 |
2 files changed, 10 insertions, 15 deletions
diff --git a/FS/FS/cust_bill.pm b/FS/FS/cust_bill.pm index f929073d6..66997e92e 100644 --- a/FS/FS/cust_bill.pm +++ b/FS/FS/cust_bill.pm @@ -697,7 +697,10 @@ sub realtime_bop { pop @$options if scalar(@$options) % 2 && $options->[-1] =~ /^\s*$/; my $cust_main = $self->cust_main; - my $amount = $self->owed; + my $balance = $cust_main->balance; + my $amount = ( $balance < $self->owed ) ? $balance : $self->owed; + $amount = sprintf("%.2f", $amount); + return "not run (balance $balance)" unless $amount > 0; my $address = $cust_main->address1; $address .= ", ". $cust_main->address2 if $cust_main->address2; diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm index d2fc76bf5..e83596166 100644 --- a/FS/FS/cust_main.pm +++ b/FS/FS/cust_main.pm @@ -1461,24 +1461,15 @@ sub collect { } } - foreach my $cust_bill ( $self->cust_bill ) { - - #this has to be before next's - my $amount = sprintf( "%.2f", $balance < $cust_bill->owed - ? $balance - : $cust_bill->owed - ); - $balance = sprintf( "%.2f", $balance - $amount ); - - next unless $cust_bill->owed > 0; + foreach my $cust_bill ( $self->open_cust_bill ) { # don't try to charge for the same invoice if it's already in a batch #next if qsearchs( 'cust_pay_batch', { 'invnum' => $cust_bill->invnum } ); - warn "invnum ". $cust_bill->invnum. " (owed ". $cust_bill->owed. ", amount $amount, balance $balance)" if $Debug; - - next unless $amount > 0; + last if $self->balance <= 0; + warn "invnum ". $cust_bill->invnum. " (owed ". $cust_bill->owed. ")" + if $Debug; foreach my $part_bill_event ( sort { $a->seconds <=> $b->seconds @@ -1495,7 +1486,8 @@ sub collect { 'disabled' => '', } ) ) { - last unless $cust_bill->owed > 0; #don't run subsequent events if owed=0 + last if $cust_bill->owed <= 0 # don't run subsequent events if owed<=0 + || $self->balance <= 0; # or if balance<=0 warn "calling invoice event (". $part_bill_event->eventcode. ")\n" if $Debug; |