<html>
<head>
<link rel="stylesheet" type="text/css" href="../../styles/Style.css">
<script language="JavaScript" type="text/javascript" src="ajax.js"></script>
</head>
<body>
<?php

include("../../bd/sql_variables.php");
$con= mysqli_connect("$sql_host", "$sql_usuario", "$sql_pass","$sql_db") or die(header ("No Disponible Servidor de Base de Datos"));
//mysql_select_db("$sql_db");

if(isset($_GET['idj']) && isset($_GET['ids']) && isset($_GET['mes']) && isset($_GET['anno'])){
$idj=$_GET['idj'];
$ids=$_GET['ids'];
$anno=$_GET['anno'];
$mes=$_GET['mes'];
$idtp=$_GET['idtp'];
$tpvaca=$_GET['tpvaca'];
if($idtp==0){
$sqlask=" SELECT  concat(b.ua_apepat,' ',b.ua_apemat,' ',b.ua_nom) as nombre, ";
$sqlask=$sqlask." (select s_abrev from tb_servicio where s_id=c.s_id and j_id=c.j_id) as SERVICIO, (select tp_desc from tb_tipoperson where tp_id=c.tp_id) as tipo_personal, ";
$sqlask=$sqlask." concat(date_format(a.v_fechaini,'%d/%m/%Y'),' - ', date_format(a.v_fechafin,'%d/%m/%Y'),' (', a.v_numdias,')') as fecha ";
$sqlask=$sqlask." FROM tb_vacaciones a inner join tb_usuasist b on a.ug_id= b.ug_id inner join tb_usudep c on b.ug_id=c.ug_id where a.v_estado='$tpvaca' and ((month(a.v_fechaini)='$mes' and year(a.v_fechaini)='$anno')";
$sqlask=$sqlask." or (month(a.v_fechafin)='$mes' and year(a.v_fechafin)='$anno')) and c.j_id='$idj' and c.s_id='$ids' order by tipo_personal, nombre";
}else{
$sqlask=" SELECT  concat(b.ua_apepat,' ',b.ua_apemat,' ',b.ua_nom) as nombre, ";
$sqlask=$sqlask." (select s_abrev from tb_servicio where s_id=c.s_id and j_id=c.j_id) as SERVICIO, (select tp_desc from tb_tipoperson where tp_id=c.tp_id) as tipo_personal, ";
$sqlask=$sqlask." concat(date_format(a.v_fechaini,'%d/%m/%Y'),' - ', date_format(a.v_fechafin,'%d/%m/%Y'),' (', a.v_numdias,')') as fecha ";
$sqlask=$sqlask." FROM tb_vacaciones a inner join tb_usuasist b on a.ug_id= b.ug_id inner join tb_usudep c on b.ug_id=c.ug_id where a.v_estado='$tpvaca' and ((month(a.v_fechaini)='$mes' and year(a.v_fechaini)='$anno')";
$sqlask=$sqlask." or (month(a.v_fechafin)='$mes' and year(a.v_fechafin)='$anno')) and c.j_id='$idj' and c.s_id='$ids' and c.tp_id='$idtp' order by tipo_personal, nombre";
}

}else{
$sqlask=" SELECT  concat(b.ua_apepat,' ',b.ua_apemat,' ',b.ua_nom) as nombre, ";
$sqlask=$sqlask." (select s_abrev from tb_servicio where s_id=c.s_id and j_id=c.j_id) as SERVICIO, (select tp_desc from tb_tipoperson where tp_id=c.tp_id) as tipo_personal, ";
$sqlask=$sqlask." concat(date_format(a.v_fechaini,'%d/%m/%Y'),' - ', date_format(a.v_fechafin,'%d/%m/%Y'),' (', a.v_numdias,')') as fecha ";
$sqlask=$sqlask." FROM tb_vacaciones a inner join tb_usuasist b on a.ug_id= b.ug_id inner join tb_usudep c on b.ug_id=c.ug_id where a.v_estado='$tpvaca' and ((month(a.v_fechaini)='$mes' and year(a.v_fechaini)='$anno')";
$sqlask=$sqlask." or (month(a.v_fechafin)='$mes' and year(a.v_fechafin)='$anno')) and c.j_id='$idj' and c.s_id='$ids' order by tipo_personal, nombre";
}
//echo $sqlask;



$resultdm = mysqli_query($con,$sqlask);
if(mysqli_num_rows($resultdm)!=0){
$salida = "<table><tr><td class='Listadohead' width='280'>APELLIDOS Y NOMBRES </td><td class='Listadohead' width='200'>TIPO DE PERSONAL</td><td class='Listadohead' width='200'>FECHA DEL VACACIONES</td><td class='Listadohead' width='250'>OBSERVACIONES</td></tr>";
while($row = mysqli_fetch_array($resultdm)){
//$observ= $row['observ'];
if($observ==''){
$observ = "-";
}

$salida = $salida."<tr><td align='left'  class='Listadobody' height='25'>".$row['nombre']."</td><td class='Listadobody' align='center'>".$row['tipo_personal']."</td><td class='Listadobody' align='center'>".$row['fecha']."</td><td class='Listadobody' align='center'>".$observ."</td></tr>";
}
$salida = $salida."<table>";
}else{
echo "<table align='center'><tr><td class='Listadohead' width='300'>NO SE ENCONTRARON NINGUN REGISTROS</td>";
}


echo $salida;
?>
</body>
</html>