<%@ 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();
    Vector categorias = ( Vector )request.getAttribute( "categorias" );
    
    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">

<script language='javascript'>
    function nextPage()
    {
        document.getElementById( 'pagina' ).value = <%=pagina%> + 1;
        document.getElementById( 'buscador' ).submit();
    }
    
    function previousPage()
    {
        document.getElementById( 'pagina' ).value = <%=pagina%> - 1;
        document.getElementById( 'buscador' ).submit();
    }
</script>
</head>
<body bgcolor="#ffffff" background="../images/shopkeeper/general/fondo.jpg" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0"  onload='showMessage("<%=message%>")'>
<script>
     function showMessage(message){
        if(message!=null && message!="")
        {
            window.alert(message);
        }
        return true;
    }
</script>

<!-- 
-->
<%
	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">
			<table width="150"  border="0" cellspacing="0" cellpadding="0">
			  <tr>
				<th scope="col" valign="top"><br>
				  <table width="150" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFF5C7">
					<tr>
					  <td colspan="2"><img src="images/mi-pedido.gif" width="150" height="26"></td>
					</tr>
					<tr>
					  <td width="149" background="images/fondo-menu.gif"><img src="images/fondo-menu.gif" width="149" height="20"></td>
					  <td width="1" rowspan="2" bgcolor="#CECCC2"><img src="images/fondo-linea.gif" width="1" height="1"></td>
					</tr>
					<tr>
					  <td height="30" align="center">Total <%=DataAccess.getCurrency( totalPrice )%> </td>
					</tr>
					<tr bgcolor="#FFF5C7">
					  <td colspan="2"><table width="150" border="0" cellspacing="0" cellpadding="0">
						  <tr>
							<td><a href="/minorista/micarrito" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('ver','','images/v-pedido2.gif',1)"><img src="images/v-pedido.gif" alt="Ver pedido" name="ver" width="68" height="23" border="0"></a></td>
							<td><a href="/minorista/micarrito" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('hacer','','images/h-pedido2.gif',1)"><img src="images/h-pedido.gif" alt="Hacer pedido " name="hacer" width="82" height="23" border="0"></a></td>
						  </tr>
					  </table></td>
					</tr>
				  </table>
			<%@ include file="menuminorista.jsp" %>
	</td>
        <td width='603' valign="top">
        
        <table>
            <tr>
                <td>
                    <table>
                        
                        <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">
                                                          <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>
                                                              </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> 
                                                            <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>

                                                              </select></td> 
                                                            </tr>
                                                            <tr>
                                                              <td><div align="left"><b>Categor&iacute;a:</b></div></td>
                                                              <td>
															  	<select name="categoria">
																	<option value="">TODAS</option>
																<%
																	for( int i = 0; i < categorias.size(); i++ )
																	{
																		String cat = ( String )categorias.elementAt(i);
																		if( cat.length() > 25 )
																		{
																			cat = cat.substring( 0, 25 );
																		}
																		//cat = cat.substring(0,10);
																		%>
																			<option <%if(cat.equals(categoria)){%>selected<%}%>><%=cat%></option>
																		<%
																	}
																%>
																</select>
															  </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>  
												-->
												<!-- fin buscador  ------------>
												
												<table width="560" border="0" cellpadding="0" cellspacing="0" bgcolor="#E8E8F4">
												<form action="/minorista/catalogo" method="post" name="buscador" id="buscador">
												  <tr>
													<td width="16" align="left" valign="top"><img src="images/bus1.gif" width="16" height="14"></td>
													<td width="529">&nbsp;</td>
													<td width="15" align="right" valign="top"><img src="images/bus3.gif" width="15" height="14"></td>
												  </tr>
												  <tr>
													<td>&nbsp;</td>
													<td><table width="100%"  border="0" cellspacing="0" cellpadding="3">
												
														<tr>
														  <td width="18%">
														  	<select name="esnombre" onChange="MM_jumpMenu('parent',this,0)">
                                                                  <option value='1' <%if( esNombre ){%>selected<%}%>>PRODUCTO</option>
                                                                  <option value='2' <%if( !esNombre ){%>selected<%}%>>CODIGO</option>
                                                             </select>
															 <!--
															  <select name="menu3" onChange="MM_jumpMenu('parent',this,0)">
																<option selected>unnamed1</option>
															  </select>
															  -->
														  </td>
														  <td width="28%"><input type="text" name="nombre" value='<%=nombre%>' size="15"></td>
														  
														  <td width="19%"><span class="style6">Categor&iacute;a</span></td>
												
														  <td width="23%">
														  <select name="categoria">
																	<option value="">TODAS</option>
																<%
																	for( int i = 0; i < categorias.size(); i++ )
																	{
																		String cat = ( String )categorias.elementAt(i);
																		if( cat.length() > 18 )
																		{
																			cat = cat.substring( 0, 18 );
																		}
																		//cat = cat.substring(0,10);
																		%>
																			<option <%if(cat.equals(categoria)){%>selected<%}%>><%=cat%></option>
																		<%
																	}
																%>
																</select>
														  </td>
														  <td width="12%"><span class="style4"></span></td>
														</tr>
														<tr>
														  <td><span class="style6">Proveedor</span></td>
														  <td> <span class="style6">
															<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();
																		if( name.length() > 15 )
																		{
																			name = name.substring( 0, 15 );
																		}

                                                                        %>
                                                                            <option value="<%=id%>"<%if( proveedor == id ){%>selected<%}%>><%=name%></option>
                                                                        <%
                                                                    }
                                                                %>

                                                              </select>
														  </span> </td>
														  <td><span class="style6">Ordenado por: </span></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><input type="submit" value='Buscar' name='Buscar' id='Buscar'></td>
														</tr>
													</table></td>
													<td>&nbsp;</td>
												
												  </tr>
												  <tr>
													<td align="left" valign="bottom"><img src="images/bus2.gif" width="16" height="15"></td>
													<td>&nbsp;</td>
													<td align="right" valign="bottom"><img src="images/bus4.gif" width="15" height="15"></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'>
                                        <%if( Integer.parseInt( pagina ) > 1 ){%>
                                        <input type="button" value='&lt;&lt;' onclick='javascript:previousPage()'>
                                        <%}%>
                                        P&aacute;gina <input type="text" id='pagina' name='pagina' value='<%=pagina%>' size='2'> de <%=paginas%>
                                        <%if( Integer.parseInt( pagina ) < Integer.parseInt( paginas ) ){%>
                                        <input type="button" value='&gt;&gt;' onclick='javascript:nextPage()'>
                                        <%}%>
                                    </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>
							-->
							<!-- PAGINACION ------------->
							<table width="379" border="0" align="center" cellpadding="0" cellspacing="0">
							  <tr>
								<td width="31" align="left" bgcolor="#99DA8F"><img src="images/a1.gif" width="29" height="48"></td>
								<td width="24" bgcolor="#99DA8F"><span class="Estilo6"><input type="image" src="images/atras.gif" onclick='javascript:previousPage()'><!--<img src="images/atras.gif" width="23" height="23">--></span></td>
								<td width="93" align="center" bgcolor="#99DA8F"><span class="Estilo6">Pag.
									  <input id='pagina' name='pagina' type="text" size="3" value='<%=pagina%>'>
								  de <%=paginas%> </span></td>
								<td width="24" bgcolor="#99DA8F"><span class="Estilo6"><input type="image" src="images/adelante.gif" onclick='javascript:nextPage()'><!--<img src="images/adelante.gif" width="23" height="23">--></span></td>
								<td width="16" bgcolor="#C5EABF"><span class="Estilo6"> </span></td>
							
								<td width="88" bgcolor="#C5EABF"><span class="Estilo6">
								  <input type="text" name='cantidad' value='<%=cantidad%>' size="3">
								  Resultados </span></td>
								<td width="80" bgcolor="#C5EABF"><input type="image" src="images/ver.gif"><!--<img src="images/ver.gif" width="55" height="23">--></td>
								<td width="23" align="right" bgcolor="#C5EABF"><img src="images/a2.gif" width="23" height="48"></td>
							  </tr>
							</table>
                             </td>       
                             </form>
                        </tr>
                    </table>
					<!-- FIN PAGINACION ------------->
                
                
                </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><font color="#FFFFFF">C&oacute;digo Barras</font></strong></div></td>
                                                <td><div align="center"><strong><font color="#FFFFFF">Nombre</font></strong></div></td>
                                                <td><div align="center"><strong><font color="#FFFFFF">Categor&iacute;a</font></strong></div></td>
                                                <td><div align="center"><strong><font color="#FFFFFF">Marca</font></strong></div></td>
                                                <td><div align="center"><strong><font color="#FFFFFF">Proveedor</font></strong></div></td>
                                                <td colspan='2'><div align="center"><strong><font color="#FFFFFF">Precio</font></strong></div></td>
                                                <td><div align="center"><strong><font color="#FFFFFF">Ver</font></strong></div></td>
                                                <td><div align="center"><strong><font color="#FFFFFF">Cantidad</font></strong></div></td>
                                              </tr>
                                                <form name="productos" method="post" action='/minorista/administrarcatalogo'>
                                                <%
                                                    int i = 0;
                                                    int count = 0;
                                                    String color = "";
                                                    while( productos.move() )
                                                    {
                                                        int id = Integer.parseInt( ( String )productos.nextElement() );
                                                        int quantity = 0;
                                                        if( cart != null )
                                                        {
                                                            quantity = cart.containsProduct( id );
                                                        }
                                                        if( count % 2 == 0 )
                                                        {
                                                            color = "FFFFFF";
                                                        }
                                                        else
                                                        {
                                                            color = "EFEFEF";
                                                        }
                                                        count++;
														if( quantity > 0 )
														{
															color = "FF0000";
														}
                                                        %>
                                                            <tr bgcolor='#<%=color%>'>
                                                                <td><%=productos.nextElement()%></td>
                                                                <td><%=DataAccess.formatText((String)productos.nextElement(),10)%></td>
                                                                <td><%=productos.nextElement()%></td>
                                                                <td><%=productos.nextElement()%></td>
                                                                <td><%=productos.nextElement()%></td>
                                                                <!--<td align="right"></td>-->
                                                                <td align="right"><%=DataAccess.getCurrency( ( new Double( productos.nextElement( ) + "" ) ).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=500,WIDTH=535,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="1" maxlength="10" value=''>
                                                                        <!--<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>
// “Copyright (C) <2008> Multilateral Investment Fund of the Inter-American Development Bank.
// Este archivo es parte de <ICT4BUS-PVL>
// < ICT4BUS-PVL > es software libre: usted puede redistribuirlo y/o modificarlo bajo los términos de la Licencia Pública General GNU publicada por la Fundación para el Software Libre, ya sea la versión 3 de la Licencia, o (a su elección) cualquier versión posterior.
// < ICT4BUS-PVL > se distribuye con la esperanza de que sea útil, pero SIN GARANTÍA ALGUNA; ni siquiera la garantía implícita MERCANTIL o de APTITUD PARA UN PROPÓSITO DETERMINADO. 
// Consulte los detalles de la Licencia Pública General GNU para obtener una información más detallada. 
// Debería haber recibido una copia de la Licencia Pública General GNU junto a este programa. En caso contrario, consulte http://www.gnu.org/licenses/.”