<%--
    Document   : inv_borr_rep
    Created on : Dec 22, 2017, 1:36:03 PM
    Author     : 1027350
--%>

<%@page import="LoginDb.DbHandler"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Connection"%>
<%@page import="java.util.ArrayList"%>
<%@page import="DataEntryBean.EnquiryBean"%>
<%@page import="java.util.Date"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.util.ArrayList" %>
<%@page import="java.lang.String" %>
<% try {
%>
<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())%>" />
        <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>

        <script>

            function downloadFiles() {

                var e = document.getElementById("reportSelection");
                var f = document.getElementById("subpacs_id");
                
                if (e.options[e.selectedIndex].value == "")
                {
                    alert("Report Name cannot be empty.");
                    document.forms[0].reportSelection.focus();
                    return false;
                }
                if (document.forms[0].to_date.value == "" )
                {
                    alert("Date cannot be empty.");
                    document.forms[0].to_date.focus();
                    return false;
                }
                
                <%--var r = "";
                if (document.getElementById("r1").checked){
                    r = document.getElementById("r1").value;
                }
                if (document.getElementById("r2").checked){
                    r = document.getElementById("r2").value;
                }
                if(r == "")
                    return;--%>
                
                if (document.forms[0].gl_id.value == "")
                {
                    alert("GL Account cannot be empty.");
                    document.forms[0].gl_id.focus();
                    return false;
                }

                switch (e.options[e.selectedIndex].value) {

                    case "i" :

                        document.forms[0].reportPath.value = "/Reports/investmentdetail";
                        document.forms[0].reportName.value = "INVESTMENT DETAIL REPORT";
                        document.forms[0].DOWNLOAD.value = "P";
                        break;

                    case "b" :

                        document.forms[0].reportPath.value = "/Reports/borrowingdetail";
                        document.forms[0].reportName.value = "BORROWING DETAIL REPORT";
                        document.forms[0].DOWNLOAD.value = "P";
                        break;

                    case "3" :

                        document.forms[0].reportPath.value = "/Reports/transferTxnReport";
                        document.forms[0].reportName.value = "TRANSFER TRANSACTION REPORT";
                        document.forms[0].DOWNLOAD.value = "P";
                        break;

                    default :

                        null;

                }

                document.forms[0].action = '/PacsApplication/ExcelReportServlet';
                if (document.getElementById("gl_id").value == ""){
                    document.getElementById("gl_id").value = "ALL";
                }
                document.forms[0].submit();

            }

            $(document).ready(function () {
                $('select#reportSelection').change(function () {
                    var shouldEnable = $(this).val();
                    switch(shouldEnable)
                    {
                        case '6':
                            $('#dep_prod').show(500);
                            break;
                        default:
                            $('#dep_prod').hide();
                            break;
                    }
                })
            });

            <%--function handleClick(opType) {
                var buttonType = 0;
                buttonType = opType.value;
                if (buttonType=='i'){
                    document.getElementById('reportSelection').options.selectedIndex=0;
                    document.getElementById('reportSelection').options[2].disabled =true;
                    document.getElementById('reportSelection').options[1].disabled =false;
                }

                if (buttonType=='b'){
                    document.getElementById('reportSelection').options.selectedIndex=0;
                    document.getElementById('reportSelection').options[1].disabled =true;
                    document.getElementById('reportSelection').options[2].disabled =false;
                }

            }--%>

            function searchGL(width, height,x)
            {

               // var r = document.getElementById("reportSelection").value;
                <%--if (document.getElementById("r1").checked){
                    r = document.getElementById("r1").value;
                }
                else if (document.getElementById("r2").checked){
                    r = document.getElementById("r2").value;
                }
                else {
                    alert("!! Please Select Any One Button !!");
                    return;
                }--%>
                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 = "inv_borr_rep.jsp";
                var  lovKey=    "searchGl";
                popWin = open('${pageContext.request.contextPath}/CommonSearchInformationLOV.jsp?screenName=' + screenName+'&lovKey='+lovKey+'&acNo='+x+'&searchKey='+r , 'GLSearch', attr);
                popWin.focus();
            }

            function ShowParent()
            {

                document.forms[0].action = "${pageContext.request.contextPath}/Deposit/inv_borr_rep.jsp";
                document.forms[0].submit();
            }
        
        // to restrict back button
            history.pushState(null, null, location.href);
            window.addEventListener('popstate', function(event) {
                history.pushState(null, null, location.href);
            });
            
        </script>

        <title>Investment/Borrowing Report</title>

    </head>
    <body  onload="noBack();">
        <script type="text/javascript">
            function noBack()
            {
                window.history.forward();
            }
        </script>
        <jsp:include page="MenuHead_Deposit.jsp" flush="true" />
        <br>
        <%!
            String blankNull(String s) {
                return (s == null) ? "" : s;
            }

            String blankNA(String s) {
                return (s == null) ? "NA" : s;
            }
        %>
        <%
             String pacsId = (String) session.getAttribute("pacsId");
             Object oEnquiryBeanSearchObj = request.getAttribute("oEnquiryBeanSearchObj");
             EnquiryBean oEnquiryBean = new EnquiryBean();
             EnquiryBean oEnquiryBeanSearch = new EnquiryBean();
             if (oEnquiryBeanSearchObj != null) {
                 oEnquiryBean = (EnquiryBean) request.getAttribute("oEnquiryBeanSearchObj");
                 session.setAttribute("oEnquiryBeanSearchObj", oEnquiryBeanSearchObj);
             }
        %>
        <%String subPacsFlag = (String) session.getAttribute("subPacsFlag");
        %>

        <div style="top:500px">
            <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">Investment/Borrowing Report</legend>

                <form name="pacsreport" method="post" action="/PacsApplication/ExcelReportServlet">
                    <br>

                    <table>
                        <%if (request.getAttribute("error") != null) {%>
                        <tr><td colspan="2" align="center"><%=request.getAttribute("error").toString()%></td></tr>
                        <%}%>

                        <%--<tr align="center">
                        <input type="radio" name="opType" id ="r1" onclick="handleClick(this);" value="i">Investment
                        <input type="radio" name="opType" id ="r2" onclick="handleClick(this);" value="b">Borrowing<br><br>
                        </tr>--%>

                        <tr>
                            <td style=" font-family: Berlin Sans FB; font-weight:normal; ">Report Name <font color="red" >*</font>: </td>
                            <td> <select id="reportSelection" name="reportSelection" >
                                    <option value="" selected  >--Select--</option>
                                    <option value="i" >Investment Detail List</option>
                                    <option value="b" >Borrowing Detail List</option>
                                </select></td>
                        </tr>
                        <tr>
                            <td style=" font-family: Berlin Sans FB; font-weight:  normal;">Date <font color="red" >*</font>: </td><td><input type="text" id="to_date" name="to_date" maxlength="11" resize="yes" readonly="true" style="text-align:center;"> <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>
                            <td style=" font-family: Berlin Sans FB; font-weight:normal; ">GL Account<font color="red" >*</font>: </td>
                            <td><input type="text" name="gl_id" id="gl_id" style="text-align:right;" onkeypress='return event.charCode >= 48 && event.charCode <= 57' />
                            <input type="button" id="gl_btn" name="gl_btn" value="Search" onclick="javascript:searchGL(220,180,document.getElementById('gl_id').value)" /></td>
                        </tr>

                        <tr>
                            <td style=" font-family: Berlin Sans FB; font-weight:normal; ">Sub-PACS Name: </td>
                            <td><select id="subpacs_id" name="subpacs_id" >
                                    <%if (oEnquiryBean.getSubpacs_id() == null) {%>
                                    <option value="" disabled selected style="display:none;">--Select--</option>
                                    <%if (subPacsFlag.equalsIgnoreCase("N")) {%>
                                    <option value="ALL" >ALL Pacs</option>
                                    <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="<%=pacsId%>" 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(oEnquiryBean.getSubpacs_id())%>" selected style="display:none;"><%=blankNull(oEnquiryBean.getSubpacs_name())%></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>
                        <tr></tr>
                        <tr id="dep_prod" style="display: none;">
                            <td>Select Product:</td><td>
                                <select id="prod_id" name="prod_id">
                                    <option value="ALL" >ALL deposit Products</option>
                                    <%
                                         Connection connection = null;
                                         ResultSet rs = null;
                                         Statement statement = null;
                                         connection = DbHandler.getDBConnection();
                                         try {
                                             statement = connection.createStatement();
                                             rs = statement.executeQuery("select dp.id,dp.prod_code||':'||dp.int_cat||' '||dp.prod_name from dep_product dp where to_number(substr(dp.prod_code,1,1))<5 and dp.pacs_id like '%" + pacsId + "#%'");
                                             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><br><br>
                    <tr><td><br></td></tr>
                    <tr><td><br></td></tr>
                    <tr><td><label><font color="red" >*</font> marked fields are mandatory.</label></td></tr>
                    <center>

                        <input type="button" value="Fetch Report" onclick="javascript:downloadFiles();">
                        <input type="button" value="Reset" id="Reset" onclick="ShowParent();" />

                    </center>

                    <input type="hidden" name="reportPath" value=""/>
                    <input type="hidden" name="reportName" value=""/>
                    <input type="hidden" name="DOWNLOAD" value=""/>

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