<%--
    Document   : CRAR Worth Master
    Created on : July 18, 2022, 12:31:10 PM
    Author     : 1242938
--%>

<%@page import="DataEntryBean.AssetEntryBean"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Connection"%>
<%@page import="DataEntryBean.AssetRegisterBean"%>
<%@page import="java.util.ArrayList"%>
<%@page import="LoginDb.DbHandler"%>
<% try {
%>

<html>

    <head>
        <title>CRAR Worth Master</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>
        <script type="text/javascript">

            function noBack()
            {
                window.history.forward();
            }
            function submitform(crarWorthMaster)
            {
                if (checkDiv(crarWorthMaster))
                {
                    document.forms[0].handle_id.value = "Create";
                    document.forms[0].action='/PacsApplication/CRARWorthMasterServlet';
                    document.forms[0].submit();
                }
            }
            function amendform(crarWorthMaster)
            { 
                if (checkDivAmend(crarWorthMaster))
                {
                document.forms[0].handle_id.value = "Amend";
                document.forms[0].action = '/PacsApplication/CRARWorthMasterServlet';
                document.forms[0].submit();
                }
            }
            function getDetails(crarWorthMaster)
            {
                document.forms[0].handle_id.value = "getDetails";
                document.forms[0].action = '/PacsApplication/CRARWorthMasterServlet';
                document.forms[0].submit();
            }
            function ShowParent()
            {
                document.forms[0].action="${pageContext.request.contextPath}/Asset_JSP/crarWorthMaster.jsp";
                document.forms[0].submit();
            }
            function checkDiv(crarWorthMaster)
            {
                var counter = document.forms[0].rowCounter.value; 
                
                for (var i = 1; i <= counter; i++) {
                    try{                        
                        var glcode = document.getElementById("glcode" + i).value;
                        var remarks = document.getElementById("remarks" + i).value;
                        
                        if ( glcode == "" || remarks =="") 
                        {
                            alert("Please enter all details.");
                            return false;
                        }                                                  
                    }
                    catch(e){}
                }                
                return true;
            } 
            function checkDivAmend(crarWorthMaster)
            {
                var counter2 = document.forms[0].rowCounter2.value; 
                
                for (var i = 2; i < counter2; i++) {
                    try{                        
                        var glcode = document.getElementById("glcode" + i).value;
                        var remarks = document.getElementById("remarks" + i).value;
                        
                        if ( glcode == "" ) 
                        {
                            alert("Please enter all details.");
                            return false;
                        }
                    }
                    catch(e){}
                }                
                return true;
            }
            function SearchGL(width, height, textIndex) 
            {
            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 = "crarWorthMaster.jsp";
            var lovKey = "gl"
            popWin = open('${pageContext.request.contextPath}/CommonSearchInformation_ASSET_LOV.jsp?screenName=' + screenName+'&lovKey='+lovKey + '&glcode=' + glcode + '&textIndex=' + textIndex, 'gl', attr);
            popWin.focus();
            }
            function checkop()
            {                
                if (document.getElementById("checkOption").value == "create")
                {
                    document.getElementById('create').style.display = 'block';
                    document.getElementById('forAmend').style.display = 'none';
                    document.getElementById('amend').style.display = 'none';
                }
                if (document.getElementById("checkOption").value == "amend")
                {
                    document.getElementById('create').style.display = 'none';
                    document.getElementById('forAmend').style.display = 'block';
                }
            }
            // to restrict going back 
            history.pushState(null, null, location.href);
            window.addEventListener('popstate', function(event) {
                history.pushState(null, null, location.href);
            });
            
        </script>
    </head>
    <body onload="noBack()">

        <%
                    int count = 1;
                    String error_msg = "";
                    Object error = request.getAttribute("message");
                    if (error != null) {
                        error_msg = error.toString();
                    }
        %>
        <%!
            String blankNull(String s) {
                return (s == null) ? "" : s;
            }
        %>
        <%
             String displayFlag = "";
             Object display = request.getAttribute("displayFlag");
             if (display != null) {
                 displayFlag = display.toString();
             }
        %>
        <%
                    Object oAssetEntryBeanObj = request.getAttribute("oAssetEntryBean");
                    Object alAssetEntryBeanObj = request.getAttribute("arrAssetEntryBean");

                    AssetEntryBean oAssetEntryBean = new AssetEntryBean();
                    if (oAssetEntryBeanObj != null) {
                        oAssetEntryBean = (AssetEntryBean) request.getAttribute("oAssetEntryBean");
                    }

                    ArrayList<AssetEntryBean> alAssetEntryBean = new ArrayList<AssetEntryBean>();
                    if (alAssetEntryBeanObj != null) {
                        alAssetEntryBean = (ArrayList<AssetEntryBean>) request.getAttribute("arrAssetEntryBean");
                    }
        %>
<style>
.vertical-menu { 
  height: 280px;
  width: 680px;
  overflow-y: auto;
}
</style>
        
        <jsp:include page="MenuHead_ASSET.jsp" flush="true" />
        <br>
        <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">CRAR Worth Master</legend>

            <form id="crarWorthMaster" name="crarWorthMaster" method="post" action="">                
               
               <%if (!error_msg.equalsIgnoreCase("")) {%>
                <center><div class="info" id="errorMessage"><center><%= error_msg%></center></div></center>
                <% }%>
                <br>

                <center><label style=" font-family: Berlin Sans FB; font-weight:  normal;">Operation Selection:</label>
                    <select id="checkOption" onchange="checkop()" name="checkOption" >
                        <option value="" style="display:none;" >--Select--</option>                            
                            <option value="create" >Create</option>
                            <option value="amend" >Amend</option>
                    </select>                    
                </center>  
                <br>
                <div id="create" style="display:none;">
                    <center>
                        <br><br>    
                        <table id="order-list" style="margin-left: 20px;" class="NumbersOnly"  border="2" cellspacing="1" cellpadding="1" style="text-align: center ;overflow-y: scroll; font-size: 15px; width: 100%;">
                            <thead  class="CSSTableGenerator" >
                                <tr border="2">
                                    <td></td>                                    
                                    <td colspan="2">GL Name</td>                                    
                                    <td>Remarks</td>
                                    <td>Status</td>
                                </tr>
                            </thead>
                            <tbody>
                                <tr>
                                    <td><input type="checkbox" name="chckbox<%=count%>" id="chckbox<%=count%>" onclick="checkboxTrue(<%=count%>);" /></td>
                                    <td><input size="30" type="text" name="glcode<%=count%>" id="glcode<%=count%>" ondrop="return false;" onpaste="return false;" /></td>  
                                    <td><input type="button" style="width: 70px" name="SearchGL<%=count%>" id="SearchGL<%=count%>" value="Search" onclick="javascript:SearchGL(550,240,<%=count%>);" /></td>                                    
                                    <td><input size="20" type="text" name="remarks<%=count%>" id="remarks<%=count%>" onmouseover="calDays(formPayroll)"/></td>
                                    <td><select style="width:100px" id="status<%=count%>" name="status<%=count%>" >
                                            <option value="N">No</option><option value="Y">Yes</option></select></td>
                                    <td style="display: none;"><input type="hidden" name="id<%=count%>" id="id<%=count%>"/></td>
                                    <td style="display: none;"><input type="hidden" name="glid<%=count%>" id="glid<%=count%>"/></td>
                                    <td style="display: none;"><input type="hidden" name="comp1<%=count%>" id="comp1<%=count%>"/></td>
                                    <td style="display: none;"><input type="hidden" name="comp2<%=count%>" id="comp2<%=count%>"/></td>
                                </tr>
                            </tbody>
                        </table>
                        <br/><br/>
                        <center>
                            <input type="button" id="addRow" value="Add Row"/>
                            <input type="button" id="deleteRow" value="Delete Row"/>
                            <input type="button" value="Submit" onclick="javascript:submitform(crarWorthMaster)"/>
                            <input type="button" value="Reset" onclick="ShowParent();" />

                        </center>
                        <input type="hidden" name="rowCounter" id="rowCounter" value="<%=count%>">
                        <input type="hidden" name="rowCounterDelete" id="rowCounterDelete" value="<%=count%>">
                        <input type="hidden" name="chkboxCounter" id="chkboxCounter" value="0"/>                    
                    </center>
                </div>
                
                <center>        
                <div id="forAmend" style="display:none;" >    
                                        
                    <center>    
                    <tr><input type="button" value="Fetch CRAR Worth Master Details" onclick="javascript:getDetails()" /></tr>
                    <input type="button" value="Reset" onclick="ShowParent();" />    
                    </center>                         
                </div>        
                </center>
                <%if (displayFlag.equalsIgnoreCase("Y")) {%>
                <div id="amend" >
                    <center>
                    <div class="vertical-menu" >                                         
                    <table id="order-listAmend" >
                        <thead  class="CSSTableGenerator" >
                            <tr>                                
                                    <td colspan="2">GL Name</td>                                    
                                    <td>Remarks</td>
                                    <td>Status</td>
                            </tr>
                        </thead>
                        <tbody style="background-color: white; font-size: 15px">
                            <%
                                oAssetEntryBean = null;
                                oAssetEntryBean = new AssetEntryBean();
                                int count2= 1;

                                for (int i = 0; i < alAssetEntryBean.size(); i++) {
                                    oAssetEntryBean = alAssetEntryBean.get(i);
                                    count2++;
                            %>
                            <tr>
                                    <td><input size="30" type="text" name="glcode<%=count2%>" id="glcode<%=count2%>" ondrop="return false;" onpaste="return false;" value="<%=blankNull(oAssetEntryBean.getGlcode())%>" /></td>  
                                    <td><input type="button" style="width: 70px" name="SearchGL<%=count2%>" id="SearchGL<%=count2%>" value="Search" onclick="javascript:SearchGL(550,240,<%=count2%>);" /></td>                                    
                                    <td><input size="20" type="text" name="remarks<%=count2%>" id="remarks<%=count2%>" value="<%=blankNull(oAssetEntryBean.getRemarks())%>"/></td>                                
                                    <td><select style="width: 150px"  name="status<%=count2%>" id="status<%=count2%>" >
                                        <option <%if (oAssetEntryBean.getStatus().equalsIgnoreCase("Y")) {%>selected <%}%> value="Y">Yes</option>
                                        <option <%if (oAssetEntryBean.getStatus().equalsIgnoreCase("N")) {%>selected <%}%> value="N">No</option>
                                    </select></td>
                                    <td style="display:none"><input type="hidden" name="id<%=count2%>" id="id<%=count2%>" value="<%=blankNull(oAssetEntryBean.getId())%>"></td>
                                    <td style="display:none"><input type="hidden" name="glid<%=count2%>" id="glid<%=count2%>" value="<%=blankNull(oAssetEntryBean.getGlid())%>"></td>
                                    <td style="display:none"><input type="hidden" name="comp1<%=count2%>" id="comp1<%=count2%>" value="<%=blankNull(oAssetEntryBean.getComp1())%>"></td>
                                    <td style="display:none"><input type="hidden" name="comp2<%=count2%>" id="comp2<%=count2%>" value="<%=blankNull(oAssetEntryBean.getComp2())%>"></td>
                            </tr>

                            <%}%></tbody>
                    </table>                    
                    </div>
                    </center> 
                    <br><br>
                        <center>
                            <input type="button" value="Submit" onclick="javascript:amendform(crarWorthMaster)"/>
                            <input type="button" value="Reset" onclick="ShowParent();" />
                        </center>    
                            <input type="hidden" name="indicator" id="indicator" value="">
                            <input type="hidden" name="rowCounter2" id="rowCounter2" value="<%=count2%>">
                            <input type="hidden" name="chkboxCounter" id="chkboxCounter" value="0">                 
                </div>
            <%}%>                
                <input type="hidden" name="handle_id" value="" />
                <input type="hidden" name="actionApl" value="" />
                <input type="hidden" name="vendor_id" id="vendor_id"/>
                <input type="hidden" id="displayFlag" name="displayFlag" value="<%=displayFlag%>"/>
            </form>
            <script>
                               
                $("#addRow").click(function(){

                   
                    counter++;
                    $('#order-list tr:last').after('<tr> <td align="center"><input type="checkbox" name="chckbox'+counter+'" id="chckbox'+counter+'" onclick="checkboxTrue('+counter+');"/></td>\n\
                                    <td><input size="30" type="text" name="glcode'+counter+'" id="glcode'+counter+'" ondrop="return false;" onpaste="return false;" /></td>\n\
                                    <td><input type="button" style="width: 70px" name="SearchGL'+counter+'" id="SearchGL'+counter+'" value="Search" onclick="javascript:SearchGL(550,240,'+counter+');" /></td>\n\
                                    <td><input size="20" type="text" id="remarks' + counter + '" name="remarks' + counter + '" onmouseover="calDays(formPayroll)" /></td>\n\
                                    <td><select style="width:100%" id="status' + counter + '" name="status' + counter + '" ><option value="N">No</option><option value="Y">Yes</option></select></td>\n\
                                    <td style="display: none;"><input type="hidden" name="id'+counter+'" id="id'+counter+'"/></td>\n\
                                    <td style="display: none;"><input type="hidden" name="glid'+counter+'" id="glid'+counter+'"/></td>\n\
                                    <td style="display: none;"><input type="hidden" name="comp1'+counter+'" id="comp1'+counter+'"/></td>\n\
                                    <td style="display: none;"><input type="hidden" name="comp2'+counter+'" id="comp2'+counter+'"/></td>\n\\n\
                                    </tr>');
                    $("#rowCounter").val(counter);
                    $("#rowCounterDelete").val(counter);
                });
                $( "#deleteRow" ).click(function() 
                {
                    var len = ($("#order-list tr").length)-1;
                    var rowcount = $("#rowCounterDelete").val();
                    var chkboxCounter=$("#chkboxCounter").val();
                    var counterDelete = rowcount-chkboxCounter;
                    
                    if (counterDelete == 0) {
                        alert("All rows can not be deleted");
                        return false;
                    }
                    else{
                        if (len ==chkboxCounter) {
                            alert("All rows can not be deleted");
                            return false;
                        }                        
                        $('input:checkbox:checked').closest('tr').remove();

                        $("#rowCounterDelete").val( $("#rowCounter").val());
                        chkboxCounter=0;
                        $("#chkboxCounter").val(chkboxCounter);
                    }                       
                });
                function checkboxTrue(i)
                {
                    if(document.getElementById("chckbox"+i).checked==true)
                    {
                        var counter = $("#chkboxCounter").val();
                        counter++;
                        $("#chkboxCounter").val(counter);
                    }
                    else{
                        var counter = $("#chkboxCounter").val();
                        counter--;
                        $("#chkboxCounter").val(counter);
                    }
                }
                
            </script>
        </fieldset>
    </body>
</html>
<% 	} catch (Exception e) {
                
            }
%>