<%@ 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>


<!-- 
-->
<body bgcolor="#ffffff" background="../images/shopkeeper/general/fondo.jpg" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" onload='showMessage("<%=request.getAttribute("message")%>")'>
<script type='text/javascript' language='javascript' src='../js/library.js'></script>
<script>
    
 function showMessage(message){
        if(message!=null && message!=""){
            window.alert(message);
        }
        return true;
    }
    
    function validate(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.startDate2.value = document.searchEngine.startDate.value;
            document.orders.endDate2.value = document.searchEngine.endDate.value;
            document.orders.order2.value = document.searchEngine.order.value;
        
            document.orders.operationType.value = "update";
            document.orders.submit();
            return true;
    }
    
    function submitView(id){
        document.orders.operationType.value="view";
        document.orders.storeId.value=id;
        document.orders.submit();
        return true;
    }
	

    function nextPage()
    {
        document.getElementById( 'page' ).value = <%=page1%> + 1;
        document.getElementById( 'searchEngine' ).submit();
    }
    
    function previousPage()
    {
        document.getElementById( 'page' ).value = <%=page1%> - 1;
        document.getElementById( 'searchEngine' ).submit();
    }

</script>

<!-- 
-->
<%
	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'>
        <form action="/minorista/mispedidos" method="post" name="searchEngine" id="searchEngine" onSubmit="return validateForm(document.searchEngine);">
          <tr> 
            <td ><table width="560" border="0" align="center" 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 width="100%"  border="0" cellspacing="0" cellpadding="3">
                      <tr> 
                        <td> <table   align="center">
                            <tr> 
                              <td height="78" valign='top'> <table>
                                  <tr valign='top'> 
                                    <td><strong>Fecha inicial</strong></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' border='0'></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><strong>Fecha final</strong></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' border='0'></a></td>
                                    <script>
                                                                        var cal_endDate = new calendar1(document.searchEngine.endDate);
                                                                    </script>
                                  </tr>
                                </table></td>
                              <td valign="top"> <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>
                              <td valign="top"> <table width="100%" border="0">
                                  <tr> 
                                    <td><div align="left"><strong>Ordenar por:</strong> 
                                      </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>
                                  <tr> 
                                    <td><input type="submit" value=' Buscar pedidos' name='Buscar' id='Buscar4'></td>
                                  </tr>
                                </table></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>&nbsp;</td>
                  <td align="right" valign="bottom"><img src="images/bus4.gif" width="15" height="15"></td>
                </tr>
              </table></td>
          </tr>
          <tr> 
            <td>&nbsp;</td>
          </tr>
          <tr> 
            <td> 
			<!-- paginador-->
				<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>
			<!-- paginador -->
              
          </tr>
        </form>
        <tr> 
          <td> 
            <%
                                                        tittle = "Mis Pedidos";
                                                    %>
            <%@ include file="/titulo.jsp" %>
          </td>
        </tr>
        <tr>
          <td>
			<!-- paginación-->
			<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>
			<!-- paginación -->
		  </td>
        </tr>
        <tr> 
          <td> 
            <!-- -->
            <form name="orders" method="post" action="/minorista/administrarpedido" >
              <table align="left" >
                <tr class='tableheader'> 
                <input type='hidden' name="startDate2" value="">
                <input type='hidden' name="endDate2" value="">
                <input type='hidden' name="order2" value="">
           
                  <!-- Encabezado del listado -->
                  <td align="center"><b><font color="White">Consecutivo</font></b></td>
                  <td align="center"><b><font color="White">Proveedor</font></b></td>
                  <td align="center"><b><font color="White">Fecha</font></b></td>
                  <td align="center"><b><font color="White">Valor</font></b></td>
                  <td align="center"><b><font color="White">Forma de pago</font></b></td>
                  <td align="center"><b><font color="White">Super Oferta</font></b></td>
                  <td align="center"><b><font color="White">Estado</font></b></td>
                  <td align="center"><b><font color="White">Ver detalle</font></b></td>
                </tr>
                <% 
                                                    OrderListViewShopKeeper view = (OrderListViewShopKeeper)request.getAttribute("view");
                                                    Object data = new Object();
                                                    if(view != null)
                                                    {
                                                            int count = 0;
                                                            String color = "";
                                                            while(view.move()){
                                                                int i=0;
                                                                String id="";
                                                                String status = "";
                                                                String statusId = "";
                                                                
                                                                if( count % 2 == 0 )
                                                                {
                                                                    color = "FFFFF";
                                                                }
                                                                else
                                                                {
                                                                    color = "#EFEFEF";
                                                                }
                                                                count++;
                                              %>
                <tr bgcolor='<%=color%>'> 
                  <% while((data=view.nextElement()) != null){
                                                                        i++;
                                                                    if(i==1) { 
                                                                        
                                                                            id=data.toString();
                                                                            %>
                                                                            <td><%= data.toString() %></td>
                                                                            <%
                                                                    }
                                                                    
                                                                    else if(i==5) { 
                                                                        
                                                                            status=data.toString();
                                                                    }
                                                                    else if(i==6) { 
                                                                        
                                                                            statusId=data.toString();
                                                                    } 
                                                                    else if(i == 8){%>
                                                                    <td align="center"><input type="checkbox" <%= !data.toString().equals("0")?"checked":""%> disabled></td>
                                                                    <%}
                                                                    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="javascript:submitView(<%=id%>)"><img src="/images/buttons/shopkeeper/detalle.gif" alt="Ver detalle"  name="view" border="0" ></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="">
              </table>
            </form>
            <!-- -->
          </td>
        </tr>
        <tr> 
          <td>
			<!-- paginación-->
			<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>
			<!-- paginación -->
		  </td>
        </tr>
        <tr> 
          <td><hr></td>
        </tr>
      </table>
	</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/.”