<%//@ 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"%>
<%
    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 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" ));

    String totalValue = (String)request.getAttribute("totalValue");
%>

<!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 Top</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/reportestop";
        document.buscador.submit();
        return true;
    }
</script>
<body bgcolor="#ffffff" background="../images/sysmanager/fondo1.gif" 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_reportes.jsp" %>
		</td>
		<td valign='top'>
                    <%
                        String tittle = "Resultados";
                        System.out.println("0");
                    %>
                    <%@ include file="/titulo.jsp" %>

                    <form name="reportBuilder" action="/administrador/reportestop" method="post">
                    <table align="center">
                        <tr>
                            <td>
                                <jsp:include page="/general/paginador.jsp" flush="true">
                                    <jsp:param name="page" value="<%=page1%>" />
                                    <jsp:param name="pages" value="<%=pages%>" />
                                    <jsp:param name="pageResults" value="<%=pageResults%>" />
                                </jsp:include>
                            </td>
                        </tr>    
                        <tr>
                            <td>
                                <jsp:include page="/general/resultados.jsp" flush="true">
                                    <jsp:param name="firstRow" value="<%=firstRow%>" />
                                    <jsp:param name="lastRow" value="<%=lastRow%>" />
                                    <jsp:param name="total" value="<%=total%>" />
                                </jsp:include>
                            </td>
                        </tr>    
                    </table>
                        
                    
        <table align="center">
          <tr> 
            <td colspan='3'><strong>REPORTE <%=request.getAttribute("reportTitle")%></td>
          </tr>
          <tr class="tableheader"> 
            <td width='5%' align="center"><font color="#FFFFFF">N°</font></td>
            <td width='60%' align="center"><font color="#FFFFFF">Nombre</font></td>
            <td align="center"><font color="#FFFFFF">Valor</font></td>
          </tr>
          <%
            ListView view = ( ListView )request.getAttribute("view");
            String data;
            int count = 0;
            boolean rows = false;
            while(view.move()){
                count++;
                int i=0;
                String id="";
          %>
          <tr bgcolor='<%=count%2==0?"#EFEFEF":"FFFFF"%>'>
            <td><%=Integer.parseInt(firstRow)+count-1%></td>
            <%  while((data=(String)view.nextElement()) != null){
                    rows = true;
                    if(i==1){
            %>
                        <td><%=data%></td>
            <%      }else if(i==2){%>
                        <td align="right"><%=data%></td>
            <%      }else{
                        id=data;
                    }
                    i++;
                }
            %>
          </tr>
          <%
            }
          %>
          <%  if(rows){%>
          <tr> 
            <td></td>
            <td align="right"><strong>TOTAL&nbsp;</strong> 
            <td align="right"><strong><%=(rows)?totalValue:""%></strong></td>
          </tr>
          <%  }%>
          <tr> 
            <td colspan='3'> 
                <jsp:include page="/general/resultados.jsp" flush="true"> 
                      <jsp:param name="firstRow" value="<%=firstRow%>" />
                      <jsp:param name="lastRow" value="<%=lastRow%>" />
                      <jsp:param name="total" value="<%=total%>" />
                </jsp:include> 
            </td>
          </tr>
            <%
                if(!rows){
            %>
                  <tr> 
                    <td colspan="3" align="center"><br><strong>No hay resultados disponibles</td>
                  </tr>
            <%
                }
            %>
        </table>
                    
                    <%
                        tittle = "Generador de Reportes";
                    %>
                    <%@ include file="/titulo.jsp" %>
                    <table width="560" border="0" cellpadding="0" cellspacing="0" bgcolor="#E8E8F4" align="center">
                        <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>
                    
                        <%
                            int reportType = ( (Integer)request.getAttribute("reportType") ).intValue();
                        %>
                        <tr>
                            <td></td>
                            <td>
                                <table>
                                    <tr>
                                        <td><strong>&nbsp;&nbsp;Tipos de Reportes</td>
                                    </tr>    
                                    <tr>
                                        <td><input type="radio" name="reportType" value="1" <%=reportType==1?"checked":""%>>Productos</td>
                                        <td><input type="radio" name="reportType" value="2" <%=reportType==2?"checked":""%>>Empresas</td>
                                    </tr>
                                </table>
                            </td>
                            <td></td>
                        </tr>
                        <tr>
                            <td colspan='3'><hr color="#333399" width='90%'></td>
                        </tr>
                        <tr>
                            <td></td>
                            <td>
                                <table>
                                    <tr>
                                        <td><br><strong>&nbsp;&nbsp;Tipo de Empresa</td>
                                    </tr>
                                    <tr>
                                        <%
                                            int companyId = ( (Integer)request.getAttribute("companyId")).intValue(); 
                                            int companyTypeId = ( (Integer)request.getAttribute("companyTypeId") ).intValue();
                                        %>

                                        <td>&nbsp;&nbsp;<input type="radio" name="companyTypeId" value="2" <%=companyTypeId==2?"checked":""%>>Proveedor</td>
                                        <td>
                                            <%
                                                ListView suppliers = ( ListView )request.getAttribute( "suppliersView" );
                                            %>
                                            <select name="supplier">
                                            <%
                                                while( suppliers.move() && suppliers != null ){
                                                    int id = new Integer((String)suppliers.nextElement()).intValue();
                                                    suppliers.nextElement();
                                                    suppliers.nextElement();
                                                    String name = (String)suppliers.nextElement();
                                                    %><option value='<%=id%>' <%=id==companyId?"selected":""%>><%=name%></option><%
                                                }
                                            %>
                                            </select>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>&nbsp;&nbsp;<input type="radio" name="companyTypeId" value='1' <%=companyTypeId==1?"checked":""%>>Minorista</td>
                                        <td>
                                            <%
                                                ListView shopKeepers = ( ListView )request.getAttribute( "shopKeepersView" );
                                            %>
                                            <select name="shopKeeper">
                                            <%
                                                while( shopKeepers.move() && shopKeepers != null ){
                                                    int id = new Integer((String)shopKeepers.nextElement()).intValue();
                                                    shopKeepers.nextElement();
                                                    String name = (String)shopKeepers.nextElement();
                                                    %><option value='<%=id%>' <%=id==companyId?"selected":""%>><%=name%></option><%
                                                }
                                            %>
                                            </select>
                                        </td>
                                    </tr>
                                </table>
                            </td>
                            <td></td>
                        </tr>       
                        <tr>
                            <td colspan='3'><hr color="#333399" width='90%'></td>
                        </tr>
                        <tr>
                            <td></td>
                            <td>
                                <table>
                                    <tr>
                                        <td><br><strong>&nbsp;&nbsp;Criterios Adicionales</td>
                                    </tr>
                                    <tr>
                                        <td>&nbsp;&nbsp;Ordenar</td>
                                        <td>
                                            <%
                                                int sort = ( (Integer)request.getAttribute("sort") ).intValue();
                                            %>
                                            <select name="sort">
                                                <option value="0" <%=sort==0?"selected":""%>>DESC</option>
                                                <option value="1" <%=sort==1?"selected":""%>>ASC</option>
                                            </select>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>&nbsp;</td>
                                    </tr>
                                    <tr>
                                        <td>&nbsp;&nbsp;Fecha inicial</td>
                                        <td><input type="text" name='startDate' value='<%=startDate%>' size='10' onclick="this.value=''" readonly></td><td><a href="javascript:cal_startDate.popup()"><img src="../images/pages/cal.gif" width='20' height='20' border='0'></a></td>
                                            <script type='text/javascript' language='javascript' src='../js/calendar1.js'></script>
                                            <script>
                                                var cal_startDate = new calendar1(document.reportBuilder.startDate);
                                            </script>
                                    </tr>
                                    <tr>
                                        <td>&nbsp;&nbsp;Fecha final</td>
                                        <td><input type="text" name='endDate' value='<%=endDate%>' size='10' onclick="this.value=''" readonly></td><td><a href="javascript:cal_endDate.popup()"><img src="../images/pages/cal.gif" width='20' height='20' border='0'></a></td>
                                            <script>
                                                var cal_endDate = new calendar1(document.reportBuilder.endDate);
                                            </script>
                                    </tr>
                                </table>
                            </td>
                        </tr>        
                        <tr>
                            <td colspan="3">&nbsp;</td>
                        </tr>
                        <tr>
                            <td colspan='3' align="center"><input type="submit" value="Generar Reporte"></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>
                    </form>
                </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/.”