<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<form>
<% Server.ScriptTimeOut = 1000 %>
<table width="100%" border="1" align="center">
<% 'Crear Fechas %>
<% fecha_Ini=Request.form("ex4")
fecha_fin=Request.Form("ex5")
puesto = request.Form("puesto")
templeado = request.Form("templeado")
all_emp = templeado
all_puesto = puesto
response.Write(f_ini) & "<br>"
response.Write(f_fin) & "<br>"
%>
<% 'Asignar fechas Inicial y Final a Variables %>
<% f_ini = Fecha_Ini %>
<% f_fin = Fecha_Fin%>
<% 'Query para consultar Fechas %>
<%
Response.write "Fecha Ini: " & f_ini
Response.Write " Fecha Fin: " & f_fin
'empleado=request.form("empleado_name")
set conn=Server.CreateObject("ADODB.Connection")
constr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("personal.mdb") & ";Persist Security Info=False"
conn.Open constr
set rs_f=Server.CreateObject("ADODB.recordset")
sqltxt_f = "select distinct(fecha) as fec from regent where fecha >='"& f_ini&"' and fecha <='"& f_fin&"' order by regent.fecha"
rs_f.Open sqltxt_f, conn,1,2
Response.Write "Fecha: " & rs_f.RecordCount & "<br>"
%>
<% 'Query para contar los registros %>
<%
set rs_cuenta=Server.CreateObject("ADODB.recordset")
sqltxt_cuenta = "select count(id_regent) as cuenta_rgs from regent where fecha >='"& f_ini&"' and fecha <='"& f_fin&"'"
rs_cuenta.Open sqltxt_cuenta, conn, 1, 2
cuenta_fecs = rs_cuenta.fields("cuenta_rgs")
Response.Write "RsCuenta: " & rs_cuenta.RecordCount & "<br>"
%>
<% 'Llenar encabezados con fechas de cada dia %>
<% if rs_cuenta.fields("cuenta_rgs") = 0 then %>
<%else%>
<tr bgcolor="#CCCCCC">
<td rowspan="2" bordercolor="2"> <div align="center"><font color="#990000">Nombre del Empleado</font></div></td>
<% rs_f.movefirst %>
<%do until rs_f.eof%>
<td colspan="3" bordercolor="2"> <div align="center"><font color="#990000"><%response.Write(rs_f.fields("fec"))%></font></div><br></td>
<%rs_f.movenext%>
<%loop%>
</tr>
<tr bgcolor="#CCCCCC">
<% rs_f.movefirst %>
<%do until rs_f.eof%>
<td colspan="1" bordercolor="2"> <div align="center"><font color="#990000">Entrada</font></div></td>
<td colspan="1" bordercolor="2"> <div align="center"><font color="#990000">Salida</font></div></td>
<td colspan="1" bordercolor="2"> <div align="center"><font color="#990000">Justificado</font></div></td>
<%rs_f.movenext%>
<%loop%>
<% 'Seleccionar Empleados deacuerdo a fechas seleccionadas %>
<% If all_emp = "todos" then all_emp= "%"
If all_puesto = "todos" then all_puesto= "%"
%>
<%
set rs_nom=Server.CreateObject("ADODB.recordset")
sqltxt_nom = "SELECT d_gen.cod, d_gen.apat, d_gen.amat, d_gen.nom, d_gen.templeado, d_gen.puesto, regent.fecha " _
& "FROM regent RIGHT JOIN d_gen ON regent.cod = d_gen.cod " _
& "GROUP BY d_gen.cod, d_gen.apat, d_gen.amat, d_gen.nom, d_gen.templeado, d_gen.puesto, regent.fecha " _
& "HAVING (((d_gen.templeado) Like '" & all_emp & "') AND ((d_gen.puesto) Like '" & all_puesto & "') AND ((regent.fecha)>='" & f_ini & "'And (regent.fecha)<='" & f_fin & "')) " _
& "ORDER BY d_gen.apat, d_gen.amat, d_gen.nom"
rs_nom.Open sqltxt_nom, conn, 1, 2
Response.Write sqltxt_nom & "<br>"
Response.Write all_emp & " " & all_puesto & "<br>"
cuen_per = rs_nom.Recordcount
Response.Write (cuen_per) & "<br>"
'Query para contar los registros
end if %> <% 'Llena columna de nombres de Empleados %>
<% if cuen_per = 0 then %>
<tr>
<td bordercolor="#FFFFFF" colspan="<%= ""& cuenta_fecs&"" %>" align="center"><div align="center"><font color="#FF0000" size="4">¡No se encontraron
registros deacuerdo a los criterios seleccionados!</font></div></td>
</tr>
<tr>
<td bordercolor="#FFFFFF" colspan="<%= ""& cuenta_fecs&"" %>" align="center"><div align="center"><font color="#FF0000" size="4"><a href="JavaScript:history.back()" ><font color="#000000" size="4">Regresar...</font></a> </font></div></td>
</tr>
<%else%>
<% 'Desplegar Hora de Entrada y Hora de Salida %>
<% rs_nom.movefirst %>
<% do until rs_nom.eof %>
<% codigo_hora = rs_nom.fields("cod") %>
<tr bgcolor="#FFFFFF">
<td colspan="1" bordercolor="2"> <div align="left"><font color="#000000"><%response.Write(rs_nom.fields("nom"))%> <%response.Write(rs_nom.fields("apat"))%> <%response.Write(rs_nom.fields("amat"))%></font></div></td>
<% rs_f.movefirst %>
<% do until rs_f.eof %>
<% fecha_hora = rs_f.fields("fec") %>
<% fecha_hora = cdate(fecha_hora) %>
<%
set rs_h_max=Server.CreateObject("ADODB.recordset")
sqltxt_h_max = "select max(regent.hora) as h_max from d_gen, regent where d_gen.cod = regent.cod and d_gen.cod = '"& codigo_hora&"' and cdate(regent.fecha) = '"& fecha_hora&"'"
rs_h_max.Open sqltxt_h_max, conn
hora_max_primera = rs_h_max.fields("h_max")
set rs_h_min=Server.CreateObject("ADODB.recordset")
sqltxt_h_min = "select min(regent.hora) as h_min from d_gen, regent where d_gen.cod = regent.cod and d_gen.cod = '"& codigo_hora&"' and cdate(regent.fecha) = '"& fecha_hora&"'"
rs_h_min.Open sqltxt_h_min, conn
hora_min_primera = rs_h_min.fields("h_min")
set rs_justifica=Server.CreateObject("ADODB.recordset")
sqltxt_justifica = "select distinct(justifica) as c_justifica from d_gen, regent where d_gen.cod = regent.cod and d_gen.cod = '"& codigo_hora&"' and cdate(regent.fecha) = '"& fecha_hora&"'"
rs_justifica.Open sqltxt_justifica, conn
cuenta_justifica = rs_justifica.fields("c_justifica")
%>
<% rs_justifica.movefirst %>
<% fondo = "#FFFFFF" %>
<% just = "" %>
<% do until rs_justifica.eof %>
<% If rs_justifica.fields("c_justifica") = 1 Then %>
<% fondo = "#009933" %>
<% just = "justificado" %>
<% Else %>
<% End If %>
<% rs_justifica.movenext %>
<% loop %>
<% If hora_max_primera <> "" and hora_min_primera <> "" Then %>
<% If cdate(hora_max_primera) > cdate(hora_min_primera) Then %>
<td colspan="1"> <div align="left"><font color="#000000"><%response.Write(rs_h_min.fields("h_min"))%> </font></div></td>
<td colspan="1" > <div align="left"><font color="#000000"><%response.Write(rs_h_max.fields("h_max"))%> </font></div></td>
<td colspan="1" bgcolor="<%= ""& fondo&"" %>"> <div align="left"><font color="#000000"> <%=just%></font></div></td>
<% Else %>
<td colspan="1" > <div align="left"><font color="#000000"><%response.Write(rs_h_max.fields("h_max"))%> </font></div></td>
<td colspan="1" > <div align="left"><font color="#000000"><%response.Write(rs_h_min.fields("h_min"))%> </font></div></td>
<td colspan="1" bgcolor="<%= ""& fondo&"" %>"> <div align="left"><font color="#000000"> <%=just%></font></div></td>
<% End If %>
<% Else %>
<% End If %>
<% rs_f.movenext %>
<% loop %>
</tr>
<% rs_nom.movenext %>
<% loop %>
<%end if%>
</table>
</form>
</body>
</html>