Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New Coder
    Join Date
    Nov 2009
    Posts
    14
    Thanks
    1
    Thanked 0 Times in 0 Posts

    what's wrong with this code?

    Code:
    function CalculatePayment(form) {
    
    // Check Amount is not a number
    if (isNaN(form.CheckAmount.value) || form.CheckAmount.value=="") {
    alert("Please enter a valid check amount.");
    form.CheckAmount.select();
    form.CheckAmount.focus();
    return;
    }
    else {
    form.CheckAmount.value = moneyConvert(form.CheckAmount.value);
    }
    
    var totalMoney = parseFloat(form.CheckAmount.value);
    var copayDue = parseFloat(form.CopayDue.value);
    var deductibleDue = parseFloat(form.DeductibleDue.value);
    var totalDue = parseFloat(form.TotalDue.value);
    
    // COPAY
    if (totalMoney > copayDue) {
    form.Copay.value = moneyConvert(copayDue);
    totalMoney = (totalMoney - copayDue);
    }
    else {
    form.Copay.value = moneyConvert(totalMoney);
    totalMoney = 0;
    }
    
    // DEDUCTIBLE
    if (totalMoney > deductibleDue) {
    form.Deductible.value = moneyConvert(deductibleDue);
    totalMoney = (totalMoney - deductibleDue);
    }
    else {
    form.Deductible.value = moneyConvert(totalMoney);
    totalMoney = 0;
    }
    
    var copay = parseFloat(form.Copay.value);
    var deductible = parseFloat(form.Deductible.value);
    
    // COPAY ADJUSTMENT
    if (form.FullPay.checked)
    form.CopayAdjustment.value = moneyConvert(copayDue - copay);
    else
    form.CopayAdjustment.value = "0.00";
    
    // DEDUCTIBLE ADJUSTMENT
    if (form.FullPay.checked)
    form.DeductibleAdjustment.value = moneyConvert(deductibleDue - deductible);
    else
    form.DeductibleAdjustment.value = "0.00";
    
    // OVERPAY
    form.Overpay.value = moneyConvert(totalMoney);
    }
    
    function convertMoneyCents(txt) {
    if (!isNaN(txt.value)) {
    txt.value = moneyConvert(txt.value);
    }
    }
    
    function DoCal(szTarget, szFieldLabel) {
    var szDate = window.showModalDialog("../Calendar.html",szFieldLabel,"dialogHeight:230px;dialogWidth:220px;;center=1;status=0");
    if((szDate != "") && (szDate != "undefined")) {
    szTarget.value = szDate; }
    }
    
    function moneyConvert(strval) {
    strval = Math.abs(strval) + "";
    if (strval.indexOf(".") == -1) {
    strval = strval + '.00';
    }
    else {
    strval = strval + "00";
    strval = strval.substr(0, strval.indexOf(".") + 3);
    }
    return strval;
    }
    HTML

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>patientCalc</title>
    <link href="patientCalc.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="patientCalc.js"></script>
    </head>
    <body>
    <form id="frmPayment" action="">
    <p>
    Total Balance: <input type="text" id="TotalDue" value="125.25" />
    </p>
    
    <p>
    Total CoPay: <input type="text" id="CopayDue" value="114.54" />
    </p>
    
    <p>
    Total Deductible: <input type="text" id="DeductibleDue" value="10.71" />
    </p>
    
    <p>
    Original Total: <input type="text" id="OriginalTotal" value="125.25" disabled="disabled" />
    </p>
    
    
    <p>
    Check Amount: <input type="text" id="CheckAmount" />
    </p>
    
    
    
    
    
    
    <p>
    Copay: <input type="text" id="Copay" />
    </p>
    
    <p>
    Deductible: <input type="text" id="Deductible" />
    </p>
    
    <p>
    Pay in Full: <input type="checkbox" id="FullPay" checked="checked" />
    </p>
    
    
    <p>
    Copay Adjustment: <input type="text" id="CopayAdjustment" />
    </p>
    
    <p>
    Deductible Adjustment: <input type="text" id="DeductibleAdjustment" />
    </p>
    
    <p>
    Overpay: <input type="text" id="Overpay" />
    </p>
    
    <p>
    <input type="button" value="Calculate Payment" onclick="CalculatePayment(document.forms[0]);" />
    </p>
    </form>
    
    </body>
    </html>
    the Deductible keeps coming up 0.00

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,992
    Thanks
    79
    Thanked 4,432 Times in 4,397 Posts
    Is it a trick question??

    First answer: The JavaScript looks ugly because it's not indented.

    Or do you mean it doesn't work in some way?
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    New Coder
    Join Date
    Nov 2009
    Posts
    14
    Thanks
    1
    Thanked 0 Times in 0 Posts
    it's not working in some way.

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,992
    Thanks
    79
    Thanked 4,432 Times in 4,397 Posts
    LOL!!! Okay, you win the battle of nerves!

    In *WHAT* way is it not working????
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #5
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,992
    Thanks
    79
    Thanked 4,432 Times in 4,397 Posts
    Here's my cleanup of the ugly code.

    It *seems* to work, but maybe not doing what it should????
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>patientCalc</title>
    <script type="text/javascript">
    function getNum(fld)
    {
        var val = fld.value;
        if ( val == "" ) return null;
        val = parseFloat(val.replace(/[^\d\.]/g,""));
        if ( isNaN(val) ) return null;
        return val;
    }
    function getNumZ(fld)
    {
        var val = getNum(fld);
        if ( val == null ) val = 0;
        return val;
    }
    function CalculatePayment(form) 
    {
    
        // Check Amount is not a number
        var camt = getNum(form.CheckAmount);
        if ( camt == null )
        {
            alert("Please enter a valid check amount.");
            form.CheckAmount.select();
            form.CheckAmount.focus();
            return;
        }
        form.CheckAmount.value = "$" + camt.toFixed(2);
    
        var totalMoney = camt;
        var copayDue = getNumZ(form.CopayDue);
        var deductibleDue = getNumZ(form.DeductibleDue);
        var totalDue = getNumZ(form.TotalDue);
    
        // COPAY
        if (totalMoney > copayDue) 
        {
            form.Copay.value = "$" + copayDue.toFixed(2);
            totalMoney = (totalMoney - copayDue);
        } else {
            form.Copay.value = "$" + totalMoney.toFixed(2);
            totalMoney = 0;
        }
    
         // DEDUCTIBLE
        if (totalMoney > deductibleDue) 
        {
            form.Deductible.value = "$" + deductibleDue.toFixed(2);
            totalMoney = (totalMoney - deductibleDue);
        } else {
            form.Deductible.value = "$" + totalMoney.toFixed(2);
            totalMoney = 0;
        }
    
        var copay = getNumZ(form.Copay);
        var deductible = getNumZ(form.Deductible);
        // COPAY ADJUSTMENT
        if (form.FullPay.checked)
        {
            form.CopayAdjustment.value = "$" + (copayDue - copay).toFixed(2);
        } else {
            form.CopayAdjustment.value = "$0.00";
        }
    
        // DEDUCTIBLE ADJUSTMENT
        if (form.FullPay.checked)
        {
            form.DeductibleAdjustment.value = "$" + (deductibleDue - deductible).toFixed(2);
        } else {
            form.DeductibleAdjustment.value = "$0.00";
        }
        // OVERPAY
        form.Overpay.value = "$" + totalMoney.toFixed(2);
    
    }
    </script>
    </head>
    <body>
    <form id="frmPayment" action="">
    <p>
    Total Balance: <input type="text" id="TotalDue" value="125.25" />
    </p>
    <p>
    Total CoPay: <input type="text" id="CopayDue" value="114.54" />
    </p>
    <p>
    Total Deductible: <input type="text" id="DeductibleDue" value="10.71" />
    </p>
    <p>
    Original Total: <input type="text" id="OriginalTotal" value="125.25" disabled="disabled" />
    </p>
    <p>
    Check Amount: <input type="text" id="CheckAmount" />
    </p>
    <p>
    Copay: <input type="text" id="Copay" />
    </p>
    <p>
    Deductible: <input type="text" id="Deductible" />
    </p>
    <p>
    Pay in Full: <input type="checkbox" id="FullPay" checked="checked" />
    </p>
    <p>
    Copay Adjustment: <input type="text" id="CopayAdjustment" />
    </p>
    <p>
    Deductible Adjustment: <input type="text" id="DeductibleAdjustment" />
    </p>
    <p>
    Overpay: <input type="text" id="Overpay" />
    </p>
    <p>
    <input type="button" value="Calculate Payment" onclick="CalculatePayment(this.form);" />
    </p>
    </form>
    
    </body>
    </html>
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #6
    New Coder
    Join Date
    Nov 2009
    Posts
    14
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Indigo1 View Post
    the Deductible keeps coming up 0.00

    ........

  • #7
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,992
    Thanks
    79
    Thanked 4,432 Times in 4,397 Posts
    Not in my cleaned up version.

    If I put in a check amount of $121.00 then I (correctly, I think) get a deductible payment of $6.46.

    Try mine.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #8
    New Coder
    Join Date
    Nov 2009
    Posts
    14
    Thanks
    1
    Thanked 0 Times in 0 Posts
    i think the deductible isn't coming out correctly though.

  • #9
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,992
    Thanks
    79
    Thanked 4,432 Times in 4,397 Posts
    With my code, and a Check Amount of 100.00, I see the following:
    Code:
    Total Balance:  125.25
    Total CoPay:  114.54
    Total Deductible:  10.71
    Original Total:  125.25
    Check Amount:  100.00
    
    Copay:  100.00 [so the check went ENTIRELY to the copay due]
    Deductible:  0.00 [and none is applied to the deductible]
    Pay in Full:  [checked]
    Copay Adjustment:  14.54 [so person still owes this much on the copay]
    Deductible Adjustment:  10.71 [and person still owes *ALL* of the deductible]
    Overpay: 0.00
    If I use a check amount of 120.00 I see this:
    Code:
    Total Balance:  125.25
    Total CoPay:  114.54
    Total Deductible:  10.71
    Original Total:  125.25
    Check Amount:  120.00
    
    Copay:  114.54 [full amount of the copay]
    Deductible:  5.46 [and this much is applied to the deductible]
    Pay in Full:  [checked]
    Copay Adjustment:  0.00 [copay is paid in full]
    Deductible Adjustment:  5.25 [and person still owes only this on the deductible]
    Overpay: 0.00
    Looks right to me.

    NOW....

    In *MOST* medical payment systems I've seen, the Deductible is paid first and *then* the Copay. It would be easy to change the code to that, if that's what you need.

    [/code]
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •