<%@ page import="com.fenalco.utilities.lists.ListView" %>
<%@ page import="com.fenalco.entities.*"%>
<%@ page import="java.util.Hashtable"%>
<%@ page import="java.util.Enumeration"%> 
<%@ page import="java.util.Vector"%>
<%
    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 date = ( String )request.getAttribute( "date" );
    String startDate = ( String )request.getAttribute( "startDate" );
    String endDate = ( String )request.getAttribute( "endDate" ); 
    
    int id = 0;
    String label = "";
    String data = "";
    int field = 0;
    int companyType = ((Integer)request.getAttribute("companyType")).intValue(); 
    int sort = ((Integer)request.getAttribute("sort")).intValue();
    Enumeration en;
%>
<%!int i;%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<link rel='stylesheet' style='text/css' href='/css/tablas.css'>
<title>Reportes Categor&iacute;as</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#ffffff" background="/images/sysmanager/fondo1.gif" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" onLoad="showMessage('<%=request.getAttribute("message")%>');showComboFields(<%=companyType%>)">
<script language='javascript' type='text/javascript' src='/js/library.js'></script>
<script>

    function showMessage(message){
        if(message!=null && message!=""){
            window.alert(message);
        }
        return true;
    }

     function submitCombo(comboName){
                document.categoriesReport.combo.value=comboName;
                document.categoriesReport.action = "/administrador/reportes/categorias";
                document.categoriesReport.submit();
                return true;
     }
     
    function showGraphic( ){
           var left = (screen.availWidth-800)/2;
	   var top = (screen.availHeight-600)/2;
	   window.open('/mostrarGrafico','','HEIGHT=600,WIDTH=800,scrollbars=yes,left='+left+',top='+top);
    }
    
    function showComboFields( fieldValue ){
        
        if( fieldValue==1){
            
            document.categoriesReport.supplier.disabled = true;
            document.categoriesReport.shopkeeper.disabled = false;
            document.categoriesReport.store.disabled = false;
        
        }else{
            
            document.categoriesReport.shopkeeper.disabled = true;
            document.categoriesReport.store.disabled = true;
            document.categoriesReport.supplier.disabled = false;
        
        }
        
           
    }

</script>
<table border="0" cellpadding="0" cellspacing="0" width="780">
        <%
            String helpId = "72";
        %>
        <%@ 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 = " Reporte de Categorías";
                %>
                <%@ include file="/titulo.jsp" %>
                <form name="categoriesReport" method="post" action="/administrador/reportes/categorias">
                <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 colspan='2' 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>
                        <%
                            int ct = ((Integer)request.getAttribute("companyType")).intValue();
                            String checked1 = (ct==1)?"checked":"";
                            String checked2 = (ct==2)?"checked":"";
                        %>
                        <td><input type="radio" name="companyType" value="1" <%=checked1%> onClick="showComboFields(this.value)" > Minoristas</td>
                        <td><input type="radio" name="companyType" value="2" <%=checked2%> onClick="showComboFields(this.value)"> Proveedor</td>
                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                        <td>&nbsp;</td>
                        <td colspan='2'>
                            <table>
                                <tr>
                                    <td colspan='2' align="left">&nbsp;&nbsp;Minorista&nbsp;
                                        <select name="shopkeeper" onChange="document.categoriesReport.submit()">
                                        <%
                                            ListView shopKeepers = (ListView)request.getAttribute( "shopkeepers" );
                                            data = "";
                                            int skId = ((Integer)request.getAttribute("shopkeeper")).intValue();
                                            while( shopKeepers.move() ){
                                                field = 0;
                                                while( (data=(String)shopKeepers.nextElement() )!= null  ){
                                                    if( field == 0 ){
                                                        id = Integer.parseInt( data );
                                                    }
                                                    if( field == 2){
                                                        label = data;
                                                    }
                                                    field++;
                                                }
                                                %>
                                                <option value='<%=id%>' <%if(id==skId){%>selected<%}%> ><%=label%></option> 
                                                <%
                                            }
                                        %>
                                        </select>
                                    </td>
                                </tr>
                                <tr>
                                    <td colspan='2' align="left">&nbsp;&nbsp;Establecimiento&nbsp;
                                    <select name="store">
                                        <option value='-1' selected>Todos</option>
                                        <%
                                            ListView stores = (ListView)request.getAttribute( "stores" );
                                            data = "";
                                            int storeId = ((Integer)request.getAttribute("store")).intValue();
                                            while( stores.move() ){
                                                field = 0;
                                                while( (data=(String)stores.nextElement() )!= null  ){
                                                    if( field == 0 ){
                                                        id = Integer.parseInt( data );
                                                    }
                                                    if( field == 2){
                                                        label = data;
                                                    }
                                                    field++;
                                                }
                                                %>
                                                <option value='<%=id%>' <%if(id==storeId){%>selected<%}%> ><%=label%></option> 
                                                <%
                                            }
                                        %>
                                    </select>
                                    </td>
                                </tr>
                            </table>
                        </td>
                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                        <td colspan='4'>&nbsp;</td>
                    </tr>
                    <tr>
                        <td>&nbsp;</td>
                        <td colspan='2'>
                            <table>
                                <tr>
                                    <td colspan='2' align="left">&nbsp;&nbsp;Proveedor&nbsp;
                                        <select name="supplier">
                                            <option value="-1">Todos</option>
                                         <%
                                            ListView suppliers = (ListView)request.getAttribute( "suppliers" );
                                            data = "";
                                            int supplierId = ((Integer)request.getAttribute("supplier")).intValue();
                                            while( suppliers.move() ){
                                                field = 0;
                                                while( (data=(String)suppliers.nextElement() )!= null  ){
                                                    if( field == 0 ){
                                                        id = Integer.parseInt( data );
                                                    }
                                                    if( field == 3){
                                                        label = data;
                                                    }
                                                    field++;
                                                }
                                                %>
                                                <option value='<%=id%>' <%if(id==supplierId){%>selected<%}%> ><%=label%></option> 
                                                <%
                                            }
                                        %>
                                        </select>
                                    </td>
                                </tr>
                            </table>
                        </td>
                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                        <td colspan='4'><hr color="#333399" width='90%'></td>
                    </tr>
                    <tr>
                        <td>&nbsp;</td>
                        <td colspan='3'>
                            &nbsp;&nbsp;Categor&iacute;a Producto&nbsp;
                            <select name='category'>
                                <option value="-1">TODAS</option>
                                <%
                                    CategoryList categories = ( CategoryList )request.getAttribute( "categories" );
                                    int categoryId = ( (Integer)request.getAttribute("categoryId") ).intValue();
                                    en = categories.getCategories().elements();
                                    String selected;
                                    int catCode;
                                    String name;
                                    while( en.hasMoreElements() ){
                                        Vector row = (Vector)en.nextElement();
                                        catCode = ( (Integer)row.elementAt(0) ).intValue();
                                        name = ( String )row.elementAt( 1 );
                                        selected = (catCode==categoryId)?"selected":"";
                                    %>
                                    <option value='<%=catCode%>' <%=selected%> ><%=name%></option>
                                    <%
                                    }
                                %>
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td colspan='4'><hr color="#333399" width='90%'></td>
                    </tr>
                    <tr>
                        <td>&nbsp;</td>
                        <td colspan='2'>
                            <table>
                                <tr>
                                    <td>&nbsp;&nbsp;Pa&iacute;s&nbsp;</td>
                                    <td>
                                        <select name="country" onChange="submitCombo(this.name)">
                                        <%
                                        Vector countriesList = (Vector)request.getAttribute("countriesList");
                                        int temp = Integer.parseInt(request.getAttribute("countryId").toString());
                                        for(int i = 0 ; i < countriesList.size() ; i++){
                                            id = ((Country)countriesList.elementAt(i)).getId();
                                            label = ((Country)countriesList.elementAt(i)).getName();
                                        %>
                                            <option value="<%=id%>" <%=(temp==id)?"selected":""%>><%=label%> </option>
                                        <%
                                        }
                                        %>
                                        </select>
                                    </td>
                                </tr>
                                <tr>
                                    <td>&nbsp;&nbsp;Departamento&nbsp;</td>
                                    <td>
                                        <select name="province" onChange="submitCombo(this.name)">
                                            <option value="-1" selected>Todos</option>
                                        <%
                                        Vector provincesList = (Vector)request.getAttribute("provincesList");
                                        temp = Integer.parseInt(request.getAttribute("provinceId").toString());
                                        for(int i = 0 ; i < provincesList.size() ; i++){
                                            id = ((Province)provincesList.elementAt(i)).getId();
                                            label = ((Province)provincesList.elementAt(i)).getName();
                                        %>
                                            <option value="<%=id%>" <%=(temp==id)?"selected":""%>><%=label%> </option>
                                        <%
                                        }
                                        %>
                                        </select>
                                    </td>
                                </tr>
                                <tr>    
                                    <td>&nbsp;&nbsp;Ciudad&nbsp;</td>
                                    <td>
                                        <select name="city" onChange="submitCombo( this.name )">
                                            <option value="-1" selected>Todas</option>
                                        <%
                                        Vector citiesList = (Vector)request.getAttribute("citiesList");
                                        temp = Integer.parseInt(request.getAttribute("cityId").toString());
                                        for(int i = 0 ; i < citiesList.size() ; i++){
                                            id = ((City)citiesList.elementAt(i)).getId();
                                            label = ((City)citiesList.elementAt(i)).getName();
                                        %>
                                            <option value="<%=id%>" <%=(temp==id)?"selected":""%>><%=label%> </option>
                                        <%
                                        }
                                        %>
                                        </select>
                                    </td>
                                </tr>
                                <tr>    
                                    <td>&nbsp;&nbsp;Zona&nbsp;</td>
                                    <td>
                                        <select name="zone"  onChange="submitCombo( this.name )">
                                            <option value="-1" selected>Todas</option>
                                        <%
                                        Vector zonesList = (Vector)request.getAttribute("zonesList");
                                        temp = Integer.parseInt(request.getAttribute("zoneId").toString());
                                        for(int i = 0 ; i < zonesList.size() ; i++){
                                            id = ((Zone)zonesList.elementAt(i)).getId();
                                            label = ((Zone)zonesList.elementAt(i)).getName();
                                        %>
                                            <option value="<%=id%>" <%=(temp==id)?"selected":""%>><%=label%> </option>
                                        <%
                                        }
                                        %>    
                                        </select>
                                    </td>
                                </tr>
                                <tr>    
                                    <td>&nbsp;&nbsp;Barrio&nbsp;</td>
                                    <td>
                                        <select name="neighbourhood">
                                            <option value="-1" selected>Todos</option>
                                        <%
                                        Vector neighbourhoodsList = (Vector)request.getAttribute("neighbourhoodsList");
                                        temp = Integer.parseInt(request.getAttribute("neighbourhoodId").toString());
                                        for(int i = 0 ; i < neighbourhoodsList.size() ; i++){
                                            id = ((Neighbourhood)neighbourhoodsList.elementAt(i)).getId();
                                            label = ((Neighbourhood)neighbourhoodsList.elementAt(i)).getName();
                                        %>
                                            <option value="<%=id%>" <%=(temp==id)?"selected":""%>><%=label%> </option>
                                        <%
                                        }
                                        %>  
                                        </select>
                                    </td>
                                </tr>
                            </table>
                        </td>
                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                        <td colspan='4'><hr color="#333399" width='90%'></td>
                    </tr>
                    <tr>
                        <td>&nbsp;</td>
                        <td colspan='2'>&nbsp;&nbsp;Ordenamiento Total Ventas&nbsp;
                            <select name="sort">
                              <option value='0' <%=(sort==0)?"selected":""%>>DESC</option>  
                              <option value='1' <%=(sort==1)?"selected":""%>>ASC</option>
                            </select>
                        </td>
                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                        <td colspan='4'><hr color="#333399" width='90%'></td>
                    </tr>
                    <tr>
                        <td>&nbsp;</td>
                        <td colspan="2">
                            <table width="90%" align="center" border="0" cellspacing="2">
                                <tr>
                                    <td width="50%" align="center">
                                        <table>
                                            <tr>
                                                <td colspan="2" align="center"><strong>Rango Fechas</strong></td>
                                            </tr>
                                            <tr>
                                                <td align="right"> Inicio :</td>
                                                <td><input type="text" name="startDate" value="<%=startDate%>" size="10" onclick="this.value=''" readonly>&nbsp;&nbsp;
                                                <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.categoriesReport.startDate);
                                                </script>
                                            </tr>
                                            <tr>
                                                <td align="right"> Fin :</td>
                                                <td><input type="text" name='endDate' value='<%=endDate%>' size='10' onclick="this.value=''" readonly>&nbsp;&nbsp;
                                                <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.categoriesReport.endDate);
                                                </script>	
                                            </tr>
                                        </table>
                                    </td>
                                    <td width="50%" align="center">
                                        <table>
                                            <tr>
                                                <td colspan="2" align="center" width="45%"><strong>Acceso Rápido</strong></td>
                                            </tr>    
                                            <tr>
                                                <td align="left"><input name="date" type="radio" value="1" <%if( date.equals("1") ){%>checked<%}%>>&nbsp;
                                                Hoy</td>
                                            </tr>
                                            <tr>
                                                <td align="left"><input name="date" type="radio" value="2" <%if( date.equals("2") ){%>checked<%}%>>&nbsp;
                                                &Uacute;ltimos Ocho D&iacute;as</td>
                                            </tr>
                                            <tr>
                                                <td align="left"><input name="date" type="radio" value="3" <%if( date.equals("3") ){%>checked<%}%>>&nbsp;
                                                Este Mes</td>
                                            </tr>
                                            <tr>
                                                <td align="left"><input name="date" type="radio" value="4" <%if( date.equals("4") ){%>checked<%}%>>&nbsp;
                                                Este A&ntilde;o</td>
                                            </tr>
                                        </table>
                                    </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 colspan='2'>&nbsp;</td>
                        <td align="right" valign="bottom"><img src="../images/bus4.gif" width="15" height="15"></td>
                    </tr>
                </table>
                <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" cellspacing='2' border='0' width='560'>
                    <tr><td colspan='5' height='10'></td></tr>
                    <tr class='tableheader'>
                        <!-- Encabezado del listado -->
                        <%
                            Vector headers = (Vector)request.getAttribute( "headers" ); 
                            en = headers.elements();
                            while( en.hasMoreElements() ){
                                %>
                                <td align="center"><font color="white"><%=(String)en.nextElement()%></font></td>
                                <%
                            }
                        %>
                    </tr>
                    <% 
                        ListView view = ( ListView )request.getAttribute( "view" );
                        int count = 0;
                        
                        while(view.move()){
                            count++;
                            int i=0;
                            try{
                    %>
                            <tr bgcolor="<%=count%2==0?"#EFEFEF":"FFFFF"%>">
                            <% while( (data=(String)view.nextElement() )!=null ){
                                    if( i > 0 ){
                                    %><td align="right"><%=data%></td><%
                                    }else{
                                    %><td><%=data%></td><%
                                    }
                                    
                                    i++;
                               }
                            }catch( Exception e ){
                                e.printStackTrace();
                            }
                            %>
                            </tr>
                        <%
                        }
                        %>
                      </table>
                        <table align="center">
                            <tr>
                                <td colspan='6' align="center">
                                <%
                                    String graphic = (String)request.getAttribute("graphic");
                                    HttpSession session2 = request.getSession(false);
                                    session2.setAttribute( "graphic", graphic );
                                %>
                                <a href="javascript: showGraphic() "><font color='#FF0000'><b> VER GRÁFICO </b></font></a>
                                </td>
                            </tr>
                            <tr>
                                <td colspan='6'>
                                    <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>    
                    <%
                        if( count == 0 ){
                    %>
                        <br>
                        <table align="center" width='560' border="0">	 
                            <tr>
                                <td colspan='6' align="center">
                                    <strong>No se encontraron resultados</strong>
                                </td>
                            </tr>
                        </table>
                    <%
                        }
                    %>
                <input type="hidden" name="combo" value="<%=(String)request.getAttribute("combo")%>">
                </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/.”