<%@ 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 communities = ( ListView )request.getAttribute( "communities" );
    ListView shopKeepers = ( ListView )request.getAttribute( "shopKeepers" );
	ListView storesShopKeeper = ( ListView )request.getAttribute( "storesShopKeeper" );
	ListView storesSupplier = ( ListView )request.getAttribute( "storesSupplier" );
    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();
    
    int companyType = new Integer( ( String )request.getAttribute( "companyType" ) ).intValue();
	System.out.println("CompanyType: "+( String )request.getAttribute( "companyType" ));
	
	int transactionType = new Integer( ( String )request.getAttribute( "transactionType" )).intValue();
	System.out.println("TransactionType: "+( String )request.getAttribute( "transactionType" ) );
	
	int superOffer = new Integer( ( String )request.getAttribute( "superOffer" ) ).intValue();
	System.out.println("SuperOffer: "+( String )request.getAttribute( "superOffer" ) );
	
    int supplier = new Integer( ( String )request.getAttribute( "supplier" ) ).intValue();
	System.out.println("Supplier: "+( String )request.getAttribute( "supplier" )  );
	
	int community = new Integer( ( String )request.getAttribute( "community" ) ).intValue();
	System.out.println("Community: "+( String )request.getAttribute( "community" ));
	
    int shopKeeper = new Integer( ( String )request.getAttribute( "shopKeeper" ) ).intValue();
	System.out.println("ShopKeeper :"+ ( String )request.getAttribute( "shopKeeper" ));
	
	int storeShopKeeper = new Integer( ( String )request.getAttribute( "storeShopKeeper" )).intValue();
	System.out.println("StoreShopKeeper: "+ ( String )request.getAttribute( "storeShopKeeper" ));
	
	int storeSupplier = new Integer( ( String )request.getAttribute( "storeSupplier" )).intValue();
	System.out.println("StoreSupplier: "+ ( String )request.getAttribute( "storeSupplier" ));
	
    //int order = new Integer( ( String )request.getAttribute( "order" ) ).intValue();
    
    String date = ( String )request.getAttribute( "date" );
	System.out.println("Date: "+ ( String )request.getAttribute( "date" ));
	
    String startDate = ( String )request.getAttribute( "startDate" );
	System.out.println( "StartDate: "+( String )request.getAttribute( "startDate" ));
	
    String endDate = ( String )request.getAttribute( "endDate" ); 
	System.out.println("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>
<script type="text/javascript" language="JavaScript">
	function submitCombo(comboName){
            document.buscador.combo.value=comboName;
            document.buscador.action="/administrador/reportespedidos";
            document.buscador.submit();
            return true;
    }
</script>
<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";
                System.out.println("0");
            %>
            <%@ include file="/titulo.jsp" %>


<p align="center">
    Resultados <%=firstRow%> - <%=lastRow%> de <%=total%>
</p>
<form action="/administrador/reportespedidos" 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>
  </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++;
            }
         %>
            </tr>
    <%
        System.out.println("1");
        }
        if( count == 0 )
        {
            %>
            <tr>
                <td colspan='6' align="center">
                    <strong>No se han encontrado pedidos</strong>
                </td>
            </tr>
            <%
        }
    %>
            <input name="operationType" type="hidden" value="">
</table>
</form>
<%
	tittle = "Generador de Reportes";
%>
<%@ include file="/titulo.jsp" %>
<form action="/administrador/reportespedidos" method="post" name="buscador" id="buscador">
	<input type="hidden" name="combo">
    <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 width="90%" color="#333399">
	<table width="90%" align="center" border="0" cellspacing="2">
		<%  
			String checked0 = "";
			String checked1 = "";
			String checked2 = "";

			if( companyType == 1){
				checked0 = "";
				checked1 = "checked";	
				checked2 = "";
			}else if (companyType == 2){
				checked0 = "";
				checked1 = "";
				checked2 = "checked";
			}else{
				checked0 = "checked";
				checked1 = "";
				checked2 = "";
			}
		%>
		<tr>
			<td><input type="radio" name="companyType" value="0" <%=checked0%>>Todos</td>
			<td colspan="6"></td>
		</tr>
		<tr>
			<td width="34%" colspan="2"><input type="radio" name="companyType" value="1" <%=checked1%>>Reportes Minoristas</td>
			<td width="34%" colspan="2"><input type="radio" name="companyType" value="2" <%=checked2%> disabled>Reportes Proveedor</td>
		</tr>
		<tr>
			<td align="right">Minorista</td>
			<td>  
				<select name="shopKeeper" onChange="submitCombo(this.name)">
				<%
					int 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++;
					}
                        System.out.println("2");
				%>
				</select>
			</td>
			<td align="right">Proveedor</td>
			<td>
				<select name="supplier" onChange="submitCombo(this.name)" disabled>
				 <%
					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++;
					}
                                        System.out.println("3");
				%>
				</select>			
			</td>
			
		</tr>
		<tr>
			<td align="right">Establecimiento</td>
			<td>
				<select name="storeShopKeeper" onChange="submitCombo(this.name)">
                                        <option value="-1" selected>Todos</option>
				<%
					i=0;
					while( storesShopKeeper.move() )
					{
						int id = Integer.parseInt( ( String )storesShopKeeper.nextElement() );
						String name = ( String )storesShopKeeper.nextElement();
						%>
							<option value="<%=id%>"<%if( storeShopKeeper == id || i==0){%>selected<%}%>><%=name%></option>
						<%
						storesShopKeeper.nextElement(); //Address
						storesShopKeeper.nextElement(); //PhoneNumber
						i++;
					}
                                        System.out.println("4");
				%>
				</select>
			</td>
			<td align="right">Comunidad</td>
			<td>
				<select name="community" onChange="submitCombo(this.name)" disabled>
                                    <option value="-1" selected>Todos</option>
				<%
					i=0;
					while( communities.move() )
					{
                                                System.out.println("dentro");
						int id = Integer.parseInt( ( String )communities.nextElement() );
						String name = ( String )communities.nextElement();
						%>
							<option value="<%=id%>"<%if( community == id || i==0){%>selected<%}%>><%=name%></option>
						<%
						i++;
                                                 System.out.println("final");
					}
                                        System.out.println("5");
				%>
				</select>
			</td>
			
		</tr>
		<tr>
			<td colspan="2">&nbsp;</td>
			<td align="right">Establecimiento</td>
			<td>
			<select name="storeSupplier" onChange="submitCombo(this.name)" disabled>
                            <option value="-1" selected>Todos</option>
			<%
					i=0;
					while( storesSupplier.move() )
					{
						int id = Integer.parseInt( ( String )storesSupplier.nextElement() );
						String name = ( String )storesSupplier.nextElement();
						%>
							<option value="<%=id%>"<%if( storeSupplier == id || i==0){%>selected<%}%>><%=name%></option>
						<%
						i++;
					}
				%>
			</select>
			</td>
		</tr>
	</table>
	<hr color="#333399" width="90%">
	<table width="25%" align="center" border="0" cellspacing="2">
		<tr>
			<td colspan="3" align="center">Rango Fechas</td>
		</tr>
		<tr>
			<td align="right"> Inicio :</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 align="right"> Fin :</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>
	</table>
	<hr color="#333399" width="90%">
	<table width="90%" align="center" border="0" cellspacing="2">
		<tr>
			<td colspan="2" align="center" width="45%">Tipo de Transacci&oacute;n</td>
			<td colspan="1" width="10%">&nbsp;</td>
			<td colspan="2" align="center" width="45%">Acceso Rápido</td>
		</tr>
		<%
			checked1 = "";
			checked2 = "";
			if( transactionType == 1 || transactionType == 0){
				checked1 = "checked";
				checked2 = "";
			}else if( transactionType == 4){
				checked1 = "";
				checked2 = "checked";
			}
		%>
		<tr>
			<td align="center"><input type="radio" name="transactionType" value="1" <%=checked1%>></td>
			<td align="left">Pedidos</td>
			<td>&nbsp;</td>
			<td align="center"><input name="date" type="radio" value="1" <%if( date.equals("1") ){%>checked<%}%>></td>
			<td align="left">Hoy</td>
		</tr>
		<tr>
			<td align="center"><input type="radio" name="transactionType" value="4" <%=checked2%>></td>
			<td align="left">Compras</td>
			<td>&nbsp;</td>
			<td align="center"><input name="date" type="radio" value="2" <%if( date.equals("2") ){%>checked<%}%>></td>
			<td align="left">&Uacute;ltimos Ocho D&iacute;as</td>
		</tr>
		<tr>
			<td colspan="3">&nbsp;</td>
			<td align="center"><input name="date" type="radio" value="3" <%if( date.equals("3") ){%>checked<%}%>></td>
			<td align="left">Este Mes</td>
			
		</tr>
		<tr>
			<td colspan="3">&nbsp;</td>
			<td align="center"><input name="date" type="radio" value="4" <%if( date.equals("4") ){%>checked<%}%>></td>
			<td align="left">Este A&ntilde;o</td>
		</tr>
		<tr>
			<td colspan="7"><hr color="#333399"></td>
		</tr>
		<tr>
			<td>Buscar SuperOfertas</td>
			<td colspan="4" align="left"><input type="checkbox" name="superOffer" value="1"></td>
		</tr>
		<tr>
			<td colspan="7">&nbsp;</td>
		</tr>
		<tr>
			<td colspan="7" align="center"><input type="submit" value='Buscar' name='Buscar' id='Buscar' onclick='submitCombo("button")'></td>
		</tr>
	</table>
</form>
  </td>
</td>
</table>


<table width="760">
	<tr>
		<td>Pie de Página</td>
	</tr>
</table>

</body>
</html>
