<%@page import="java.util.*,javax.sql.*,java.sql.*,javax.naming.*,m05bClasses.*,m05bBD.m05bOrdenesTrabajo" %>
<%@include file="/mantenimientosJSP/includes/m05b.inc"%>

<HTML>
	
<!-- Fecha de creacion: (07/09/04) -->
<%	// _______________________________XLNETs______________________________________
	// Evaluar variable de session que indica si esta conectado a XLNets
	if (session.getAttribute("objetoSeguridad") == null)  { 
		// Verificar que no ha transcurrido el tiempo de sesion (web.xml) %>
			<%@ include file="/m05bControlAcceso.inc"%> 
<%	} 
	String persona = (String) session.getAttribute("persona");
%>
	<%@ include file="/m05bIdioma.inc"%>


<head>
		<title><%= resTit.getString("titOTPendientes")%></title>
		<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
		<link rel="stylesheet" href="<%=m05bConstantesPaginas.PATH_ESTILOS%>/m05bestilos.css" type="text/css">
        <script language="javascript1.2" src="<%=m05bConstantesPaginas.PATH_SCRIPTS%>/m05Funciones.js"></script>
        <script language="javascript1.2" src="<%=m05bConstantesPaginas.PATH_SCRIPTS%>/formateador.js"></script>			
</head>
<BODY style="cursor: wait" onkeydown="cancelaEnter();" onload="document.body.style.cursor='default';InitMenu();" onunload="document.body.style.cursor='wait';">
		<%
			int contTotal = 0;
			String sql = "", sql2 = "";
			String codigo=request.getParameter("NOrden");
			String matricula=request.getParameter("Matricula");
			String FEntrada =request.getParameter("FEntrada");
			String KmEntrada =request.getParameter("KmEntrada");
		    String Persona = request.getParameter("Abierta");
		    String FSalida="", Taller="";
		    String forFecha="YYYYMMDDHH24MISS";
		    String Reparacion="";
		    String orden="";
            orden = request.getParameter("Orden")==null?"FECHA":request.getParameter("Orden");		
            java.sql.Connection conn=null;
			PreparedStatement pstmt = null;
			ResultSet rs = null;		
%>	
<SCRIPT language=JavaScript>
		var urlIdioma;		//URL recarga en funcion del idioma
		var rutaCabecera;	//Camino de migas
		var detActual;		//Ventana actual
		urlIdioma = "<%=m05bConstantesPaginas.VEH_OT_PENDIENTE%>";
		detActual = '<%=resCM.getString("cmOTPendientes")%>';
		rutaCabecera="";
		//rutaCabecera = "<%=m05bConstantesPaginas.DATOS_CABECERA%>" + urlIdioma + "'>\\"+detActual+"</a>";
</SCRIPT>
<%@ include file="/mantenimientosJSP/includes/m05Cabecera_c.jsp"%>

<p>
<table  width="100%" height="100%" border="0" cellspacing="0" cellpadding="0" align="center">
	<tr><td colspan=3></td></tr>
	<tr valign="top">
		<td width="2%">
			<DIV ID="thessm" style="visibility:hidden;Position : Absolute ;Left : 0 ;Top : 80 ;Z-Index : 20;">
	      		<DIV ID="thessm2" style="Position : Absolute ;Left : (-150) ;Top : 0 ;Z-Index : 20;">
	                <%@ include file="/m05bMenuInicial.inc"%>
	       		</DIV>
			</DIV>
		</td>
		<td>&nbsp</td>
		<td width="98%">
		<FORM NAME="FormPenOrdenes" METHOD="POST" >
			<!--   BOTONERA     -->
		 <TABLE class="general">
					    <tr >
					      <td width="70%" valign="top" class="searchTitle"><%= res.getString("etOrdenarPor")%></td>
					    </tr>
					    <tr> 
					 	  <td class="grupoAsignacion" align="left">
					      	  <% if (orden.equals("MATRICULA")) { %>
						          <input type="RADIO" NAME="Orden" CHECKED VALUE="MATRICULA"  onclick="JavaScript:fncCambiarOrden()" border='0'/><FONT size=2><%= res.getString("etMatricula")%></FONT>
						          <input type="RADIO" NAME="Orden" VALUE="FECHA"  onclick="JavaScript:fncCambiarOrden()" border='0'/><FONT size=2><%= res.getString("etFechaEntrada")%></FONT>
						          <input TYPE="RADIO" NAME="Orden" VALUE="TALLER"  onclick="JavaScript:fncCambiarOrden()" border='0'/><FONT size=2><%= res.getString("etTaller")%></FONT>
					      	  <% } else if (orden.equals("FECHA")) { %>
						  	      <input type="RADIO" NAME="Orden" VALUE="MATRICULA"  onclick="JavaScript:fncCambiarOrden()" border='0'/><FONT size=2><%= res.getString("etMatricula")%></FONT>
							      <input type="RADIO" NAME="Orden" CHECKED VALUE="FECHA"  onclick="JavaScript:fncCambiarOrden()" border='0'/><FONT size=2><%= res.getString("etFechaEntrada")%></FONT>
							      <input TYPE="RADIO" NAME="Orden" VALUE="TALLER" onclick="JavaScript:fncCambiarOrden()" border='0'/><FONT size=2><%= res.getString("etTaller")%></FONT>
					      	  <% } else if (orden.equals("TALLER")) { %>
						  	      <input type="RADIO" NAME="Orden" VALUE="MATRICULA"  onclick="JavaScript:fncCambiarOrden()" border='0'/><FONT size=2><%= res.getString("etMatricula")%></FONT>
							      <input type="RADIO" NAME="Orden" VALUE="FECHA"  onclick="JavaScript:fncCambiarOrden()" border='0'/><FONT size=2><%= res.getString("etFechaEntrada")%></FONT>
							      <input TYPE="RADIO" NAME="Orden" CHECKED VALUE="TALLER" onclick="JavaScript:fncCambiarOrden()" border='0'/><FONT size=2><%= res.getString("etTaller")%></FONT>
							  <% }  %>
							  		  
					      </td>
					    <td align="right">
					        <!--INPUT TYPE="IMAGE" style="cursor:hand" VALUE="Imprimir" ONCLICK="JavaScript:fncImprimir();return false;" onMouseOver="top.status='Imprimir'; return true" onMouseOut="top.status=''; return true" src="<%=m05bConstantesPaginas.PATH_IMAGENES%>/imprimir.gif"-->
                            <input type="button" class="boton" name="<%= res.getString("etBOT_PRESENTAR")%>" value="<%= res.getString("etBOT_PRESENTAR")%>" ONCLICK="JavaScript:fncImprimir();return false;" onMouseOver="top.status='<%= res.getString("etBOT_STATUSPRESENTAR")%>'; return false" onMouseOut="top.status=''; return false" />				      					        
					    </td>
         		    	<td width="10%" align="right">
		    			<!--INPUT TYPE="IMAGE" style="cursor:hand" VALUE="Retornar" ONCLICK="JavaScript:history.back();return false" onMouseOver="top.status='Retornar'; return true" onMouseOut="top.status=''; return true" src="<%//=m05bConstantesPaginas.PATH_IMAGENES%>/retornar.gif"-->
						<!--INPUT TYPE="IMAGE" style="cursor:hand" VALUE="Buscar" ONCLICK="JavaScript:fncBuscar();return false;" onMouseOver="top.status='Retornar'; return true" onMouseOut="top.status=''; return true" src="<%=m05bConstantesPaginas.PATH_IMAGENES%>/buscar.gif"-->
						<input type="button" class="boton" name="<%= res.getString("etBOT_BUSCAR")%>" value="<%= res.getString("etBOT_BUSCAR")%>" ONCLICK="JavaScript:fncBuscar();return false;" onMouseOver="top.status='<%= res.getString("etBOT_STATUSBUSCAR")%>'; return false" onMouseOut="top.status=''; return false" />				      					        
				</td>
			</tr>
		</TABLE> 
						
		 <TABLE class="general">
		    <tr>
		       <td class="searchTitle" style="text-align: center" width="6%"><%= res.getString("etNOrden")%></td>
		       <td class="searchTitle" style="text-align: center" width="10%"><%= res.getString("etMatricula")%></td>
		       <td class="searchTitle" style="text-align: center" width="14%"><%= res.getString("etFEntrada")%></td>
		       <td class="searchTitle" style="text-align: center" width="12%"><%= res.getString("etKmEntrada")%></td>
		       <!--td class="searchTitle" width="10%">C&oacute;d. Taller</td-->
		       <td class="searchTitle" width="20%"><%= res.getString("etTaller")%></td>
		       <td class="searchTitle" width="38%"><%= res.getString("etReparaciones")%></td>
		    </tr>
	<%
	
	m05bFileLog miLog = new m05bFileLog();
		try{
		    m05bComun comun = new m05bComun();
		
 

		    session.removeAttribute("ordenestrabajo");
		    sql = "select " + m05bConstantes.COL_20_CODIGO + "," + m05bConstantes.COL_20_MATRICULA +
		    	"," + m05bConstantes.COL_20_FENTRADA +"," + m05bConstantes.COL_20_DESCRIP +
		    	"," + m05bConstantes.COL_30_DESCRIP + "," + m05bConstantes.COL_20_KM_ENTRADA +
		    	" FROM " + m05bConstantes.TAB_ORDENESTRAB + " , " + m05bConstantes.TAB_TALLER + 
		    	" WHERE " + m05bConstantes.COL_20_FSALIDA + " IS  NULL" +
		    	" AND " + m05bConstantes.COL_30_CODIGO + " = " + m05bConstantes.COL_20_CODTALLER;

			//sql = sql + sql2 + " order by "+m05bConstantes.COL_20_CODIGO+" desc";
			if (orden.equals("MATRICULA"))
				sql += " order by "+ m05bConstantes.COL_20_MATRICULA+","+m05bConstantes.COL_20_FENTRADA+" desc,"+ m05bConstantes.COL_30_DESCRIP;
			else if (orden.equals("FECHA"))
				sql += " order by "+ m05bConstantes.COL_20_FENTRADA+" desc,"+m05bConstantes.COL_20_MATRICULA+","+ m05bConstantes.COL_30_DESCRIP;
			else if (orden.equals("TALLER"))
				sql += " order by "+  m05bConstantes.COL_30_DESCRIP+","+m05bConstantes.COL_20_MATRICULA+","+m05bConstantes.COL_20_FENTRADA+" desc";
			
			miLog.addTraza(persona, "OT pendientes JSP", "SQL: " + sql, m05bConstantes.LOG_NIVEL_BAJO);
		    //m05bbBeginSelect(sql);
		    m05bConexion miConex = new m05bConexion();
            conn = miConex.getConnection();
            conn.setAutoCommit(false);  // Al final si todo ha ido bien se hace commit	 		    
		    pstmt = conn.prepareStatement(sql);
			rs = pstmt.executeQuery();

			while (rs.next() == true){
				codigo = rs.getString(1);
				matricula= rs.getString(2);
				FEntrada= rs.getString(3);
				KmEntrada= rs.getString(6)==null?"0":rs.getString(6);
		        Reparacion=rs.getString(4)==null?"":rs.getString(4);
		        Taller=rs.getString(5);
				 %>
				<tr>
				   <td class="inputFieldTitle" valign="top"><FONT size="1"><A href="JavaScript:seleccionar('<%=codigo%>')"><%=codigo%></A></FONT></td>
		           <td class="inputFieldTitle" valign="top"><FONT size="1"><%=matricula%></FONT></td>
		   		   <td class="inputFieldTitle" style="text-align: center" valign="top"><FONT size="1"><%=comun.formatearFechaHora(FEntrada,campoTexto3)%></FONT></td>
                   <input type="hidden" name=<%="KmEntrada"+contTotal%> value="<%=KmEntrada%>"> 
		   		   <script>
                        formatNumero(document.FormPenOrdenes.<%="KmEntrada" + contTotal%>);
		   		   </script>
                   <td  class="inputFieldTitle" style="text-align: right" valign="top"><FONT size="1"><script> document.write(document.FormPenOrdenes.<%="KmEntrada"+contTotal%>.value);</script></FONT></td>
		   		   <td class="inputFieldTitle" valign="top"><FONT size="1"><%=Taller%></FONT></td>
		   		   <td class="inputFieldTitle" valign="top"><FONT size="1"><%=Reparacion%></FONT></td>
				</tr>
		<% ++contTotal;
			} %>
				<tr align="center">
					<td class="inputField" colspan="6"><%= res.getString("etTotal")%> <%=contTotal%></td>
				</tr>	
			</TABLE>
		</FORM>
		</td>
	</tr>
	<tr>
			<td colspan="3"><%@ include file="/mantenimientosJSP/includes/m05Pie_c.jsp"%>	</td>
	</tr>
</table>
<SCRIPT language='javascript'>
	function fncBuscar (){
	      doc=document.FormPenOrdenes;
	      doc.action="m05bBuscarOTJsp.jsp";
	      doc.submit();
	}
	
	function seleccionar (codigo){
		  document.forms[0].action="m05bGenerarOrdenTrabajoServlet?Codigo=" + codigo + "&Mensaje=buscar";
		  document.forms[0].submit();
	}
	function fncCambiarOrden() {
		var orden;
		if (document.FormPenOrdenes.Orden[0].checked) {
			orden="MATRICULA";
		}else if (document.FormPenOrdenes.Orden[1].checked) {
			orden="FECHA";
		}else {
			orden="TALLER";
		}
			document.FormPenOrdenes.action="m05bPenOrdenesJsp.jsp?Orden=" + orden;
		    document.FormPenOrdenes.submit();
	}
			function fncImprimir (){
				var sOrden;
		        var docu=document.FormPenOrdenes;
				if (docu.Orden[0].checked) {
					sOrden="MATRICULA";
				} else if (docu.Orden[1].checked) {
					sOrden="FECHA";
				} else  {
					sOrden="TALLER";
				}
		        docu.action="m05bImpOrdPtesPDFJsp.jsp?Orden=" + sOrden;
		        docu.submit();
		    }  // Fin funcion fncImprimir
		    	
	
    setTimeout('initSlide();', 1);
</SCRIPT>
<%
} catch (Exception SQLException) {
	miLog.addTraza(SQLException);
} finally {
		//m05bEndSelect();
		if (rs != null)
			rs.close();
		if (pstmt != null)
			pstmt.close();
		if (conn != null)
			conn.close();
}
%>
</div>	
</BODY>
</HTML>