<%@ page contentType="text/html; charset=iso-8859-1" language="java" errorPage="" %>
<%@ page import="com.fenalco.utilities.lists.ListView"%>
<%@ page import="com.fenalco.entities.User"%>
<%@ page import="com.fenalco.entities.DataAccess"%>
<%@ page import="com.fenalco.entities.ShoppingCart"%>
<%@ page import="java.util.Vector"%>
<%
    ListView proveedores = ( ListView )request.getAttribute( "proveedores" );
    ListView productos = ( ListView )request.getAttribute( "productos" );
    
    String inicio = ( String )request.getAttribute( "inicio" );
    String fin = ( String )request.getAttribute( "fin" );
    String total = ( String )request.getAttribute( "total" );
    String pagina = ( String )request.getAttribute( "pagina" );
    String paginas = ( String )request.getAttribute( "paginas" );
    String cantidad = ( String )request.getAttribute( "cantidad" );
    
    boolean esNombre = ( ( Boolean )request.getAttribute( "esNombre" ) ).booleanValue();
    String nombre = ( String )request.getAttribute( "nombre" );
    int proveedor = ( ( Integer )request.getAttribute( "proveedor" ) ).intValue();
    String categoria = ( String )request.getAttribute( "categoria" );
    int ordenamiento = ( ( Integer )request.getAttribute( "ordenamiento" ) ).intValue();
    
    String message = null;
    message = ( String )request.getAttribute( "message" );
    if( message == null )
    {
        message = "";
    }
    
    Vector prices = ( Vector )request.getAttribute( "prices" );
    
    ShoppingCart cart = ( ShoppingCart )( ( HttpSession )request.getSession() ).getAttribute( "cart" );
    double totalPrice = 0;
    if( cart != null )
    {
        totalPrice = cart.getTotalPrice();
    }
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link rel='stylesheet' style='text/css' href='../css/tablas.css'>
<title>Cat&aacute;logo de Productos</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#ffffff" background="../images/shopkeeper/general/fondo.jpg" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<!-- 
-->
<%
	String helpId = "40";
%>
<table border="0" cellpadding="0" cellspacing="0" width="780">
    <%@ include file="encabezado.jsp" %>
</table>


<table width="760" border="0" cellspacing="0" cellpadding="0">
    
    <tr>
        <td width="155" valign="top">
			<%@ include file="menuminorista.jsp" %>
	</td>
        <td width='603' valign="top">
        
        <table>
            <tr>
                <td>
                    <table>
                        <tr>
                            <td>
                                <font color='#FF0000'><%=message%></font>
                            </td>
                        </tr>
                        <tr align='left'>
                            <td align='left'>
                                <%
                                    String tittle = "Buscador";
                                %>
                                <%@ include file="/titulo.jsp" %>
                            
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <table>
                                    <tr>
                                        <td valign='top'>
                                            <!-- vista-->
                                                    <table border="0" cellpadding="0" cellspacing="0" width="170">
                                                          <!-- fwtable fwsrc="BARRA_~1.PNG" fwbase="resu_pedido.jpg" fwstyle="Dreamweaver" fwdocid = "742308039" fwnested="0" -->
                                                          <tr> 
                                                            <td><img src="../images/shopkeeper/general/spacer.gif" name="undefined_2" width="7" height="1" border="0"></td>
                                                            <td><img src="../images/shopkeeper/general/spacer.gif" name="undefined_2" width="74" height="1" border="0"></td>
                                                            <td><img src="../images/shopkeeper/general/spacer.gif" name="undefined_2" width="81" height="1" border="0"></td>
                                                            <td><img src="../images/shopkeeper/general/spacer.gif" name="undefined_2" width="8" height="1" border="0"></td>
                                                            <td><img src="../images/shopkeeper/general/spacer.gif" name="undefined_2" width="1" height="1" border="0"></td>
                                                          </tr>
                                                          <tr> 
                                                            <td colspan="4"><img name="resu_pedido_r1_c1" src="../images/shopkeeper/general/resu_pedido_r1_c1.jpg" width="170" height="31" border="0"></td>
                                                            <td><img src="../images/shopkeeper/general/spacer.gif" name="undefined_2" width="1" height="31" border="0"></td>
                                                          </tr>
                                                          <tr> 
                                                            <td  height='10' background="../images/shopkeeper/general/resu_pedido_r2_c1.jpg">&nbsp;</td>
                                                            <td colspan="2"><table width="152" border="0" cellspacing="1" cellpadding="0">
                                                                <tr> 
                                                                  <td bgcolor="#F2F2F2">&nbsp;</td>
                                                                </tr>
                                                                <tr> 
                                                                  <td align='center'><b>TOTAL</b> <%=DataAccess.getCurrency( totalPrice )%></td>
                                                                </tr>
                                                                <tr> 
                                                                  <td bgcolor="#F2F2F2">&nbsp;</td>
                                                                </tr>
                                                                <!--<tr> 
                                                                  <td height="20">&nbsp;</td>
                                                                </tr>
                                                                <tr> 
                                                                  <td bgcolor="#F2F2F2">&nbsp;</td>
                                                                </tr> -->
                                                              </table></td>
                                                            <td height='10' background="../images/shopkeeper/general/resu_pedido_r2_c4.jpg">&nbsp;</td>
                                                            <td><img src="../images/shopkeeper/general/spacer.gif" name="undefined_2" width="1" height="10" border="0"></td>
                                                          </tr>
                                                          <tr> 
                                                                                                                        <!-- botones-->
                                                            <td colspan="2">
                                                                    <form name="ver_carrito" action="/minorista/micarrito">
                                                                            <input type="image" src="../images/shopkeeper/general/resu_pedido_r3_c1.jpg" >
                                                                    </form>
                                                                    
                                                            </td>
                                                            <td colspan="2">
                                                                    
                                                                    <form name="ver_carrito" action="/minorista/actualizarcarrito">
                                                                        <input type="hidden" name="event" value='pedido'>
                                                                         <%
                                                                            if( totalPrice > 0 )
                                                                            {   
                                                                        %>
                                                                        <input type="image" src="../images/shopkeeper/general/resu_pedido_r3_c3.jpg">
                                                                        <%  }
                                                                            else{%>
                                                                            <img name="resu_pedido_r3_c3" src="../images/shopkeeper/general/resu_pedido_r3_c3.jpg" width="89" height="28" border="0">
                                                                         <%}%>
                                                                    </form>
                                                                    
                                                            </td>
                                                            
                                                            <td>
                                                                 
                                                                <img src="../images/shopkeeper/general/spacer.gif" name="undefined_2" width="1" height="28" border="0">
                                                            </td>
                                                          </tr>
                                                        </table>
                                        </td>
                                        <td width='1' bgcolor='#efefef'>&nbsp;
                                            
                                        </td>
                                        <td>
                                            <!-- buscador -->
                                                     <table border="0">
    
                                                            <form action="/minorista/catalogo" method="post" name="buscador" id="buscador">
                                                            <tr>
                                                              <td ><div align="right">
                                                                <select name="esnombre">
                                                                  <option value='1' <%if( esNombre ){%>selected<%}%>>NOMBRE</option>
                                                                  <option value='2' <%if( !esNombre ){%>selected<%}%>>CODIGO</option>
                                                                </select>
                                                              </div></td>
                                                              <td ><input type="text" name="nombre" value='<%=nombre%>'></td>
                                                            </tr>
                                                            <tr>
                                                              <td><div align="left"><b>Proveedor:</b></div></td>
                                                              <td><select name="proveedor">
                                                                    <option value='0' <%if( proveedor == 0 ){%>selected<%}%>>TODOS</option>
                                                                <%
                                                                    while( proveedores.move() )
                                                                    {
                                                                        int id = Integer.parseInt( ( String )proveedores.nextElement() );
                                                                        proveedores.nextElement(); // me salto 2 para obtener el nombre
                                                                        proveedores.nextElement();
                                                                        String name = ( String )proveedores.nextElement();
                                                                        %>
                                                                            <option value="<%=id%>"<%if( proveedor == id ){%>selected<%}%>><%=name%></option>
                                                                        <%
                                                                    }
                                                                %>

                                                              </select></td>
                                                            </tr>
                                                            <tr>
                                                              <td><div align="left"><b>Categor&iacute;a:</b></div></td>
                                                              <td><input type="text" name="categoria" value="<%=categoria%>"></td>
                                                            </tr>
                                                            <tr>
                                                              <td><div align="left"><b>Ordenar por: </b></div></td>
                                                              <td><select name="ordenamiento">
                                                                <option value="1" <%if( ordenamiento == 1 ){%>selected<%}%>>CODIGO BARRAS</option>
                                                                <option value="2" <%if( ordenamiento == 2 ){%>selected<%}%>>NOMBRE</option>
                                                                <option value="3" <%if( ordenamiento == 3 ){%>selected<%}%>>CATEGORIA</option>
                                                                <option value="4" <%if( ordenamiento == 4 ){%>selected<%}%>>PROVEEDOR</option>
                                                              </select></td>
                                                            
                                                                <td colspan='4' align="center">
                                                                    <input type="submit" value='Buscar' name='Buscar' id='Buscar'>
                                                                </td>
                                                            </tr>
                                                            
                                                           
                                                          </table>  
                                        </td>
                                    </tr>
                                    
                                </table>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <hr>
                            </td>
                        </tr>
                        <tr align='center'>
                            <td>
                            <table align='center'>
                                <tr>
                        
                                    <td align="center" colspan='5'>
                                        P&aacute;gina <input type="text" name='pagina' value='<%=pagina%>' size='2'> de <%=paginas%>
                                    </td>
                                    </tr>
                                <tr>
                                    <td>
                                        <input type="submit" name='ir' value='Ver' id='ir'><input type="text" name='cantidad' value='<%=cantidad%>' size='2'> Resultados por p&aacute;gina
                                       
                                    </td>
                                </tr>
                            </table>
                             </td>       
                             </form>
                        </tr>
                    </table>
                
                
                </td>
                
            </tr>
            <!-- buscador y vista-->
            <tr>
                <td>
                
                    <table>
                        <tr>
                            <td>
                                <%
                                    tittle = "Cat&aacute;logo de productos";
                                %>
                                <%@ include file="/titulo.jsp" %>
                            </td>
                            
                        </tr>
                        <tr>
                            <td>
                                    <table border="0" align="left" width='100%'>
                                              <tr class='tableheader'>
                                                <td><div align="center"><strong>C&oacute;digo Barras</strong></div></td>
                                                <td><div align="center"><strong>Nombre</strong></div></td>
                                                <td><div align="center"><strong>Categor&iacute;a</strong></div></td>
                                                <td><div align="center"><strong>Marca</strong></div></td>
                                                <td><div align="center"><strong>Proveedor</strong></div></td>
                                                <td colspan='2'><div align="center"><strong>Precio</strong></div></td>
                                                <td><div align="center"><strong>Ver</strong></div></td>
                                                <td><div align="center"><strong>carrito</strong></div></td>
                                              </tr>
                                                <form name="productos" method="post" action='/minorista/administrarcatalogo'>
                                                <%
                                                    int i = 0;
                                                    int count = 0;
                                                    String color = "";
                                                    while( productos.move() )
                                                    {
                                                        if( count % 2 == 0 )
                                                        {
                                                            color = "FFFFFF";
                                                        }
                                                        else
                                                        {
                                                            color = "EFEFEF";
                                                        }
                                                        count++;
                                                        int id = Integer.parseInt( ( String )productos.nextElement() );
                                                        int quantity = 0;
                                                        if( cart != null )
                                                        {
                                                            quantity = cart.containsProduct( id );
                                                        }
                                                        %>
                                                            <tr bgcolor='#<%=color%>'>
                                                                <td><%=productos.nextElement()%></td>
                                                                <td><%=productos.nextElement()%></td>
                                                                <td><%=productos.nextElement()%></td>
                                                                <td><%=productos.nextElement()%></td>
                                                                <td><%=productos.nextElement()%></td>
                                                                <td align="right"><%=DataAccess.getCurrency( ( ( Double )prices.elementAt( i++ ) ).doubleValue() )%></td>
                                                                <td><a href="#"><img  name="view" src="/images/buttons/shopkeeper/escalas.gif" border="0" onclick="window.open('/minorista/verescala?prodid=<%=id%>','','WIDTH=200,HEIGHT=200');" alt='ver escalas'></a></td>
                                                                
                      <td align="center"><a href="#"><img  name="view" src="/images/buttons/shopkeeper/detalle.gif" border="0" onclick="window.open('/minorista/verproducto?key=<%=id%>','','HEIGHT=400,WIDTH=448,scrollbars=yes');" alt='ver producto'></a></td>
                                                                <td align="center">
                                                                <%
                                                                    if( quantity > 0 )
                                                                    {
                                                                        %>
                                                                            <%=quantity%>
                                                                        <%
                                                                    }
                                                                %>
                                                                    <!--<form name="form1" method="post" action="">-->
                                                                        <input name="producto_<%=id%>" type="text" size="2" maxlength="10" value='0'>
                                                                        <!--<input type="submit" name="Submit" value="OK">-->
                                                                    <!--</form>-->
                                                                </td>
                                                            </tr>
                                                        <%
                                                    }
                                                    if( count == 0 )
                                                    {
                                                        %>
                                                        <tr>
                                                            <td align="center" colspan='8'>
                                                                <strong>No se han encontrado productos</strong>
                                                            </td>
                                                        </tr>
                                                        <%
                                                    }
                                                %>
                                              <tr>
                                              </tr>
                                              <tr>
                                                <td colspan='9'>
                                                    <%if( count > 0 ){%><div align="right"><input type='image' name='agregar al carrito' src='/images/buttons/shopkeeper/agregarcarrito.gif'></div><%}%>
                                                </td>
                                              </tr>
                                            </table>
                                                </form>
                            </td>
                        </tr>
                    </table>
                
                </td>
            </tr>
            <!-- catalogo -->
            
            
        </table>
        <!-- final tabla mario-->
  
<p>
    Resultados <%=inicio%> - <%=fin%> de <%=total%>
</p>
</td>
</tr>
</table>
<table width="760">
	<tr>
		<td><%@ include file="/piepagina.jsp" %></td>
	</tr>
</table>


</body>
</html>
