<?php

$idj = $_GET['idj'];
$ids = $_GET['ids'];
$idtp = $_GET['idtp'];
$anno = $_GET['anno'];
$mm = $_GET['mes'];

//Echo $idj."-".$ids."-".$idtp."-".$anno."-".$mm."<br>";

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");

//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 = "<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' class ='FacetDataTextC'>".$codprog."</td><td 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;

?>