<%--
    Document   : PrintPassbook
    Created on : Jul 18, 2017, 1:49:12 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" %>
<% out.flush(); %>
<!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>Print Passbook</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>
        #records{
            white-space: nowrap;
}
</style>--%>
    </head>
    <body onload="showPrint()">

        <script type="text/javascript">
            function popup_Acc(width, height, acc, accType, accSubType) {
                if((document.getElementById("accSubType").value == '') && (document.getElementById("accType").value == "D")){
                    alert("Select Account Sub-Type.");
                    passbookPrint.accSubType.focus();
                    return false;
                }
                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 = "PrintPassbook.jsp";
                var  lovKey="accSrch"
                popWin = open('${pageContext.request.contextPath}/CommonSearchInfoLOVNew.jsp?acc=' + acc + '&accType=' + accType+ '&accSubType=' + accSubType + '&screenName=' + screenName+'&lovKey='+lovKey, 'accSrch', attr);
                popWin.focus();

            }

            function submitform(passbookPrint)
            {
                var v;
                if(checkDiv(passbookPrint)){
                    if($('#printType').val() == "U")
                        v="Click OK for print confirmation. Records cannot be printed again";
                    if($('#printType').val() == "F")
                        v="Please confirm printing of first page";
                    
                    if(confirm(v)){
                        document.forms[0].action = '/PacsApplication/PassbookServlet';
                        document.forms[0].submit();
                    }
                }
            }

            function sendFileToServer(temp)
            {
                if(temp==1)
            {
                var formDownloadNormal = document.getElementById("PrinterSetup");
                formDownloadNormal.action = '/PacsApplication/BulkFileUploadServlet';
                formDownloadNormal.submit();
            }
            else if(temp==2)
            {
                var formDownloadNormal = document.getElementById("SamplePassbook");
                formDownloadNormal.action = '/PacsApplication/BulkFileUploadServlet';
                formDownloadNormal.submit();
                }
            }

            function ShowParent()
            {
                document.forms[0].action="${pageContext.request.contextPath}/Deposit/PrintPassbook.jsp";
                document.forms[0].submit();
            }
            
            function showPrint(){
                var printableContents = document.getElementById("records").value;
                if(printableContents == "" || printableContents == null){
                    $('#records').hide();
                    $('#print').hide();
                } else {
                    $('#records').show();
                    $('#print').show();
                }
            }

            function printPB(){
                var printableContents = document.getElementById("records").value;
                var originalContents = document.body.innerHTML;

                document.body.innerHTML = printableContents;

                window.print();

                document.body.innerHTML = originalContents;
            }

            function printTextArea() {
                records = document.getElementById('records').value;
                if(records == ""){
                    alert("No records to print");
                    return false;
                }
                childWindow = window.open('','childWindow','location=yes, menubar=yes, toolbar=yes');
                childWindow.document.open();
                childWindow.document.write('<html><head><style>@page { size: auto;  margin: 0mm; }</style></head><pre><body>');
               // childWindow.document.write(document.getElementById('records').value.replace(/\n/gi,'<br>'));
                childWindow.document.write('</body></pre></html>');
                childWindow.print();
                childWindow.document.close();
                childWindow.close();
            }

            function checkDiv(passbookPrint)
            {
                if(document.getElementById("accType").value == ''){
                    alert("Select Account Type.");
                    passbookPrint.accType.focus();
                    return false;
                }
                if((document.getElementById("accSubType").value == '') && (document.getElementById("accType").value == "D")){
                    alert("Select Account Sub-Type.");
                    passbookPrint.accSubType.focus();
                    return false;
                }
                if(document.getElementById("accNo").value == ''){
                    alert("Account number cannot be blank.");
                    passbookPrint.accNo.focus();
                    return false;
                }
                if(document.getElementById("custno").value == ''){
                    alert("Please search the account number to proceed");
                    passbookPrint.accNo.focus();
                    return false;
                }
                if(document.getElementById("printType").value == ''){
                    alert("Select Print Type.");
                    passbookPrint.printType.focus();
                    return false;
                }
                re = /^(?=.*\d)\d*(?:\.\d*)?$/; //this checks whether field contains digits
                if (!re.test(passbookPrint.accNo.value))
                {
                    alert("Account No. could only contain numbers");
                    passbookPrint.accNo.focus();
                    return false;
                }
                if(passbookPrint.printType.value == 'R'){
                    if(passbookPrint.from_date.value == '' || passbookPrint.to_date.value == ''){
                        alert("From Date and To Date cannot be blank for Re-print option");
                        return false;
                    }
                }
                return true;
            }

            $(document).ready(function () {  
                if(document.getElementById("accType").value == "K"){
                    $('#subTp').hide();
                }
                if(document.getElementById("accType").value == "L"){
                    $('#subTp').hide();
                }
                
                $('select#printType').change(function () {
                    $('#to_date').val('');
                    $('#from_date').val('');
                    var shouldEnable = $(this).val();
                    switch(shouldEnable)
                    {
                        case 'U':
                            $('#showDate1').hide();
                            $('#showDate2').hide();
                            break;
                        case 'R':
                            $('#showDate1').show();
                            $('#showDate2').show();
                            break;
                        default:
                            $('#showDate1').hide();
                            $('#showDate2').hide();
                    }
                });
                $('select#accType').change(function () {      
                    $('#accSubType').val('');
                    $('#accNo').val('');
                    var shouldEnable = $(this).val();
                    switch(shouldEnable)
                    {
                        case 'D':
                            $('#subTp').show();
                            break;
                        case 'K':
                            $('#subTp').hide();
                            break;
                        case 'L':
                            $('#subTp').hide();
                            break;    
                        default:
                            $('#subTp').show();
                    }
                });
            });
            
            // to restrict back button
            history.pushState(null, null, location.href);
            window.addEventListener('popstate', function(event) {
                history.pushState(null, null, location.href);
            });
            
        </script>

        <jsp:include page="MenuHead_Deposit.jsp" flush="true" />
        <br>
        <%   String userRole = (String) session.getAttribute("userRole");
             String error_msg = "";
             Object error = request.getAttribute("message");
             if (error != null) {
                 error_msg = error.toString();
             }

             String addToPrinter = "";
             error = request.getAttribute("addToPrinter");
             if (error != null) {
                 addToPrinter = error.toString();
             }

             String reprint = "";
             error = request.getAttribute("reprint");
             if (error != null) {
                 reprint = error.toString();
             }

             String accNo = "";
             error = request.getAttribute("accNo");
             if (error != null) {
                 accNo = error.toString();
             }
             
             String accSubType = "";
             error = request.getAttribute("accSubType");
             if (error != null) {
                 accSubType = error.toString();
             }

             String printType = "";
             error = request.getAttribute("printType");
             if (error != null) {
                 printType = error.toString();
             }
                    
            String accType = "";
             error = request.getAttribute("accType");
             if (error != null) {
                 accType = error.toString();
             }        

             String from_date = "";
             error = request.getAttribute("from_date");
             if (error != null) {
                 from_date = error.toString();
             }

             String to_date = "";
             error = request.getAttribute("to_date");
             if (error != null) {
                 to_date = error.toString();
             }


             String pageNo = "1";
             error = request.getAttribute("page");
             if (error != null) {
                 pageNo = error.toString();
             }

             int startrow = 0;
             error = request.getAttribute("startrow");
             if (error != null) {
                 startrow = Integer.parseInt(error.toString());
             }

             int endrow = 0;
             error = request.getAttribute("endrow");
             if (error != null) {
                 endrow = Integer.parseInt(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">Print Passbook</legend>
            <form name="passbookPrint" id="passbookPrint" action="" method="post">

                <%
                     if (reprint.equalsIgnoreCase("Y")) {
                %>
                <script>
                    alert("Printing is not yet complete. Please reprint from here to complete");
                </script>
                <% }%>
                <%--<center><div class="info" id="errorMessage"><center>This Screen is Under TESTING. Please DONOT Print Passbook</center></div></center> --%>

                <center>
                    <table>
                        <tr><td style="text-align:right;">Account Type<font color="red" >*</font>:</td><td></td>
                            <td><select id="accType" name="accType" ><%if ((!userRole.equalsIgnoreCase(
                     "201603000005020"))) {%>
                     <option value="D" <%if (accType.equalsIgnoreCase("D")) {%> selected <%}%>>Deposit</option><%}%>
                     <option value="K" <%if (accType.equalsIgnoreCase("K")) {%> selected <%}%>>KCC</option> 
                     <option value="L" <%if(accType.equalsIgnoreCase("L")){%> selected <%}%>>Loan</option></select>
                            </td>
                        </tr>                        
                        <tr id="subTp"><td>Account Sub-Type:</td><td></td>
                            <td><select id="accSubType" name="accSubType" onchange="javascript:$('#accNo').val('');$('#custno').val('');$('#accNo').prop('readonly', false);"><%if ((!userRole.equalsIgnoreCase(
                     "201603000005020"))) {%>
                     <option value="" selected>--Select--</option> <%}%><%{%>
                     <option value="SB" <%if(accSubType.equalsIgnoreCase("SB")) {%>selected<%}%>>Savings</option> <%}%><%{%>
                     <option value="RD" <%if(accSubType.equalsIgnoreCase("RD")) {%>selected<%}%>>Recurring</option><%}%><%{%>
                     <option value="CR" <%if(accSubType.equalsIgnoreCase("CR")) {%>selected<%}%>>Current</option><%}%><%{%>
                     <option value="SHG" <%if(accSubType.equalsIgnoreCase("SHG")) {%>selected<%}%>>SHG</option></select><%}%>
                            </td></tr>
                        <tr><td>Account Number<font color="red" >*</font>:</td><td></td><td><input type="text" maxlength="25" name="accNo" id="accNo" value="<%=accNo%>" style="text-align:right;" onkeypress='return event.charCode >= 48 && event.charCode <= 57' /></td>
                            <td><input type="button" value="Search" onclick="javascript:popup_Acc(800, 180, document.passbookPrint.accNo.value,document.passbookPrint.accType.value,document.passbookPrint.accSubType.value);"/></td></tr>
                        <tr><td style="text-align:right;">Print Type<font color="red" >*</font>:</td><td></td>
                            <td><select id="printType" name="printType" ><%if ((!userRole.equalsIgnoreCase(
                     "201603000005020"))) {%>
                     <option value="U" <%if (printType.equalsIgnoreCase("U")) {%> selected <%}%>>Update Passbook</option><%}%>
                     <option value="F" <%if (printType.equalsIgnoreCase("F")) {%> selected <%}%>>Print First Page</option> <%--<option value="R" <%if(printType.equalsIgnoreCase("Y")){%> selected <%}%>>Re-print</option> --%></select>
                            </td></tr>
                        <tr id="showDate1" style="display: none">
                            <td style=" font-family: Berlin Sans FB; font-weight:  bold;">From Date: </td><td></td><td><input type="text" style="text-align:center;" name="from_date" id="from_date" maxlength="11" resize="yes" readonly="true" value="<%=from_date%>">&nbsp;<a href="#" onclick="return getCalendar(document.forms[0].from_date);"><img src="${pageContext.request.contextPath}/img/calendar.jpg" name="imgr" border="0" width="25" height="20" /></a></td></tr><tr  id="showDate2" style="display: none">
                            <td style=" font-family: Berlin Sans FB; font-weight:  bold;">To Date: </td><td></td><td><input type="text" style="text-align:center;" name="to_date" id="to_date" maxlength="11" resize="yes" readonly="true" value="<%=to_date%>">&nbsp;<a href="#" onclick="return getCalendar(document.forms[0].to_date);"><img src="${pageContext.request.contextPath}/img/calendar.jpg" name="imgr" border="0" width="25" height="20" /></a></td>
                        </tr>
                        <tr></tr><tr></tr><tr></tr><tr></tr>


                    </table>
                    <br>
                    <input type="button" value="Get Details" id="Submit" onclick="javascript:submitform(passbookPrint)"/><input type="button" value="Reset" id="Reset" onclick="ShowParent();" />
                    <br><br>
                    <textarea id="records" name="records"  cols="125" rows="12" readonly="true"><%=addToPrinter%></textarea>

                    <br><br>
                    <input type="button" value="Print" id="print" onclick="javascript:printTextArea()"/>
                    <input type="hidden" id="custno" name="custno" value=""/>
                    <input type="hidden" id="reprint" name="reprint" value="<%=reprint%>"/>
                    <input type="hidden" id="startrow" name="startrow" value="<%=startrow%>"/>
                    <input type="hidden" id="endrow" name="endrow" value="<%=endrow%>"/>
                    <input type="hidden" id="page" name="page" value="<%=pageNo%>"/>

                </center>
            </form>

            <br><hr><br>
            <form name="PrinterSetup" id="PrinterSetup" action="" method="post" >
                    <input type="hidden" id="actionId" value="PSetup" name="actionTag">
                    <input type="button" value="Download Printer Setup Document" id ="PrinterSetup" name="FileType" onclick="sendFileToServer(1)" style="float: right"/>
            </form>
            <form name="SamplePassbook" id="SamplePassbook" action="" method="post" >
                    <input type="hidden" id="actionId" value="SPassbook" name="actionTag">
                    <input type="button" value="Download Sample Passbook File" id ="SamplePassbook" name="FileType" onclick="sendFileToServer(2)" style="float: right"/>
            </form>

        </fieldset>
    </body>
</html>
<% 	} catch (Exception e) {
                
            }
%>