# adjusting the amount for partially paid bills
map {
my $payment = $_;
- my $paybal = $payment->amount;
+ my $paybal = $payment->amount * 100;
while ($paybal > 0) {
# get next billing
my $bill = shift @{$bills};
- my $newbal = (($paybal*100) - ($bill->amount*100))/100;
+ my $newbal = $paybal - $bill->amount*100;
if ($newbal < 0) {
$newbal = 0;
- my $new_bill_amount = (($bill->amount*100) - ($paybal*100))/100;
- $bill->amount($new_bill_amount);
+ my $new_bill_amount = $bill->amount*100 - $paybal;
+ $bill->amount($new_bill_amount/100);
unshift(@{$bills}, $bill); # put the partially-paid bill back on top of the stack
}