<%@ page import="com.fenalco.utilities.lists.OrderListViewShopKeeper"%>
<%@ page import="com.fenalco.entities.User"%>
<%@ page import="com.fenalco.entities.DataAccess"%>
<%@ page import="com.fenalco.utilities.MessageBuilder"%>
<%@ page import="com.fenalco.entities.StoreList"%>
<%@ page import="java.util.Enumeration"%>
<%@ page import="java.util.Hashtable"%>


<%
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 order = ( ( Integer )request.getAttribute( "order" ) ).intValue();
    String date = ( String )request.getAttribute( "date" );
    String startDate = ( String )request.getAttribute( "startDate" );
    String endDate = ( String )request.getAttribute( "endDate" );

%>

    
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<link rel='stylesheet' style='text/css' href='../css/tablas.css'>
<title>Mis pedidos</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>


<!-- 
-->

<script type='text/javascript' language='javascript' src='../js/library.js'></script>
<script>
    function validateForm(formName){
        var message = "Han ocurrido los siguientes errores:\n";
        var flag = true;
        
       if(formName.startDate.value > formName.endDate.value ){
            flag = false;
            message = message + "- El campo fecha incial debe ser menor o igual al campo fecha final.\n";
        }
        
        
        if(!flag){
            window.alert(message);
        }
        return flag;
    }


    function submitCombo(id){
            document.orders.combo.value=id;
            document.orders.operationType.value = "update";
            document.orders.submit();
            return true;
    }
</script>
<body bgcolor="#ffffff" background="../images/shopkeeper/general/fondo.jpg" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<!-- 
-->
<%
	String helpId = "33";
%>
<table border="0" cellpadding="0" cellspacing="0" width="780">
    <%@ include file="encabezado.jsp" %>
</table>
<table width="760" border="0" cellspacing="0" cellpadding="0">
    
    <tr>
        <td width="155" valign="top">
			<%@ include file="menuminorista.jsp" %>
	</td>
        <td width='505' valign="top" align='left'>
            <%
                String tittle = "Buscador";
            %>
            <%@ include file="/titulo.jsp" %>

			<table width="100%" align="center" cellpadding='0' cellspacing='0'>
				<tr>
                                    <td >
				
                                    <%String message = ( String )request.getAttribute("message");
                                        if( message != null )
                                        {
                                            %>
                                            <%=message%>
                                            <%
                                        }      
                                    %>
                                    </td>
                                </tr>
                                    <tr>
                                        <td >
                                            <form action="/minorista/mispedidos" method="post" name="searchEngine" id="searchEngine" onSubmit="return validateForm(document.searchEngine);">
                                                
                                              <table   align="center">
                                                
                                                <tr>
                                                    <td valign='top'>
                                                        <table>
                                                             <tr valign='top'>
                                                                <td>Fecha inicial</td>
                                                                <td><input type="text" name='startDate' value='<%=startDate%>' size='10' readonly></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.searchEngine.startDate);
                                                                    </script>
                                                             </tr>
                                                             <tr>
                                                                <td>Fecha final</td>
                                                                <td><input type="text" name='endDate' value='<%=endDate%>' size='10' readonly></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.searchEngine.endDate);
                                                                    </script>

                                                            </tr>
                                                             <tr>
                                                                  <td><div align="left">Ordenar por: </div>
                                                                    <select name="order">
                                                                    <option value="1" <%if( order == 1 ){%>selected<%}%>>Empresa</option>
                                                                    <option value="2" <%if( order == 2 ){%>selected<%}%>>Fecha</option>
                                                                    <!-- <option value="3" <%if( order == 3 ){%>selected<%}%>>Valor</option> -->
                                                                    <option value="4" <%if( order == 4 ){%>selected<%}%>>Estado</option>
                                                                  </select></td>
                                                                  
                                                  
                                                                                                  
                                                            </tr>
                                                            
                                                        </table>
                                                    </td>
                                                    <td>
                                                        <table>
                                                            <tr align='left'>
                                                                <td><input name="date" type="radio" value="1" <%if( date.equals("1") ){%>checked<%}%>> Hoy </td>
                                                            </tr>
                                                            <tr align='left'>
                                                                <td><input name="date" type="radio" value="2" <%if( date.equals("2") ){%>checked<%}%>> &Uacute;ltimos 8 d&iacute;as </td>
                                                            </tr>
                                                            <tr align='left'>    
                                                                <td><input name="date" type="radio" value="3" <%if( date.equals("3") ){%>checked<%}%>> Este Mes </td>
                                                             </tr>
                                                            <tr align='left'>   
                                                                <td><input name="date" type="radio" value="4" <%if( date.equals("4") ){%>checked<%}%>> Este Aņo </td>
                                                            </tr>   
                                                        </table>
                                                    </td>
                                                    
                                                </tr>
                                                <tr >
                                                    <td >
                                                          <input type="submit" value=' Buscar pedidos' name='Buscar' id='Buscar'>
                                                      </td>
                                                </tr>
                                                 
                                                
                                           
                                              </table>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>
                                            <table cellpadding='0' cellspacing='0'>
                                              <tr>
                                                <td >
                                                    <%
                                                        tittle = "Mis Pedidos";
                                                    %>
                                                   <%@ include file="/titulo.jsp" %>
                                                </td>
                                            </tr>
                                             
                                                <tr align='center'>
                                                    <td >
                                                        P&aacute;gina <input type="text" name='page' value='<%=page1%>' size='2'> de <%=pages%>
                                                    </td>
                                                </tr>
                                                <tr align='center'>    
                                                    <td>
                                                        <input type="submit" name='ir' value='Ver' id='ir'>
                                                    
                                                        <input type="text" name='pageResults' value='<%=pageResults%>' size='2'> Resultados por p&aacute;gina<br>
                                                    </td> 
                                                    
                                                </tr>
                                              </table>  
                                        </form>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>
                                            <hr>
                                        </td>
                                   </tr>
                                   <tr><td>
                                    <!-- -->
                                    
                                    <form name="orders" method="post" action="/minorista/administrarpedido" >
                                    <table align="center" >
                                            <tr class='tableheader'>
                                                    <!-- Encabezado del listado -->
                                                    <td align="center"><b>Proveedor</b></td>
                                                    <td align="center"><b>Fecha</b></td>
                                                    <td align="center"><b>Valor</b></td>
                                                    <td align="center"><b>Estado</b></td>
                                                    <td align="center"><b>Ver detalle</b></td>
                                                    
                                                    
                                            </tr>
                                    <% 
                                                    OrderListViewShopKeeper view = (OrderListViewShopKeeper)request.getAttribute("view");
                                                    Object data = new Object();
                                                    if(view != null)
                                                    {
                                                        while(view.move()){
                                                                int i=0;
                                                                String id="";
                                                                String status = "";
                                                                String statusId = "";
                                                                
                                              %>
                                                                <tr>
                                                                <% while((data=view.nextElement()) != null){
                                                                        i++;
                                                                    if(i==1) { 
                                                                        
                                                                            id=data.toString();
                                                                    }
                                                                    
                                                                    else if(i==5) { 
                                                                        
                                                                            status=data.toString();
                                                                    }
                                                                    else if(i==6) { 
                                                                        
                                                                            statusId=data.toString();
                                                                    } 
                                                                    else { %>
                                                                        
                                                                        <td><%= data.toString() %></td>
                                                                    <%} 
                                                                        
                                                               }    
                                                            %>
                                                                    <!-- Columnas para las opciones -->
                                                                    <td align="center">
                                                                    <%
                                                                      if(statusId.equals("2") || statusId.equals("3")){%>
                                                                      
                                                                          <select name='status<%=id%>' onchange='submitCombo(<%=id%>);'>
                                                                              <option value='<%=statusId%>' selected><%=status%></option> 
                                                                              <option value='4' >Recibido</option> 

                                                                          </select>
                                                                     <%
                                                                     }
                                                                     else{%>
                                                                        <%=status%>
                                                                    <%}%>
                                                                    <!-- 
                                                                     -->
                                                                    </td>
                                                                    <td align="center"><a href="#"><img  name="view" src="/images/buttons/shopkeeper/detalle.gif" border="0" onClick="operationType.value='view';storeId.value='<%=id%>';document.orders.submit();"></a></td>
                                                                    <!-- <td align="center"><a href="/minorista/administrarlista?operationType=load&id=<%=id%>"><img  name="update" src="" width="" height="" border="0" onClick="')"></a></td>
                                                                    -->
                                                                    
                                                                    
                                                                    
                                                            </tr>
                                                        <% 
                                                        }
                                                    }%>
                                                              <input name="operationType" type="hidden" value="">
                                                              <input name="combo" type="hidden" value="">
                                                              <input name="storeId" type="hidden" value="">
                                                              
                                                              
                                            </form>
                                    </table>
                                    
                                    <!-- -->
                                    </td></tr>
                                    <tr>
                                    <td><hr></td>

                                    </tr>
                                    <tr><td>
                                    <!-- -->
                                    
                                    </td></tr>

				
			</table>
	</td>
    </tr>
	

</table>
<!-- -->
<table width="760">
	<tr>
		<td><%@ include file="/piepagina.jsp" %></td>
	</tr>
</table>

</body>
</html>