1

I am checked the value of one variable against the sum total of 2 variables. The value of the first variable $InterestAmount=4549.89 and the other two variables $InterestAccrued=3106.89 and $InterestReceivable=1839. All 3 variables are float data type. Yet when I'm checking if $InterestAmount <= $InterestAccrued+$InterestReceivable it is executing the else part even though the condition is true!!!

Please see the screenshot of DBGP debugger in Notepad++ below, I have highlighted the relevant sections. The execution pointer is on line 206 clearly in the 'else' part of the if condition. What could be wrong here?

Image can be viewed separately - https://prototype.womb.healthcare/php-error.png

Screenshot

Code follows...

if ($InterestAmount <= $InterestReceivable) {
    $Narration = "To Interest";
    saveTransaction($VoucherID, $TransactionDate, $DR, $AccountID, $InterestAmount, $Narration, $isCash, $postNow, $INACTIVE);
    saveTransaction($VoucherID, $TransactionDate, $DR, $InterestAccountID, $InterestAmount, $Narration, $isCash, $postNow, $INACTIVE);
    saveTransaction($VoucherID, $TransactionDate, $CR, $PnLInterestAccountID, $InterestAmount, $Narration, $isCash, $postNow, $INACTIVE);
    $PrinBal -= $InterestAmount;
} else {
    $totInt = ($InterestReceivable+$InterestAccrued);
    if ($InterestAmount <= $totInt) {
        $balInterest = $InterestAmount - $InterestReceivable;
        $Narration = "To Interest";
        saveTransaction($VoucherID, $TransactionDate, $DR, $AccountID, $InterestAmount, $Narration, $isCash, $postNow, $INACTIVE);
        saveTransaction($VoucherID, $TransactionDate, $CR, $InterestAccountID, $balInterest, $Narration, $isCash, $postNow, $INACTIVE);
        saveTransaction($VoucherID, $TransactionDate, $DR, $InterestAccountID, $InterestAmount, $Narration, $isCash, $postNow, $INACTIVE);
        saveTransaction($VoucherID, $TransactionDate, $CR, $PnLInterestAccountID, $InterestAmount, $Narration, $isCash, $postNow, $INACTIVE);
        $sql = "INSERT INTO `acc_interest_accrued`
                    (AccountID, Type, Date, Amount, VoucherID, Posted, PostedDate)
                VALUES (?,?,STR_TO_DATE(?, '%d-%m-%Y'),?,?,?,STR_TO_DATE(?, '%d-%m-%Y'))";
        $stmt = $dbCon->prepare($sql);
        $stmt->bind_param("sssssss", $AccountID, $DR, $TransactionDate, $balInterest, 
                                     $VoucherID, $postNow, $PostedDate);
        $stmt->execute() || $anyError=true;
        $PrinBal -= $InterestAmount;
    } else {
        // Ideally this situation will not arise as we're already validating the Interest amount 
        // against IR+IA in JS. But if it does, we'll invalidate the whole transaction
        $anyError=true;
    }
}
Qirel
  • 25,449
  • 7
  • 45
  • 62
Nitin Mistry
  • 59
  • 1
  • 8

0 Answers0