<%-- 
    Document   : ModifyAccount
    Created on : Apr 24, 2017, 5:38:06 PM
    Author     : 594267
--%>

<%@page import="java.sql.Statement"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Connection"%>
<%@page import="java.util.Date"%>
<%@page import="LoginDb.DbHandler"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>

<%@page import="java.util.UUID" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Account Modification</title>
        <link rel="shortcut icon" href="${pageContext.request.contextPath}/img/favicon.ico" type="image/x-icon" />
        <link rel="stylesheet" type="text/css" href="/PacsApplication/css/TableCSSCode.css" />
        <link rel="stylesheet" type="text/css" href="/PacsApplication/css/styles.css?pacs=<%=((new java.util.Date()).getTime())%>"/>
        <link rel="stylesheet" type="text/css" href="/PacsApplication/css/ButtonAndText.css?pacs=<%=((new java.util.Date()).getTime())%>" />
        <link rel="stylesheet" type="text/css" href="/PacsApplication/css/info.css?pacs=<%=((new java.util.Date()).getTime())%>" />

        <script type="text/javascript" src="${pageContext.request.contextPath}/jquery-ui-1.10.4.custom/development-bundle/jquery-1.10.2.js?pacs=<%=((new java.util.Date()).getTime())%>"></script>
        <script type="text/javascript" src="/PacsApplication/chromejs/chrome.js?pacs=<%=((new java.util.Date()).getTime())%>"></script>
        <script type="text/javascript" src="/PacsApplication/js/iFrame_killer.js"></script>
    </head>
    <body  onload="noBack()">
        <script type="text/javascript">
            function noBack()
            {
                window.history.forward();
            }

            function ShowParent()
            {
                document.forms[0].action="${pageContext.request.contextPath}/Loan/RepayLoan.jsp";
                document.forms[0].submit();
            }

            function checkDiv(RepayLoan){
                var repayAmt = parseFloat(Math.abs(RepayLoan.repayAmt.value)).toFixed(2);
                var resTXNAmt = parseFloat(Math.abs(RepayLoan.resTXNAmt.value)).toFixed(2);

                if(RepayLoan.loanAcc.value == ""){
                    alert("Account Number field is empty");
                    RepayLoan.loanAcc.focus();
                    return false;
                }
                if(RepayLoan.custName.value == ""){
                    alert("Please select the account number from the search button to populate the other values");
                    RepayLoan.loanAcc.focus();
                    return false;
                }
                re = /^(?=.*\d)\d*(?:\.\d*)?$/; //this checks whether field contains digits
                if (!re.test(RepayLoan.loanAcc.value))
                {
                    alert("Account No. could only contain numbers");
                    RepayLoan.loanAcc.focus();
                    return false;
                }
                if(RepayLoan.repayAmt.value == ""){
                    alert("Please enter the repay amount first");
                    RepayLoan.repayAmt.focus();
                    return false;
                }
                if (!re.test(RepayLoan.repayAmt.value))
                {
                    alert("Repayment amount could contain only numbers");
                    RepayLoan.repayAmt.focus();
                    return false;
                }
                if (RepayLoan.intAdjAmt.value == "")
                {
                    alert("Please enter interest adjustment amount");
                    RepayLoan.intAdjAmt.focus();
                    return false;
                }
                if(RepayLoan.payMode.value == ""){
                    alert("Please select the payment mode first");
                    RepayLoan.payMode.focus();
                    return false;
                }
                if(RepayLoan.narration.value == ""){
                    alert("Please provide narration");
                    RepayLoan.narration.focus();
                    return false;
                }
                if(RepayLoan.payMode.value == "T"){
                    if(RepayLoan.transAcc.value == ""){
                        alert("Transfer account Number field is empty");
                        RepayLoan.transAcc.focus();
                        return false;
                    }
                    if (!re.test(RepayLoan.transAcc.value))
                    {
                        alert("Transfer account No. could only contain numbers");
                        RepayLoan.transAcc.focus();
                        return false;
                    }
                }
                if((RepayLoan.payMode.value == "C") && (Number(resTXNAmt) != Number(repayAmt))){
                    alert("Please fill-in the cash denominations");
                    $("#repayAmt").click();
                    return false;
                }
                if (parseFloat($("#intAdjAmt").val()) < 0)
                {
                    if(confirm("Negetive Interest adjustment amount increases the interest"))
                        alert("Repay Amount: " + document.getElementById("repayAmt").value);
                    else
                        return false;

                }
                if (parseFloat($("#intAdjAmt").val()) > 0)
                {
                    var amt = parseFloat(document.getElementById("repayAmt").value);
                    //alert("Repay Amount: " + amt);
                    if(confirm("Positive Interest adjustment amount decreases the interest")){
                        if(!confirm("Repay Amount: " + amt))
                            return false;
                        }
                    else
                        return false;

                }
                return true;
            }

            function popup_LonAcc(width, height, loanAcc, repayType) {
                if (window.innerWidth) {
                    LeftPosition = (window.innerWidth - width) / 2;
                    TopPosition = ((window.innerHeight - height) / 2) - 20;
                }
                else {
                    LeftPosition = (parseInt(window.screen.width) - width) / 2;
                    TopPosition = ((parseInt(window.screen.height) - height) / 2) - 20;
                }
                attr = 'resizable=yes,scrollbars=yes,width=' + width + ',height=' +
                    height + ',screenX=300,screenY=200,left=' + LeftPosition + ',top=' +
                    TopPosition + '';
                var screenName = "RepayLoan.jsp";
                var  lovKey="LoanAcctSearch"
                popWin = open('${pageContext.request.contextPath}/CommonSearchInformationLoanLOV.jsp?repayType=' + repayType + '&loanAcc=' + loanAcc + '&screenName=' + screenName+'&lovKey='+lovKey, 'LoanAcctSearch', attr);
                popWin.focus();

            }

            function popup_TransferAcc(width, height, loanAcc) {
                if (window.innerWidth) {
                    LeftPosition = (window.innerWidth - width) / 2;
                    TopPosition = ((window.innerHeight - height) / 2) - 20;
                }
                else {
                    LeftPosition = (parseInt(window.screen.width) - width) / 2;
                    TopPosition = ((parseInt(window.screen.height) - height) / 2) - 20;
                }
                attr = 'resizable=yes,scrollbars=yes,width=' + width + ',height=' +
                    height + ',screenX=300,screenY=200,left=' + LeftPosition + ',top=' +
                    TopPosition + '';
                var screenName = "RepayLoan.jsp";
                var  lovKey="transferAccSrch"
                popWin = open('${pageContext.request.contextPath}/CommonSearchInformationLoanLOV.jsp?loanAcc=' + loanAcc + '&screenName=' + screenName+'&lovKey='+lovKey, 'LoanAcctSearch', attr);
                popWin.focus();

            }

            function popup_glAcc(width, height, glAcc) {
                if (window.innerWidth) {
                    LeftPosition = (window.innerWidth - width) / 2;
                    TopPosition = ((window.innerHeight - height) / 2) - 20;
                }
                else {
                    LeftPosition = (parseInt(window.screen.width) - width) / 2;
                    TopPosition = ((parseInt(window.screen.height) - height) / 2) - 20;
                }
                attr = 'resizable=yes,scrollbars=yes,width=' + width + ',height=' +
                    height + ',screenX=300,screenY=200,left=' + LeftPosition + ',top=' +
                    TopPosition + '';
                var screenName = "RepayLoan.jsp";
                var  lovKey="glAccSrch"
                popWin = open('${pageContext.request.contextPath}/CommonSearchInformationLoanLOV.jsp?glAcc=' + glAcc + '&screenName=' + screenName+'&lovKey='+lovKey, 'glAcctSearch', attr);
                popWin.focus();

            }

            function submitform(RepayLoan)
            {
                if(checkDiv(RepayLoan)){
                    document.forms[0].handle_id.value = "SearchLoanAcc";
                    document.forms[0].action = '/PacsApplication/RepayLoanServlet';
                    document.forms[0].submit();
                }

            }

            function isNumberKey(evt)
            {
                //alert(event.charCode);
                var charCode = (evt.which) ? evt.which : evt.keyCode;

                if (charCode != 46 && charCode > 31 && charCode != 45
                    && (charCode < 48 || charCode > 57))
                    return false;

                //$( "#btnReset" ).click();
                /*if(document.getElementById("repayType").value == "C" && document.getElementById("intAdjAmt").value != "")
                    calcAmt();*/
                return true;
            }

            function checkAmt(){
                if(document.getElementById("repayType").value == "C" && document.getElementById("intAdjAmt").value != "")
                    calcAmt();
                else if(document.getElementById("repayType").value == "C" && document.getElementById("intAdjAmt").value == "")
                    document.getElementById("repayAmt").value = $("#closeAmt").val();
            }

            function calcAmt() {
                var closeAmt = parseFloat($("#closeAmt").val());
                //var txnamt = parseFloat($("#txnamt").val());
                //var tranType = $("#tranType").val();
                var intAdjAmt = parseFloat($("#intAdjAmt").val());
                var net = parseFloat(0);

                net = closeAmt - intAdjAmt;
                document.getElementById("repayAmt").value = net;

            }

            $(document).ready(function () {
                $('select#payMode').change(function () {
                    $( "#btnReset" ).click();
                    $('#transAcc').val('');
                    //$('#repayAmt').val('');
                    var shouldEnable = $(this).val();
                    $('#narration').val('');
                    switch(shouldEnable)
                    {
                        case 'C':
                            $('#transferAccount').hide();
                            $('#glAccount').hide();
                            break;
                        case 'T':
                            $('#transferAccount').show(500);
                            $('#glAccount').hide();
                            break;
                        case 'G':
                            $('#glAccount').show();
                            $('#transferAccount').hide();
                            break;
                        default:
                            $('#transferAccount').hide();
                    }
                });
                $('select#repayType').change(function () {
                    var shouldEnable = $(this).val();
                    $('#lonDetails').hide();
                    //$('#narration').val('');
                    switch(shouldEnable)
                    {
                        case 'C':
                            document.getElementById("repayAmt").readOnly = true;
                            break;
                        case 'R':
                            document.getElementById("repayAmt").readOnly = false;
                            break;
                        default:
                            document.getElementById("repayAmt").readOnly = false;
                    }
                });
            });

            $(function() {
                $("#repayAmt").click(function() {
                    if($('#loanAcc').val() == ""){
                        alert("Please select a proper loan a/c number.");
                    } else if($('#intAdjAmt').val() == ""){
                        alert("Please enter interest adjustment amount");
                    } else if($('#status').val() == "C" && $('#payMode').val() == "C"){
                        alert("Cash Drawer isn't opened yet!");
                    }else{
                        if ($('#payMode').val() == "C"){

                            $("#myform").show(500);
                        }
                        else if ($('#payMode').val() == null){

                            alert("Please select payment mode first");
                        }
                    }
                })
            });


        </script>
        <%!
            String blankNull(String s) {
                return (s == null) ? "" : s;
            }
        %>
        <%
             String ModuleName = new String();

             ModuleName = (String) session.getAttribute("moduleName");
        %>
        <%
             String error_msg = "";
             Object error = request.getAttribute("message");
             if (error != null) {
                 error_msg = error.toString();
             }
        %>


        <%if (ModuleName.equalsIgnoreCase("Deposit")) {%>
        <jsp:include page="/Deposit/MenuHead_Deposit.jsp" flush="true" />
        <%} else if (ModuleName.equalsIgnoreCase("Loan")) {%>
        <jsp:include page="/Loan/MenuHead_Loan.jsp" flush="true" />
        <%}%>
        <br>

        <fieldset style="border-color: black; background-image: url('/PacsApplication/img/download.jpg'); border-width: 3px">
            <legend style="padding: 8px; border-radius: 20px; background-color: #006600; color: white">ACCOUNT MODIFICATION OPERATION</legend>

            <form name="AccModifyForm" method="post">

                <%if (!error_msg.equalsIgnoreCase("")) {%>
                <center><div class="info" id="errorMessage"><center><%= error_msg%></center></div></center>
                <% }%>
                <br>

                <center><lable style=" font-family: Berlin Sans FB; font-weight:  normal;">Operation Selection</lable>
                    <select name="checkOption" id="checkOption">
                        <option value="">--select--</option>
                        <option value="c">CIF Change</option>

                    </select>
                </center>
                <br>
            </form>
                </fieldset>
    </body>
</html>
