<%@ page import="com.fenalco.utilities.lists.ListView"%>
<%@ page import="com.fenalco.entities.User"%>
<%@ page import="com.fenalco.entities.DataAccess"%>
<%@ page import="com.fenalco.entities.Province"%>
<%@ page import="com.fenalco.entities.City"%>
<%@ page import="java.util.Hashtable"%>
<%@ page import="java.util.Vector"%>
<%@ page import="java.util.Enumeration"%>
<html>
<head>
<link rel='stylesheet' style='text/css' href='../css/tablas.css'>
<link rel='stylesheet' style='text/css' href='../css/fuentes.css'>
<title>Clientes de la Empresa</title>
</head>
<body bgcolor="#ffffff" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" onload='showMessage("<%=request.getAttribute("message")%>")'>
<script language='javascript' type='text/javascript' src='../js/library.js'></script>
<script language='javascript' type='text/javascript'>

    function showMessage(message){
        if(message!=null && message!=""){
            window.alert(message);
        }
        return true;
    }
    
    function showCompany(id){
           var left = (screen.availWidth-515)/2;
	   var top = (screen.availHeight-500)/2;
	   window.open('/proveedor/verminorista?key='+id,'','HEIGHT=360,WIDTH=515,scrollbars=no,left='+left+',top='+top);
    }
</script>
<%
	String helpId = "52";
        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();
%>
<table border="0" cellpadding="0" cellspacing="0" width="760">
    <%@ include file="encabezado.jsp" %>
</table>
<table width="760" border='0'>
    
    <tr>
        <td width="152" valign='top'>
			<%@ include file="menuproveedor.jsp" %>
	</td>
        <td valign='top'>
            <%
                User supplier = ( User )request.getSession().getAttribute("user");
                String tittle = "Clientes de "+supplier.getCompanyName();
            %>
            <%@ include file="/titulo.jsp" %>

			<table width="100%">
				<!--<tr><td align="center"><%--= request.getAttribute("message")--%></td></tr>-->
				<tr>
                                    <td>&nbsp;</td>
				</tr>
				<form name="clientList" method="post" action ="/proveedor/clientesproveedor">
				<table align="center" width='70%' border="0" cellpadding="0" cellspacing="0" bgcolor="#E8E8F4" align="center">
                                        <tr>
                                            <td width="16" align="left" valign="top"><img src="/proveedor/images/bus1.gif" width="16" height="14"></td>
                                            <td colspan='4'>&nbsp;</td>
                                            <td width="15" align="right" valign="top"><img src="/proveedor/images/bus3.gif" width="15" height="14"></td>
                                        </tr>
                                        <input type="hidden" name="clicked" value=""> 
                                        <tr>
                                            <td>&nbsp;</td>
                                        <%
                                            Vector provinces = (Vector)request.getAttribute("provinces");
                                            Vector cities = (Vector)request.getAttribute("cities");
                                            int provinceId = ((Integer)request.getAttribute("provinceId")).intValue();
                                            int cityId = ((Integer)request.getAttribute("cityId")).intValue();
                                        %>
                                            <td>Departamento</td>
                                            <td>
                                                <select name="province" onChange="document.clientList.clicked.value=0;document.clientList.submit()">
                                                    <option value='-1'>Todos</option>
                                                <%
                                                Enumeration en = provinces.elements();
                                                String selected = "";
                                                while( en.hasMoreElements() ){
                                                    Province p = (Province)en.nextElement();
                                                    selected = ( p.getId() == provinceId )?"selected":"";
                                                    %><option value='<%=p.getId()%>' <%=selected%> ><%=p.getName()%></option><%
                                                }
                                                %>
                                                </select>
                                            </td>
                                            <td>Ciudad</td>
                                            <td>
                                                <select name="city" onChange="document.clientList.clicked.value=1;document.clientList.submit()">
                                                    <option value='-1'>Todas</option>
                                                <%
                                                en = cities.elements();
                                                selected = "";
                                                while( en.hasMoreElements() ){
                                                    City c = (City)en.nextElement();
                                                    selected = ( c.getId() == cityId )?"selected":"";
                                                    %><option value='<%=c.getId()%>' <%=selected%> ><%=c.getName()%></option><%
                                                }
                                                %>    
                                                </select>
                                            </td>
                                            <td>&nbsp;</td>
                                        </tr>
                                        <tr>
                                            <td colspan='6'>&nbsp;</td>
                                        </tr>
                                        <tr>
                                            <td>&nbsp;</td>
                                            <td colspan='4'>Nombre Comercial <input type="text" name="shopKeeperName"> <input type="submit" value="Consultar"></td>
                                            <td>&nbsp;</td>
                                        </tr>
                                        <tr>
                                            <td colspan='6'>&nbsp;</td>
                                        </tr>
                                        <tr>
                                            <td align="left" valign="bottom"><img src="/proveedor/images/bus2.gif" width="16" height="15"></td>
                                            <td colspan='4'>&nbsp;</td>
                                            <td align="right" valign="bottom"><img src="/proveedor/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" width="80%" border='0'>
                                        <tr>
                                            <td colspan='5'>&nbsp;</td>
                                        </tr>
                                        <tr>
                                            <td colspan='5' align='center'><input type='submit' value='Agregar Minorista' onClick="document.clientList.operationType.value='add';document.clientList.action='/proveedor/verminoristas';"></td>
					</tr>
					<tr>
                                            <td colspan='5'>&nbsp;</td>
                                        </tr>
                                        <tr class="tableheader" align="center">
						<!-- Encabezado del listado -->
						<td><strong>Nombre Comercial</td>
						<td><strong>Ciudad</td>
						<td><strong>Forma Pago</td>
						<td align='center'><strong>Ver Detalle</td>
						<td align='center'><strong>Retirar</strong></td>
					</tr>
					
                                        <% 
                                        ListView view = (ListView)request.getAttribute("view");
                                            String data;
                                            int count = 0;
                                            int countRows = 0;
                                            String color = "";
                                            while(view.move())
                                            {
                                                if( countRows % 2 == 0 )
                                            	{
                                            		color = "FFFFF0";
                                            	}
                                            	else
                                            	{
                                            		color = "EFEFEF";
                                            	}
                                            	countRows++;
                                            	count++;
                                                    int i=0;
                                                    String id="";
                                                    String status="";
                                        %>
                                                    <tr bgcolor='<%=color%>'>
                                                    <% while((data=(String)view.nextElement()) != null){
                                                            if(i==2){%>
                                                                    <td><%= data %></td>
                                                          <%}else if(i==1){
                                                              i=2;
                                                              status = data;
                                                           }else{ 
                                                                    i=1; 
                                                                    id=data;
                                                            }%>
                                                    <%
                                                    }
                                                    %>
                                                        <!--
                                                        Columnas para las opciones
                                                        -->
                                                        
                                                        <!--<td align='center'><a href="/proveedor/verminorista?key=<%=id%>"><img name='stores' src='' height='10' width='10'></a></td>-->
                                                        <td align='center'><a href='/proveedor/formaspagominorista?key=<%=id%>'><img name='payment' alt="Forma de Pago" src='/images/buttons/supplier/detalle.gif'  border='0'></a></td>
                                                        <td align='center'><a href='javascript: showCompany(<%=id%>)'><img name='stores' alt="Ver Detalle" src='/images/buttons/supplier/detalle.gif'  border='0'></a></td>
                                                        <td align='center'><input type='checkbox' name='item' value='<%=id%>'></td>
                                                    </tr>  

                                        <%
                                        }
                                        if( count == 0 )
                                        {
                                        	%>
                                                    <tr>
                                                            <td colspan='5' align='center'>
                                                                    <b>No ha definido ning&uacute;n minorista como cliente en esta ciudad</b>
                                                            </td>
                                                    </tr>
                                                    <%
                                        }
                                        %>
                                <tr>
                                    <td colspan='5'>
                                        <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>
                                <tr><td colspan='5'>&nbsp;</td></tr>
                                <tr>
                                    <td colspan='4'>&nbsp;</td>
                                    <%if( count > 0 ){%><td align='center'><input type="submit" name='delete' value='Retirar' onClick="document.clientList.operationType.value='delete';document.clientList.action='/proveedor/adminclientesproveedor';return window.confirm('Esta a punto de retirar clientes de su lista, desea continuar?');"></td><%}%>
                                </tr>
                                <input name="operationType" type="hidden" value="">
				</table>
				</form>
				</tr>
	</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/.”