<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>CUENTAS HORAS DEL PERSONAL</title>
<link rel="stylesheet" type="text/css" href="../styles/Style.css">
<script language="JavaScript" type="text/javascript" src="ajax.js"></script>
<script type="text/javascript"> 
//ver programacion
function verprog(ugid){
var mes = document.getElementById("mes").value;
var anno= document.getElementById("anno").value;
var idj= document.getElementById("idj").value;
var ids= document.getElementById("ids").value;
window.open("../verdetallerepro.php?ugid="+ugid+"&anno="+anno+"&mes="+mes+"&idjp="+idj+"&idsp="+ids,"","height=500,width=1250,scrollbars=YES");
}
</script>
</head>
<body>
<?php

//if(isset($_GET['idj']) && isset($_GET['ids']) && isset($_GET['idtp']) && isset($_GET['anno'])  && isset($_GET['mes'])){
$idj = $_GET['idj'];
$ids = $_GET['ids'];
//$idtp = $_GET['idtp'];
$anno = $_GET['anno'];
$mm = $_GET['mes'];
//}


//$idj = 1;
//$ids = 2;
//$idtp = 1;
//$anno = 2011;
//$mm = 1;

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


echo "<input type='hidden' id='idj' value='".$idj."'>";
echo "<input type='hidden' id='ids' value='".$ids."'>";
echo "<input type='hidden' id='mes' value='".$mm."'>";
echo "<input type='hidden' id='anno' value='".$anno."'>";


//combo tipo de personal
$sqltpersonal = "select a.tp_id as cod, (select tp_desc from tb_tipoperson where tp_id=a.tp_id) as descripcion from tb_areatipopersona a where a.j_id='$idj' and a.s_id='$ids'";
//echo $sqltpersonal;
$resulttpersonal = mysql_query($sqltpersonal);
//$cadenatp="<select id='tipopersonal' name='tipopersonal'>";
$a=0;
$idtp="";
$cadenatp = "<select id='progtp' onchange='buscalistapersonal()'>";
while ($rowtp= mysql_fetch_array($resulttpersonal)){
$cadenatp=$cadenatp."<option value='".$rowtp['cod']."'";
if($a==0){
$cadenatp=$cadenatp." selected ";
$a=1;
$idtp=$rowtp['cod'];
}
$cadenatp=$cadenatp." >".$rowtp['descripcion']."</option>";
}
$cadenatp=$cadenatp."</select>";



//armando grupo de servicios y sus dependencias
$sqldepa="select j_id as codj, 0 as cods ,j_abrev as nom from tb_jefatura where j_id='$idj'";
$sqlserv="select j_id as codj, s_id as cods, s_abrev as nom from tb_servicio where j_id='$idj'";
$resultdepa = mysql_query($sqldepa);
$resultserv = mysql_query($sqlserv);
$a=0;
$cad="";
//$cad = $cad."<tr>";
$serv[] = array();
$nomserv[] = array();
//echo $sqlserv;
while ($rows= mysql_fetch_array($resultserv)){
$a=$a+1;
$serv[$a]=$rows['cods'];
$nomserv[$a]=$rows['nom'];
}
while ($rowj= mysql_fetch_array($resultdepa)){
$a=$a+1;
$serv[$a]=$rowj['cods'];
$nomserv[$a]=$rowj['nom'];
}

$cdhrs ="<td class='facetfilaTD'>GD</td><td class='facetfilaTD'>GN</td><td class='facetfilaTD'>HO</td><td class='facetfilaTD'>HE</td>";

$ncadena = 4*(count($serv)-1);
$ntotal = $ncadena + 11;
$cadena1 = $cadena1."<table align='center'><tr><td class='facetfilaTD'>Selecionar el tipo de Personal</td></tr>";
$cadena1 = $cadena1."<tr><td class ='FacetDataTextC'>".$cadenatp."</td></tr></table><br>";
echo $cadena1;

?>
<div id='listapersonal'>
<?php

$cadena1 = "<table align='center'><tr><td colspan='$ntotal' align='center' class='LlenarTablaGarea'>LISTADO DEL PERSONAL PROGRAMADO</td></tr>";
$cadena1 = $cadena1."<tr><td width='50' class='facetfilaTD' rowspan='2'>CODIGO</td><td width='300' class='facetfilaTD' rowspan='2' align='center'>NOMBRE DEL PERSONAL</td><td class='facetfilaTD' align='center' colspan='4'  >TOTALES</td><td class='facetfilaTD' align='center' rowspan='2'>HRS A <br>PROGRAMAR<br> X MES</td><td class='facetfilaTD' align='center' colspan='4' rowspan='2'>PROG<BR>INDIVIDUAL</td></tr>";
$cadena1 = $cadena1.$cdhrs;

//pregunta por el personal
$sqlper1="select a.ug_id as cod, b.ut_codprog as codigo, CONCAT(a.ua_apepat,' ',a.ua_apemat,' ',a.ua_nom) as nombre, ";
$sqlper1= $sqlper1." b.ut_idserva as idsa from tb_usutrab b  inner join tb_usuasist a on a.ug_id= b.ug_id where b.j_id='$idj'";
$sqlper1= $sqlper1." and b.tp_id='$idtp' and b.ut_idserva='$ids' and b.uap_anno='$anno' and b.uap_mes ='$mm' order by nombre";
//Echo $sqlper1."<br>";
//horas por los servicios
//$cadena1 = $cadena1."<tr></tr>";

//$cadena1 = $cadena1.$cdhrs."</tr>";

$resultper = mysql_query($sqlper1);
while ($rowp= mysql_fetch_array($resultper)){
$ugid = $rowp['cod'];
$codprog = $rowp['codigo'];
$nombre = $rowp['nombre'];
$registro=$registro."<tr><td align='center' width='50' class ='FacetDataTextC'>".$codprog."</td><td width='300' class ='FacetDataTextC'>".$nombre."</td>";


//total de horas
$sqltotalhrs="select sum(chr_numgd) as tgd, sum(chr_numgn) as tgn, sum(chr_numho) as tho, sum(chr_numhe) as the from tb_consolhreprog where ug_id='$ugid' and uap_anno='$anno' and uap_mes='$mm' and tp_id='$idtp'";
$resultthrs = mysql_query($sqltotalhrs);
//echo $sqltotalhrs."<br>";
	if(mysql_num_rows($resultthrs)==0){
			$registro=$registro."<td class ='FacetDataTextC'>0</td><td class ='FacetDataTextC'>0</td><td class ='FacetDataTextC'>0</td><td class ='FacetDataTextC'>0</td>";
			echo 0;
	}else{
		while ($rowth= mysql_fetch_array($resultthrs)){
		
		$tgd = $rowth['tgd'];
		$tgn = $rowth['tgn'];
		$tho = $rowth['tho'];
		$the = $rowth['the'];
	
		$registro=$registro."<td align='center' class ='FacetDataTextC'>".$tgd."</td><td align='center' class ='FacetDataTextC'>".$tgn."</td><td align='center' class ='FacetDataTextC'>".$tho."</td><td align='center' class ='FacetDataTextC'>".$the."</td>";
	}}


//cantidad de horas programadas por mes
$sqltotalhrs="select b.tc_hrsprog as hora from tb_usuasist a inner join tb_tipocont b on a.tc_idcont = b.tc_idcont where a.ug_id='$ugid'";
$resulttproghrs = mysql_query($sqltotalhrs);
while ($rowtph= mysql_fetch_array($resulttproghrs)){
		$thrs = $rowtph['hora'];
			
		$registro=$registro."<td align='center' class ='FacetDataTextC'>".$thrs."</td><td align='center' class='FacetDataTextC'><img src='../img/ver.jpg' width='17' height='17' value='$ugid' onClick=verprog(this.value);></td></tr>";
	}

}
ECHO $cadena1.$registro;
?>
</div>
</body>
</html>