<%@ page language="java"%> 

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


<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
<link rel="stylesheet" href="<%=m05bConstantesPaginas.PATH_ESTILOS%>/m05bestilos.css" type="text/css">
<title><%= resTit.getString("titLstResumenItvs")%></title>
<SCRIPT language=JavaScript>
		function fncRetornar() {
				 document.formSolicitud.action="/m05bParqueMovilWar/m05bImpDesdeHastaJsp.jsp?Tipo=0" ;
				 document.formSolicitud.submit();
		}
</SCRIPT>
</HEAD>	
<!-- Hojas de Estilo -->
<%	String sResumenItv="";
m05bFileLog miLog = new m05bFileLog();
     String sListado= request.getParameter("Listado");
     miLog.addTraza(persona, "RsumenPDfITV", "sListado"+sListado, m05bConstantes.LOG_NIVEL_BAJO);
    if (sListado.equals("0")){ 
    sResumenItv = m05bFicheroProperties.getInstance().getParameter("PDF.ResumenItv"); }
    else{
    sResumenItv = m05bFicheroProperties.getInstance().getParameter("PDF.ResumenItvPendientes"); }
    
    miLog.addTraza(persona, "RsumenPDfITV", "sResumenItv"+sResumenItv, m05bConstantes.LOG_NIVEL_BAJO);
%>

<BODY style="cursor: wait" 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="formSolicitud" METHOD="POST">
<%

	//String sDpto = request.getParameter("codDpto");
String sFDesde= request.getParameter("FecDesde");
String sFHasta= request.getParameter("FecHasta");
    
	//String srcPDF = SancionPendiente + "?DPTO="+sDpto;
	String srcPDF = sResumenItv + "?FecDesde="+sFDesde+ "&FecHasta="+sFHasta+ "&Listado="+sListado ;
	java.sql.Connection conn=null;
	PreparedStatement pstmt = null;
	ResultSet rs = null;
      try
      {  //HttpSession session = request.getSession(true);
			m05bConexion miConex = new m05bConexion();
			conn = miConex.getConnection();
String sSentencia="";
    if (sListado.equals("0")){ 

sSentencia="SELECT 1 " + 
" FROM "+
m05bConstantes.TAB_ITV +","+ m05bConstantes.TAB_HIST_VEHICULOS +
" WHERE ((" +
m05bConstantes.COL_27_MATRICULA+"="+m05bConstantes.COL_44_MATRICULA +") AND "+
"(("+m05bConstantes.COL_27_FINSPEC+">="+m05bConstantes.COL_44_FCAMBIO+
") AND ("+m05bConstantes.COL_27_FINSPEC+"<=DECODE("+m05bConstantes.COL_44_FFIN+
",'',TO_DATE('31/12/2999','dd/mm/yyyy'),"+m05bConstantes.COL_44_FFIN+"))) AND ("+
m05bConstantes.COL_27_FINSPEC+">= TO_DATE('"+sFDesde+"','"+formatoFecha+"')) AND ("+
m05bConstantes.COL_27_FINSPEC+"<= TO_DATE('"+sFHasta+"','"+formatoFecha+"')) "+ 
"  AND (" +
m05bConstantes.COL_27_MATRICULA+"||"+ m05bConstantes.COL_27_FINSPEC + " NOT IN ("+
" SELECT "+
m05bConstantes.COL_27_MATRICULA+"||MIN("+m05bConstantes.COL_27_FINSPEC+
") FROM " + m05bConstantes.TAB_ITV + 
" GROUP BY " + m05bConstantes.COL_27_MATRICULA + ")))";
	}else{
sSentencia=" SELECT 1 "+ 
" FROM "+
  m05bConstantes.TAB_ITV+","+
  m05bConstantes.TAB_VEHICULOS+
" WHERE " + m05bConstantes.COL_34_MATRICULA+"||"+m05bConstantes.COL_27_FINSPEC + 
" in(SELECT "+
  m05bConstantes.COL_27_MATRICULA+
" ||max("+m05bConstantes.COL_27_FINSPEC+
" ) FROM "+
  m05bConstantes.TAB_ITV +
" GROUP BY "+m05bConstantes.COL_27_MATRICULA+
" ) AND "+m05bConstantes.COL_27_MATRICULA+
" ="+m05bConstantes.COL_34_MATRICULA+
" AND "+
" (((((DECODE("+m05bConstantes.COL_27_FPRXINSPEC+",'',DECODE("+
m05bConstantes.COL_27_FREPINSP+",'',TO_DATE('99991231','YYYYMMDD'),"+
m05bConstantes.COL_27_FREPINSP+"),"+m05bConstantes.COL_27_FPRXINSPEC+"))"+
"-SYSDATE)<0)  AND ("+m05bConstantes.COL_34_SITUACION+" ='A'))) AND ("+
m05bConstantes.COL_27_FINSPEC+">= TO_DATE('"+sFDesde+"','"+formatoFecha+"')) AND ("+
m05bConstantes.COL_27_FINSPEC+"<= TO_DATE('"+sFHasta+"','"+formatoFecha+"'))";
	}
	     miLog.addTraza(persona, "RsumenPDfITV", "sSentencia"+sSentencia, m05bConstantes.LOG_NIVEL_BAJO);
		   pstmt = conn.prepareStatement(sSentencia);
		   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"-->
         <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 colspan="2">
    <% if (rs.next() == true){ %>
		<embed name='pdfREsumenItv' src='<%=srcPDF%>' type="application/pdf" width='736' height='500'></embed>
    <%} else {%>
		<embed name='pdfREsumenItv' src='/parquemovil/SinDatos.pdf' type="application/pdf" width='736' height='500'></embed>
    <%}%>
	<%	} catch (Exception SQLException) {
			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>
