
<%--
    Document   : PACS_REPORT
    Created on : Sep 17, 2015, 12:59:59 PM
    Author     : 454222
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.util.ArrayList" %>
<%@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 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 ch=document.getElementById("reportSelection").value;
                var e = document.getElementById("reportSelection");

                if (e.options[e.selectedIndex].value == "")
                {
                    alert("Report Name cannot be empty.");
                    document.forms[0].reportSelection.focus();
                    return false;
                }
                if( ch== 9 || ch==10  || ch==7 )
                {
                    if (document.forms[0].from_date.value == "" )
                    {
                     document.forms[0].from_date.focus();
                     alert("From Date cannot be empty.");
                     return false;
                    }
                }
               // if((ch!=4)&&(ch!=5) && (ch!=6) && (ch!=7) && (ch!=8))
               if( ch==1 || ch==2 || ch==3 )
                {                    
                    if (document.forms[0].shg_name.value == "")
                    {
                        alert("SHG Code cannot be empty.");
                        document.forms[0].shg_name.focus();
                        return false;
                    }
                }
//                if( ch==9 )
//                {                    
//                    if (document.forms[0].shg_name_Bank.value == "")
//                    {
//                        alert("SHG Code cannot be empty.");
//                        document.forms[0].shg_name_Bank.focus();
//                        return false;
//                    }
//                }
                <%--if( ch==6 || ch==7 || ch==8 )
                {
                    if (document.forms[0].from_date.value == "" )
                    {
                    document.forms[0].from_date.focus();
                    alert("From Date cannot be empty.");
                    return false;
                    }                    
                }--%>
                if( ch==6 || ch==8 || ch==11 || ch==12 || ch==13 )
                {
                    if (document.forms[0].from_date.value == "" )
                    {
                    document.forms[0].from_date.focus();
                    alert("From Date cannot be empty.");
                    return false;
                    }
                    if (document.forms[0].to_date.value == "" )
                    {
                    document.forms[0].to_date.focus();
                    alert("To Date cannot be empty.");
                    return false;
                    }

                    var startDate = $('#from_date').val();
                    var endDate = $('#to_date').val();
                    var adata = startDate.split('/');
                    var dd = parseInt(adata[0],10);
                    var mm = parseInt(adata[1],10);
                    var yyyy = parseInt(adata[2],10);
                    var from_date = new Date(yyyy,mm-1,dd);

                    adata = endDate.split('/');
                    var dd = parseInt(adata[0],10);
                    var mm = parseInt(adata[1],10);
                    var yyyy = parseInt(adata[2],10);
                    var to_date = new Date(yyyy,mm-1,dd);

                    if(Date.parse(from_date) > Date.parse(to_date)){
                        alert("From Date cannot be greater than To Date");
                        return false;
                    }

                }

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

                    case "1" :

                        document.forms[0].reportPath.value = "/Reports/shg_basic_info_report";
                        document.forms[0].reportName.value = "SHG MEMBER DETAILS REPORT";
                        document.forms[0].DOWNLOAD.value = "P";
                        break;                    

                    case "2" :

                        document.forms[0].reportPath.value = "/Reports/shg_loan_account_details";
                        document.forms[0].reportName.value = "SHG LOAN ACCOUNT DETAILS REPORT";
                        document.forms[0].DOWNLOAD.value = "P";
                        break;

                    case "3" :

                        document.forms[0].reportPath.value = "/Reports/shg_deposit_account_details";
                        document.forms[0].reportName.value = "SHG DEPOSIT ACCOUNT DETAILS REPORT";
                        document.forms[0].DOWNLOAD.value = "P";
                        break;

                    case "4" :

                        document.forms[0].reportPath.value = "/Reports/shg_return";
                        document.forms[0].reportName.value = "SHG RETURN REPORT";
                        document.forms[0].DOWNLOAD.value = "P";
                        break;


                    case "5" :

                        document.forms[0].reportPath.value = "/Reports/coverage_of_membership";
                        document.forms[0].reportName.value = "COVERAGE OF MEMBERSHIP";
                        document.forms[0].DOWNLOAD.value = "P";
                        break;

                    case "6" :

                        document.forms[0].reportPath.value = "/Reports/SHGSubvention";
                        document.forms[0].reportName.value = "SUBVENSION REPORT";
                        document.forms[0].DOWNLOAD.value = "P";
                        break;

                    case "7" :

                        document.forms[0].reportPath.value = "/Reports/shgloanDetailList";
                        document.forms[0].reportName.value = "SHG LOAN DETAIL LIST MEMBER WISE";
                        document.forms[0].DOWNLOAD.value = "P";
                        break;

                    case "8" :

                        document.forms[0].reportPath.value = "/Reports/MemberWiseSHGSubvention";
                        document.forms[0].reportName.value = "SHG Subvention Member Wise";
                        document.forms[0].DOWNLOAD.value = "P";
                        break;
                        
//                    case "9" :
//
//                        document.forms[0].reportPath.value = "/Reports/bank_shg_basic_info_report";
//                        document.forms[0].reportName.value = "Member Details Report";
//                        document.forms[0].DOWNLOAD.value = "P";
//                        break;

                    case "9" :

                        document.forms[0].reportPath.value = "/Reports/dep_dtl_list";
                        document.forms[0].reportName.value = "DEPOSIT DETAILS LIST REPORT";
                        document.forms[0].DOWNLOAD.value = "P";
                        break;

                    case "10" :

                        document.forms[0].reportPath.value = "/Reports/bank_shgloanDetailList";
                        document.forms[0].reportName.value = "Loan Detail List Report";
                        document.forms[0].DOWNLOAD.value = "P";
                        break;

                    case "11" :

                        document.forms[0].reportPath.value = "/Reports/bank_shgLoanRepayReg";
                        document.forms[0].reportName.value = "Repayment Register Report";
                        document.forms[0].DOWNLOAD.value = "P";
                        break;

                    case "12" :

                        document.forms[0].reportPath.value = "/Reports/bank_shgloanDisburseReg";
                        document.forms[0].reportName.value = "Disbursement Register Report";
                        document.forms[0].DOWNLOAD.value = "P";
                        break;


                    case "13" :

                        document.forms[0].reportPath.value = "/Reports/bank_SHGSubvention";
                        document.forms[0].reportName.value = "Subvention Report";
                        document.forms[0].DOWNLOAD.value = "P";
                        break;    

                    default :

                        null;

                }

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

            }
            function ShowParent()
            {

                document.forms[0].action = "${pageContext.request.contextPath}/Shg_JSP/shg_reports.jsp";
                document.forms[0].submit();
            }

            function popup_SHG(width, height, shg_name) {
                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 = "shg_reports.jsp";
                var  lovKey="SearchShg"
                popWin = open('/PacsApplication/CommonSearchInformationShgLOV.jsp?shg_name=' + shg_name + '&screenName=' + screenName+'&lovKey='+lovKey, 'SearchShg', attr);
                popWin.focus();

            }
            function popup_SHG_Bank(width, height, shg_name_Bank, pacs_code) {
                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 = "shg_reports.jsp";
                var  lovKey="SearchShg_Bank"
                popWin = open('/PacsApplication/CommonSearchInformationShgLOV.jsp?shg_name_Bank=' + shg_name_Bank + '&pacs_code=' + pacs_code + '&screenName=' + screenName+'&lovKey='+lovKey, 'SearchShg', attr);
                popWin.focus();

            }

            function changeSelect()
            {
                var ch=document.getElementById("reportSelection").value;

                    if((ch==1) || (ch==2) || (ch==3))
                    {
                        document.getElementById("shg_code_tr").style.display="table-row";
                        document.getElementById("tr_fromdt").style.display="none";
                        document.getElementById("tr_todt").style.display="none";
                        document.getElementById("subvention_trPacs").style.display="none";
                        document.getElementById("pacs_list").style.display="none";
                    }
                    else if((ch==4)||(ch==5))
                    {
                        document.getElementById("shg_code_tr").style.display="none";
                        document.getElementById("tr_fromdt").style.display="none";
                        document.getElementById("tr_todt").style.display="none";
                        document.getElementById("subvention_trPacs").style.display="table-row";
                        document.getElementById("pacs_list").style.display="none";
                    }                    
                    else if( ch==7 )
                    {
                        document.getElementById("tr_fromdt").style.display="table-row";
                        document.getElementById("tr_todt").style.display="none";
                        document.getElementById("subvention_trPacs").style.display="table-row";
                        document.getElementById("shg_code_tr").style.display="none";
                        document.getElementById("pacs_list").style.display="none";
                    }
                    else if(ch==6 || ch==8)
                    {
                        document.getElementById("tr_fromdt").style.display="table-row";
                        document.getElementById("tr_todt").style.display="table-row";
                        document.getElementById("subvention_trPacs").style.display="table-row";
                        document.getElementById("shg_code_tr").style.display="none";
                        document.getElementById("pacs_list").style.display="none";
                    }
                    else if(ch==9)
                    {
                        document.getElementById("shg_code_Bank").style.display="none";
                        document.getElementById("tr_fromdt").style.display="table-row";
                        document.getElementById("tr_todt").style.display="none";
                        document.getElementById("subvention_trPacs").style.display="none";
                        document.getElementById("pacs_list").style.display="table-row";
                    }
                    else if(ch==10)
                    {
                        document.getElementById("shg_code_Bank").style.display="none";
                        document.getElementById("tr_fromdt").style.display="table-row";
                        document.getElementById("tr_todt").style.display="none";
                        document.getElementById("subvention_trPacs").style.display="none";
                        document.getElementById("pacs_list").style.display="table-row";
                    }
                    else if((ch==11) || (ch==12) || (ch==13))
                    {
                        document.getElementById("shg_code_Bank").style.display="none";
                        document.getElementById("tr_fromdt").style.display="table-row";
                        document.getElementById("tr_todt").style.display="table-row";
                        document.getElementById("subvention_trPacs").style.display="none";
                        document.getElementById("pacs_list").style.display="table-row";
                    }
                    else
                        {
                            document.getElementById("shg_code_tr").style.display="table-row";
                            document.getElementById("tr_fromdt").style.display="none";
                            document.getElementById("tr_todt").style.display="none";
                            document.getElementById("subvention_trPacs").style.display="none";
                            document.getElementById("pacs_list").style.display="none";
                            document.getElementById("shg_code_Bank").style.display="none";

                        }
            }

            // to restrict back button
            history.pushState(null, null, location.href);
            window.addEventListener('popstate', function(event) {
                history.pushState(null, null, location.href);
            });
            
        </script>
         <%
             String pacsId = (String) session.getAttribute("pacsId");
             String userRole = (String) session.getAttribute("userRole");
             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");
        %>
         <%!
            String blankNull(String s) {
                return (s == null) ? "" : s;
            }

            String blankNA(String s) {
                return (s == null) ? "NA" : s;
            }
        %>

        <title>SHG Report</title>

    </head>
    <body  onload="noBack();">
        <script type="text/javascript">
            function noBack()
            {
                window.history.forward();
            }
        </script>
        <jsp:include page="MenuHead_SHG.jsp" flush="true" />
        <br>
        <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">SHG Report</legend>

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

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

                        <tr></tr>
                        <tr></tr>
                        <tr></tr>
                        <tr></tr>
                        <tr></tr>
                        <tr></tr>
                        <tr></tr>
                        <tr></tr>
                                                
                        <tr>

                            <td style=" font-family: Berlin Sans FB; font-weight:normal; ">Report Name<font color="red" >*</font>: </td>
                            <td colspan="2"> <select id="reportSelection" name="reportSelection" onchange="changeSelect()" >
                                    <%if ((userRole.equalsIgnoreCase("201603000008020"))) {%>
                                    <option value="" disabled selected style="display:none;" >--Select--</option>
                                <!--<option value="9">Member Details Report</option>-->
                                <!--<option value="9">Deposit Details List Report</option>-->
                                    <option value="10">Loan Detail List Report</option>
                                    <option value="11">Repayment Register Report</option>
                                    <option value="12">Disbursement Register Report</option>
                                    <option value="13">Subvention Report</option>                                    
                                    <%}else{%>
                                    <option value="" disabled selected style="display:none;" >--Select--</option>
                                    <option value="1">SHG Member Details Report</option>
                                    <option value="2">SHG Loan Account Report</option>
                                    <option value="3">SHG Deposit Account Report</option>
                                    <option value="4">SHG Return Report</option>
                                    <option value="5">Coverage Of Membership Report</option>
                                    <option value="6">SHG Subvention Report</option>
                                    <option value="7">SHG LOAN DETAIL LIST MEMBER WISE</option>
                                    <option value="8">SHG Subvention Member Wise</option>
                                    
                                    <%}%>
                                 </select></td>
                        </tr>

                        <tr id="tr_fromdt" style="display: none">
                            <td style=" font-family: Berlin Sans FB; font-weight:  normal;">From Date: </td><td><input type="text" style="text-align:center;" id="from_date" name="from_date" maxlength="11" resize="yes" readonly="true">&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="tr_todt" style="display: none">
                            <td style=" font-family: Berlin Sans FB; font-weight:  normal;">To Date: </td><td><input type="text" style="text-align:center;" id="to_date" name="to_date" maxlength="11" resize="yes" readonly="true">&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 id="pacs_list" style="display: none;">                           
                            <td>Select PACS Name:</td><td>
                            <select id="pacs_code" name="pacs_code">
                               
                                <%
                                        Connection connection1 = null;
                                        ResultSet rs1 = null;
                                        Statement statement1 = null;
                                        connection1 = DbHandler.getDBConnection();
                                        try {
                                            statement1 = connection1.createStatement();
                                            rs1 = statement1.executeQuery("select dp.pacs_id,dp.pacs_id||':'||upper(dp.pacs_name) from pacs_master dp where dp.pacs_id <> '" + pacsId + "' and dp.pacs_id in (select pacs_id from pacs_master pma where lpad(to_number(pma.dccb_code), 2, '0') = (select lpad(to_number(tba.dccb_code), 2, '0') from pacs_master tba where tba.pacs_id = '" + pacsId + "') and lpad(to_number(pma.cbs_br_code), 5, '0') =(select lpad(to_number(tba.cbs_br_code), 5, '0') from pacs_master tba where tba.pacs_id = '" + pacsId + "')) and dp.pacs_id not in (select pacs_id from pacs_neft_interface) order by upper(dp.pacs_name) ");
                                            while (rs1.next()) {%>
                                            <option value="<%=rs1.getString(1)%>"><%=rs1.getString(2)%></option>
                              <%
                                                 }
                                                // statement1.close();
                                                // connection1.close();
                                             } catch (Exception e) {
                                                System.out.println("Error occurred during processing.");
                                             } finally {
                try {
                    if(statement1 !=null)
                        statement1.close();
                    if (connection1 != null)
                    connection1.close();

            } catch (Exception e) {               
               System.out.println("Error Occurred during connection close.");
            }
            }
                                         %>
                            </select>
                        </td>
                        </tr>
                        <tr id="subvention_trPacs" style="display: none">
                            <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 id="shg_code_tr" style="display: none">

                            <td style=" font-family: Berlin Sans FB; font-weight:  normal;">SHG Code:</td><td> <input type="text" style="text-align:right;" name="shg_name" id="shg_name" onkeypress='return event.charCode >= 48 && event.charCode <= 57' ></td>
                            <td><input type="button" name="shgSearch" id="shgSearch" value="Search" onclick="javascript:popup_SHG(220, 180, document.pacsreport.shg_name.value);"/></td>
                        </tr>
                        <tr id="shg_code_Bank" style="display: none">

                            <td style=" font-family: Berlin Sans FB; font-weight:  normal;">SHG Code:</td><td> <input type="text" style="text-align:right;" name="shg_name_Bank" id="shg_name_Bank" readonly onkeypress='return event.charCode >= 48 && event.charCode <= 57' ></td>
                            <td><input type="button" name="shgSearch" id="shgSearch" value="Search" onclick="javascript:popup_SHG_Bank(220, 180, document.pacsreport.shg_name_Bank.value, document.pacsreport.pacs_code.value);"/></td>
                        </tr>
                        
                    </table><br><br><br><br>

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

                    <input type="hidden" name="shg_id" id="shg_id" value=""/>
                    <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) {
                
            }
%>