<%--
    Document   : glTransactionEnquiry
    Created on : Aug 3, 2015, 2:23:35 PM
    Author     : Administrator
--%>
<%@page import="DataEntryBean.GLTransactionEnquiryBean"%>
<%@page import="LoginDb.DbHandler"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Connection"%>
<%@page import="java.util.ArrayList"%>
<html>
    <head>
        <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())%>" />
        <title>GL Transaction Enquiry</title>
        <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>
    <body  onload="noBack()">
        <script type="text/javascript">
            function noBack()
            {
                window.history.forward();
            }

            function accountsubmitform(enquiryForm)
            {
                if(!checkdate()){

                    alert("Please Select valid date range");
                    return false;
                }
                if( document.forms[0].accountNo.value == ""  )
                {
                    alert("Please enter Account Number.");
                    document.forms[0].accountNo.focus();
                    return false;
                }
                if ( document.forms[0].fromDate.value =="" )
                {
                    alert("Please enter From Date.");
                    document.forms[0].fromDate.focus();
                    return false;
                }
                if ( document.forms[0].toDate.value =="" )
                {
                    alert("Please enter To Date.");
                    document.forms[0].toDate.focus();
                    return false;
                }
                document.forms[0].totalRecordCount.value=0;
                document.forms[0].action = '/PacsApplication/EnquiryServlet';
                document.forms[0].submit();
            }
            function ShowParent()
            {
                document.forms[0].action = "glTransactionEnquiry.jsp";
                document.forms[0].submit();
            }

            function excelDownload() {

                document.forms[0].action = '/PacsApplication/ExcelReportServlet';
                document.forms[0].submit();
            }

             ///added Later
            function checkdate()
            {
                var s1 = document.getElementById("fromDate").value;
                var s2 = document.getElementById("toDate").value;
                var dateParts1 = s1.split("/");
                var dateParts2 = s2.split("/");

                var dateObject1 = new Date(dateParts1[2], dateParts1[1] - 1, dateParts1[0]);
                var dateObject2 = new Date(dateParts2[2], dateParts2[1] - 1, dateParts2[0]);

                if (dateObject1>dateObject2){

                    return false;
                }

                return true;
            }

            function callNextPage()
            {
                var totalRecordCount=document.forms[0].totalRecordCount.value;
                var recordCount=document.forms[0].recordCount.value;

                if (totalRecordCount==recordCount){

                    alert("No more record to display");
                    return false;
                }

                document.forms[0].but_type.value = 'N';
                document.forms[0].action = '/PacsApplication/EnquiryServlet';
                document.forms[0].submit();
            }

            function callPrevPage()
            {
                var totalRecordCount= document.forms[0].totalRecordCount.value;
                var noOfRecords= document.forms[0].noOfRecords.value;
                document.forms[0].totalRecordCount.value= Number(totalRecordCount) - Number(noOfRecords)-10;
                document.forms[0].but_type.value = 'P';
                document.forms[0].action = '/PacsApplication/EnquiryServlet';
                document.forms[0].submit();
            }

            function popup_glAcc(width, height, prodName) {
                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 = "glTransactionEnquiry.jsp";
                var lovKey = "PopupGlAcc"
                popWin = open('${pageContext.request.contextPath}/CommonSearchInformationLOV.jsp?prodName=' + prodName + '&screenName=' + screenName + '&lovKey=' + lovKey, 'PopupGlAcc', attr);
                popWin.focus();
            }
            
            // to restrict back button
            history.pushState(null, null, location.href);
            window.addEventListener('popstate', function(event) {
                history.pushState(null, null, location.href);
            });

        </script>

        <%
            String displayFlag = "";
            Object display = request.getAttribute("displayFlag");
            if (display != null) {
                displayFlag = display.toString();
            }
        %>

                <%
                    String ModuleName = new String();

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

        <% if (ModuleName.equalsIgnoreCase("KCC")) {%>
        <jsp:include page="MenuHead.jsp" flush="true" />
        <%} else 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" />
        <%}else if (ModuleName.equalsIgnoreCase("SpecialBothKcc")) {%>
        <jsp:include page="/MenuHead.jsp" flush="true" />
        <%}else if (ModuleName.equalsIgnoreCase("SpecialBothDep")) {%>
        <jsp:include page="/Deposit/MenuHead_Deposit.jsp" flush="true" />
        <%}else if (ModuleName.equalsIgnoreCase("SpecialBoth")) {%>
        <jsp:include page="/Deposit/MenuHead_Deposit.jsp" flush="true" />
        <%}else if (ModuleName.equalsIgnoreCase("Special")) {%>
        <jsp:include page="/Deposit/MenuHead_Deposit.jsp" flush="true" />
        <%}%>
        <br>

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

        <%
            String error_msg = "";
            Object error = request.getAttribute("message");
            if (error != null) {
                error_msg = error.toString();
            }
        %>
        <%
            String pacsId = (String) session.getAttribute("pacsId");
            Object alGlTransactionEnquiryBeanObj = request.getAttribute("alGlTransactionEnquiryBean");
            ArrayList<GLTransactionEnquiryBean> alTransactionEnquiryBean = new ArrayList<GLTransactionEnquiryBean>();
            if (alGlTransactionEnquiryBeanObj != null) {
                alTransactionEnquiryBean = (ArrayList<GLTransactionEnquiryBean>) request.getAttribute("alGlTransactionEnquiryBean");

            }
        %>
        <%
            Object oGlTransactionEnquiryBeanobj = request.getAttribute("oGlTransactionEnquiryBeanSearchObj");
            GLTransactionEnquiryBean oGLTransactionEnquiryBean = new GLTransactionEnquiryBean();
            if (oGlTransactionEnquiryBeanobj != null) {
                oGLTransactionEnquiryBean = (GLTransactionEnquiryBean) request.getAttribute("oGlTransactionEnquiryBeanSearchObj");

                session.setAttribute("oGlTransactionEnquiryBeanobj", oGlTransactionEnquiryBeanobj);

            }
        %>


        <%
                    int flag2 = 1;
                    int curPage = 0;
                    try {
                        curPage = Integer.parseInt(request.getAttribute("currentPage").toString());
                    } catch (Exception e) {
                        curPage = 1;
                    }
                    if (alTransactionEnquiryBean.size() > 0) {
                        flag2 = 2;
                    }
                    int totalRecordCount = 0;
                    int recordCount = 0;

                    try {
                        totalRecordCount = Integer.parseInt(request.getAttribute("totalRecordCount").toString());
                        recordCount = Integer.parseInt(request.getAttribute("recordCount").toString());
                    } catch (Exception e) {
                        totalRecordCount = 0;
                        recordCount = 0;
                    }
                    totalRecordCount = totalRecordCount + alTransactionEnquiryBean.size();

        %>
        <%String subPacsFlag = (String) session.getAttribute("subPacsFlag");
        %>


        <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">GL Transaction Enquiry Details</legend>
            <form name="enquiryForm" method="post" action="EnquiryServlet">

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

                <div id="filterDiv">
                    <%--<center>--%>
                        <table>
                            <tr>
                                <td align="right">GL Account Number<font color="red" >*</font>:</td>
                                <td align="left"><input value="<%=blankNull(oGLTransactionEnquiryBean.getAccountNo())%>" type="text" name="accountNo" id="accountNo" style="text-align:right;" onkeypress='return event.charCode >= 48 && event.charCode <= 57'/></td>
                                <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
                                <%--<td align="right">Product Name:</td>
                                <td><input type="text" id="prodName" name="prodName" value="<%=blankNull(oGLTransactionEnquiryBean.getProductName())%>"/><input type="button" value="Search" onclick="javascript:popup_glAcc(220, 180, document.enquiryForm.prodName.value);"/><input type="hidden" id="productName" name="productName" value=""/></td> --%>
                            </tr>
                            <tr><td><br></td></tr>
                            <tr>
                                <td align="right">From Date<font color="red" >*</font>:</td>
                                <td align="left"><input value="<%=blankNull(oGLTransactionEnquiryBean.getFromDate())%>" type="text" style="text-align:center;" name="fromDate" id="fromDate"  resize="yes" readonly="true"/>&nbsp;<a href="#" onclick="return getCalendar(document.forms[0].fromDate);"><img src="img/calendar.jpg" name="imgr" border="0" width="25" height="20" /></a></td>
                                <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
                                <td align="right">To Date<font color="red" >*</font>:</td>
                                <td align="left"><input value="<%=blankNull(oGLTransactionEnquiryBean.getToDate())%>" type="text" style="text-align:center;" name="toDate"  id="toDate" resize="yes" readonly="true"/>&nbsp;<a href="#" onclick="return getCalendar(document.forms[0].toDate);"><img src="img/calendar.jpg" name="imgr" border="0" width="25" height="20" /></a></td>
                            </tr>
                            <tr><td><br></td></tr>
                            <tr>
                                <td align="right">From Amount:</td>
                                <td align="left"><input value="<%=blankNull(oGLTransactionEnquiryBean.getFromAmount())%>" type="text" style="text-align:right;" onkeypress='return event.charCode >= 46 && event.charCode <= 57' name="fromAmount"  /></td>
                                <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
                                <td align="right">To Amount:</td>
                                <td align="left"><input value="<%=blankNull(oGLTransactionEnquiryBean.getToAmount())%>" type="text" style="text-align:right;" onkeypress='return event.charCode >= 46 && event.charCode <= 57' name="toAmount" /></td>
                            </tr>
                            <tr>
                            <td><br></td>
                             <tr>
                                 <td align="right">Transaction Reference Number:</td>
                                 <td align="left"><input value="<%=blankNull(oGLTransactionEnquiryBean.getTranRefSearch())%>" type="text" style="text-align:right;" onkeypress='return event.charCode >= 48 && event.charCode <= 57' name="tranRefSearch"  /></td>
                                 <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
                                 <td style="text-align: right">Sub-PACS Name: </td>
                                <td ><select id="subpacs_id"  name="subpacs_id" >
                                        <%if (oGLTransactionEnquiryBean.getSubpacs_id() == null) {%>
                                        <option value="" disabled selected style="display:none;">--Select--</option>
                                        <%if (subPacsFlag.equalsIgnoreCase("N")) {%>
                                            <option value="<%=pacsId%>">Own Pacs</option>
                                            <% }%>
                                        <%
                                            Connection connection = null;
                                            ResultSet rs = null;
                                            Statement statement = null;
                                            connection = DbHandler.getDBConnection();
                                            try {
                                                statement = connection.createStatement();
                                                rs = statement.executeQuery("select m.pacs_id,m.pacs_name from pacs_master m where m.head_pacs_id = '" + pacsId + "' and m.pacs_id <> '" + pacsId + "'");
                                                if(!rs.isBeforeFirst()){%>
                                                <option value="" selected>No Item to Select</option>
                                                <%}
                                                else{
                                                while (rs.next()) {%>
                                        <option value="<%=rs.getString(1)%>"><%=rs.getString(2)%></option>
                                        <%}
                                                }
                                               // statement.close();
                                               // connection.close();
                                            }  catch (Exception e) {
                System.out.println("Error occurred during processing.");
            } finally {
                try {
                    if(statement !=null)
                        statement.close();
                    if (connection != null)
                    connection.close();

            } catch (Exception e) {               
               System.out.println("Error Occurred during connection close.");
            }

            }
                                        } else {%>
                                        <option value="<%=blankNull(oGLTransactionEnquiryBean.getSubpacs_id())%>" selected style="display:none;"><%=blankNull(oGLTransactionEnquiryBean.getSubpacs_name())%></option>
                                        <%if (subPacsFlag.equalsIgnoreCase("N")) {%>
                                            <option value="<%=pacsId%>">Own Pacs</option>
                                            <% }%>
                                        <%
                                            Connection connection = null;
                                            ResultSet rs = null;
                                            Statement statement = null;
                                            connection = DbHandler.getDBConnection();
                                            try {
                                                statement = connection.createStatement();
                                                rs = statement.executeQuery("select m.pacs_id,m.pacs_name from pacs_master m where m.head_pacs_id = '" + pacsId + "' and m.pacs_id <> m.head_pacs_id ");
                                                if(!rs.isBeforeFirst()){%>
                                                <option value="" selected>No Item to Select</option>
                                                <%}
                                                else{
                                                while (rs.next()) {%>
                                        <option value="<%=rs.getString(1)%>"><%=rs.getString(2)%></option>
                                        <%}
                                                }
                                                           // statement.close();
                                                           // connection.close();
                                                        }  catch (Exception e) {
                System.out.println("Error occurred during processing.");
            } finally {
                try {
                    if(statement !=null)
                        statement.close();
                    if (connection != null)
                    connection.close();

            } catch (Exception e) {               
               System.out.println("Error Occurred during connection close.");
            }

            }
                                                    }%>
                                    </select></td>
                            </tr>
                        </table>
                        <br>
                        <br>
                    <center>
                        <input type="button" value="Submit" onclick="javascript:accountsubmitform(enquiryForm)">
                        <input type="button" value="Reset" name="reset" onclick="ShowParent();" />
                    </center>
                </div><br><br>
                <input type="hidden" value="glTransactionEnquiry" name="screenName" />

                <input name="handle_id" id="handle_id" type="hidden" value="" />
                <input name="reportname" id="reportname" type="hidden" value="GL_TRANSACTION_ENQUIRY_REPORT" />
                <input type="hidden" name="page" value="<%=request.getAttribute("currentPage")%>">
                <input type="hidden" name="but_type" >
                <input type="hidden" name="totalRecordCount" id="totalRecordCount" value="<%=totalRecordCount%>">
                <input type="hidden" name="recordCount" id="recordCount" value="<%=recordCount%>">
                <input type="hidden" name="noOfRecords" id="noOfRecords" value="<%=request.getAttribute("noOfRecords")%>">

            </form>

            <%if (displayFlag.equalsIgnoreCase("Y")) {%>
            <center>
                <div id="displayDiv" >

                    <table border="2" width="auto" cellspacing="1" cellpadding="1" style="text-align: center ;overflow-y: scroll">
                        <thead class="CSSTableGenerator">
                            <tr>
                                <td>GL Account No.</td>
                                <td>GL NAME</td>
                                <td>Reference No.</td>
                                <td>Transaction Date</td>
                                <td>Journal No.</td>
                                <td>Transaction Type</td>
                                <td>End Balance</td>
                                <td>Transaction Amount</td>
                                <td>Narration</td>
                                <%--<td>Transaction Account Number</td>
                                <td>Account Type</td>--%>

                            </tr>
                        </thead>
                        <tbody style="background-color: white; font-size: 15px">
                            <%
                                oGLTransactionEnquiryBean=null;

                                for (int i = 0; i < alTransactionEnquiryBean.size(); i++) {
                                    oGLTransactionEnquiryBean = alTransactionEnquiryBean.get(i);
                            %>

                            <tr>
                                <td><%=blankNull(oGLTransactionEnquiryBean.getAccountNo())%></td>
                                <td><%=blankNull(oGLTransactionEnquiryBean.getGl_code())%></td>
                                <td><%=blankNull(oGLTransactionEnquiryBean.getCbs_Ref_No())%></td>
                                <td><%=blankNull(oGLTransactionEnquiryBean.getTransactionDate())%></td>
                                <td><%=blankNull(oGLTransactionEnquiryBean.getJournalNumber())%></td>
                                <td><%=blankNull(oGLTransactionEnquiryBean.getTransactionType())%></td>
                                <td><%=blankNull(oGLTransactionEnquiryBean.getEnd_bal())%></td>
                                <td><%=blankNull(oGLTransactionEnquiryBean.getTransactionAmount())%></td>
                                <td><%=blankNull(oGLTransactionEnquiryBean.getGl_txn_narration())%></td>
                                <%--<td><%=blankNull(oGLTransactionEnquiryBean.getDest_Account_no())%></td>
                                <td><%=blankNull(oGLTransactionEnquiryBean.getAcc_Type())%></td>--%>
                            </tr>
                            <%}%>
                        </tbody>
                    </table><br><br>

                     <%--For displaying Previous link except for the 1st page --%>

                    <table align="right" colspan="2">
                        <% if (curPage > 1 && flag2 == 2) {%>
                        <td><input type="button"  name="nextPage" value="Previous" onclick="callPrevPage()"><input type="button"  name="nextPage" value="Next" onclick="callNextPage()">
                            <% }%>
                            <% if (flag2 == 2) {%>

                            <% if (curPage == 1) {%>
                        <td><input type="button"  name="nextPage" value="Next" onclick="callNextPage()">
                            <% }
                                }%>

                    </table><br><br>

                    <input type="button" value="Export Result" onclick="javascript:excelDownload()">
                </div>
            </center>
            <%}%>
        </fieldset>
    </body>
</html>

