<%-- 
    Document   : ChequePosting
    Created on : Jul 7, 2018, 2:34:34 PM
    Author     : 1004242
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.sql.SQLException"%>
<%@page import="LoginDb.DbHandler"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Connection"%>
<%@page import="java.util.Date"%>
<%@page import="DataEntryBean.ChequeDetailsBean"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.util.UUID" %>
<%String uuid = UUID.randomUUID().toString();%>
<% try {
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>

        <title>Cheque Posting</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <script src="${pageContext.request.contextPath}/js/Calendar.js?pacs=<%=((new java.util.Date()).getTime())%>"></script>
        <link rel="stylesheet" type="text/css" href="/PacsApplication/css/TableCSSCode.css?pacs=<%=((new java.util.Date()).getTime())%>" />
        <link rel="shortcut icon" href="${pageContext.request.contextPath}/img/favicon.ico?pacs=<%=((new java.util.Date()).getTime())%>" type="image/x-icon" />
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <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>
    <style>
        .tab {
            overflow: hidden;
            border: 1px solid #ccc;
            background-color: #d3ffd3;
        }

        /* Style the buttons that are used to open the tab content */
        .tab button {
            background-color: inherit;
            float: left;
            border: none;
            outline: none;
            cursor: pointer;
            padding: 14px 16px;
            transition: 0.3s;
        }

        /* Change background color of buttons on hover */
        .tab button:hover {
            background-color: rgb(136, 210, 140);
        }

        /* Create an active/current tablink class */
        .tab button.active {

            background-color: rgb(136, 210, 140);
        }


        /* Style the tab content */
        .tabcontent {
            display: none;
            padding: 6px 12px;
            border: 1px solid #ccc;
            border-top: none;
        }
        .tabcontent {
            animation: fadeEffect 1s; /* Fading effect takes 1 second */
        }

        /* Go from zero to full opacity */
        @keyframes fadeEffect {
            from {opacity: 0;}
        to {opacity: 1;}
        }

    </style>

    <script>
        var selectedTab = null;
        function popup_depAccount(width, height, accNo) {
            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 = "ChequePosting.jsp";
            var lovKey = "depositAccount"
            popWin = open('${pageContext.request.contextPath}/CommonSearchInfoLOVNew.jsp?accNo=' + accNo + '&screenName=' + screenName + '&lovKey=' + lovKey, 'depositAccount', attr);
            popWin.focus();

        }
        function popup_depAccountEnq(width, height, accNo) {
            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 = "ChequePosting.jsp";
            var lovKey = "chqEnq";
            popWin = open('${pageContext.request.contextPath}/CommonSearchInfoLOVNew.jsp?accNo=' + accNo + '&screenName=' + screenName + '&lovKey=' + lovKey, 'chqEnq', attr);
            popWin.focus();

        }
        function checkDiv(transferForm)
        {
            if (transferForm.accNo.value == "")
            {
                alert("Please enter Account Number.");
                transferForm.accNo.focus();
                return false;
            }
            if (transferForm.chqNo.value == "" )
            {
                alert("Please provide Cheque Number.");
                transferForm.chqNo.focus();
                return false;
            }
            if (transferForm.chqDt.value == "" )
            {
                alert("Please provide cheque date.");
                transferForm.chqDt.focus();
                return false;
            }
            if (transferForm.chqAmt.value == "" || transferForm.chqAmt.value == 0 )
            {
                alert("Cheque amount must be provided(Can not be zero).");
                transferForm.chqAmt.focus();
                return false;
            }
            if (transferForm.chqBnk.value == "" )
            {
                alert("Please provide issuer bank name.");
                transferForm.chqBnk.focus();
                return false;
            }

            return true;
        }

        function submitform(transferForm)
        {
            if(checkDiv(transferForm)){
                document.transferForm.selectedTab.value=selectedTab;
                document.transferForm.action = '/PacsApplication/ChequePostingServlet';
                document.transferForm.submit();
            }
        }

         function submitformEnq()
        {
                    document.chequeViewForm.selectedTab.value=selectedTab;
                    document.chequeViewForm.action = '/PacsApplication/ChequePostingServlet';
                    document.chequeViewForm.submit();
                    return true;
        }

        function openTab(evt, cityName) {
            // Declare all variables
            var i, tabcontent, tablinks;
            $('#transferForm').trigger("reset");
            
            if(cityName=='ChequePosting'){
            $('#chequDetTab').hide();
           
            }

            // Get all elements with class="tabcontent" and hide them
            tabcontent = document.getElementsByClassName("tabcontent");
            for (i = 0; i < tabcontent.length; i++) {
                tabcontent[i].style.display = "none";
            }

            // Get all elements with class="tablinks" and remove the class "active"
            tablinks = document.getElementsByClassName("tablinks");
            for (i = 0; i < tablinks.length; i++) {
                tablinks[i].className = tablinks[i].className.replace(" active", "");
            }

            // Show the current tab, and add an "active" class to the button that opened the tab
            document.getElementById(cityName).style.display = "block";
            evt.currentTarget.className += " active";
            selectedTab = cityName;
            
            
            
        }   


        

         function setVisibility(){
                //document.getElementById("searchBatch").style.visibility='visible';
                $('#chequDetTab').show();

            }
              function setTab(){

                  var evnt={currentTarget:null};
                  
                  evnt.currentTarget = document.getElementById("toggleTab");
                  Selectedtab = document.getElementById("toggleTab").value;
                  if(Selectedtab=="ChequePosting")
                      {
                          openTab(evnt, 'ChequePosting');
                           //$('#Posting').trigger("click");
                      }
                    if (Selectedtab=="ChequeEnquiry")
                        {
                            openTab(evnt, 'ChequeEnquiry');
                            //$('#Enquiry').click();
                        }
                        <%--else
                            {
                                openTab(evnt, 'ChequePosting');
                                 //$('#Posting').trigger("click");
                               //openTab(jquery.Event,'ChequePosting')  ;
                            }--%>                                

            }
           function processCheque(chequeViewForm ,indicator){


                    document.chequeViewForm.indicator.value=indicator;
                    document.chequeViewForm.selectedTab.value=selectedTab+"Process";
                    document.chequeViewForm.action = '/PacsApplication/ChequePostingServlet';
                    document.chequeViewForm.submit();
                    return true;

           }
               function ShowParent()
            {
                document.forms[0].action = "${pageContext.request.contextPath}/Deposit/ChequePosting.jsp";
                document.forms[0].submit();
            }
             function noBack()
            {
                window.history.forward();
            }
            
            // to restrict back button
            history.pushState(null, null, location.href);
            window.addEventListener('popstate', function(event) {
                history.pushState(null, null, location.href);
            });
        
    </script>
            <%
                 int count = 1;
                 String error_msg1 = "";
                 String error_msg2 = "";
                 Object tabSelect = null;
                 Object accNoServer = request.getAttribute("accNo");
                 String accNo ="";
                 if(accNoServer !=null)accNo=(String)accNoServer;
                 
                 ArrayList<ChequeDetailsBean> chqDetBeanList=null;
                 Object allChq = request.getAttribute("allcheque");
                 Object error1 = request.getAttribute("message1");
                 Object error2 = request.getAttribute("message2");


                 if(request.getAttribute("toggleTab") != null){
                  tabSelect = request.getAttribute("toggleTab");
                 }else
                     {
                      //  tabSelect ="CHEQUE POSTING";
                     }

                 

                 ChequeDetailsBean chqBean = null;
                 if (error1 != null) {
                     error_msg1 = error1.toString();
                 
                 }
                 else if (error2 !=null){
                        error_msg2 = error2.toString();
                 }
                 else {

                    chqDetBeanList = null;//new ArrayList<ChequeDetailsBean>();

                     if (allChq != null) {
                         chqDetBeanList = (ArrayList<ChequeDetailsBean>) request.getAttribute("allcheque");

                     }
                 }
             
                 String userRole = (String) session.getAttribute("userRole");
            %>

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


    <body onload="javascript:<%if (allChq != null) {%>setVisibility();<%}%>setTab();noBack();">
        <jsp:include page="MenuHead_Deposit.jsp" flush="true" />

        
        <div class="tab">
            <%if ((userRole.equalsIgnoreCase(
                     "201606000004041")) ) {%>
                   <button class="tablinks" onclick="openTab(event, 'ChequeEnquiry')" id="Enquiry">Cheque Enquiry-Posting</button>
                     <%}else{%>
                     <button class="tablinks" onclick="openTab(event, 'ChequePosting')" id="Posting" >Cheque Posting</button>
                     <%}%>
        </div>

        <div id="ChequePosting" class="tabcontent">
            <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"></legend>--%>
                <form name="transferForm" method="post" action="" id="transferForm">
                    <%if (!error_msg1.equalsIgnoreCase("")) {%>
                    <center><div class="info" id="errorMessage"><center><%= error_msg1%></center></div></center>
                    <% }%>
                    <br>
                    <center>
                        <td>Account Number<font color="red" >*</font>: </td>
                        <td><input type="text" name="accNo" id="accNo" style="text-align:right;" onkeypress='return event.charCode >= 48 && event.charCode <= 57' /></td>
                        <td><input type="button"  value="Search" onclick="javascript:popup_depAccount(750, 250,document.transferForm.accNo.value);"/></td>
                        <br><br>
                        <%-- <td style="text-align: right">Customer Name.: </td>
                         <td><input type="text " name="custNm" id="custNm" value="" readonly/></td>--%>
                    </center>
                    <br><br>
                    <center>
                        <table >
                            <tr>
                                <td style="text-align: right">Cheque Number<font color="red" >*</font>: </td>
                                <td><input type="text" name="chqNo" id="chqNo" value="" style="text-align:right;" onkeypress='return event.charCode >= 48 && event.charCode <= 57' /></td>
                                <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
                                <td style="text-align: right">Cheque Date<font color="red" >*</font>: </td>
                                <td><input  type="text" id="chqDt" name="chqDt" readonly style="text-align:center" />&nbsp;<a href="#" onclick="return getCalendar(document.forms[0].chqDt);"><img src="${pageContext.request.contextPath}/img/calendar.jpg" name="imgr" border="0" width="25" height="20" /></a></td>


                            </tr>
                            <tr>
                                <td style="text-align: right">Cheque Amount<font color="red" >*</font>: </td>
                                <td><input type="text" name="chqAmt" id="chqAmt" value="" style="text-align:right;" onkeypress='return event.charCode >= 46 && event.charCode <= 57'/></td>
                                <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
                                <td style="text-align: right">Cheque Issuer Bank<font color="red" >*</font>: </td>
                                <td><input type="text" name="chqBnk" id="chqBnk" value=""/></td>
                            </tr>

                        </table>
                    </center>
                    <br><br>



                    <center>
                        <input type="button" id="submitButton"  value="Submit" onclick="javascript:submitform(transferForm)">
                        <input type="reset" value="Reset" onclick="ShowParent();" />
                    </center>
                    <input type="hidden" name="screenName" value="DepositTransferOperation">

                   <input type="hidden" name="selectedTab" id="selectedTab">
                </form>
            </fieldset>
        </div>

        <div id="ChequeEnquiry" class="tabcontent" >
            <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"></legend>--%>
                <form name="chequeViewForm" method="post" action="" id="chequeViewForm">
                    <%if (!error_msg2.equalsIgnoreCase("")) {%>
                    <center><div class="info" id="errorMessage"><center><%= error_msg2%></center></div></center>
                    <% }%>
                    <br>
               
                    <center>
                        <td>Account Number:</td>
                        <td><input type="text" name="accNoEnq" id="accNoEnq" value="<%=blankNull(accNo)%>" style="text-align:right;" onkeypress='return event.charCode >= 48 && event.charCode <= 57' /></td>
                        <td><input type="button"  value="Search" onclick="javascript:popup_depAccountEnq(750, 250,document.chequeViewForm.accNoEnq.value);"/></td>
                        <br><br>
                    </center>
                    <div align="center" style="display:none" id="chequDetTab">
                        <table border="2" width="auto" cellspacing="1" cellpadding="1" style="text-align: center ;overflow-y: scroll; font-size: 15px">
                            <thead class="CSSTableGenerator">
                                <tr>

                                    <td>Cheque No</td>
                                    <td>Amount</td>
                                    <td>Bank Name</td>
                                    <td>Cheque Date</td>
                                    <td>Post Date</td>
                                    <td>Comission</td>
                                    <td>Narration</td>
                                    <td>Action</td>
                                </tr>
                            </thead>
                            <tbody>
                                <%
                                        if(chqDetBeanList !=null){
                                            for (int k = 0; k < chqDetBeanList.size(); k++) {
                                                chqBean = chqDetBeanList.get(k);
                                %>
                                <tr class="tRow">


                                    <td>  <input type="text"  readonly style="width: 120px" name="ChqNO<%=k%>" id="ChqNO<%=k%>" value="<%=chqBean.getChqno()%>" /> </td>
                                    <td>  <input type="text"  readonly  name="Amt<%=k%>" id="Amt<%=k%>" value="<%=chqBean.getChqAmnt()%>" /></td>
                                    <td>  <input type="text"  readonly style="width: 120px" name="BankName<%=k%>" id="BankName<%=k%>" value="<%=chqBean.getChqBank()%>" /> </td>
                                    <td>  <input type="text"  readonly style="text-align:center;" style="width: 120px" name="chqDate<%=k%>" id="chqDate<%=k%>" value="<%=chqBean.getChqDate()%>" /> </td>
                                    <td>  <input type="text"  readonly style="text-align:center;" style="width: 120px" name="PostDate<%=k%>" id="PostDate<%=k%>" value="<%=chqBean.getChqPostDate()%>" /> </td>
                                    <td>  <input type="text"  onkeypress='return event.charCode >= 48 && event.charCode <= 57' style="width: 120px" name="commission<%=k%>" id="commission<%=k%>"/> </td>
                                    <td>  <input type="text"   style="width: 120px" name="narration<%=k%>" id="narration<%=k%>"/> </td>
                                    <td>
                                        <select  style="width: 150px" name="action<%=k%>" id="action<%=k%>" >
                                            <option value="PASS">Pass</option>
                                            <option value="RETURN">Return</option>
                                            <option value="DELETE">Delete</option>
                                        </select>
                                         <input type="button"  value="submit" onclick="processCheque(chequeViewForm,<%=k%>)"/>
                                    </td>
                                </tr>

                                <%}
                                }%>

                            </tbody>
                        </table>
                               
                    </div>
                
                <input type="hidden" name="selectedTab" id="selectedTab">
                <input type="hidden" name="indicator" id="indicator">
                </form>
            </fieldset>
        </div>
    <input type="hidden" name="toggleTab" id="toggleTab" value="<%=tabSelect%>">
    </body>
    
</html>
<% 	} catch (Exception e) {
                
            }
%>