<%@ 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"%>
<%
    ListView suppliers = ( ListView )request.getAttribute( "suppliers" );
    ListView shopKeepers = ( ListView )request.getAttribute( "shopKeepers" );
    ListView view = ( ListView )request.getAttribute( "view" );
    
    String firstRow = ( String )request.getAttribute( "firstRow" );
    String lastRow = ( String )request.getAttribute( "lastRow" );
    String total = ( String )request.getAttribute( "total" );
    String page1 = ( String )request.getAttribute( "page" );
    String pages = ( String )request.getAttribute( "pages" );
    int pageResults = Integer.valueOf(request.getAttribute( "pageResults" ).toString()).intValue();
    
    String companyType = ( String )request.getAttribute( "companyType" );
    int supplier = ( ( Integer )request.getAttribute( "supplier" ) ).intValue();
    int shopKeeper = ( ( Integer )request.getAttribute( "shopKeeper" ) ).intValue();
    int order = ( ( Integer )request.getAttribute( "order" ) ).intValue();
    String historical = ( String )request.getAttribute( "historical" );
    
    String date = ( String )request.getAttribute( "date" );
    String startDate = ( String )request.getAttribute( "startDate" );
    String endDate = ( String )request.getAttribute( "endDate" );
    
%>
<!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>Listado de Pedidos</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#ffffff" background="../images/sysmanager/general/fondo.jpg" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<table border="0" cellpadding="0" cellspacing="0" width="780">
        <%
            String helpId = "10";
        %>
        <%@ include file="encabezado.jsp" %>
</table>

<table width="760">
	<tr>
		<td width="152" valign='top'>
			<%@ include file="menuadministrador.jsp" %>
		</td>
		<td valign='top'>
            <%
                String tittle = "Pedidos";
            %>
            <%@ include file="/titulo.jsp" %>


<p align="center">
    Resultados <%=firstRow%> - <%=lastRow%> de <%=total%>
</p>
<form action="/administrador/administrarpedidos" method="post">
<table align="center">
  <tr class='tableheader'>
    <td><div align="center">Proveedor</div></td>
    <td><div align="center">Minorista</div></td>
    <td><div align="center">Fecha</div></td>
    <td><div align="center">Valor</div></td>
    <td><div align="center">Estado</div></td>
    <td><div align="center">Ver</div></td>
    <% if(historical.equals("false")){
    %>    
        <td><div align="center">Marcar como<br>Hist&oacute;rico</div></td>
    <%}%>
  </tr>
    <%
        int count = 0;
        while( view.move() )
        {
            count++;
            int id = Integer.parseInt( ( String )view.nextElement() );
            String data="";
            int k=0;
    %>
            <tr>
         <%
            while((data=(String)view.nextElement())!=null){
                if(k==3){
         %>
                <td><%=DataAccess.getCurrency((Double.valueOf(data)).doubleValue())%></td>
         <%     }else{
         %>         
                <td><%=data%></td>
         <%     }
                k++;
            }
         %>
                <td align="center"><a href="#"><img  name="view" src="/images/buttons/sysmanager/detalle.gif" border="0" onClick="window.open('/administrador/verpedido?key=<%= id %>','','HEIGHT=400,WIDTH=600')"></a></td>
            <% if(historical.equals("false")){
            %>    
                <td align="center"><input name="item" type="checkbox" value="<%= id %>"></td>
             <%}%>
            </tr>
    <%
        }
        if( count == 0 )
        {
            %>
            <tr>
                <td colspan='7' align="center">
                    <strong>No se han encontrado pedidos</strong>
                </td>
            </tr>
            <%
        }
    %>
            <% if(historical.equals("false")){
            %>    
                <tr>
                    <td colspan='6'></td>
                    <%if( count > 0 ){%><td align="center"><input name="history" type="submit" value="Marcar" onClick="operationType.value='history';return window.confirm('Los pedidos serán marcados como históricos, desea continuar?');"><td><%}%>
                </tr>   
             <%}%>
            <input name="operationType" type="hidden" value="">
</table>
</form>

<form action="/administrador/listapedidos" method="post" name="buscador" id="buscador">
    <p align="center">
        P&aacute;gina <input type="text" name='page' value='<%=page1%>' size='2'> de <%=pages%><br>
        <input type="text" name='pageResults' value='<%=pageResults%>' size='2'> Resultados por p&aacute;gina<br>
        <input type="submit" name='ir' value='ir' id='ir'>
    </p>
    <hr>
  <table width="50%" border="0" align="center">
    <tr>    
        <td align="left"><input name="companyType" type="radio" value="3" <%if( companyType.equals("3") ){%>checked<%}%>>Todos</td> 
    </tr>
    <tr>
      <td align="left"><input name="companyType" type="radio" value="2" <%if( companyType.equals("2") ){%>checked<%}%>>Proveedor:</td>
      <td><select name="supplier" size='3'>
        <%
            int i=0;
            while( suppliers.move() )
            {
                int id = Integer.parseInt( ( String )suppliers.nextElement() );
                suppliers.nextElement(); // me salto 2 para obtener el nombre
                suppliers.nextElement();
                String name = ( String )suppliers.nextElement();
                %>
                    <option value="<%=id%>"<%if( supplier == id || i==0){%>selected<%}%>><%=name%></option>
                <%
                i++;
            }
        %>
        
      </select></td>
    </tr>
      <tr>
          <td align="left"><input name="companyType" type="radio" value="1" <%if( companyType.equals("1") ){%>checked<%}%>>Minorista:</td>
          <td><select name="shopKeeper" size='3'>
        <%
            i=0;
            while( shopKeepers.move() )
            {
                int id = Integer.parseInt( ( String )shopKeepers.nextElement() );
                shopKeepers.nextElement(); // me salto 2 para obtener el nombre
                String name = ( String )shopKeepers.nextElement();
                %>
                    <option value="<%=id%>"<%if( shopKeeper == id || i==0){%>selected<%}%>><%=name%></option>
                <%
                i++;
            }
        %>
        </select></td>
      </tr>
    <tr><td><br></td></tr>
    <tr>
        <td>
        <table>
        <tr><td align="left"><input name="date" type="radio" value="1" <%if( date.equals("1") ){%>checked<%}%>>Hoy</td></tr>
        <tr><td align="left"><input name="date" type="radio" value="2" <%if( date.equals("2") ){%>checked<%}%>>Últimos 8<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;días</td></tr>
        <tr><td align="left"><input name="date" type="radio" value="3" <%if( date.equals("3") ){%>checked<%}%>>Este mes</td></tr>    
        <tr><td align="left"><input name="date" type="radio" value="4" <%if( date.equals("4") ){%>checked<%}%>>Este año</td></tr>    
        </table>
        </td>
        
        <td>
        <table>
        <tr>
            
            <td>Fecha inicial</td>
            <td><input type="text" name='startDate' value='<%=startDate%>' size='10' ></td><td><a href="javascript:cal_startDate.popup()"> <img src="../images/pages/cal.gif" width='20' height='20'></a></td>
            <script type='text/javascript' language='javascript' src='../js/calendar1.js'></script>
            <script>
		var cal_startDate = new calendar1(document.buscador.startDate);
 	    </script>
        </tr>
        <tr>
            <td>Fecha final</td>
            <td><input type="text" name='endDate' value='<%=endDate%>' size='10' ></td><td><a href="javascript:cal_endDate.popup()"> <img src="../images/pages/cal.gif" width='20' height='20'></a></td>
            <script>
		var cal_endDate = new calendar1(document.buscador.endDate);
 	    </script>
            
        </tr>
        <tr><td><br></td></tr>
        <tr>
            <td>Hist&oacute;ricos</td>
            <td align="left"><input name="historical" type="checkbox" <%if(historical.equals("true")){%>checked <%}%>value="1"></td> 
        </tr>
        <!--<tr>
          <td>Ordenar por:
          <select name="order">
            <option value="1" <%if( order == 1 ){%>selected<%}%>>Empresa</option>
            <option value="2" <%if( order == 2 ){%>selected<%}%>>Fecha</option>
            <option value="3" <%if( order == 3 ){%>selected<%}%>>Valor</option>
            <option value="4" <%if( order == 4 ){%>selected<%}%>>Estado</option>
          </select></td>
        </tr>
        -->
        </table>
        </td>        
    </tr>
    <tr><td><br></td></tr>
    <tr>
        <td colspan='2' align="center">
            <input type="submit" value='Buscar' name='Buscar' id='Buscar'>
        </td>
    </tr>
  </table>
</form>

  </td>
</td>
</table>


<table width="760">
	<tr>
		<td><%@ include file="/piepagina.jsp" %></td>
	</tr>
</table>

</body>
</html>
