<%--
    Document   : CashDrawerEnquiry
    Created on : Nov 9, 2016, 1:33:18 PM
    Author     : 986137
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Connection"%>
<%@page import="java.util.Date"%>
<%@page import="LoginDb.DbHandler"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.util.UUID" %>
<%String uuid = UUID.randomUUID().toString();%>
<% try {
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <title>Cash Drawer  Enquiry</title>
        <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>

    </head>
    <body onload="noback()">
        <script type="text/javascript">
            function noBack()
            {
                window.history.forward();
            }

            function popup_pacstellers(width, height, tellerid) {
                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 = "CashDrawerEnquiry.jsp";
                var lovKey = "PopupTellers"
                popWin = open('${pageContext.request.contextPath}/CommonSearchInformationDepositLOV.jsp?tellerid=' + tellerid + '&screenName=' + screenName + '&lovKey=' + lovKey, 'PopupTellers', attr);
                popWin.focus();

            }

            // to restrict back button
            history.pushState(null, null, location.href);
            window.addEventListener('popstate', function(event) {
                history.pushState(null, null, location.href);
            });

        </script>
        <%
             String ModuleName = new String();

             ModuleName = (String) session.getAttribute("moduleName");
        %>
        <% if (ModuleName.equalsIgnoreCase("kcc")) {%>
        <jsp:include page="/MenuHead.jsp" flush="true" />
        <%} else if (ModuleName.equalsIgnoreCase("Deposit")) {%>
        <jsp:include page="/Deposit/MenuHead_Deposit.jsp" flush="true" />
        <%} else if (ModuleName.equalsIgnoreCase("Loan")) {%>
        <jsp:include page="/Loan/MenuHead_Loan.jsp" flush="true" />
        <%}%>
        <br>

        <form name="teller" id="teller" method="post" action="">
            <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">Cash Drawer Enquiry</legend>
                <%
                     String odeno2000 = "";
                     String odeno500 = "";
                     String odeno200 = "";
                     String odeno100 = "";
                     String odeno50 = "";
                     String odeno20 = "";
                     String odeno10 = "";
                     String odeno5 = "";
                     String odeno2 = "";
                     String odeno1 = "";
                     String odeno50p = "";
                     String odeno1p = "";
                     String open_bal = "";
                     String totalAmt = "";
                     String pacsid = (String) session.getAttribute("pacsId");
                     String userRole = (String) session.getAttribute("userRole");
                     String user = (String) session.getAttribute("user");

                     Connection connection = null;
                     ResultSet rs = null;
                     Statement statement = null;
                     connection = DbHandler.getDBConnection();
                     try {
                         statement = connection.createStatement();
                         rs = statement.executeQuery("select pacs_id,source,destination,nvl(deno_2000,0),nvl(deno_500,0),nvl(deno_100,0),nvl(deno_50,0),nvl(deno_20,0),nvl(deno_10,0),nvl(deno_5,0),nvl(deno_2,0),nvl(deno_1,0),nvl(deno_50P,0),nvl(deno_1P,0),nvl(deno_200,0) from cash_movement_log where id=(select min(id) from cash_movement_log where source like 'R%' and destination like 'D%' and transaction_date = (select system_date from system_date) and pacs_id='"
                                 + pacsid + "' and teller_to='" + user + "' group by pacs_id,source,destination,transaction_date)");
                         while (rs.next()) {
                             odeno2000 = rs.getString(4);
                             odeno500 = rs.getString(5);
                             odeno100 = rs.getString(6);
                             odeno50 = rs.getString(7);
                             odeno20 = rs.getString(8);
                             odeno10 = rs.getString(9);
                             odeno5 = rs.getString(10);
                             odeno2 = rs.getString(11);
                             odeno1 = rs.getString(12);
                             odeno50p = rs.getString(13);
                             odeno1p = rs.getString(14);
                             odeno200 = rs.getString(15);

                         }
                        statement.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.");
//            }
//
//            }

                %>

                <%
                     String error_msg = "";
                     Object error = request.getAttribute("message");
                     if (error != null) {
                         error_msg = error.toString();
                     }
                %>
                <center>
                    <%if (!error_msg.equalsIgnoreCase("")) {%>
                    <center><div class="info" id="errorMessage"><center><%= error_msg%></center></div></center>
                    <% }%>

                    <br>

                </center>

                <script>
                    $(document).ready(function () {
                        $('select#tellerselect').change(function () {
                            var val = $(this).val();
                            if(val != "")
                                $('#denotable').show();
                            else
                                $('#denotable').hide();
                        });
                    });

                    function closeDrawer()
                    {
                        document.forms[0].action = '/PacsApplication/CloseCashDrawerServlet';
                        document.forms[0].submit();
                    }
                </script>

                <%

                     String deno2000 = "";
                     String deno500 = "";
                     String deno100 = "";
                     String deno50 = "";
                     String deno20 = "";
                     String deno10 = "";
                     String deno5 = "";
                     String deno2 = "";
                     String deno1 = "";
                     String deno50p = "";
                     String deno1p = "";
                     String status = "";
                     String deno200 = "";

                     String Hdeno2000 = "0";
                     String Hdeno500 = "0";
                     String Hdeno100 = "0";
                     String Hdeno50 = "0";
                     String Hdeno20 = "0";
                     String Hdeno10 = "0";
                     String Hdeno5 = "0";
                     String Hdeno2 = "0";
                     String Hdeno1 = "0";
                     String Hdeno50p = "0";
                     String Hdeno1p = "0";
                     String Hdeno200 = "0";

                     try {
                         statement = connection.createStatement();
                         rs = statement.executeQuery("select nvl(deno_2000,0),nvl(deno_500,0),nvl(deno_100,0),nvl(deno_50,0),nvl(deno_20,0),nvl(deno_10,0),nvl(deno_5,0),nvl(deno_2,0),nvl(deno_1,0),nvl(cash_denominations.total_amt(deno_2000,deno_500,deno_100,deno_50,deno_20,deno_10,deno_5,deno_2,deno_1,DENO_50P,DENO_1P,deno_200),0),decode(status,'C','Closed','O','Open','Unknown Status'),nvl(open_balance,0),nvl(deno_50P,0),nvl(deno_1p,0),nvl(deno_200,0) from cash_drawer where pacs_id='" + pacsid + "' and teller_id='" + user + "' and entry_date = (select system_date from system_date)");
                         if (!rs.isBeforeFirst()) {
                             open_bal = "NA";
                             status = "Not Opened yet!!!";
                         } else {
                             while (rs.next()) {
                                 deno2000 = rs.getString(1);
                                 deno500 = rs.getString(2);
                                 deno100 = rs.getString(3);
                                 deno50 = rs.getString(4);
                                 deno20 = rs.getString(5);
                                 deno10 = rs.getString(6);
                                 deno5 = rs.getString(7);
                                 deno2 = rs.getString(8);
                                 deno1 = rs.getString(9);
                                 totalAmt = rs.getString(10);
                                 status = rs.getString(11);
                                 open_bal = rs.getString(12);
                                 deno50p = rs.getString(13);
                                 deno1p = rs.getString(14);
                                 deno200 = rs.getString(15);
                             }
                             statement.close();
                         }

                         rs = statement.executeQuery("select nvl(sum(nvl(c.deno_2000_in,0) - nvl(c.deno_2000_out,0)),0) as Hdeno_2000,nvl(sum(nvl(c.deno_500_in,0) - nvl(c.deno_500_out,0)),0) as Hdeno_500 ,nvl(sum(nvl(c.deno_100_in,0) - nvl(c.deno_100_out,0)),0) as Hdeno_100 ,nvl(sum(nvl(c.deno_50_in,0) - nvl(c.deno_50_out,0)),0)   as Hdeno_50  ,nvl(sum(nvl(c.deno_20_in,0) - nvl(c.deno_20_out,0)),0) as Hdeno_20,nvl(sum(nvl(c.deno_10_in,0) - nvl(c.deno_10_out,0)),0) as Hdeno_10 ,nvl(sum(nvl(c.deno_5_in,0) - nvl(c.deno_5_out,0)),0) as Hdeno_5 ,nvl(sum(nvl(c.deno_2_in,0) - nvl(c.deno_2_out,0)),0) as Hdeno_2,nvl(sum(nvl(c.deno_1_in,0) - nvl(c.deno_1_out,0)),0) as Hdeno_1,nvl(sum(nvl(c.deno_50p_in,0) - nvl(c.deno_50p_out,0)),0) as Hdeno_50p ,nvl(sum(nvl(c.deno_1p_in,0) - nvl(c.deno_1p_out,0)),0) as Hdeno_1p,nvl(sum(nvl(c.deno_200_in,0) - nvl(c.deno_200_out,0)),0) as Hdeno_200  from cash_txn_hist c where c.status='P' and c.pacs_id='" + pacsid + "' and c.teller_id='"
                                 + user + "'");
                         while (rs.next()) {
                             Hdeno2000 = rs.getString(1);
                             Hdeno500 = rs.getString(2);
                             Hdeno100 = rs.getString(3);
                             Hdeno50 = rs.getString(4);
                             Hdeno20 = rs.getString(5);
                             Hdeno10 = rs.getString(6);
                             Hdeno5 = rs.getString(7);
                             Hdeno2 = rs.getString(8);
                             Hdeno1 = rs.getString(9);
                             Hdeno50p = rs.getString(10);
                             Hdeno1p = rs.getString(11);
                             Hdeno200 = rs.getString(12);
                         }
                         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.");
//            }
//
//            }

                %>

                <%if (!user.equalsIgnoreCase("")) {%>
                <center>
                    <table>
                        <thead>
                            <tr>
                                <td style="text-align: center">Teller ID</td>
                                <td style="text-align: center">Opening Balance</td>
                                <td style="text-align: center">Status</td>
                            </tr>
                        </thead>
                        <tbody>
                            <tr>
                                <td><input type="text" style="text-align: right" readonly value="<%= user%>" /></td>
                                <td><input type="text" style="text-align: right" readonly value="<%=open_bal%>"/></td>
                                <td><input type="text" style="text-align: left" readonly value="<%=status%>"/></td>
                            </tr>
                        </tbody>
                    </table>
                </center>

                <br>
                <%if (!("NA").equalsIgnoreCase(open_bal)) {%>

                <center>
                    <table id="denotable" name="denotable" border="2" width="auto" cellspacing="1" cellpadding="1" style="text-align: center ;overflow-y: scroll; font-size: 15px;">
                        <thead class="CSSTableGenerator">
                            <tr><td><b>Denomination</b></td>

                                <td><b>Available</b></td>
                                <td><b>Drawer Opening value</b></td>
                                <td><b>Cash on Hold</b></td>

                            </tr>

                        </thead>

                        <tbody style="background-color: white; font-size: 15px">
                            <tr>
                                <td style="text-align: left">Rs 2000</td>
                                <td style="text-align: right"><%=deno2000%></td>
                                <td style="text-align: right"><%=odeno2000%></td>
                                <td style="text-align: right"><%=Hdeno2000%></td>
                            </tr>
                            <tr>
                                <td style="text-align: left">Rs 500</td>
                                <td style="text-align: right"><%=deno500%></td>
                                <td style="text-align: right"><%=odeno500%></td>
                                <td style="text-align: right"><%=Hdeno500%></td>
                            </tr>
                            <tr>
                                <td style="text-align: left">Rs 200</td>
                                <td style="text-align: right"><%=deno200%></td>
                                <td style="text-align: right"><%=odeno200%></td>
                                <td style="text-align: right"><%=Hdeno200%></td>
                            </tr>
                            <tr>
                                <td style="text-align: left">Rs 100</td>
                                <td style="text-align: right"><%=deno100%></td>
                                <td style="text-align: right"><%=odeno100%></td>
                                <td style="text-align: right"><%=Hdeno100%></td>
                            </tr>
                            <tr>
                                <td style="text-align: left">Rs 50</td>
                                <td style="text-align: right"><%=deno50%></td>
                                <td style="text-align: right"><%=odeno50%></td>
                                <td style="text-align: right"><%=Hdeno50%></td>
                            </tr>
                            <tr>
                                <td style="text-align: left">Rs 20</td>
                                <td style="text-align: right"><%=deno20%></td>
                                <td style="text-align: right"><%=odeno20%></td>
                                <td style="text-align: right"><%=Hdeno20%></td>
                            </tr>
                            <tr>
                                <td style="text-align: left">Rs 10</td>
                                <td style="text-align: right"><%=deno10%></td>
                                <td style="text-align: right"><%=odeno10%></td>
                                <td style="text-align: right"><%=Hdeno10%></td>
                            </tr>
                            <tr>
                                <td style="text-align: left">Rs 5</td>
                                <td style="text-align: right"><%=deno5%></td>
                                <td style="text-align: right"><%=odeno5%></td>
                                <td style="text-align: right"><%=Hdeno5%></td>
                            </tr>
                            <tr>
                                <td style="text-align: left">Rs 2</td>
                                <td style="text-align: right"><%=deno2%></td>
                                <td style="text-align: right"><%=odeno2%></td>
                                <td style="text-align: right"><%=Hdeno2%></td>
                            </tr>
                            <tr>
                                <td style="text-align: left">Rs 1</td>
                                <td style="text-align: right"><%=deno1%></td>
                                <td style="text-align: right"><%=odeno1%></td>
                                <td style="text-align: right"><%=Hdeno1%></td>
                            </tr>
                            <tr>
                                <td style="text-align: left">50 Paisa</td>
                                <td style="text-align: right"><%=deno50p%></td>
                                <td style="text-align: right"><%=odeno50p%></td>
                                <td style="text-align: right"><%=Hdeno50p%></td>
                            </tr>
                            <tr>
                                <td style="text-align: left">1 Paisa</td>
                                <td style="text-align: right"><%=deno1p%></td>
                                <td style="text-align: right"><%=odeno1p%></td>
                                <td style="text-align: right"><%=Hdeno1p%></td>
                            </tr>
                        </tbody>

                    </table>
                    <p style="font-size:medium; font-weight: bold">
                        Total Cash Available: <input type="text" style="text-align: right; font-weight: bold" readonly id="totalcash" name="totalcash" value="<%=totalAmt%>"/>
                    </p>

                    &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp
                    <input type="button" value="Close Cash Drawer" onclick="closeDrawer()"/>

                </center>

                <%}%>
                <% }%>
            </fieldset>
        </form>

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

