<%--
    Document   : Audit_Report
    Created on : Nov 2, 2021, 5:18:24 PM
    Author     : 1242938
--%>

<%@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");
                //Both From and To date are mandatory
               // var reports = [1,2,3,4,5,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,35,36,37,41,43,44,45,46,47,48,49,50,51,52,53,54,55,56];
                var reports = ["1","2","3","4","5","6","7","8","9","10","11","12"];
                var fromdate_reports = ["34","38","39","40","57","63"]; //From date not mandatory
                var todate_reports = ["34","38","39","40","42","57"];//To Date not mandatory
                var val = e.options[e.selectedIndex].value;                

                if (e.options[e.selectedIndex].value == "")
                {
                    alert("Report Name cannot be empty.");
                    document.forms[0].reportSelection.focus();
                    return false;
                }

                if ((document.forms[0].from_date.value == "" || document.forms[0].to_date.value == "") && reports.includes(val) )
                {
                    alert("From Date or To Date cannot be empty for this report.");
                    return false;
                }
                if (document.forms[0].subpacs_id.value == "" )
                {
                    alert("Please select Sub-PACS Name.");
                    document.forms[0].subpacs_id.focus();
                    return false;
                }
                <%--if (document.forms[0].from_date.value == "" &&  (e.options[e.selectedIndex].value == "1" || e.options[e.selectedIndex].value == "2" || e.options[e.selectedIndex].value == "7" || e.options[e.selectedIndex].value == "12" || e.options[e.selectedIndex].value == "15" || e.options[e.selectedIndex].value == "16" || e.options[e.selectedIndex].value == "5" || e.options[e.selectedIndex].value == "8" || e.options[e.selectedIndex].value == "9" ))
                {
                    alert("From Date cannot be empty.");
                    document.forms[0].txn_date.focus();
                    return false;
                } if (document.forms[0].to_date.value == "" && (e.options[e.selectedIndex].value == "1" || e.options[e.selectedIndex].value == "2" || e.options[e.selectedIndex].value == "7" || e.options[e.selectedIndex].value == "12" || e.options[e.selectedIndex].value == "15" || e.options[e.selectedIndex].value == "16" || e.options[e.selectedIndex].value == "5" || e.options[e.selectedIndex].value == "8" || e.options[e.selectedIndex].value == "9" ))
                {
                    alert("To Date cannot be empty.");
                    document.forms[0].txn_date.focus();
                    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) &&  reports.includes(val)){
                    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/Trial_balance_Mod_abs";
                        document.forms[0].reportName.value = "Trial Balance Report";
                        document.forms[0].DOWNLOAD.value = "P";
                        break;

                    case "2" :

                        document.forms[0].reportPath.value = "/Reports/B_committee_Trial_Balance_dtl_abs";
                        document.forms[0].reportName.value = "B-Committee Trial Balance Report";
                        document.forms[0].DOWNLOAD.value = "P";
                        break;

                    case "3" :

                        document.forms[0].reportPath.value = "/Reports/trading_acc_stmt_abs";
                        document.forms[0].reportName.value = "Trading Account Statement Report";
                        document.forms[0].DOWNLOAD.value = "P";
                        break;

                    case "4" :

                        document.forms[0].reportPath.value = "/Reports/B_committee_trading_dtl_abs";
                        document.forms[0].reportName.value = "B-Committee Trading Account Statement-Detailed Report";
                        document.forms[0].DOWNLOAD.value = "P";
                        break;

		    case "5" :

                        document.forms[0].reportPath.value = "/Reports/B_committee_trading_cons_abs";
                        document.forms[0].reportName.value = "B-Committee Trading Account Statement-Consolidated Report";
                        document.forms[0].DOWNLOAD.value = "P";
                        break;

                    case "6" :

                        document.forms[0].reportPath.value = "/Reports/profit_loss_abs";
                        document.forms[0].reportName.value = "Profit Loss Report";
                        document.forms[0].DOWNLOAD.value = "P";
                        break;

                    case "7" :

                        document.forms[0].reportPath.value = "/Reports/B_committee_Profit_Loss_dtl_abs";
                        document.forms[0].reportName.value = "B-Committee Profit Loss-Detailed Report";
                        document.forms[0].DOWNLOAD.value = "P";
                        break;

                    case "8" :

                        document.forms[0].reportPath.value = "/Reports/B_committee_profit_loss_cons_abs";
                        document.forms[0].reportName.value = "B-Committee Profit Loss-Consolidated Report";
                        document.forms[0].DOWNLOAD.value = "P";
                        break;

                    case "9" :

                        document.forms[0].reportPath.value = "/Reports/balance_sheet_abs";
                        document.forms[0].reportName.value = "Balance Sheet Report";
                        document.forms[0].DOWNLOAD.value = "P";
                        break;
                        
                    case "10" :
                       
                        document.forms[0].DOWNLOAD.value = "P";
                        document.forms[0].reportPath.value = "/Reports/B_committee_Balance_sheet_dtl_abs";
                        document.forms[0].reportName.value = "B-Committee Balance Sheet-Detailed Report";                     
                        break;

                    case "11" :

                        document.forms[0].reportPath.value = "/Reports/B_committee_Balance_sheet_cons_abs";
                        document.forms[0].reportName.value = "B-Committee Balance Sheet-Consolidated Report";                        
                        document.forms[0].DOWNLOAD.value = "P";
                        break;
                        
                    case "12" :

                        document.forms[0].reportPath.value = "/Reports/cash_account_abs";
                        document.forms[0].reportName.value = "Cash Account Report";
                        document.forms[0].DOWNLOAD.value = "P";
                        break;
                        
                    case "13" :

                        document.forms[0].reportPath.value = "/Reports/pl_appropriation";
                        document.forms[0].reportName.value = "Profit & Loss Appropriation Report";
                        document.forms[0].DOWNLOAD.value = "P";
                        break;    
                    
                    default :

                        null;
                }

                if(e.options[e.selectedIndex].value == "19" && ((document.getElementById("userRole").value=="201603000005020")||(document.getElementById("userRole").value=="201603000007020")))
                    {
                        document.forms[0].action = '/PacsApplication/DirectBenifitTransferServlet';
                        document.forms[0].submit();
                    }                
                else{
                    document.forms[0].action = '/PacsApplication/ExcelReportServlet';
                    document.forms[0].submit();
                }                                
            }

            $(document).ready(function () {
                $('select#reportSelection').change(function () {
                            $('#dep_prod').hide();
                            $('#fromDate').show();
                            $('#toDate').show();
                            $('#subGLReport').hide();
                    var shouldEnable = $(this).val();
                    switch(shouldEnable)
                    {                        
                       case '60':
                            $('#pacs_list').show(500);
                            $('#subPacsName').hide();
                            break;
                        case '61':
                            $('#pacs_list').show(500);
                            $('#subPacsName').hide();
                            break;
                       case '62':
                            $('#pacs_list').show(500);
                            $('#subPacsName').hide();
                            break;
                        case '63':
                            $('#pacs_list').hide();                           
                            $('#fromDate').hide();
                            break;    
                       
                       default:
                            $('#dep_prod').hide();
                            $('#fromDate').show();
                            $('#toDate').show();
                            $('#subPacsName').show();
                            $('#pacs_list').hide();
                            break;
                    }
                })
            });
            function ShowParent()
            {
                document.forms[0].action = "${pageContext.request.contextPath}/Deposit/Audit_Report.jsp";
                document.forms[0].submit();
            }
            // to restrict going back 
            history.pushState(null, null, location.href);
            window.addEventListener('popstate', function(event) {
                history.pushState(null, null, location.href);
            });
            
        </script>

        <title>Audit 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");
             String userRole = (String) session.getAttribute("userRole");
             String moduleName = new String();
                moduleName = (String) session.getAttribute("moduleName");
             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">Audit Report</legend>

                <form name="pacsreport" method="post" action="/PacsApplication/ExcelReportServlet">
                    <br>
                     <input type="hidden" name="userRole" id ="userRole" value="<%=userRole%>">
                    <table>
                        <%if (request.getAttribute("error") != null) {%>
                        <tr><td colspan="2" align="center"><%=request.getAttribute("error").toString()%></td></tr>
                        <%}%>

                        <tr id="fromDate">
                            <td style=" font-family: Berlin Sans FB; font-weight:  normal;">From Date<font color="red" >*</font>: </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="toDate">
                            <td style=" font-family: Berlin Sans FB; font-weight:  normal;">To Date<font color="red" >*</font>: </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>
                            <td style=" font-family: Berlin Sans FB; font-weight:normal; ">Report Name<font color="red" >*</font>: </td>
                            <td> <select id="reportSelection" name="reportSelection" >
                                      <%if ((userRole.equalsIgnoreCase(
                     "201603000005020")) ||(userRole.equalsIgnoreCase("201603000007020")) ) {%>
                                    <option value="" disabled selected style="display:none;" >--Select--</option>                                    
                                    <%} else if (userRole.equalsIgnoreCase("201606000004041") && moduleName.equalsIgnoreCase("Special") || moduleName.equalsIgnoreCase("SpecialBothDep")) {%>
                                    <option value="" disabled selected style="display:none;" >--Select--</option>                                    
                                    <%} else if ((userRole.equalsIgnoreCase("201603000004024"))) {%>
                                    <option value="" disabled selected style="display:none;" >--Select--</option>                                    
                                    <%} else if ((userRole.equalsIgnoreCase("201603000008020"))) {%>
                                    <option value="" disabled selected style="display:none;" >--Select--</option>                                    
                                    <%}else{%>
                                    <option value="" disabled selected style="display:none;" >--Select--</option>
                                    <option value="1">Trial Balance Report</option>
                                    <option value="2">B-Committee Trial Balance Report</option>
                                    <option value="3">Trading Account Statement Report</option>
                                    <option value="4">B-Committee Trading Account Statement-Detailed Report</option>
				    <option value="5">B-Committee Trading Account Statement-Consolidated Report</option>
                                    <option value="6">Profit Loss Report</option>
                                    <option value="7">B-Committee Profit Loss-Detailed Report</option>
                                    <option value="8">B-Committee Profit Loss-Consolidated Report</option>
                                    <option value="9">Balance Sheet Report</option>
                                    <option value="10">B-Committee Balance Sheet-Detailed Report</option>
                                    <option value="11">B-Committee Balance Sheet-Consolidated Report</option>
                                    <option value="12">Cash Account Report</option>                                                                        
                                    <option value="13">Profit & Loss Appropriation Report</option>
                                    <%}%>
                                </select></td>
                        </tr>
                        <tr></tr>                      
                        
                        <tr id="subPacsName">
                            <td style=" font-family: Berlin Sans FB; font-weight:normal; ">Sub-PACS Name<font color="red" >*</font>: </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>
                        
                    </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) {
                
            }
%>
