<%--
    Document   : Loan Principal Adjustment
    Created on : Aug 29, 2019, 6:00:55 PM
    Author     : 1242938
--%>

<%@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">
<%String uuid = UUID.randomUUID().toString();%>
<% try {
%>

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Loan Principal Adjustment</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 src="${pageContext.request.contextPath}/js/Calendar.js?pacs=<%=((new java.util.Date()).getTime())%>"></script>
        <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>

        <style>
            .beforeAccSrch {
                display: none;
            }
        </style>
    </head>
    <body  onload="noBack()">
        <script type="text/javascript">
            function noBack()
            {
                window.history.forward();
                document.getElementById("Submit").disabled = true;
                document.getElementById("Submit").style.backgroundColor ='grey';
                
            }
                       
            function ShowParent()
            {

                document.forms[0].action = "${pageContext.request.contextPath}/Loan/LoanPrincipalAdjustment.jsp";
                document.forms[0].submit();
            }
            
            $(document).ready(function(){
	                $('#newPrincipal').on("cut copy paste",function(e) {
	                    e.preventDefault();
	                });
	                $('#bglAccNo').on("cut copy paste",function(e) {
	                    e.preventDefault();
	                });
	            });

            function popup_Acc(width, height, Acc) {

                document.getElementById("Submit").disabled = false;
                document.getElementById("Submit").style.backgroundColor ='#006600';

                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 = "LoanPrincipalAdjustment.jsp";
                var  lovKey="AccSrch"
                popWin = open('${pageContext.request.contextPath}/CommonSearchInfoLOVNew.jsp?Acc=' + Acc + '&screenName=' + screenName+'&lovKey='+lovKey, 'AccSrch', attr);
                popWin.focus();

            }
            function popup_bglAcc(width, height, Acc) {

                document.getElementById("Submit").disabled = false;
                document.getElementById("Submit").style.backgroundColor ='#006600';

                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 = "LoanPrincipalAdjustment.jsp";
                var  lovKey="bglAcc"
                popWin = open('${pageContext.request.contextPath}/CommonSearchInfoLOVNew.jsp?Acc=' + Acc + '&screenName=' + screenName+'&lovKey='+lovKey, 'bglAcc', attr);
                popWin.focus();

            }

            function submitform(){
                if(validateForm()){
                    document.loanPrinAdj.action = '/PacsApplication/LoanPrincipalAdjustmentServlet';
                    document.loanPrinAdj.submit();
                }
            }
            <%--function validateForm(){
                
                var newPrin = document.getElementById("newPrincipal").value;
                var num = parseFloat(newPrin).toFixed(2);
                document.getElementById("newPrincipal").value = num;

                if($('#accNo').val() == ""){
                    alert("Account Number cannot be blank.");
                    loanPrinAdj.accNo.focus();
                    return false;
                }
                if($('#newPrincipal').val() == ""){
                    alert("New Principal cannot be blank.");
                    loanPrinAdj.newPrincipal.focus();
                    return false;
                }
                if($('#bglAccNo').val() == ""){
                    alert("BGL Account Number cannot be blank.");
                    loanPrinAdj.bglAccNo.focus();
                    return false;
                }
                if($('#narration').val() == ""){
                    alert("Narration cannot be blank.");
                    loanPrinAdj.narration.focus();
                    return false;
                }
                
                return true;
            } --%>

            function validateForm(){

	                var newPrin = document.getElementById("newPrincipal").value;

	                var filter = /^[0-9]{17}$/;

	                if($('#accNo').val() == ""){
	                    alert("Account Number cannot be blank.");

	                    return false;
	                }

	                if($('#curPrincipal').val() == ""){
	                    alert("Please search the account number to proceed.");
	                    $('#accNo').focus();
	                    return false;
	                }

	                if($('#newPrincipal').val() == ""){
	                    alert("New principal cannot be blank.");
	                    $('#newPrincipal').focus();
	                    return false;
	                } else {
	                    var num = parseFloat(newPrin).toFixed(2);
	                    document.getElementById("newPrincipal").value = num;
	                }

	                if(newPrin >= 0){
	                    alert("Please enter new principal in negative figure.");
	                    document.getElementById("newPrincipal").focus();
	                    return false;
	                }

	                if($('#bglAccNo').val() == ""){
	                    alert("BGL Account Number cannot be blank.");
	                    $('#bglAccNo').focus();
	                    return false;
	                }

	                if(!filter.test($('#bglAccNo').val())){
	                    alert("BGL account number is incorrect. Please search BGL to proceed.");
	                    $('#bglAccNo').focus();
	                    return false;
	                }

	                if($('#narration').val() == ""){
	                    alert("Narration cannot be blank");
	                    $('#narration').focus();
	                    return false;
	                }

	                return true;
	            }
                    
            // to restrict back button
            history.pushState(null, null, location.href);
            window.addEventListener('popstate', function(event) {
                history.pushState(null, null, location.href);
            });        
            
        </script>

        <%
             String ModuleName = new String();
             ModuleName = (String) session.getAttribute("moduleName");
        %>

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

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

                 String error_msg = "";
                 Object error = request.getAttribute("message1");
                  if (error != null) {
                     error_msg = error.toString();

                 }
         %>

        <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">Loan Principal Adjustment</legend>
            <%if (!error_msg.equalsIgnoreCase("")) {%>
                    <center><div class="info" id="errorMessage"><center><%= error_msg%></center></div></center>
                    <% }%>
            <form name="loanPrinAdj" id="loanPrinAdj" action="" method="post">
                
                <br><br>

                <center>
                    <table>
                        <tbody>
                            <tr>
                                <td style="text-align: right">Account Number<font color="red" >*</font>: </td>
                                <td><input type="text" name="accNo" id="accNo" value="" style="text-align:right;" onkeypress='return event.charCode >= 48 && event.charCode <= 57' /></td>
                                <td><input type="button" value="Search" onclick="javascript:popup_Acc(500,300,$('#accNo').val());"/></td>
                                <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
                            </tr>
                            <tr>         
                              <td style="text-align: right">Current Principal: </td>
                              <td><input type="text" readOnly name="curPrincipal" id="curPrincipal" style="text-align:right;" /></td>
                              <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
                           </tr>
                           <tr>
                              <td style="text-align: right">New Principal<font color="red" >*</font>: </td>
                              <td><input type="text" name="newPrincipal" id="newPrincipal" value="" style="text-align:right;" onkeypress='return event.charCode >= 45 && event.charCode <= 57' /></td>
                              <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td> 
                           </tr>
                           <tr>
                                <td>Reconciliation BGL Account Number<font color="red" >*</font>: </td>
                                <td><input type="text" name="bglAccNo" id="bglAccNo" value="" style="text-align:right;" onkeypress='return event.charCode >= 48 && event.charCode <= 57' /></td>
                                <td><input type="button" value="Search" onclick="javascript:popup_bglAcc(500,300,$('#bglAccNo').val());" /></td>
                                <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
                           </tr>
                            <tr>
                              <td style="text-align: right">Narration<font color="red" >*</font>: </td>
                              <td><input type="description" name="narration" id="narration" /></td>
                              <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
                           </tr>
                            
                        </tbody>

                    </table>
                    <br> <br>
                    <input type="button" value="Submit  " id="Submit" onclick="submitform();" />
                    <input type="button" value="Reset" id="Reset" onclick="ShowParent();" />
                   
                    <input type="hidden" value="" id="intCat" name="intCat" />
                </center>
            </form>
        </fieldset>
    </body>
</html>
<% 	} catch (Exception e) {
               
            }
%>