<%@ page import="java.util.*,javax.sql.*,java.sql.*,javax.naming.*,java.text.*,m05bClasses.*" %>
<%	// _______________________________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"%>

<HTML>
<link rel="stylesheet" href="<%=m05bConstantesPaginas.PATH_ESTILOS%>/m05bestilos.css" type="text/css">
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
<HEAD>
 <title><%= resTit.getString("titLstVehReparaciones")%></title>
	
<SCRIPT language=JavaScript>
		function fncRetornar() {
			var docu = document.formPDFVehReparaciones;
			docu.action="/m05bParqueMovilWar/m05bVehReparacionesJsp.jsp" ;
			docu.submit();
		}
</SCRIPT>
</HEAD>	
<BODY style="cursor: wait" onkeydown="cancelaEnter();" onload="document.body.style.cursor='default';document.all['general'].style.visibility='visible';document.all['general'].style.cursor='default';"  onunload="document.body.style.cursor='wait';document.all['general'].style.cursor='wait';">
<div  id="general" style="POSITION: absolute;visibility:hidden;cursor: wait">
<form NAME="formPDFVehReparaciones" METHOD="POST">
<%	m05bComun miComun = new m05bComun();
	String sVehReparaciones = miComun.leerPropiedad("PDF.VehiculosReparaciones");
	String matricula = request.getParameter("Matricula");
	String fecha= request.getParameter("FEntrada")==null?"":request.getParameter("FEntrada");
	String srcPDF = sVehReparaciones + "?Matricula=" + matricula + "&FEntrada=" + fecha;

	
	//Miro si hay datos que mostrar para el pdf vacío si fuera necesario
	String sMatricula="", sFEntrada="";
	java.sql.Connection conn=null;
	PreparedStatement pstmt = null;
	ResultSet rs = null;
	sMatricula=request.getParameter("Matricula")==null?"":request.getParameter("Matricula");
	sFEntrada=request.getParameter("FEntrada")==null?"":request.getParameter("FEntrada");
	try
      {  //HttpSession session = request.getSession(true);
			m05bConexion miConex = new m05bConexion();
			conn = miConex.getConnection();
			String sSQL="select min(" + m05bConstantes.COL_20_MATRICULA + "), min(" + m05bConstantes.COL_20_CODIGO + 
     					"), min(to_char(" + m05bConstantes.COL_20_FENTRADA +	 ",'dd-mm-yyyy hh24:mi')), min(to_char(" + m05bConstantes.COL_20_FSALIDA + ",'dd-mm-yyyy hh24:mi'))" +
						", min(" + m05bConstantes.COL_20_IMPORTE + "), min(" + m05bConstantes.COL_19_CODIGO + 
						"), min(" + m05bConstantes.COL_19_CONCEPTO + "), min(" + m05bConstantes.COL_07_NOMBRE + 
						"), min(" + m05bConstantes.COL_19_TIEMPO + "), min(" + m05bConstantes.COL_19_IMPORTE  +
						"), sum(" + m05bConstantes.COL_23_TOTAL  + ")" +
					" from " + m05bConstantes.TAB_ORDENESTRAB + ", " + m05bConstantes.TAB_ORDEREPAR + 
						", " + m05bConstantes.TAB_PIEZAREP + ", " + m05bConstantes.TAB_EMPTALLER  +
					" where  " + m05bConstantes.COL_20_MATRICULA + " = '" +  sMatricula + "'" +
						" and " + m05bConstantes.COL_19_COD_ORD + " = " + m05bConstantes.COL_20_CODIGO  +
						" and " + m05bConstantes.COL_23_ORDEN + " (+) = " + m05bConstantes.COL_19_COD_ORD  +
						" and " + m05bConstantes.COL_23_CODIGO + " (+) = " + m05bConstantes.COL_19_CODIGO  +						
						" and " + m05bConstantes.COL_07_CODIGO + " = " + m05bConstantes.COL_19_EMPLEADO;
			if (!(sFEntrada.equals(""))) {
				sSQL+=" and " + m05bConstantes.COL_20_FENTRADA + " >= to_date('" + sFEntrada + "','dd/mm/yyyy')";
			}
			sSQL+=" group by " + m05bConstantes.COL_20_MATRICULA + ", " + m05bConstantes.COL_20_CODIGO + 
					", " + m05bConstantes.COL_19_CODIGO;
			sSQL+=" order by " + m05bConstantes.COL_20_CODIGO + " desc, " + m05bConstantes.COL_19_CODIGO ;			
            pstmt = conn.prepareStatement(sSQL);
            rs = pstmt.executeQuery();
%>
<TABLE class="general">
  <tr>
       <!--td width="90%" align="right"><INPUT TYPE="IMAGE" style="cursor:hand" VALUE="Retornar" ONCLICK="JavaScript:fncRetornar();" onMouseOver="top.status='Retornar'; return true" onMouseOut="top.status=''; return true" src="<%=m05bConstantesPaginas.PATH_IMAGENES%>/retornar.gif"></td-->
       <td width="90%" align="right"><input type="button" class="boton" name="<%= res.getString("etBOT_RETORNAR")%>" value="<%= res.getString("etBOT_RETORNAR")%>" ONCLICK="JavaScript:fncRetornar();return false;" onMouseOver="top.status='<%= res.getString("etBOT_STATUSRETORNAR")%>'; return false" onMouseOut="top.status=''; return false" /></td>			       
  </tr>
  <tr>
    <td>
	<% if (rs.next() == true){ %>
		<embed name='pdfVehReparaciones' src='<%=srcPDF%>' type="application/pdf" width='736' height='500'></embed>
    <%} else {%>
		<embed name='pdfVehReparaciones' src='/parquemovil/SinDatos.pdf' type="application/pdf" width='736' height='500'></embed>
    <%}%>
	<%	} catch (Exception SQLException) {
		m05bClasses.m05bFileLog miLog = new m05bClasses.m05bFileLog();
			miLog.addTraza(SQLException);
		} 	finally{
				if (rs != null)
					rs.close();			
				if (pstmt != null)
					pstmt.close();
				if (conn != null)
					conn.close();}%>
  	</td>
  </tr>
</TABLE>
</form>
<script type="text/javascript" src="<%=m05bConstantesPaginas.PATH_SCRIPTS%>/m05bMsControl.js"></script>
 
</div>	  
</body>
</html>