<%--
    Document   : share_reports
    Created on : Oct 30, 2017, 4:17:20 PM
    Author     : 981898
--%>


<%@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())%>" />
        <link rel="stylesheet" type="text/css" href="/PacsApplication/css/InputBoxStyle.css?pacs=<%=((new java.util.Date()).getTime())%>"/>
        <link rel="stylesheet" type="text/css" href="/PacsApplication/css/SelectStyle.css?pacs=<%=((new java.util.Date()).getTime())%>"/>
        <link rel="preconnect" href="https://fonts.googleapis.com">
        <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
        <link href="https://fonts.googleapis.com/css2?family=Rubik:ital,wght@0,300..900;1,300..900&display=swap" rel="stylesheet">
        <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 v11 = document.getElementById("subpacs_id");
//                alert(v11.options[v11.selectedIndex].value);
                var e = document.getElementById("reportSelection");

                if (e.options[e.selectedIndex].value == "")
                {
                    alert("Please select Report Name.");
                    document.forms[0].reportSelection.focus();
                    return false;
                }
                if (e.options[e.selectedIndex].value == '1')
                {
                    if (document.forms[0].from_date.value == "")
                    {
                        alert("Please enter From Date.");
                        document.forms[0].from_date.focus();
                        return false;
                    }
                    if (document.forms[0].prod_id.value == "")
                    {
                        alert("Please select one Product.");
                        document.forms[0].prod_id.focus();
                        return false;
                    }
                }
                if (e.options[e.selectedIndex].value == '2')
                {
                    if (document.forms[0].accNo.value == "")
                    {
                        alert("Please enter Account No.");
                        document.forms[0].accNo.focus();
                        return false;
                    }
                }

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

                    case "1" :
                        document.forms[0].reportPath.value = "/Reports/Member_dtl_list";
                        document.forms[0].reportName.value = "Member Details";
                        document.forms[0].DOWNLOAD.value = "P";
                        break;

                    case "2" :
                        document.forms[0].reportPath.value = "/Reports/share_certificate";
                        document.forms[0].reportName.value = "Share Certificate Report";
                        document.forms[0].DOWNLOAD.value = "P";
                        break;

                    default :

                        null;
                }

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

            $(document).ready(function () {
                $('select#reportSelection').change(function () {
                    var val = $(this).val();
                    
                    switch (val) {

                        case '1':
                            $('#fromDate').show();
                            $('#trProd').show();
                            $('#accno').hide();
                            break;

                        case '2':
                            $('#fromDate').hide();
                            $('#trProd').hide();
                            $('#accno').show();
                            break;

                        default:
                            $('#fromDate').hide();
                            $('#trProd').hide();
                            $('#accno').hide();
                            break;
                    }
                });
            });
//            $(document).ready(function(){
//                $('select#subpacs_id').change(function(){                    
//                    var pacs=$(this).val();
//                    alert(pacs);
//                    
//                });
//            });

//            $(document).ready(function(){
//                
//                var pacsValueInput = "<%= request.getAttribute("pacsvalue")%>";
//                alert(pacsvalue);
//                $('select#prod_id').change(function(){
//                    var pr=$(this).val();                    
//                    
//                });
//            });
            function ShowParent()
            {

                document.forms[0].action = "${pageContext.request.contextPath}/Share_Module/share_reports.jsp";
                document.forms[0].submit();
            }
            function popup_shareAccount(width, height, accNo) {
                if (window.innerWidth) {
                    LeftPosition = (window.innerWidth - width) / 2;
                    TopPosition = ((window.innerHeight - height) / 2) - 20;
                } else {
                    LeftPosition = (parseInt(window.screen.width) - width) / 2;
                    TopPosition = ((parseInt(window.screen.height) - height) / 2) - 20;
                }
                attr = 'resizable=yes,scrollbars=yes,width=' + width + ',height=' +
                        height + ',screenX=300,screenY=200,left=' + LeftPosition + ',top=' +
                        TopPosition + '';
                var screenName = "share_reports.jsp";
                var lovKey = "shareAccount"
                popWin = open('${pageContext.request.contextPath}/CommonSearchInformationLOV.jsp?accNo=' + accNo + '&screenName=' + screenName + '&lovKey=' + lovKey, 'shareAccount', 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>

        <title>Share Report</title>

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

            String blankNA(String s) {
                return (s == null) ? "NA" : s;
            }
        %>
        <%
            // String pacsval = request.getParameter("subpacs_id");
            // String pacsvalue1 = (String) session.getAttribute("pacsvalue");
            //String pacsval = (String) session.getAttribute("subpacs_id");
            //System.out.println(pacsval);
            String name = "abc";
            request.setAttribute("pacsValueInput", name);
            // String pacsvalue1 = (String) session.getAttribute("subpacs");
            String pacsId = (String) session.getAttribute("pacsId");
            String str = pacsId.substring(0, 2);
            String dccb = str.replaceFirst("^0+(?!$)", "");
            String br_code = pacsId.substring(2, 5);
            System.out.println(dccb + "+" + br_code);
            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");
        %>

        <div style="top:500px">
            <%--changed on 24/4/23<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">Share Report</legend>--%>
            <fieldset style="border-radius: 20px; border-color: rgb(177, 224, 178); border-width: 2px; margin-left: 75px;margin-right: 75px">
                <legend style="margin-left: 40px; width:100px; padding: 8px; border-radius: 18px; background-color: rgb(177, 224, 178); color: rgb(0, 140, 69)"><b>Share Report</b></legend>

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

                    <!--                    added center on 26/4/24-->
                    <center>

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

                            <tr>
                                <!--                            font-family: Berlin Sans FB changed on 26/4/24-->
                                <td style=" font-family: Rubik; font-weight:normal; ">Report Name<font color="red" >*</font>: </td>
                                <!--                            added style-->
                                <td> <select id="reportSelection" name="reportSelection" >
                                        <%--    <% if (userRole.equalsIgnoreCase("201603000008020")) {%>
                                                <option value="" selected > --Select-- </option>
                                                <option value="1">Member Details</option>
                                            <%} else{%> --%>
                                        <option value="" selected > --Select-- </option>
                                        <option value="1">Member Details</option>
                                        <option value="2">Share Certificate Report</option>
                                        <%--    <%}%>  --%>
                                    </select></td>
                            </tr>
                            <tr></tr>                       
                            <tr></tr>
                            <tr id="accno" style="display:none;" >
                                <td>Account Number<font color="red" >*</font>:</td>
                                <td><input type="text" name="accNo" id="accNo" value="" style="text-align:right;" onkeypress='return event.charCode >= 48 && event.charCode <= 57'/>
                                    <input type="button" name="accNoSearch" id="accNoSearch" value="Search" onclick="javascript:popup_shareAccount(920, 480, document.pacsreport.accNo.value);"/></td>

                            </tr>

                            <tr id="fromDate" style="display:none;">
                                <td style=" font-family: Rubik; width: 172.5px">From Date<font color="red" >*</font>: </td><td><input type="text" style="text-align:center;width: 170px" 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></tr>


                            <%--   <% if (userRole.equalsIgnoreCase("201603000008020")) {%>
                                                                                     
                                           <tr>
                                               <td style=" font-family: Berlin Sans FB; font-weight:normal; ">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")) {%>                                    
                                                       <% }%>
                                                       <%
                                                           Connection connection = null;
                                                           ResultSet rs = null;
                                                           Statement statement = null;
                                                           connection = DbHandler.getDBConnection();
                                                           try {
                                                               statement = connection.createStatement();
                                                               rs = statement.executeQuery("select pm.pacs_id,pm.pacs_name from pacs_master pm where pm.dccb_code = '" + dccb + "' and pm.cbs_br_code like '%" + br_code + "' ");
                                                               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><%} else{%> --%>
                            <tr>
                                <td style=" font-family: Rubik; font-weight:normal; ">Sub-PACS Name: </td>
                                <td><select  id="subpacs_id" name="subpacs_id" style ="font-family: Rubik; width: 170px">
                                        <%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>
                            <%--    <% if (userRole.equalsIgnoreCase("201603000008020")) {%>
                                <tr id="trProd" style="display:none;">
                                        <td>Select Product of PACS<font color="red" >*</font>:</td><td>
                                        <select id="prod_id" name="prod_id">
                                            <option value="" > --Select-- </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 dp.prod_code = '1017' and dp.pacs_id like(select '%' || pacs_id || '%' from pacs_master where pacs_id='"+name+"'");
                                                        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><%} else{%> --%>
                            <tr id="trProd" style="display:none;">
                                <td>Select Product<font color="red" >*</font>:</td><td>
                                    <select id="prod_id" name="prod_id" style ="font-family: Rubik; width: 170px">
                                        <option value="" > --Select-- </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 dp.prod_code = '1017' and dp.pacs_id like '%" + pacsId + "%'");
                                                while (rs.next()) {%>
                                        <option value="<%=rs.getString(1)%>"style ="font-family: Rubik;" ><%=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>
                    </center>     

                    <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="reportPath" value=""/>
                    <input type="hidden" name="reportName" value=""/>
                    <input type="hidden" name="DOWNLOAD" value=""/>


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