<%@ page import="com.fenalco.utilities.lists.ListView"%>
<%@ page import="com.fenalco.entities.User"%>
<%@ page import="com.fenalco.entities.DataAccess"%>
<%@ page import="com.fenalco.entities.ReportShopKeeperStoreList"%>
<%@ page import="com.fenalco.entities.ReportSupplierCommunityList"%>
<%@ page import="com.fenalco.entities.ReportSupplierStoreList"%>
<%@ page import="java.util.Enumeration"%>
<%@ page import="java.util.Vector"%>
<%
    ListView suppliers = ( ListView )request.getAttribute( "suppliers" );
	ListView storesShopKeeper = ( ListView )request.getAttribute( "storesShopKeeper" );
    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 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" ) );
	
	String operation = ( String )request.getAttribute( "operation" );
	System.out.println("Operation: "+( String )request.getAttribute( "operation" ) );
        
    int supplier = new Integer( ( String )request.getAttribute( "supplier" ) ).intValue();
	System.out.println("Supplier: "+( String )request.getAttribute( "supplier" )  );
	
    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 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" ));
    
%>
<%int i;%>
<!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>Reportes</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="/minorista/reportespedidos";
            document.buscador.submit();
            return true;
    }
</script>
<body bgcolor="#ffffff" background="../images/shpkeeper/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="menuminorista.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="/minorista/reportespedidos" method="post">
<table align="center">
  <tr class='tableheader'>
  <%int count = 0;
    if(operation.equals("")){%>
        <td><div align="center">Proveedor</div></td>
        <!--<td><div align="center">Minorista</div></td>-->
        <!--<td><div align="center">Comunidad</div></td>-->
        <td><div align="center">Establecimiento</div></td>    
        <td><div align="center">Fecha</div></td>
        <td><div align="center">Valor</div></td>
        <td><div align="center">Estado</div></td>
  </tr>
        <%
            while( view.move() ){
                count++;
                int id = Integer.parseInt( ( String )view.nextElement() );
                String data="";
                int k=0;

                String color = "";
                if(count % 2 == 0){
                    color = "#EFEFEF";
                }else{
                    color = "FFFFF";
                }

        %>
                <tr bgcolor='<%=color%>'>
             <%
                while((data=(String)view.nextElement())!=null){
                    if(k==5){
             %>
                    <td><%=DataAccess.getCurrency((Double.valueOf(data)).doubleValue())%></td>
             <%     }else{
                        if(k!=2 && k!=3){
             %>         
                            <td><%=data%></td>
             <%     
                        }
                    }
                    k++;
                }
             %>
                </tr>
            
        <% } 
    }else{ %> 
        <tr class='tableheader'>
        <td><div align="center">Establecimiento</div></td>
        <td><div align="center">Total</div></td>        
        </tr>
       <%
            Enumeration e = ((Vector)request.getAttribute("group")).elements();
            while( e.hasMoreElements() ){
                count++;
                ReportShopKeeperStoreList report = (ReportShopKeeperStoreList)e.nextElement();
        %>
                <tr>
                    <td><%=report.getStore()%></td>
                    <td><%=DataAccess.getCurrency((Double.valueOf(report.getTotal()).doubleValue()))%></td>
                </tr>
        <%  } %>
  <% }%> 
    
    <%
        System.out.println("1");
        if( count == 0 ){
    %>
            <tr>
                <td colspan='6' align="center">
                    <strong>No se han encontrado resultados</strong>
                </td>
            </tr>
            <%
        }
    %>
            <input name="operationType" type="hidden" value="">
</table>
</form>
<%
	tittle = "Generador de Reportes";
%>
<%@ include file="/titulo.jsp" %>
<form action="/minorista/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 checked1 = "checked";%>
		<%String checked2 = "";%>
		<%String checked3 = "";%>
		<%String checked4 = "";%>
        	<tr>
                    <td align="right">Establecimiento</td>
                    <td>
                            <select name="storeShopKeeper" onChange="submitCombo(this.name)">
                            <option value="-1" selected>Todos</option>
                            <%
                                    if( storesShopKeeper != null){
                                            i=0;
                                            while( storesShopKeeper.move() )
                                            {
                                                    int id = Integer.parseInt( ( String )storesShopKeeper.nextElement() );
                                                    String name = ( String )storesShopKeeper.nextElement();
                                                    %>
                                                                    <option value="<%=id%>"<%if( storeShopKeeper == id){%>selected<%}%>><%=name%></option>
                                                    <%
                                                    storesShopKeeper.nextElement(); //Address
                                                    storesShopKeeper.nextElement(); //PhoneNumber
                                                    i++;
                                            }
                                            System.out.println("4");
                                    }    
                            %>
                            </select>
                    </td>
                 </tr>
                 <tr>
                    <td align="right">Proveedor</td>
                    <td>
                            <select name="supplier">
                                    <option value="-1" selected>TODOS</option>
                             <%
                                    if( suppliers != null){
                                            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){%>selected<%}%>><%=name%></option>
                                                    <%
                                                    i++;
                                            }
                                        System.out.println("3");
                                    }
                            %>
                            </select>
                    </td>
		</tr>
                <!--
                <tr>
                        <td align="right">Categoría de Producto</td>
                        <td>
                                <select name="productCategory">
                                <option value="-1" selected>Todas</option>
                                <%%>
                                </select>
                        </td>
                </tr>
                -->
		
		<!--
		<tr>
			<td colspan="2"><input type="radio" name="companyType" value="3" <%=checked3%>>Reportes Por Zonas</td>
			<td><input type="radio" name="companyType" value="4" <%=checked4%>>Reportes Por Dirección</td>
		</tr>
		<tr>
			<td valign="top">
				<table width="100%">
					<tr>
						<td align="right">Pa&iacute;s</td>
						<td>
							<select></select>
						</td>
					</tr>
					<tr>
						<td align="right">Departamento</td>
						<td>
							<select></select>
						</td>
					</tr>
					<tr>
						<td align="right">Ciudad</td>
						<td>
							<select></select>
						</td>
					</tr>
					<tr>
						<td align="right">Zona</td>
						<td>
							<select></select>
						</td>
					</tr>
				</table>
			</td>
			<td valign="top">
				<table width="100%">
					<tr>
						<td><input type="checkbox" name="checkStreet" value="1"></td>
						<td>Calle</td>
						<td><input type="text" name="street" size="3" maxlength="3"></td>
						<td>
							<select name="streetOrientation">
								<option value="1">Norte</option>
								<option value="2">Este</option>
								<option value="3">Oeste</option>
								<option value="4">Sur</option>
							</select>
						</td>
					</tr>
					<tr>
						<td><input type="checkbox" name="checkAvenue" value="1"></td>
						<td>Carrera</td>
						<td><input type="text" name="avenue" size="3" maxlength="3"></td>
						<td>
							<select name="avenueOrientation">
								<option value="1">Norte</option>
								<option value="2">Este</option>
								<option value="3">Oeste</option>
								<option value="4">Sur</option>
							</select>
						</td>
					</tr>
				</table>
			</td>
			
		</tr>
		-->
		<tr>
			<td colspan="2">&nbsp;</td>
		</tr>
		<!--
		<tr>
			<td colspan="2"><input type="checkbox" name="addProduct" value="1">Adicionar producto como criterio</td>
		</tr>
		<tr>
			<td align="right"><input type="text" name="product" value="<%--=productName--%>"></td>
			<td><input type="submit" name="addProduct" value="Seleccionar Producto"></td>
		</tr>
		-->
	</table>
	<hr color="#333399" width="90%">
	<table width="25%" align="center" border="0" cellspacing="2">
		<tr>
			<td colspan="3" align="center"><strong>Rango Fechas</strong></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%"><strong>Tipo de Transacci&oacute;n</strong></td>
			<td colspan="1" width="10%">&nbsp;</td>
			<td colspan="2" align="center" width="45%"><strong>Acceso Rápido</strong></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" <%if(superOffer==1){%>checked<%}%>></td>
		</tr>
		<tr>
			<td>Totales</td>
			<td colspan="4" align="left"><input type="checkbox" name="operation" value="1" <%if(!operation.equals("")){%>checked<%}%>></td>
		</tr>
		<tr>
			<td colspan="7">&nbsp;</td>
		</tr>
		<tr>
			<td colspan="7" align="center"><input type="submit" value='  Buscar  ' name='Buscar' onclick="combo.value='button'; return buscador.submit()"></td>
			<!--onclick='submitCombo("button")'--> 
		</tr>
	</table>
</form>
  </td>
</td>
</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/.”