<?php

include("../../../class/class.conectar.php");
include("../../../class/class.jefatura2.php");
include("../../../class/class.servicio2.php");
include("../../../class/class.tipopersonal2.php");
include("../../../class/class.tipocontrato2.php");
include("../../../class/class.vacaciones.php");
include("../../../class/class.blkpersonal2.php");

$ugid = $_GET['ugid'];
$idj = $_GET['idj'];
$anno = date("Y");

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

$Objj = new Jefatura();
$res_j = array();
$res_j = $Objj->buscar_jefaturaxidj($conex,$idj);

//listarpersonalterm1();
//combo jefatura
$cbjef = "";
$cbjef = $cbjef."<select id='cbjef' style='width: 270px;' onChange='consultarserv();listarpersonal(1)'>";
$cbjef = $cbjef."<option value='0'>Seleccione Area/Dpto</option>";

for($a=0;$a<count($res_j);$a++){
	$cbjef = $cbjef."<option value='".$res_j[$a]['id']."' ";
		if($res_j[$a]['id']==$idj){
		$cbjef = $cbjef." selected";
		}
	$cbjef = $cbjef.">".$res_j[$a]['nom']."</option>";
}
$cbjef = $cbjef."</select>";


//combo servicio
$Objs = new Servicio();
$res_s = array();
$res_s = $Objs->buscar_servicioxidj($conex,$idj);

//nombre de servicio
$cbserv = "";
$cbserv = $cbserv."<select id='cbserv' style='width: 270px;' onchange='listarpersonal(1);'>";
$cbserv = $cbserv."<option value='-1'>TODOS </option>";

for($b=0;$b<count($res_s);$b++){
$cbserv = $cbserv."<option value='".$res_s[$b]['ids']."'>".$res_s[$b]['nom']."</option>";
}
$cbserv = $cbserv."</select>";


//combo tipo de personal
$Obj_blk = new BlkPersonal();
$res_blk = array();
$res_blk = $Obj_blk->buscar_grupoocupacionalxidj($conex,$idj);
$cbtipoper = "";
$cbtipoper = $cbtipoper."<select id='cbtp' style='width: 200px;' onChange='listarpersonal(1);'>";
$cbtipoper = $cbtipoper."<option value='-1'>TODOS</option>";
	for($c=0;$c<count($res_blk);$c++){
		$cbtipoper = $cbtipoper."<option value='".$res_blk[$c]['id']."'>".$res_blk[$c]['nom']."</option>";
	}
$cbtipoper = $cbtipoper."</select>";

//comnbo tipo de contrato
$Objtc = new TipoContrato();
$res_tc = array();
$res_tc = $Objtc->buscar_tipocontrato($conex);
$cbtc = "";
$cbtc="<select id='cbtc' onChange='listarpersonal(1);'>";
$cbtc = $cbtc."<option value='0'>Seleccione Tipo Contrato</option>";
$cbtc = $cbtc."<option value='-1'>TODOS</option>";
	for($c=0;$c<count($res_tc);$c++){
		$cbtc = $cbtc."<option value='".$res_tc[$c]['id']."'>".$res_tc[$c]['nom']."</option>";
	}
$cbtc=$cbtc."</select>";

//combo Periodo
$cbper = "";
$cbper="<select id='cbper' onChange='listarpersonal(1);'>";
for($x=2013;$x<=2030;$x++){
	$cbper = $cbper."<option value='".$x."'";
	if($x==$anno){
		$cbper = $cbper." selected ";
		$per = $anno;
	}
	$cbper = $cbper.">".$x."</option>";
}
$cbper=$cbper."</select>";

//construytento listado
$Objbp = new BlkPersonal();
$res_bp = array();
$res_bp = $Objbp->buscar_detpersonal_activo($conex,0,0,0,0,'');

$sumap=0;
$a=1;
$muestra="";
$cadenalis="";

	for($p=0;$p<count($res_bp);$p++){
		$codigo=$res_bp[$p]['cod'];
		$vacaprog=0;
		$muestra = $muestra."<input type='hidden' id='codper".$a."'  name='codper".$a."' value='".$codigo."'>";
		$cadenalis=$cadenalis."<tr><td align='left'>".$res_bp[$p]['nombre']."</td>";
			$cadenalis=$cadenalis."<td align='center'>".$res_bp[$p]['servicio']."</td>";
			$cadenalis=$cadenalis."<td align='center'>".$res_bp[$p]['tpersona']."</td>";
			$cadenalis=$cadenalis."<td align='center'>".$res_bp[$p]['especialidad']."</td>";
			$cadenalis=$cadenalis."<td align='center'>".$res_bp[$p]['tipocontrato']."</td>";
			$cadenalis=$cadenalis."<td align='center'>".$res_bp[$p]['fingreso']."</td>";
			$cadenalis=$cadenalis."<td align='center'>".$per."</td>";

			$Obj_vp = new Vacaciones();
			$res_vp = array();
			$res_vp=$Obj_vp->aks_vacaciones($conex,$codigo,$per,0);
			if(count($res_vp)>0){
				if($res_vp[0]['suma']==$res_vp[0]['numdias']){
					$cadenalis=$cadenalis."<td align='center'><img src='../../img/b_check.png' width='17' height='17' border='0' ></td>";
					$vacaprog=1;
				}else{
					$cadenalis=$cadenalis."<td align='center'><img src='../../img/b_drop.png' width='17' height='17' border='0' ></td>";
				}
			}else{
			$cadenalis=$cadenalis."<td align='center'><img src='../../img/b_drop.png' width='17' height='17' border='0' ></td>";
			}

			//vacaciones ejecutadas
			$Obj_ve = new Vacaciones();
			$res_ve = array();
			$res_ve=$Obj_ve->aks_vacaciones($conex,$codigo,$per,1);
			if(count($res_ve)>0){
				if($res_ve[0]['suma']==$res_ve[0]['numdias']){
						$cadenalis=$cadenalis."<td align='center'><img src='../../img/b_check.png' border='0'></td>";
						$vacaprog=1;
				}else{
					$cadenalis=$cadenalis."<td align='center'><img src='../../img/b_drop.png' border='0'></td>";
				}
			}else{
			$cadenalis=$cadenalis."<td align='center'><img src='../../img/b_drop.png' border='0'></td>";
	 		}

			if($vacaprog==1){
				$cadenalis=$cadenalis."<td align='center'><input type='hidden' id='vacdet".$p."' value='".$codigo."'><img src='../../img/b_green.png' width='17' height='17' border='0' ></td>";
			}else{
				$cadenalis=$cadenalis."<td align='center'><input type='hidden' id='vacdet".$p."' value='".$codigo."'><img src='../../img/b_red.png' width='17' height='17' border='0' ></td>";
		  }

			$cadenalis=$cadenalis."<td align='center'><input type='hidden' id='vacdet".$p."' value='".$codigo."'><a href='#' onClick='ver_detallevaca($p);'><img src='../../img/b_ver.png' width='17' height='17' border='0' ><a/></td>";
	}
	$sumap=count($res_bp);
	$cadenalis=$cadenalis."<tr><td colspan='11' align='center'>El numero de Personal es ".$sumap."</td></tr>";
?>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<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 agregarpersonal(){
	var idj = document.getElementById("depa").value;
	var ids = document.getElementById("serv").value;
    var ugid = document.getElementById("ugid").value;
   window.open("adminpersonal.php?idj="+idj+"&ids="+ids+"&ugid="+ugid,"","height=400,width=600,scrollbars=NO");
}
function verdetallevacaprog(a){
	var codigo = document.getElementById("codper"+a).value;
	var idj = document.getElementById("depa").value;
	var ids = document.getElementById("serv").value;
    var ugid = document.getElementById("ugid").value;
   window.open("verdetvacacionesprog.php?ugid="+ugid+"&idj="+idj+"&ids="+ids+"&codigo="+codigo,"","height=400,width=600,scrollbars=NO");
}

function datospersonal(a){
	var codigo = document.getElementById("codper"+a).value;
	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 askprogramacion(a){
	var codigo = document.getElementById("codper"+a).value;
	var idj = document.getElementById("depa").value;
	var ids = document.getElementById("serv").value;
	window.open("consultaprog.php?ugid="+codigo+"&idj="+idj+"&ids="+ids,"","height=310,width=390,scrollbars=NO");
}
function verdetallecap(a){
  var codigo = document.getElementById("codper"+a).value;
	window.open("detallecap.php?ugid="+codigo,"","height=450,width=900,scrollbars=NO");
}

//function verdescansomedico(codigo){
    //var codigox = codigo;
    //alert(codigox);
	//var codigo = document.getElementById("codper"+a).value;
	//window.open("verdmedicoprog.php?ugid="+codigo,"","height=200,width=200,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 retornarmenu(){
		var ugid = document.getElementById("ugid").value;
		var idj = document.getElementById("depa").value;
		document.location= "../listarvacaciones.php?ugid="+ugid+"&idj="+idj;
}
</script>
</head>
<body id="lista" name="lista" onload="listarpersonal(1)">
<?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."'>";
?>
<br>
<table align='center'>
<tr><td>

<fieldset>
	<legend align='left'><font color='blue'>Listado del Personal Asistencial</font></legend>
	<br>
	<table align='center' >
	<tr><td align='left'>DIDAE / DPTO</td>
	<td height='30'><div id='divtp'><?php echo $cbjef;?></div></td>
			<td rowspan='4' width='50'><img src='../../img/btn_regresar.png' width='70' height='60' onClick='retornarmenu()' alt='Regresar al Menu Principal'></td></tr>
	<tr><td align='left' height='30'>Servicio</td>
		<td><div id='divserv'><?php echo $cbserv;?></div></td></tr>
	<tr><td align='left' height='30'>Tipo de Personal</td>
		<td><?php echo $cbtipoper;?></td></tr>
	<tr><td align='left'>Tipo de Contrato</td>
	<td><?php echo $cbtc;?></td><td><img src='../../img/icoexcel.png' width='27' height='27' onClick='' alt='Exportar al Excel'></td></tr>
	<tr><td align='left' height='30'>Periodo</td>
		<td><?php echo $cbper;?></td></tr>
	<tr><td align='left'>Busqueda por Apellido </td><td><input type='text' size='40' id='txtnombre' onKeyPress='listarpersonal(2)'></td></tr>
	</table>
	<br>
	<div id='admlista'>

	<!--table align='center' class='FacetFormTABLE'>
	<tr><td colspan='11'class='FacetFieldCaptionTDT' align='center'> PERSONAL ASISTENCIAL </td></tr>
	<tr>
		<td class='FacetFieldCaptionTD' align='center' width='250'>APELLIDOS Y NOMBRES</td>
		<td class='FacetFieldCaptionTD' align='center' width='100'>SERVICIO</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' width='70'>PERIODO</td>
		<td class='FacetFieldCaptionTD' align='center'>VAC. PROG</td>
		<td class='FacetFieldCaptionTD' align='center'>VAC. EJE</td>
		<td class='FacetFieldCaptionTD' align='center'>ESTADO</td>
		<td class='FacetFieldCaptionTD' align='center'>VER DET.</td>
	</tr>

	<?php //echo $cadenalis; echo $muestra;?>

</table-->
	</div>
	<br>
</fieldset>
</td></tr>
</table>
</body>
</html>
