<%@ page language="java"%> 

<%@ page import="java.util.*,javax.sql.*,java.sql.*,javax.naming.*,java.text.*,m05bClasses.*" %>
<HTML>

<%
	// _______________________________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"%> <%
			
	} 
%>	
	<%@ include file="/m05bIdioma.inc"%>

<HEAD>
<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=JavaScript>
		function fncRetornar(cia) {
				document.formPDFSeguroSoli.action="/m05bParqueMovilWar/m05bImpSoliSeguroJsp.jsp";
				document.formPDFSeguroSoli.submit();
		}
</SCRIPT>
</HEAD>	
<!-- Hojas de Estilo -->
<%	String SeguroSoli = m05bFicheroProperties.getInstance().getParameter("PDF.SeguroSoli"); %>

<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';document.all['general'].style.cursor='wait';">
<div  id="general" style="POSITION: absolute;visibility:hidden;cursor: wait">	
<form NAME="formPDFSeguroSoli" METHOD="POST">
<%
	String sCia = request.getParameter("CIA");
    
	String srcPDF = SeguroSoli + "?CIA="+sCia;
	String persona = (String) session.getAttribute("persona");	 
	java.sql.Connection conn=null;
	PreparedStatement pstmt = null;
	ResultSet rs = null;
	m05bFileLog miLog = new m05bFileLog();
      try
      {  //HttpSession session = request.getSession(true);
    	m05bConexion miConex = new m05bConexion();
		conn = miConex.getConnection();
		String sMatriculasErr="";
        String sSentencia = "select count(*)" +
                             " from " + m05bConstantes.TAB_HIST_SEGUROS + 
                             " WHERE " + m05bConstantes.COL_13_ESTADO + " = 'S'" +
                             " AND " + m05bConstantes.COL_13_IMPRESO + " = 'N'" +
                             " AND " + m05bConstantes.COL_13_POLIZA + " = '" +sCia + "'" +
                             " ORDER BY 1" ;
        int nCount=0;
        String sSentencia2 = "select count(*) " +
                             " from " + m05bConstantes.TAB_HIST_SEGUROS + ","+ m05bConstantes.TAB_TARJETAS+ 
                             " WHERE " + m05bConstantes.COL_13_ESTADO + " = 'S'" +
                             " AND " + m05bConstantes.COL_13_IMPRESO + " = 'N'" +
                             " AND " + m05bConstantes.COL_13_POLIZA + " = '" +sCia + "'" + 
                             " AND " + m05bConstantes.COL_13_MATRICULA + " = " + m05bConstantes.COL_31_MATRICULA +
                             " AND " + m05bConstantes.COL_31_TIPO + " = '" + m05bConstantes.TAR_GASTO +
                             "' AND " + m05bConstantes.COL_31_CENTRO + " IS NOT NULL " ;
                             
         String sSentencia3= "select distinct "+m05bConstantes.COL_13_MATRICULA +
                             " from " + m05bConstantes.TAB_HIST_SEGUROS + 
                             " WHERE " + m05bConstantes.COL_13_ESTADO + " = 'S'" +
                             " AND " + m05bConstantes.COL_13_IMPRESO + " = 'N'" +
                             " AND " + m05bConstantes.COL_13_POLIZA + " = '" +sCia + "'" +
                             " AND " + m05bConstantes.COL_13_MATRICULA  + " NOT IN (SELECT "+ m05bConstantes.COL_31_MATRICULA +
                             " FROM " +  m05bConstantes.TAB_TARJETAS +" WHERE "+ m05bConstantes.COL_31_TIPO + " = '" + m05bConstantes.TAR_GASTO +"')";

         int nCount2=0;
         miLog.addTraza(persona, "SeguroPdfSolicitud", "sSentencia "+sSentencia, m05bConstantes.LOG_NIVEL_BAJO);
         miLog.addTraza(persona, "SeguroPdfSolicitud", "sSentencia2 "+sSentencia2, m05bConstantes.LOG_NIVEL_BAJO);
         miLog.addTraza(persona, "SeguroPdfSolicitud", "sSentencia3 "+sSentencia3, 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('<%=sCia%>');" 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('<%=sCia%>');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())  {
         nCount=rs.getInt(1);
         pstmt = conn.prepareStatement(sSentencia2);
		 rs = pstmt.executeQuery();
		    if (rs.next()){
     	     nCount2=rs.getInt(1);
        	 if ((nCount==nCount2) && (nCount!=0)){%>
  		      
  		       <embed name='pdfSegurosoli' src='<%=srcPDF%>' type="application/pdf" width='736' height='500'></embed>
            <%}else if ((nCount==nCount2) && (nCount==0)){%>

		         <embed name='pdfSegurosoli' src='/parquemovil/SinDatos.pdf' type="application/pdf" width='736' height='500'></embed>
  		       
	        <%}else if (nCount!=nCount2 ){ 
                 pstmt = conn.prepareStatement(sSentencia3);
		         rs = pstmt.executeQuery();
		         while (rs.next()){
		            sMatriculasErr=rs.getString(1)+" " +sMatriculasErr;
		         }%>
	             <script>
	      	        alert(dameAlerta(idioma, 112) + " : " + "<%=sMatriculasErr%>" );
	             </script>
	             <%if (nCount2>0){%>
	             <embed name='pdfSegurosoli' src='<%=srcPDF%>' type="application/pdf" width='736' height='500'></embed>
	             <%}else{%>
	             <embed name='pdfSegurosoli' 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>
