
<?php
require_once("../class/class.conectar.php");
require_once("../class/class.tipocontrato.php");
require_once("../class/class.especialidad.php");
require_once("../class/class.especialidad.php");
require_once("../class/class.tipopersonal.php");
require_once("../class/class.usudep.php");
require_once("../class/class.vacaciones.php");

$idj = $_GET['idj'];
$ids = $_GET['ids'];
$ugid = $_GET['ugid'];

$Objcon = new Conectar();
$conex = $Objcon->con();

date_default_timezone_set("America/Lima"); setlocale(LC_TIME,"es_PE.UTF-8");

$periodo=date("Y",time());

//seleccionando al combo tipo de personal
$Objtp = new TipoPersonal();
$res_tp = array();
$res_tp = $Objtp->buscar_tipoper_dep($conex,$idj,$ids);
$cadenatp="<select id='tipopersonal' onChange='listarpersonalvac();'><option value='0' selected>TODOS</option>";
for ($i=0;$i<count($res_tp);$i++){
$cadenatp=$cadenatp."<option value='".$res_tp[$i]['id']."'>".$res_tp[$i]['nom']."</option>";
}
$cadenatp=$cadenatp."</select>";
$cadenalis="";
//seleccionando al comnbo tipo de contrato
$Objtc = new TipoContrato();
$res_tc = array();
$res_tc = $Objtc->listar_tp_cont_dep($conex,$idj,$ids);
$cadenatc="<select id='tcontrato' onChange='listarpersonalvac()'><option value='0' selected>TODOS</option>";
for ($i=0;$i<count($res_tc);$i++){
$cadenatc=$cadenatc."<option value='".$res_tc[$i]['cod']."'>".$res_tc[$i]['tipocont']."</option>";
}
$cadenatc=$cadenatc."</select>";

//construytento listado
$Objud = new UsuarioDependencia();
$res_ud = array();
$res_ud = $Objud->listar_per_dep($conex,$idj,$ids);
$sumap=0;
$s=0;
for ($i=0;$i<count($res_ud);$i++){
$codigo=$res_ud[$i]['cod'];
$vacaprog=0;

$cadenalis=$cadenalis."<tr><td align='left'>".utf8_encode($res_ud[$i]['nombre'])."</td><td align='center'>".utf8_encode($res_ud[$i]['tpersona'])."</td><td align='center'>".utf8_encode($res_ud[$i]['especialidad'])."</td><td align='center'>".utf8_encode($res_ud[$i]['tipocontrato'])."</td><td align='center'>".$res_ud[$i]['fingreso']."</td><td align='center'>".$periodo."</td>";

//vacaciones programadas
$Objvp = new Vacaciones();
$res_vp = array();
$res_vp=$Objvp->aks_vacaciones($conex,$codigo,$periodo,0);

if(count($res_vp)>0){
	if($res_vp[0]['suma']==$res_vp[0]['numdias']){
	$cadenalis=$cadenalis."<td align='center'><img src='img/check.png' width='15' height='15'></td>";
	$vacaprog=1;
	}else{
	$cadenalis=$cadenalis."<td align='center'><img src='img/b_drop.png'></td>";
	}///termina el if del else
}else{
$cadenalis=$cadenalis."<td align='center'><img src='img/b_drop.png'></td>";
}

//vacaciones ejecutadas
$Objve = new Vacaciones();
$res_ve = array();
$res_ve=$Objve->aks_vacaciones($conex,$codigo,$periodo,1);

if(count($res_ve)>0){
	if($res_ve[0]['suma']==$res_ve[0]['numdias']){
	$cadenalis=$cadenalis."<td align='center'><img src='img/check.png' width='15' height='15'></td>";
	$vacaprog=1;
	}else{
	$cadenalis=$cadenalis."<td align='center'><img src='img/b_drop.png'></td>";
	}
}else{
$cadenalis=$cadenalis."<td align='center'><img src='img/b_drop.png'></td>";
}


$s = $s + 1;
$cadenalis=$cadenalis."<td align='center'><input type='hidden' id='vacdet".$s."' value='".$codigo."'><img src='img/ver.jpg' width='17' height='17'  onClick=verdetallevaca($s);></td>";
if($vacaprog==1){
$cadenalis=$cadenalis."<td align='center'><img src='img/green.png' width='17' height='17' value='$codigo'></td></tr>";
}else{
$cadenalis=$cadenalis."<td align='center'><input type='hidden' id='vacing".$s."' value='".$codigo."'><img src='img/red.png' width='17' height='17'  onClick=registravaca($s);></td></tr>";
}
$sumap=$sumap+1;
}
$cadenalis=$cadenalis."<tr><td colspan='10' align='center'>El numero de Personal es ".$sumap."</td></tr>";
//<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
?>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="styles/Style.css">
<script language="JavaScript" type="text/javascript" src="ajax.js"></script>
<script type="text/javascript"> 
function verdetallevaca(id){
	var codigo = document.getElementById("vacdet"+id).value;
	var idj = document.getElementById("depa").value;
	var ids = document.getElementById("serv").value;
    var ugid = document.getElementById("ugid").value;
   window.open("verdetvacaciones.php?ugid="+ugid+"&idj="+idj+"&ids="+ids+"&codigo="+codigo,"","height=400,width=600,scrollbars=NO");
}
function reportarvaca(){

	var idj = document.getElementById("depa").value;
	var ids = document.getElementById("serv").value;
    var periodo = document.getElementById("anno").value;
	var idtp = document.getElementById("tipopersonal").value;
	var tcont = document.getElementById("tcontrato").value;
   window.open("../reporte/listarvacaciones.php?periodo="+periodo+"&idj="+idj+"&ids="+ids+"&idtp="+idtp+"&tcont="+tcont,"","height=1000,width=850,scrollbars=NO");
}
function reportarvacapp(){

	var idj = document.getElementById("depa").value;
	var ids = document.getElementById("serv").value;
    var periodo = document.getElementById("anno").value;
	var idtp = document.getElementById("tipopersonal").value;
	var tcont = document.getElementById("tcontrato").value;
   window.open("../reporte/listarvacatopersonal.php?periodo="+periodo+"&idj="+idj+"&ids="+ids+"&idtp="+idtp+"&tcont="+tcont,"","height=1000,width=850,scrollbars=NO");
}
function registravaca(id){
    var codigo = document.getElementById("vacing"+id).value;
	var idj = document.getElementById("depa").value;
	var ids = document.getElementById("serv").value;
    var ugid = document.getElementById("ugid").value;
   window.open("vacacionesprog.php?ugidp="+ugid+"&idj="+idj+"&ids="+ids+"&ugid="+codigo,"","height=400,width=600,scrollbars=NO");
}
function datospersonal(codigo){
	var idj = document.getElementById("depa").value;
	var ids = document.getElementById("serv").value;
	window.open("vistapersonal.php?ugid="+codigo+"&idj="+idj+"&ids="+ids,"","height=410,width=390,scrollbars=NO");
} 
function transferirpersonal(codigo){
	var idj = document.getElementById("depa").value;
	var ids = document.getElementById("serv").value;
	window.open("transferirpersonal.php?ugid="+codigo+"&idj="+idj+"&ids="+ids,"","height=200,width=700,scrollbars=NO");
} 
function editarpersonal(codigo){
		var idj = document.getElementById("depa").value;
		var ids = document.getElementById("serv").value;
		window.open("modificarpersonal.php?ugid="+codigo+"&idj="+idj+"&ids="+ids,"","height=400,width=600,scrollbars=NO");
} 
function suspenderpersonal(codigo){
		window.open("suspenderpersonal.php?ugid="+codigo,"","height=400,width=600,scrollbars=NO");
} 
function retornarmenu(){
		var idj = document.getElementById("depa").value;
		var ids = document.getElementById("serv").value;
        var ugid = document.getElementById("ugid").value;		
		document.location= "menuadmin.php?idj="+idj+"&ids="+ids+"&ugid="+ugid;
} 
</script> 
</head>
<body id="lista" name="lista">
<?php
echo "<input type='hidden' id='depa' name='depa' value='".$idj."'>";
echo "<input type='hidden' id='serv'  name='serv' value='".$ids."'>";
echo "<input type='hidden' id='ugid'  name='ugid' value='".$ugid."'>";
?>
<table align='center'>
<tr><td>
<div id='adminpersonal'>
<fieldset>
	<legend align='left'><font color='blue'>Listado del Personal Asistencial</font></legend>
	<br>
	<table align='center' ><tr><td align='left'>Tipo de Personal</td><td align='left'>Tipo Contrato</td><td class ='FacetDataTextC'>A&ntilde;o</td>
	<td width='50'></td><td  rowspan='2'><img src='../img/home.png' width='70' height='60' onClick='retornarmenu()'><button type='button' id='pprog' style='width:80px' class='FacetButton' onclick='reportarvaca();' > Reporte de <br> Vacaciones </button><button type='button' id='pprog' style='width:80px' class='FacetButton' onclick='reportarvacapp();' > Reporte de <br> Vacaciones <br>Para Personal</button></td>
	</tr>
	<tr><td><?php echo $cadenatp;?></td><td><?php echo $cadenatc;?></td>
	<td class ='FacetDataTextC'>
	<?php
	echo "<select name='anno' id='anno' onchange='listarpersonalvac();'>";
	for ($i=2000;$i<2100;$i++){
	echo "<option value='".$i."'";
	if(date("Y",time())==$i){?> selected
	<?php 
	$anno=$i;
	} echo ">".$i."</option>";
	}
	echo "</select>";
	?>
	</td></tr>
	</table>
	<br>
	<div id='admlistavac'>
	<table align='center' class='FacetFormTABLE' border='1' style='border-collapse: collapse ;border-spacing:  0px;'>
	<tr><td colspan='10'class='FacetFieldCaptionTDT' align='center' height='30'> PERSONAL ASISTENCIAL </td></tr>
	<tr><td class='FacetFieldCaptionTD' align='center' width='250' height='25'>APELLIDOS Y NOMBRES</td><td class='FacetFieldCaptionTD' align='center' width='130'>TIPO PERSONAL</td><td class='FacetFieldCaptionTD' align='center' width='130'>ESPECIALIDAD</td><td class='FacetFieldCaptionTD' align='center' width='130'>TIPO DE CONTRATO</td><td class='FacetFieldCaptionTD' align='center' width='100'>FECHA DE INGRESO</td><td class='FacetFieldCaptionTD' align='center'>PERIODO</td><td class='FacetFieldCaptionTD' align='center'>VAC. PROG</td><td class='FacetFieldCaptionTD' align='center'>VAC. EJE</td><td class='FacetFieldCaptionTD' align='center'>VER DET.</td><td class='FacetFieldCaptionTD' align='center'>EDITAR</td></tr>
	
	<?php echo $cadenalis;?>
	
	</table>
	</div>
	<br>
</fieldset>
</td></tr>
</table>
</body>
</html>