<%@ 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="/minorista/reportestop";
            document.buscador.submit();
            return true;
    }
</script>
<body bgcolor="#ffffff" background="../images/shopkeeper/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" height="197">
        <tr>
            <td width="152" valign='top'>
                    <%@ include file="menuminorista.jsp" %>
            </td>
		
            <td valign='top'> <table width="100%" border=" " cellspacing="0" cellpadding="0">
                <%
                   String tittle = "Generador de Reportes";
                %>
                <%@ include file="/titulo.jsp" %>
                
                <!-- buscador -->
                <form name="reportBuilder" action="/minorista/reportestop" method="post">
                
                <table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#E8E8F4">
                    <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 align="center" width="100%" border="0">
                            <%
                                int reportType = ( (Integer)request.getAttribute("reportType") ).intValue();
                                System.out.println("2");
                            %>
                                <tr> 
                                    <td colspan="4"><strong>Tipos de Reportes</strong></td>
                                </tr>
                                <tr> 
                                    <td colspan="2"><input type="radio" name="reportType" value="1" <%=reportType==1?"checked":""%>>Productos más comprados</td>
                                    <td colspan="2"><input type="radio" name="reportType" value="2" <%=reportType==2?"checked":""%>>Compras por Proveedor</td>
                                </tr>
                                <tr> 
                                    <td colspan='6'><hr color="#333399"></td>
                                </tr>
                                <tr> 
                                    <td colspan="4"><br>
                                      <strong>Criterios Adicionales</strong></td>
                                </tr>
                                <tr> 
                                    <td>Ordenar</td>
                                    <td colspan='2'> 
                                    <%  System.out.println("3");
                                        int sort = ( (Integer)request.getAttribute("sort") ).intValue();
                                    %>
                                        <select name="sort">
                                            <option value="0" <%=sort==0?"selected":""%>>DESCENDENTE</option>
                                            <option value="1" <%=sort==1?"selected":""%>>ASCENDENTE</option>
                                        </select>
                                    </td>
                                    <%System.out.println("4");%>
                                </tr>
                                <tr> 
                                    <td colspan="6">&nbsp;</td>
                                </tr>
                                <tr> 
                                    <td>Fecha inicial</td>
                                    <td width='15%'><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>
                                    <td>Fecha final</td>
                                    <td width='15%'><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>
                                <tr> 
                                    <td colspan="6">&nbsp;</td>
                                </tr>
                                <tr> 
                                    <td colspan='6' align="center"><input name="submit" type="submit" value="Generar Reporte"></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>
                <!-- fin buscador -->
                
                <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>
                
                <%
                    tittle = "Resultados";
                    System.out.println("0");
		%>
		<%@ include file="/titulo.jsp" %>
		
                <!-- resultados -->
                <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>
                </form>
                <!-- fin resultados -->
            </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/.”