<%@ page import="java.util.Hashtable"%>
<%@ page import="java.util.Vector"%>
<%@ page import="java.util.Enumeration"%>
<%@ page import="com.fenalco.entities.User"%>
<%@ page import="com.fenalco.entities.DataAccess"%>
<%@ page import="com.fenalco.entities.PriceScale"%>
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<html>
<head>
<link rel='stylesheet' style='text/css' href='../css/tablas.css'>
<title>Escala de Precios</title>
</head>
<!-- 
	Esta pÃ¡gina le permite al proveedor agregar una nueva comunidad
	Para ello debe ingresar como datos de registro el nombre y
	la descripciÃ³n de la comunidad.
	
-->
<script type='text/javascript' language='javascript' src='../js/library.js'></script>
<script>

    function submitCombo(comboName){
            document.community.combo.value=comboName;
            document.community.submit();
            document.community.operationType.value="view";
            return true;
    }
    
    function validateForm(formName)
    {
            var message = "Han ocurrido los siguientes errores:\n";
            var flag = true;
            if( isEmpty(formName.newMax) )
            {
                    message = message + "- El campo máximo de la escala está vacío.\n";
                    flag = false;
            }
            else if(!isNumber(formName.newMax)){
                     message = message + "- El campo máximo de la escala no es de tipo numérico.\n";
                     flag = false;
                
            }else if(formName.newMax.value < formName.newMin.value){
                    message = message + "- El campo máximo de la escala no es mayor que el campo mínimo\n";
                     flag = false;
            }else{
                if(isEmpty(formName.newPrice)){
                    message = message + "- El campo precio de la escala está vacío.\n";
                    flag = false;
                }else{
                    if(!isNumber(formName.newPrice)){
                         message = message + "- El campo precio de la escala no es de tipo numérico.\n";
                         flag = false;
                    }
                }
            }
            
            
            
            
            
            if(!flag){
                    window.alert(message);
            }
                        
            return flag;
    }

</script>
<body bgcolor="#ffffff" background="../images/supplier/general/fondo.jpg" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<%
	String helpId = "59";
%>
<table border="0" cellpadding="0" cellspacing="0" width="760">
    <%@ include file="encabezado.jsp" %>
</table>

<table width="760" border='0' align='left'>
   
    <tr>
        <td width="152" valign='top'>
			<%@ include file="menuproveedor.jsp" %>
	</td>
        <td valign='top'>
            <%
                String tittle = "Escala de Precios - "+(String)request.getAttribute( "supplierProductName" );
            %>
            <%@ include file="/titulo.jsp" %>

			<table width="100%">
                                <tr><td align="center"><%=(String)request.getAttribute("message")%></td></tr>
				<tr>
                                    <form name="priceScale" method="post" action="/proveedor/administrarescala">
                                        <table align="center" width='70%'>
                                                <tr align='center' class='tableheader'>
                                                    <td><strong>Cantidad M&iacute;nima</td>
                                                    <td><strong>Cantidad M&aacute;xima</td>
                                                    <td><strong>Precio por unidad $</td>
                                                    <td><strong>Actualizar</td>
                                                    <td><strong>Eliminar</td>
                                                </tr>    
                                                
                                                <%
                                                PriceScale priceScale= (PriceScale)request.getAttribute("priceScale");
                                                int j =0;
                                                int size = priceScale.getValues().size();
                                                int i =0;
                                                while(j < priceScale.getValues().size()){
                                                    i++;
                                                    %><tr align='center'><%
                                                    Vector v = (Vector)(priceScale.getValues().elementAt(j));
                                                    int id = ((Integer)v.elementAt(0)).intValue();
                                                    %><td><%=((Integer)v.elementAt(1)).intValue()%></td><%
                                                    %><td><%=((Integer)v.elementAt(2)).intValue()%></td><%
                                                    %><td><input type='text' name='<%=id%>' value='<%=((Double)v.elementAt(3)).doubleValue()%>' size='6'></td>
                                                    <td><a href='#'><img name='Actualizar' src='/images/buttons/supplier/actualizar.gif' border='0'  onClick="document.priceScale.operationType.value='update';document.priceScale.action='/proveedor/administrarescala?key=<%=id%>';document.priceScale.submit();"></a></td>
                                                    <%if(i==size){%>
                                                        <td><a href='#'><img name='Eliminar' src='/images/buttons/supplier/eliminar.gif' border='0' onClick="document.priceScale.operationType.value='delete';document.priceScale.action='/proveedor/administrarescala?key=<%=id%>';document.priceScale.submit();"></a></td>
                                                    <%}
                                                    j++;%>
                                                    </tr>
                                                <%}%>
                                                
                                                <tr><td colspan="5" align="center">&nbsp;</td></tr>
                                                <tr><td colspan="5" align="center">&nbsp;</td></tr>
                                                <input type='hidden' name='communityId' value='<%=((Integer)request.getAttribute("communityId")).intValue()%>'>
                                                <input type='hidden' name='supplierProductId' value='<%=((Integer)request.getAttribute("supplierProductId")).intValue()%>'>
                                                <input type='hidden' name='key' value='<%=((Integer)request.getAttribute("supplierProductId")).intValue()%>'>
                                        </table>
                                        <%
                                            tittle = "Nuevo Rango Escala";
                                        %>
                                        <%@ include file="/titulo.jsp" %> 
                                        <table align='center'>
                                                <tr align='center' class='tableheader'>
                                                    <td><strong>M&iacute;nimo</td>
                                                    <td><strong>M&aacute;ximo</td>
                                                    <td><strong>Precio</td>
                                                </tr>
                                                <tr>
                                                    <%
                                                        int newMin = ((Integer)request.getAttribute("nextMin")).intValue();
                                                        String readonly= "";
                                                        if(newMin>1){
                                                            readonly = "readonly";
                                                        }
                                                    %>
                                                    <td><input type='text' name='newMin' size='6' value="<%=newMin%>" <%=readonly%>></td>
                                                    <td><input type='text' name='newMax' size='6'></td>
                                                    <td><input type='text' name='newPrice' size='6'></td>
                                                </tr>
                                                <tr>
                                                    
                                                    <td colspan='3'>&nbsp;</td>
                                                    
                                                </tr>
                                                <tr>
                                                    <td colspan='3' align='center'><input type='submit' name='agregar' value='Agregar Rango' onClick="document.priceScale.operationType.value='add';return validateForm(document.priceScale);"></td>
                                                </tr>
                                                <input type='hidden' name='operationType' value=''>
                                                <tr><td colspan='3' align='center'>&nbsp;</td></tr>
                                                <tr><td colspan='3' align='center'>&nbsp;</td></tr>
                                                <tr><td colspan='3' align='center'><input type='submit' name='agregar' value='Ver Productos' onClick="document.priceScale.action='/proveedor/productoescalas';"></td></tr>
                                        </table>		
                                </form>
				</tr>
	</td>
    </tr>
	
</table>
</body>
</html>
