<?php
require('fpdf/fpdf.php');

date_default_timezone_set('UTC');
//$idj=1;
//$ids=2;
//$ids=1;
//$idtp=1;
$anno=$_GET['anno'];
$mm=$_GET['mes'];
$ugid=$_GET['ugid'];

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

$datos ="SELECT a.ug_id as ugid, a.ua_apepat, a.ua_apemat, a.ua_nom, b.tp_id as idtp, b.s_id as ids, b.j_id as idj  FROM tb_usuasist a inner join tb_usudep b on a.ug_id=b.ug_id where a.ug_id='$ugid'";
$resultdatos = mysql_query($datos);
while ($rowd= mysql_fetch_array($resultdatos)){
$idj=$rowd['idj'];
$ids=$rowd['ids'];
$idtp=$rowd['idtp'];
}

//armando grupo de servicios y sus dependencias
$sqldepa="select j_id as codj, 0 as cods ,j_abrev as nom, j_desc as nomc from tb_jefatura where j_id='$idj'";
$sqlserv="select j_id as codj, s_id as cods, s_abrev as nom, s_desc as nomc from tb_servicio where j_id='$idj'";
$resultdepa = mysql_query($sqldepa);
$resultserv = mysql_query($sqlserv);
$a=0;
$cad="";
$serv[] = array();
$nomserv[] = array();
while ($rows= mysql_fetch_array($resultserv)){
$cad = $cad."<td width='10' class='facetfilaTD' colspan='4' align='center' >".$rows['nom']."</td>";
$a=$a+1;
$serv[$a]=$rows['cods'];
$nomserv[$a]=$rows['nomc'];
}
while ($rowj= mysql_fetch_array($resultdepa)){
$cad = $cad."<td width='10' class='facetfilaTD' colspan='4'  align='center' >".$rowj['nom']."</td>";
$a=$a+1;
$serv[$a]=$rowj['cods'];
$nomserv[$a]=$rowj['nomc'];
}

//datos del personal
$sqlper="select a.ug_id as codigo, CONCAT(a.ua_apepat,' ',a.ua_apemat,' ',a.ua_nom) as nombre, a.ua_dni as dni,  ";
$sqlper= $sqlper." (select j_desc from tb_jefatura where j_id=b.j_id) as jefatura, (select s_desc from tb_servicio where s_id=b.s_id and j_id=b.j_id) as servicio,";
$sqlper= $sqlper." (select c_desc from tb_cargo where c_id=a.c_id) as cargo, (select esp_desc from tb_especialidad where ua_idespec=a.ua_idespec) as especialidad,";
$sqlper= $sqlper." a.ua_numplanilla as planilla, a.ua_numesp as numespecialidad from tb_usuasist a inner join tb_usudep b on a.ug_id=b.ug_id where a.ug_id='$ugid'";
$resultper = mysql_query($sqlper);
while ($row= mysql_fetch_array($resultper)){
$codigo = $row['codigo'];
$nombre = $row['nombre'];
$jefatura = $row['jefatura'];
$servicio = $row['servicio'];
$cargo = $row['cargo'];
$dni = $row['dni'];
$especialidad = $row['especialidad'];
$numplanilla = $row['planilla'];
$numespecilidad = $row['numespecilidad'];
}

//$idhora=$_GET['idhora'];
$mes = mktime( 0, 0, 0, $mm, 1, $anno ); 
$numeroDeDias = intval(date("t",$mes)); 


$arraymes = array();
$arraymes[] = array('idmes'=>'1','mes'=>'ENERO');
$arraymes[] = array('idmes'=>'2','mes'=>'FEBRERO');
$arraymes[] = array('idmes'=>'3','mes'=>'MARZO');
$arraymes[] = array('idmes'=>'4','mes'=>'ABRIL');
$arraymes[] = array('idmes'=>'5','mes'=>'MAYO');
$arraymes[] = array('idmes'=>'6','mes'=>'JUNIO');
$arraymes[] = array('idmes'=>'7','mes'=>'JULIO');
$arraymes[] = array('idmes'=>'8','mes'=>'AGOSTO');
$arraymes[] = array('idmes'=>'9','mes'=>'SETIEMBRE');
$arraymes[] = array('idmes'=>'10','mes'=>'OCTUBRE');
$arraymes[] = array('idmes'=>'11','mes'=>'NOVIEMBRE');
$arraymes[] = array('idmes'=>'12','mes'=>'DICIEMBRE');

//analizando los espacios
$diasresta = $numeroDeDias-27;
$diasrestantes = $diasresta + 1;
$diascabecera = $diasresta + 16;
$cabeceramayor = $diascabecera + 16;


//parte 1 del cuerpo
$data = array();
$data[] = array('area'=>'UCI','hi'=>'7:00','hf'=>'13:00','nh'=>'6','tipo'=>'M');




$dato1cab = array();
//$dato1cab[] = array('RED ASISTENCIAL','dra'=>'INSTITUTO NACIONAL CARDIOVASCULAR','ca'=>'CENTRO ASISTENCIAL','rca'=>'INSTITUTO NACIONAL CARDIOVASCULAR');
//$dato1cab[] = array('ra'=>'AREA','dra'=>'AREA CLINICA QUIRURGICA','ca'=>'SERVICIO','rca'=>'HOSPITALIZACION UCI Y UCIN');

$dato1cab[] = array('RED ASISTENCIAL','INSTITUTO NACIONAL CARDIOVASCULAR','CENTRO ASISTENCIAL','INSTITUTO NACIONAL CARDIOVASCULAR');
$dato1cab[] = array('AREA / DPTO',$jefatura,'SERVICIO',$servicio);
$dato2cab[] = array('ESPECIALIDAD',$especialidad,'CARGO',$cargo,'NRO COLEGIATURA',$numcolegiatura);
$dato3cab[] = array('APELLIDOS Y NOMBRES',$nombre,'NRO DNI',$dni,'NRO ESPECIALIDAD',$numespecialidad);
$dato4cab[] = array('MES QUE INICIA',$arraymes[$mm-1]['mes']);
$dato5cab[] = array('TOTAL DE HORAS');
$dato6cab[] = array('AREAS / ACTIVIDADES','TURNO','N. HRS');

//titulos
$cabeceraho = 'HORAS ORDINARIAS';
$cabecerahe = 'HORAS EXTRAS';
$cabecerahoa = 'HORAS ORDINARIAS DE APOYO';
$cabecerahea = 'HORAS EXTRAS DE APOYO';
//parte 2 del cuerpo
$data2 = array(); 
$dj=1;
for ($i=1;$i<=$numeroDeDias;$i++){
$dj = $i-1;
$dia= date("w",mktime( 0, 0, 0, $mm, $i, $anno )); 
switch ($dia) {
    case 0:
        $data2[$dj]= 6;
        break;
    case 1:
    case 2:
    case 3:
    case 4:
    case 5:
    case 6:
        $data2[$dj]= '';
        break;
}
}




$header = array('AREA','HORARIO','TURNO','NH');

$header2 = array(); 
$j = 1;
for ($i=1;$i<=$numeroDeDias;$i++){
$j = $i-1;
$dia= date("w",mktime( 0, 0, 0, $mm, $i, $anno )); 
switch ($dia) {
    case 0:
        $header2[$j]= 'DOM';
		break;
    case 1:
        $header2[$j]= 'LUN';
        break;
    case 2:
        $header2[$j]= 'MAR';
        break;
	case 3:
        $header2[$j]= 'MIE';
        break;
	case 4:
        $header2[$j]= 'JUE';
        break;
	case 5:
        $header2[$j]= 'VIE';
        break;
	case 6:
        $header2[$j]= 'SAB';
        break;
}
}

$header3 = array(); 
$pinta = array();
$pintap = array();
$pintast = array();
$pintat = array();
$ancho= array();
$alinea= array();
$j=1;
$suma= 0;
for ($i=1;$i<=$numeroDeDias;$i++){
$j = $i-1;
$dia= date("w",mktime( 0, 0, 0, $mm, $i, $anno )); 
switch ($dia) {
    case 0:
		//dias domingos
        $header3[$j]= $i;
		$pinta[$j]= array(254,249,152);
		$pintap[$j]= array(254,259,152);
		$pintast[$j]= array(254,259,152);
		$pintat[$j]= array(254,259,152);
		$ancho[$j]= 5.5;
		$suma = $suma + 5.5;
		$alinea[$j]= 'C';
        break;
    case 1:
    case 2:
    case 3:
    case 4:
    case 5:
    case 6:
        $header3[$j]= $i;
		$pinta[$j]= array(196,251,252);
		$pintap[$j]= array(255,255,255);
		$pintast[$j]= array(228,254,255);
		$pintat[$j]= array(255,238,254);
		$ancho[$j]= 5.5;
		$suma = $suma + 5.5;
		$alinea[$j]= 'C';
        break;
}
}
///17 longitudes del dia
$sumat = $suma + (15*5.5);


class PDF extends FPDF
{


//function FancyTable($cabeza,$data,$y)
function colordia()
{
    //Colores, ancho de línea y fuente en negrita
    $this->SetFillColor(255,0,0);
    $this->SetTextColor(255);
    $this->SetDrawColor(128,0,0);
    $this->SetLineWidth(.3);
    $this->SetFont('','B');
}	


function ImprimirTabla($data,$x, $y, $h, $w,$alig)
{
    $this->SetFillColor(224,200,255);
    $this->SetTextColor(0);
    $this->SetDrawColor(128,0,0);
    $this->SetLineWidth(.3);
    $this->SetFont('','B');
	$this->SetXY($x,$y);
    //Datos
	$dib=false;
   	for($i=0;$i<count($data);$i++)
    {
	for($j=0;$j<count($w);$j++)
		{
        $this->Cell($w[$j],$h,$data[$i][$j],1,0,$alig[$j],$dib);
		$dib = !$dib;
        }
		$y = $y + $h;
		$this->SetXY($x,$y);
		
    }

}

function ImprimirTablaTitulo($data,$x, $y, $h, $w,$alig,$dib)
{
    $this->SetFillColor(224,200,255);
    $this->SetTextColor(0);
    $this->SetDrawColor(128,0,0);
    $this->SetLineWidth(.3);
    $this->SetFont('','B');
	$this->SetXY($x,$y);
    //Datos
	  	
	
        $this->Cell($w,$h,$data,1,0,$alig,$dib);
		//$dib = !$dib;
    
		//$this->SetXY($x,$y);
		
    
}

function ImprimirTablaSinColor($data,$x, $y, $h, $w,$alig)
{
    $this->SetFillColor(224,200,255);
    $this->SetTextColor(0);
    $this->SetDrawColor(128,0,0);
    $this->SetLineWidth(.3);
    $this->SetFont('','B');
	$this->SetXY($x,$y);
    //Datos
	$dib=false;
   	for($i=0;$i<count($data);$i++)
    {
	for($j=0;$j<count($w);$j++)
		{
        $this->Cell($w[$j],$h,$data[$i][$j],1,0,$alig[$j],$dib);
		//$dib = !$dib;
        }
		$y = $y + $h;
		$this->SetXY($x,$y);
		
    }

}

function ImprimirTablaSinColorLineal($data,$x, $y, $h, $w,$alig)
{
    $this->SetFillColor(224,200,255);
    $this->SetTextColor(0);
    $this->SetDrawColor(128,0,0);
    $this->SetLineWidth(.3);
    $this->SetFont('','B');
	$this->SetXY($x,$y);
    //Datos
	$dib=false;
   	for($i=0;$i<count($data);$i++)
    {
	        $this->Cell($w[$i],$h,$data[$i],1,0,$alig[$i],$dib);
		//$dib = !$dib;
    }
		//$y = $y + $h;
		//$this->SetXY($x,$y);
		
    //}

}

function ImprimirTablaSinColorFirma($data,$x, $y, $h, $w,$alig,$dibuja)
{
    $this->SetFillColor(224,200,255);
    $this->SetTextColor(0);
    $this->SetDrawColor(128,0,0);
    $this->SetLineWidth(.3);
    $this->SetFont('','B');
	$this->SetXY($x,$y);
    //Datos
	$dib=false;
   	for($i=0;$i<count($data);$i++)
    {
	        $this->Cell($w[$i],$h,$data[$i],$dibuja[$i],0,$alig[$i],$dib);
		//$dib = !$dib;
    }
		//$y = $y + $h;
		//$this->SetXY($x,$y);
		
    //}

}

function ImprimirTablaHorario($data,$x, $y, $h, $w,$alig)
{
    $this->SetFillColor(224,200,255);
    $this->SetTextColor(0);
    $this->SetDrawColor(128,0,0);
    $this->SetLineWidth(.3);
    $this->SetFont('','B');
	$this->SetXY($x,$y);
    //Datos
	$dib=false;
   		for($j=0;$j<count($w);$j++)
		{
        $this->Cell($w[$j],$h,$data[$j],1,0,$alig,$dib);
		//$dib = !$dib;
		$x = $x + $w[$j];
		$this->SetXY($x,$y);
        }
		
		
    

}

function ImprimirTablaJustificada($data,$x, $y, $h, $w,$alig,$d)
{
    $this->SetFillColor(224,200,255);
    $this->SetTextColor(0);
    $this->SetDrawColor(128,0,0);
    $this->SetLineWidth(.3);
    $this->SetFont('','B');
	$this->SetXY($x,$y);
    //Datos
	$dib=false;
	$h=$h/$d;
   	for($i=0;$i<count($data);$i++)
    {
	for($j=0;$j<count($w);$j++)
		{
		$this->MultiCell($w[$j],$h,$data[$i][$j],1,$alig[$j],$dib);
		$dib = !$dib;
        }
		$y = $y + $h;
		$this->SetXY($x,$y);
		
    }

}

function ImprimirTablaArea($data,$x, $y, $h, $w,$alig,$d,$horario)
{
    $this->SetFillColor(224,200,255);
    $this->SetTextColor(0);
    $this->SetDrawColor(128,0,0);
    $this->SetLineWidth(.3);
    $this->SetFont('','B');
	$this->SetXY($x,$y);
    //Datos
	$dib=false;
	//$h=($h/$d)*$horario;
	//$h = $h*$horario;
		$this->Cell($w,$h,$data,1,0,$alig,$dib);
		//$this->MultiCell($w,$h,$data,1,$alig,$dib);
		//$dib = !$dib;
        //$y = $y + $h;
		//$this->SetXY($x,$y);

}

function ImprimirDias($data,$x, $y, $h, $w,$alig,$pint)
{
    
    $this->SetTextColor(42,20,172);
    $this->SetDrawColor(128,0,0);
    $this->SetLineWidth(.3);
    $this->SetFont('','B');
	$this->SetXY($x,$y);
    //Datos
   	for($i=0;$i<count($data);$i++)
    {
	$this->SetFillColor($pint[$i][0],$pint[$i][1],$pint[$i][2]);
	
        $this->Cell($w[$i],$h,$data[$i],1,0,$alig[$i],true);
        //$y = $y + $h;
	}

}

function ImprimirDiasHoras($data,$x, $y, $h, $w,$alig,$pint)
{
    
    $this->SetTextColor(42,20,172);
    $this->SetDrawColor(128,0,0);
    $this->SetLineWidth(.3);
    $this->SetFont('','B');
	$this->SetXY($x,$y);
    //Datos
   	for($i=0;$i<count($data);$i++)
    {
	$this->SetFillColor($pint[$i][0],$pint[$i][1],$pint[$i][2]);
	
        $this->Cell($w[$i],$h,$data[$i],1,0,$alig[$i],true);
        //$x = $x + $w[$i];
		//$this->SetXY($x,$y);
	}

}

}

$texto="FORMATO UNICO DE LA PROGRAMACION DEL PERSONAL - ESSALUD";

//print_r($header2);

$alturaX = 25;
$ha = 3.7;

$pdf=new PDF();
$pdf->FPDF('L');
$pdf->AddPage();
$pdf->SetFont('Helvetica','B',12);
$pdf->Image('../img/logoincor.jpg', 10, 10, 45, 16,'jpg');
$pdf->Image('../img/logoessalud.jpg', 243, 12, 40, 11,'jpg');
$pdf->Text(75,$alturaX,$texto);
$alturaX = $alturaX+$ha;
//$pdf->Text(55,30,$arraymes[$mm]['idmes']);
$pdf->SetFont('Arial','',6);

$posicionx = $sumat*0.12 + $sumat*0.1655 + 25;
$posicionx2 = ($sumat - ($posicionx + $suma)) - 14.75;
//altura


//creando cabecera 1
$a = 0.20*$suma;
$b= 0.30*$suma;
$c= 0.20*$suma;
$d = $suma - ($a+$b+$c);
$w = array($a,$b,$c,$d);
$alig = array('L','C','L','C');
//imprimir (datos, posc x, posc y, altura, ancho, alineacion)

$s = $sumat*0.2;
$x= $sumat*0.3;
$y= $sumat*0.2;
$z= $sumat*0.3;

$w1 = array($sumat*0.12,$sumat*0.32,$sumat*0.12,$sumat*0.44);
$w2 = array($sumat*0.12,$sumat*0.32,$sumat*0.12,$sumat*0.22,$sumat*0.10,$sumat*0.12);
$w3 = array($sumat*0.12,$sumat*0.44,$sumat*0.10,$sumat*0.12,$sumat*0.10,$sumat*0.12);
$w4 = array($sumat*0.12,$sumat*0.1655);
$wancho = $sumat - ($sumat*0.12 + $sumat*0.165 + $suma);
$w5 = array($wancho);
$posicionx = $sumat*0.12 + $sumat*0.1655 + 25;
$valorxx = $posicionx + $suma;
$posicionx2 = $valorxx;
//$posicionx2 = ($sumat - ($posicionx + $suma)) - 14.75;
$alig6 = array('L','C','C');
$w6 = array($sumat*0.12,$sumat*0.12, $sumat*0.0455);

$alturaX = $alturaX + $ha - 3.5;
$pdf->ImprimirTabla($dato1cab,25,$alturaX,$ha,$w1, $alig);
$alturaX = $alturaX + $ha + $ha;
$pdf->ImprimirTabla($dato2cab,25,$alturaX,$ha,$w2, $alig);
$alturaX = $alturaX + $ha;
$pdf->ImprimirTabla($dato3cab,25,$alturaX,$ha,$w3, $alig);
$alturaX = $alturaX + $ha;
$pdf->ImprimirTabla($dato4cab,25,$alturaX,$ha,$w4, $alig);
$pdf->SetFont('Arial','',4.5);
$pdf->ImprimirTablaJustificada($dato5cab,$posicionx2,$alturaX,3*$ha,$w5,'C',3);
$pdf->SetFont('Arial','',6);
$alturaX = $alturaX + $ha;
$pdf->ImprimirTablaSinColor($dato6cab,25,$alturaX,$ha,$w6, $alig6);
$alturaX = $alturaX - $ha;
$pdf->SetFont('Arial','',5.5);
$pdf->ImprimirDias($header2,$posicionx,$alturaX,$ha,$ancho,$alinea,$pinta);
$alturaX = $alturaX + $ha;
$pdf->ImprimirDias($header3,$posicionx,$alturaX,$ha,$ancho,$alinea,$pinta);
$alturaX = $alturaX + $ha;
$pdf->SetFont('Arial','',6);
$aw= $sumat*0.12 + $sumat*0.32 + $sumat*0.12 + $sumat*0.44;
$pdf->ImprimirTablaTitulo($cabeceraho,25,$alturaX,$ha,$aw,'L',true);

//$alturaX = 50;
/////////////////////////////////////
$sqlgarea="select distinct(a.ga_id) as idga, (select ga_desc from tb_garea where ga_id=a.ga_id) as garea from tb_horaeje a where a.tp_id='$idtp' and a.uap_anno='$anno' and a.uap_mes='$mm' and a.j_id='$idj' and a.s_id='$ids' and a.he_idserva='$ids' and a.ug_id='$ugid' and a.he_tipohora='0' order by idga asc";
//$pdf->Text(10,90,$sqlgarea);
$alturaX = $alturaX + $ha;
			$resultga = mysql_query($sqlgarea);
			if(mysql_num_rows($resultga)!=0){
			while ($rowga= mysql_fetch_array($resultga)){
			$idga= $rowga['idga'];
			$pdf->ImprimirTablaTitulo($rowga['garea'],25,$alturaX,$ha,$aw,'L',false);
			//pregunta por las areas
						$alturaX = $alturaX + $ha;
						$sqlarea ="select distinct(a_id) as ida from tb_horaeje where ga_id='$idga' and tp_id='$idtp' and uap_anno='$anno' and uap_mes='$mm' and j_id='$idj' and he_idserva='$ids' and s_id='$ids' and ug_id='$ugid' and he_tipohora='0' order by a_id";
						$resulta = mysql_query($sqlarea);
						if(mysql_num_rows($resulta)!=0){
						while ($row= mysql_fetch_array($resulta)){
						$ida=$row['ida'];
						$sqlcantturno = "select a.a_id as codarea, (select a_desc from tb_area where a_id=a.a_id and ga_id=a.ga_id) as area, count(distinct(a.h_id)) as idhora from tb_horaeje a where a.j_id='$idj' and a.s_id='$ids' and a.uap_anno='$anno' and a.uap_mes='$mm' and a.tp_id='$idtp' and a.a_id='$ida' and a.ug_id='$ugid' and a.ga_id='$idga' and a.he_tipohora='0' group by a.a_id";
						$resultcantturno = mysql_query($sqlcantturno);
						while ($rownt= mysql_fetch_array($resultcantturno)){
						$area= $rownt['area'];
						$cantreg = $rownt['idhora'];
						$hp = $ha*$cantreg;
						$wa = $sumat*0.12;
						$pdf->ImprimirTablaArea($area,25,$alturaX,$hp,$wa,'C',2,$cantreg);
						
						//
					//pregunta por los horarios
						$sqlhora="select distinct(a.h_id) as idhora, b.h_horaturn as horaturn, (select o_idturn from tb_ordena where o_turn=b.h_horaturn) as tt from tb_horaeje a inner join tb_horario b on a.h_id = b.h_id where a.j_id='$idj' and a.s_id='$ids' and a.uap_anno='$anno' and a.uap_mes='$mm' and a.tp_id='$idtp' and a.a_id='$ida' and a.ga_id='$idga' and a.ug_id='$ugid' and a.he_tipohora='0' order by tt";
						$resulthora=mysql_query($sqlhora);
						//echo $sqlhora."<br><br>";
						$alturaXH = $alturaX;
						$alturaXT = $alturaX;
						while ($rowh= mysql_fetch_array($resulthora)){
						$idh=$rowh['idhora'];
						//pregunta por el turno
						$sqlturno = "select h_id, concat(date_format(h_horaini,'%k:%i %p'),' - ',date_format(h_horafin,'%k:%i %p')) as hora, h_horaturn as turno, h_horanum as numhora from tb_horario where h_id='$idh'";
						$resultturno = mysql_query($sqlturno);
						//echo $sqlturno."<br><br>";
						
						while ($rowtt= mysql_fetch_array($resultturno)){
						$horario = array($rowtt['hora'], $rowtt['turno'],$rowtt['numhora']);
						$wh= array($sumat*0.095, $sumat*0.025, $sumat*0.0455);
						$pdf->ImprimirTablaHorario($horario,25+$wa,$alturaXH ,$ha,$wh,'C');	
						$alturaXH = $alturaXH + $ha;					
						}
						
						$diaprog = array();	
						for ($j=1;$j<=$numeroDeDias;$j++){
						$sqlconsultaturno="select (select h_horanum from tb_horario where h_id=a.h_id) as hora  from tb_horaeje a where a.j_id='$idj' and a.s_id='$ids' and a.uap_mes='$mm' and a.uap_anno='$anno' and a.he_dia='$j' and a.h_id='$idh' and a.a_id='$ida' and a.ga_id='$idga' and a.tp_id='$idtp' and a.he_idserva='$ids' and a.he_tipohora=0 and a.ug_id='$ugid'";
						
						$resultcontur = mysql_query($sqlconsultaturno);
						$dia= date("w",mktime( 0, 0, 0, $mm, $j, $anno )); 
						if(mysql_num_rows($resultcontur)==0){
						switch ($dia) {
						    case 0: $diaprog[$j-1]=" "; break;
						    case 1: 
						    case 2:
						    case 3:
						    case 4:
						    case 5:
						    case 6:
						        $diaprog[$j-1]=" "; break;
						}

						}else{
						while($rowt= mysql_fetch_array($resultcontur)){
						$hrord = $rowt['hora'];
							switch ($dia) {
						    case 0: $diaprog[$j-1]=$hrord; break;
						    case 1: 
						    case 2:
						    case 3:
						    case 4:
						    case 5:
						    case 6:
						        $diaprog[$j-1]=$hrord;; break;
						}}
						}
																	
						}
						$pdf->ImprimirDiasHoras($diaprog,$posicionx,$alturaXT,$ha,$ancho,$alinea,$pintap);
						
													
						
								//horas por turno
								$askhrsturno = "select sum(b.h_horanum) as sumhrs from tb_horaeje a inner join tb_horario b on a.h_id=b.h_id where a.j_id='$idj' and a.s_id='$ids' and a.uap_mes='$mm' and a.uap_anno='$anno' and a.h_id='$idh' and a.a_id='$ida' and a.ga_id='$idga' and a.tp_id='$idtp' and a.he_idserva='$ids' and a.he_tipohora=0 and a.ug_id='$ugid' group by a.h_id";
								$resultaskhrst = mysql_query($askhrsturno);
								$wst= $sumat - ($sumat*0.12 + $sumat*0.165 + $suma);
								if(mysql_num_rows($resultaskhrst)==0){
									$pdf->ImprimirTablaArea(0,$posicionx, $alturaX, $ha, $wst,'C',2,1);
								}else{
									while($rowht= mysql_fetch_array($resultaskhrst)){
									$totalhorasturno = $rowht['sumhrs'];
									$pdf->ImprimirTablaArea($totalhorasturno,$posicionx2, $alturaXT, $ha, $wst,'C',2,1);
									}
								}
						$alturaXT = $alturaXT + $ha;
							}
											
					//finaliza por el horario
					$alturaX = $alturaX + $ha*$cantreg; 
				}
				
				}}
				///////sub cantidades de los grupos de areas
						
						$subthrsprog = array();
						for ($k=1;$k<=$numeroDeDias;$k++){
							$sqlaskhrsga = "select sum(b.h_horanum) as numhrs from tb_horaeje a inner join tb_horario b on a.h_id = b.h_id where a.j_id='$idj' and a.s_id='$ids' and a.uap_mes='$mm' and a.uap_anno='$anno' and a.he_dia='$k' and a.ga_id='$idga' and a.tp_id='$idtp' and a.he_idserva='$ids' and a.he_tipohora=0 and a.ug_id='$ugid'";
							//echo $sqlaskhrsga."<br>";
							$resultaskhrstga = mysql_query($sqlaskhrsga);
							if(mysql_num_rows($resultaskhrstga)!=0){
							while($rownh= mysql_fetch_array($resultaskhrstga)){
							$subthrsprog[$k-1] = $rownh['numhrs'];
							}
							}else{
							//echo $sqlaskhrsga."<br>";
							$subthrsprog[$k-1] = 0;
							}
						}
						$sqlsumahrs="select sum(b.h_horanum) as tothrs from tb_horaeje a inner join tb_horario b on a.h_id = b.h_id where a.j_id='$idj' and a.s_id='$ids' and a.uap_mes='$mm' and a.uap_anno='$anno' and a.ga_id='$idga' and a.tp_id='$idtp' and a.he_idserva='$ids' and a.he_tipohora=0 and a.ug_id='$ugid'";
						$resultsumahrs = mysql_query($sqlsumahrs);
						while($rowth= mysql_fetch_array($resultsumahrs)){
									$tothrs = $rowth['tothrs'];
						}
				$wast = $sumat*0.2855;
				$wst= $sumat - ($sumat*0.12 + $sumat*0.165 + $suma);
				$txtst = 'SUB TOTAL DE HORAS';
				$pdf->ImprimirTablaArea($txtst,25,$alturaX,$ha,$wast,'C',2,1);		
			    $pdf->ImprimirDiasHoras($subthrsprog,$posicionx,$alturaX,$ha,$ancho,$alinea,$pintast);
				$pdf->ImprimirTablaArea($tothrs,$posicionx2, $alturaX, $ha, $wst,'C',2,1);
						
			$alturaX = $alturaX + $ha;
			/////////////////
			}}
	
	//total de hrs ordinarias
	
	$totalhrs = array();
	for ($p=1;$p<=$numeroDeDias;$p++){
							$sqlaskhrt = "select sum(b.h_horanum) as numhrs from tb_horaeje a inner join tb_horario b on a.h_id = b.h_id where a.j_id='$idj' and a.s_id='$ids' and a.uap_mes='$mm' and a.uap_anno='$anno' and a.he_dia='$p' and a.tp_id='$idtp' and a.he_idserva='$ids' and a.he_tipohora=0 and a.ug_id='$ugid'";
							//echo $sqlaskhrsga."<br>";
							$resultaskhrt = mysql_query($sqlaskhrt);
							if(mysql_num_rows($resultaskhrt)!=0){
							while($rownh= mysql_fetch_array($resultaskhrt)){
							$numhrs = $rownh['numhrs'];
							$totalhrs[$p-1]= $numhrs;
							}
							}else{
							//echo $sqlaskhrsga."<br>";
							$totalhrs[$p-1]= 0;
							}
						}
						$sqlsumath="select sum(b.h_horanum) as tothrs from tb_horaeje a inner join tb_horario b on a.h_id = b.h_id where a.j_id='$idj' and a.s_id='$ids' and a.uap_mes='$mm' and a.uap_anno='$anno' and a.tp_id='$idtp' and a.he_idserva='$ids' and a.he_tipohora=0 and a.ug_id='$ugid'";
						$resultsumatr = mysql_query($sqlsumath);
						while($rowth= mysql_fetch_array($resultsumatr)){
									$tothrs = $rowth['tothrs'];
						}
						
						$wast = $sumat*0.2855;
						$wst= $sumat - ($sumat*0.12 + $sumat*0.165 + $suma);
						$txtst = 'TOTAL DE HORAS ORDINARIAS';
						$pdf->ImprimirTablaArea($txtst,25,$alturaX,$ha,$wast,'C',2,1);		
					    $pdf->ImprimirDiasHoras($totalhrs,$posicionx,$alturaX,$ha,$ancho,$alinea,$pintat);
						$pdf->ImprimirTablaArea($tothrs,$posicionx2, $alturaX, $ha, $wst,'C',2,1);
						$alturaX = $alturaX + $ha;
	//final de horas ordinarias
	//final de horas ordinarias del servicio

//HORAS EXTRAS
	
	$pdf->ImprimirTablaTitulo($cabecerahe,25,$alturaX,$ha,$aw,'L',true);
	//$hextrasencabeza = $hextrasencabeza."<tr><td align='left' colspan='".$cabeceramayor."' class='facetfilaTD'><b>HORAS EXTRAS</b></td></tr>";
	$alturaX = $alturaX + $ha;
///HORAS EXTRAS EN EL SERVICIO

		//pregunta por el grupo area
			$sqlgarea="select distinct(a.ga_id) as idga, (select ga_desc from tb_garea where ga_id=a.ga_id) as garea from tb_horaeje a where a.tp_id='$idtp' and a.uap_anno='$anno' and a.uap_mes='$mm' and a.j_id='$idj' and a.s_id='$ids' and a.he_idserva='$ids' and a.ug_id='$ugid' and a.he_tipohora='1' order by idga asc";
			//echo $sqlgarea."<br>";
			$resultga = mysql_query($sqlgarea);
			if(mysql_num_rows($resultga)!=0){
			while ($rowga= mysql_fetch_array($resultga)){
			$idga= $rowga['idga'];
			$pdf->ImprimirTablaTitulo($rowga['garea'],25,$alturaX,$ha,$aw,'L',false);
				
					//pregunta por las areas
						$alturaX = $alturaX + $ha;
						$sqlarea ="select distinct(a_id) as ida from tb_horaeje where ga_id='$idga' and tp_id='$idtp' and uap_anno='$anno' and uap_mes='$mm' and j_id='$idj' and he_idserva='$ids' and s_id='$ids' and he_tipohora='1' order by a_id";
						$resulta = mysql_query($sqlarea);
						//echo $sqlarea."<br>";
						if(mysql_num_rows($resulta)!=0){
						while ($row= mysql_fetch_array($resulta)){
						$ida=$row['ida'];
						$sqlcantturno = "select a.a_id as codarea, (select a_desc from tb_area where a_id=a.a_id and ga_id=a.ga_id) as area, count(distinct(a.h_id)) as idhora from tb_horaeje a where a.j_id='$idj' and a.s_id='$ids' and a.he_idserva='$ids' and a.uap_anno='$anno' and a.uap_mes='$mm' and a.tp_id='$idtp' and a.a_id='$ida' and a.ga_id='$idga' and a.he_tipohora='1' and a.ug_id='$ugid' group by a.a_id order by area asc";
						//echo $sqlcantturno."<br>";
						$resultcantturno = mysql_query($sqlcantturno);
						//echo $sqlcantturno."<br><br>";
						while ($rownt= mysql_fetch_array($resultcantturno)){
						$area= $rownt['area'];
						$cantreg = $rownt['idhora'];
						$hp = $ha*$cantreg;
						$wa = $sumat*0.12;
						$pdf->ImprimirTablaArea($area,25,$alturaX,$hp,$wa,'C',2,$cantreg);
						//pregunta por el horario
						$sqlhora="select distinct(a.h_id) as idhora, b.h_horaturn as horaturn, (select o_idturn from tb_ordena where o_turn=b.h_horaturn) as tt from tb_horaeje a inner join tb_horario b on a.h_id = b.h_id where a.j_id='$idj' and a.he_idserva='$ids' and a.s_id='$ids' and a.uap_anno='$anno' and a.uap_mes='$mm' and a.tp_id='$idtp' and a.a_id='$ida' and a.ga_id='$idga' and a.ug_id='$ugid' and a.he_tipohora='1' order by tt";
						$resulthora=mysql_query($sqlhora);
						//echo $sqlhora."<br><br>";
						$alturaXH = $alturaX;
						$alturaXT = $alturaX;
						while ($rowh= mysql_fetch_array($resulthora)){
						$idh=$rowh['idhora'];
						//pregunta por el turno
						$sqlturno = "select h_id, concat(date_format(h_horaini,'%k:%i %p'),' - ',date_format(h_horafin,'%k:%i %p')) as hora, h_horaturn as turno, h_horanum as numhora from tb_horario where h_id='$idh'";
						$resultturno = mysql_query($sqlturno);
						//echo $sqlturno."<br><br>";
						while ($rowtt= mysql_fetch_array($resultturno)){
						$horario = array($rowtt['hora'], $rowtt['turno'],$rowtt['numhora']);
						$wh= array($sumat*0.095, $sumat*0.025, $sumat*0.0455);
						$pdf->ImprimirTablaHorario($horario,25+$wa,$alturaXH ,$ha,$wh,'C');	
						$alturaXH = $alturaXH + $ha;
						}
						$diaprog = array();	
						for ($i=1;$i<=$numeroDeDias;$i++){
						$sqlconsultaturno="select (select h_horanum from tb_horario where h_id=a.h_id) as hora  from tb_horaeje a where a.j_id='$idj' and a.s_id='$ids' and a.uap_mes='$mm' and a.uap_anno='$anno' and a.he_dia='$i' and a.h_id='$idh' and a.a_id='$ida' and a.ga_id='$idga' and a.tp_id='$idtp' and a.he_idserva='$ids' and a.he_tipohora=1 and a.ug_id='$ugid'";
						//echo $sqlconsultaturno."<br>";
						//echo $sqlconsultaturno."<br>";
						$resultcontur = mysql_query($sqlconsultaturno);
						$dia= date("w",mktime( 0, 0, 0, $mm, $i, $anno )); 
						if(mysql_num_rows($resultcontur)==0){
						switch ($dia) {
						    case 0: $diaprog[$i-1]=" "; break;
						    case 1: 
						    case 2:
						    case 3:
						    case 4:
						    case 5:
						    case 6:
									$diaprog[$i-1]=" "; break;
						}

						}else{
						while($rowt= mysql_fetch_array($resultcontur)){
						$hrord = $rowt['hora'];
							switch ($dia) {
						    case 0: $diaprog[$i-1]=$hrord; break;
						    case 1: 
						    case 2:
						    case 3:
						    case 4:
						    case 5:
						    case 6:
						        $diaprog[$i-1]=$hrord; break;
						}}
						}
						}
						$pdf->ImprimirDiasHoras($diaprog,$posicionx,$alturaXT,$ha,$ancho,$alinea,$pintap);
		//horas por turno
		$askhrsturno = "select sum(b.h_horanum) as sumhrs from tb_horaeje a inner join tb_horario b on a.h_id=b.h_id where a.j_id='$idj' and a.s_id='$ids' and a.uap_mes='$mm' and a.uap_anno='$anno' and a.h_id='$idh' and a.a_id='$ida' and a.ga_id='$idga' and a.tp_id='$idtp' and a.he_idserva='$ids' and a.he_tipohora=1 and a.ug_id='$ugid' group by a.h_id";
		$resultaskhrst = mysql_query($askhrsturno);
		$wst= $sumat - ($sumat*0.12 + $sumat*0.165 + $suma);
		if(mysql_num_rows($resultaskhrst)==0){
			$pdf->ImprimirTablaArea(0,$posicionx2, $alturaXT, $ha, $wst,'C',2,1);
		}else{
			while($rowht= mysql_fetch_array($resultaskhrst)){
			$totalhorasturno = $rowht['sumhrs'];
			$pdf->ImprimirTablaArea($totalhorasturno,$posicionx2, $alturaXT, $ha, $wst,'C',2,1);
			}
		}
		$alturaXT = $alturaXT + $ha;
		}
				//finaliza por el horario
					$alturaX = $alturaX + $ha*$cantreg; 	
	}
		}
	}	
///PARA REVISAR  PARA ABAJO
	//sub cantidades de los grupos de areas
						$subthrsprog = array();
						for ($kk=1;$kk<=$numeroDeDias;$kk++){
							$sqlaskhrsga = "select sum(b.h_horanum) as numhrs from tb_horaeje a inner join tb_horario b on a.h_id = b.h_id where a.j_id='$idj' and a.s_id='$ids' and a.uap_mes='$mm' and a.uap_anno='$anno' and a.he_dia='$kk' and a.ga_id='$idga' and a.tp_id='$idtp' and a.he_idserva='$ids' and a.he_tipohora=1 and a.ug_id='$ugid'";
							//echo $sqlaskhrsga."<br>";
							$resultaskhrstga = mysql_query($sqlaskhrsga);
							if(mysql_num_rows($resultaskhrstga)!=0){
							while($rownh= mysql_fetch_array($resultaskhrstga)){
							$numhrs = $rownh['numhrs'];
							$subthrsprog[$kk-1] = $rownh['numhrs'];
							}
							}else{
							//echo $sqlaskhrsga."<br>";
							$subthrsprog[$kk-1] = 0;
							}
						}
						$sqlsumahrs="select sum(b.h_horanum) as tothrs from tb_horaeje a inner join tb_horario b on a.h_id = b.h_id where a.j_id='$idj' and a.s_id='$ids' and a.uap_mes='$mm' and a.uap_anno='$anno' and a.ga_id='$idga' and a.tp_id='$idtp' and a.he_idserva='$ids' and a.he_tipohora=1 and a.ug_id='$ugid'";
						$resultsumahrs = mysql_query($sqlsumahrs);
						while($rowth= mysql_fetch_array($resultsumahrs)){
									$tothrs = $rowth['tothrs'];
						}
						$wast = $sumat*0.2855;
						$wst= $sumat - ($sumat*0.12 + $sumat*0.165 + $suma);
						$txtst = 'SUB TOTAL DE HORAS';
						$pdf->ImprimirTablaArea($txtst,25,$alturaX,$ha,$wast,'C',2,1);		
					    $pdf->ImprimirDiasHoras($subthrsprog,$posicionx,$alturaX,$ha,$ancho,$alinea,$pintast);
						$pdf->ImprimirTablaArea($tothrs,$posicionx2, $alturaX, $ha, $wst,'C',2,1);
						
			$alturaX = $alturaX + $ha;
						
    }}
		//total de hrs extras
	//if($hextras !=''){
	$totalhrs = array();
	for ($a=1;$a<=$numeroDeDias;$a++){
							$sqlaskhrt = "select sum(b.h_horanum) as numhrs from tb_horaeje a inner join tb_horario b on a.h_id = b.h_id where a.j_id='$idj' and a.s_id='$ids' and a.uap_mes='$mm' and a.uap_anno='$anno' and a.he_dia='$a' and a.tp_id='$idtp' and a.he_idserva='$ids' and a.he_tipohora=1 and a.ug_id='$ugid'";
							//echo $sqlaskhrt."<br>";
							$resultaskhrt = mysql_query($sqlaskhrt);
							if(mysql_num_rows($resultaskhrt)!=0){
							while($rownh= mysql_fetch_array($resultaskhrt)){
							$numhrs = $rownh['numhrs'];
							$totalhrs[$a-1]= $numhrs;
							}
							}else{
							//echo $sqlaskhrsga."<br>";
							$totalhrs[$a-1]= 0;
							}
						}
						$sqlsumath="select sum(b.h_horanum) as tothrs from tb_horaeje a inner join tb_horario b on a.h_id = b.h_id where a.j_id='$idj' and a.s_id='$ids' and a.uap_mes='$mm' and a.uap_anno='$anno' and a.tp_id='$idtp' and a.he_idserva='$ids' and a.he_tipohora=1 and a.ug_id='$ugid'";
						$resultsumatr = mysql_query($sqlsumath);
						while($rowth= mysql_fetch_array($resultsumatr)){
									$tothrs = $rowth['tothrs'];
						}
						
						$wast = $sumat*0.2855;
						$wst= $sumat - ($sumat*0.12 + $sumat*0.165 + $suma);
						$txtst = 'TOTAL DE HORAS EXTRAS';
						$pdf->ImprimirTablaArea($txtst,25,$alturaX,$ha,$wast,'C',2,1);		
					    $pdf->ImprimirDiasHoras($totalhrs,$posicionx,$alturaX,$ha,$ancho,$alinea,$pintat);
						$pdf->ImprimirTablaArea($tothrs,$posicionx2, $alturaX, $ha, $wst,'C',2,1);
						$alturaX = $alturaX + $ha;
	
	//}
		
////////////////////FIN H. EXTRAS EN EL SERVICIO


//armando grupo de servicios y sus dependencias
$sqldepa="select j_id as codj, 0 as cods ,j_abrev as nom, j_desc as nomc from tb_jefatura where j_id='$idj'";
$sqlserv="select j_id as codj, s_id as cods, s_abrev as nom, s_desc as nomc 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)){
$cad = $cad."<td width='10' class='facetfilaTD' colspan='4' align='center' >".$rows['nom']."</td>";
$a=$a+1;
$serv[$a]=$rows['cods'];
$nomserv[$a]=$rows['nomc'];
}
while ($rowj= mysql_fetch_array($resultdepa)){
$cad = $cad."<td width='10' class='facetfilaTD' colspan='4'  align='center' >".$rowj['nom']."</td>";
$a=$a+1;
$serv[$a]=$rowj['cods'];
$nomserv[$a]=$rowj['nomc'];
}

$dato7cab=array('OBSERVACIONES:','');
$dato8cab=array('','Firma del Jefe del Servicio','','Firma del Jefe del Departamento','');
$w7=array($sumat*0.2855,$sumat*0.7145);
$alig7=array('C','C');
$w8=array($sumat*0.15,$sumat*0.25,$sumat*0.15,$sumat*0.25,$sumat*0.15);
$alig8=array('C','C','C','C','C');
$hh = $ha*2.3;
$pdf->ImprimirTablaSinColorLineal($dato7cab,25,$alturaX,$hh,$w7, $alig7);
$alturaX = $alturaX + (3.5*$ha) + $hh - 4;
$dibu =array(0,'T',0,'T',0);
$pdf->ImprimirTablaSinColorFirma($dato8cab,25,$alturaX,$ha,$w8, $alig8,$dibu);



//HORAS ORDINARIAS EN OTRO SERVICIOS

//buscando programacion por servicio

$aaa= 0;
$bbb=0;	
//$h=25;
for($i=0;$i<count($serv)-1;$i++){
$idso = $serv[$i+1];
$sqlask="select * from tb_horaeje where ug_id='$ugid' and uap_anno='$anno' and uap_mes='$mm' and  tp_id='$idtp' and s_id='$ids' and he_idserva='$idso' and he_idserva not in ('$ids')  and j_id='$idj' and he_tipohora='0'";
//echo $sqlask."<br>";
$resultask = mysql_query($sqlask);
	if(mysql_num_rows($resultask)!=0){
			$nomservicio = $nomserv[$i+1];
			$nomservicio = "APOYO AL ".$nomservicio;
			if($aaa==0 && $bbb==0){
			$pdf->AddPage();
			$alturaX = 25;
			$ha = 4;
			$pdf->SetFont('Helvetica','B',12);
			$pdf->Image('../img/logoincor.jpg', 10, 10, 45, 16,'jpg');
			$pdf->Image('../img/logoessalud.jpg', 243, 12, 40, 11,'jpg');
			$pdf->Text(75,$alturaX,$texto);
			$pdf->SetFont('Arial','',6);
			$alturaX = $alturaX+$ha;
			$alturaX = $alturaX + $ha - 3.5;
			$pdf->ImprimirTabla($dato1cab,25,$alturaX,$ha,$w1, $alig);
			$alturaX = $alturaX + $ha + $ha;
			$pdf->ImprimirTabla($dato2cab,25,$alturaX,$ha,$w2, $alig);
			$alturaX = $alturaX + $ha;
			$pdf->ImprimirTabla($dato3cab,25,$alturaX,$ha,$w3, $alig);
			$alturaX = $alturaX + $ha;
			$pdf->ImprimirTabla($dato4cab,25,$alturaX,$ha,$w4, $alig);
			$pdf->SetFont('Arial','',4.5);
			$pdf->ImprimirTablaJustificada($dato5cab,$posicionx2,$alturaX,3*$ha,$w5,'C',3);
			$pdf->SetFont('Arial','',6);
			$alturaX = $alturaX + $ha;
			$pdf->ImprimirTablaSinColor($dato6cab,25,$alturaX,$ha,$w6, $alig6);
			$alturaX = $alturaX - $ha;
			$pdf->SetFont('Arial','',5.5);
			$pdf->ImprimirDias($header2,$posicionx,$alturaX,$ha,$ancho,$alinea,$pinta);
			$alturaX = $alturaX + $ha;
			$pdf->ImprimirDias($header3,$posicionx,$alturaX,$ha,$ancho,$alinea,$pinta);
			$alturaX = $alturaX + $ha;
			$pdf->SetFont('Arial','',6);
			$aw= $sumat*0.12 + $sumat*0.32 + $sumat*0.12 + $sumat*0.44;
			//$pdf->ImprimirTablaTitulo($cabeceraho,25,$alturaX,$ha,$aw,'L',true);
			//////
			
			$pdf->ImprimirTablaTitulo($cabecerahoa,25,$alturaX,$ha,$aw,'L',true);
			$alturaX = $alturaX + $ha;
			$aaa=1; $bbb=1;
			}
			$pdf->ImprimirTablaTitulo($nomservicio,25,$alturaX,$ha,$aw,'L',false);
			$alturaX = $alturaX + $ha;
		//pregunta por el grupo area
			$sqlgarea="select distinct(a.ga_id) as idga, (select ga_desc from tb_garea where ga_id=a.ga_id) as garea from tb_horaeje a where a.tp_id='$idtp' and a.uap_anno='$anno' and a.uap_mes='$mm' and a.j_id='$idj' and a.s_id='$ids' and a.he_idserva='$idso' and a.ug_id='$ugid' and a.he_tipohora='0' order by idga asc";
			//echo $sqlgarea."<br>";
			$resultga = mysql_query($sqlgarea);
			if(mysql_num_rows($resultga)!=0){
			while ($rowga= mysql_fetch_array($resultga)){
			$idga= $rowga['idga'];
			$pdf->ImprimirTablaTitulo($rowga['garea'],25,$alturaX,$ha,$aw,'L',false);
			$alturaX = $alturaX + $ha;
			//}
					//pregunta por las areas
						$sqlarea ="select distinct(a_id) as ida from tb_horaeje where ga_id='$idga' and tp_id='$idtp' and uap_anno='$anno' and uap_mes='$mm' and j_id='$idj' and he_idserva='$idso' and s_id='$ids' and he_tipohora='0' and ug_id='$ugid' order by a_id";
						$resulta = mysql_query($sqlarea);
						//echo $sqlarea."<br>";
						if(mysql_num_rows($resulta)!=0){
						while ($row= mysql_fetch_array($resulta)){
						$ida=$row['ida'];
						$sqlcantturno = "select a.a_id as codarea, (select a_desc from tb_area where a_id=a.a_id and ga_id=a.ga_id) as area, count(distinct(a.h_id)) as idhora from tb_horaeje a where a.j_id='$idj' and a.s_id='$ids' and a.he_idserva='$idso' and a.uap_anno='$anno' and a.uap_mes='$mm' and a.tp_id='$idtp' and a.a_id='$ida' and a.ga_id='$idga' and a.he_tipohora='0' and a.ug_id='$ugid' group by a.a_id";
						//echo $sqlcantturno."<br>";
						$resultcantturno = mysql_query($sqlcantturno);
						//echo $sqlcantturno."<br><br>";
						while ($rownt= mysql_fetch_array($resultcantturno)){
						$area= $rownt['area'];
						$cantreg = $rownt['idhora'];
						$hp = $ha*$cantreg;
						$wa = $sumat*0.12;
						$pdf->ImprimirTablaArea($area,25,$alturaX,$hp,$wa,'C',2,$cantreg);
						//pregunta por el horario
						$sqlhora="select distinct(a.h_id) as idhora, b.h_horaturn as horaturn, (select o_idturn from tb_ordena where o_turn=b.h_horaturn) as tt from tb_horaeje a inner join tb_horario b on a.h_id = b.h_id where j_id='$idj' and s_id= '$ids' and he_idserva='$idso' and uap_anno='$anno' and uap_mes='$mm' and tp_id='$idtp' and a_id='$ida' and ga_id='$idga' and ug_id='$ugid' and he_tipohora='0' order by tt";
						$resulthora=mysql_query($sqlhora);
						//echo $sqlhora."<br><br>";
						$alturaXH = $alturaX;
						$alturaXT = $alturaX;
						while ($rowh= mysql_fetch_array($resulthora)){
						$idh=$rowh['idhora'];
						//pregunta por el turno
						$sqlturno = "select h_id, concat(date_format(h_horaini,'%k:%i %p'),' - ',date_format(h_horafin,'%k:%i %p')) as hora, h_horaturn as turno, h_horanum as numhora from tb_horario where h_id='$idh'";
						$resultturno = mysql_query($sqlturno);
						//echo $sqlturno."<br><br>";
						while ($rowtt= mysql_fetch_array($resultturno)){
						$horario = array($rowtt['hora'], $rowtt['turno'],$rowtt['numhora']);
						$wh= array($sumat*0.095, $sumat*0.025, $sumat*0.0455);
						$pdf->ImprimirTablaHorario($horario,25+$wa,$alturaXH ,$ha,$wh,'C');	
						$alturaXH = $alturaXH + $ha;
						}
						$diaproga = array();
						for ($j=1;$j<=$numeroDeDias;$j++){
						$sqlconsultaturno="select (select h_horanum from tb_horario where h_id=a.h_id) as hora  from tb_horaeje a where a.j_id='$idj' and a.s_id='$ids' and a.uap_mes='$mm' and a.uap_anno='$anno' and a.he_dia='$j' and a.h_id='$idh' and a.a_id='$ida' and a.ga_id='$idga' and a.tp_id='$idtp' and a.he_idserva='$idso' and a.he_tipohora=0 and a.ug_id='$ugid'";
						//echo $sqlconsultaturno."<br>";
						//echo $sqlconsultaturno."<br>";
						$resultcontur = mysql_query($sqlconsultaturno);
						$dia= date("w",mktime( 0, 0, 0, $mm, $j, $anno )); 
						if(mysql_num_rows($resultcontur)==0){
						switch ($dia) {
						    case 0: $diaproga[$j-1]=" "; break;
						    case 1: 
						    case 2:
						    case 3:
						    case 4:
						    case 5:
						    case 6:
									$diaproga[$j-1]=" "; break;
						}

						}else{
						while($rowt= mysql_fetch_array($resultcontur)){
						$hrord = $rowt['hora'];
							switch ($dia) {
						    case 0: $diaproga[$j-1]=$hrord; break;
						    case 1: 
						    case 2:
						    case 3:
						    case 4:
						    case 5:
						    case 6:
						        $diaproga[$j-1]=$hrord; break;
						}}
						}
							//$pdf->Text(5,$h,$sqlconsultaturno);	
						//$h = $h + 5;													
						}
						$pdf->ImprimirDiasHoras($diaproga,$posicionx,$alturaXT,$ha,$ancho,$alinea,$pintap);
							
						
						
		//horas por turno
		$askhrsturno = "select sum(b.h_horanum) as sumhrs from tb_horaeje a inner join tb_horario b on a.h_id=b.h_id where a.j_id='$idj' and a.s_id='$ids' and a.uap_mes='$mm' and a.uap_anno='$anno' and a.h_id='$idh' and a.a_id='$ida' and a.ga_id='$idga' and a.tp_id='$idtp' and a.he_idserva='$idso' and a.he_tipohora=0 and a.ug_id='$ugid' group by a.h_id";
		$resultaskhrst = mysql_query($askhrsturno);
		$wst= $sumat - ($sumat*0.12 + $sumat*0.165 + $suma);
		if(mysql_num_rows($resultaskhrst)==0){
			$pdf->ImprimirTablaArea(0,$posicionx2, $alturaXT, $ha, $wst,'C',2,1);
		}else{
			while($rowht= mysql_fetch_array($resultaskhrst)){
			$totalhorasturno = $rowht['sumhrs'];
			$pdf->ImprimirTablaArea($totalhorasturno,$posicionx2, $alturaXT, $ha, $wst,'C',2,1);
			}
		}
		$alturaXT = $alturaXT + $ha;
	}
		$alturaX = $alturaX + $ha*$cantreg; 
	}
		}
	}
	//sub cantidades de los grupos de areas
						$subthrsprog = array();
						for ($k=1;$k<=$numeroDeDias;$k++){
							$sqlaskhrsga = "select sum(b.h_horanum) as numhrs from tb_horaeje a inner join tb_horario b on a.h_id = b.h_id where a.j_id='$idj' and a.s_id='$ids' and a.uap_mes='$mm' and a.uap_anno='$anno' and a.he_dia='$k' and a.ga_id='$idga' and a.tp_id='$idtp' and a.he_idserva='$idso' and a.he_tipohora=0 and a.ug_id='$ugid'";
							//echo $sqlaskhrsga."<br>";
							$resultaskhrstga = mysql_query($sqlaskhrsga);
							if(mysql_num_rows($resultaskhrstga)!=0){
							while($rownh= mysql_fetch_array($resultaskhrstga)){
							$numhrs = $rownh['numhrs'];
							$subthrsprog[$k-1] = $rownh['numhrs'];
							}
							}else{
							//echo $sqlaskhrsga."<br>";
							$subthrsprog[$k-1] = 0;
							}
						}
						$sqlsumahrs="select sum(b.h_horanum) as tothrs from tb_horaeje a inner join tb_horario b on a.h_id = b.h_id where a.j_id='$idj' and a.uap_mes='$mm' and a.uap_anno='$anno' and a.ga_id='$idga' and a.tp_id='$idtp' and a.s_id='$ids' and a.he_idserva='$idso' and a.he_tipohora=0 and a.ug_id='$ugid'";
						$resultsumahrs = mysql_query($sqlsumahrs);
						while($rowth= mysql_fetch_array($resultsumahrs)){
									$tothrs = $rowth['tothrs'];
						}
						$wast = $sumat*0.2855;
						$wst= $sumat - ($sumat*0.12 + $sumat*0.165 + $suma);
						$txtst = 'SUB TOTAL DE HORAS';
						$pdf->ImprimirTablaArea($txtst,25,$alturaX,$ha,$wast,'C',2,1);		
					    $pdf->ImprimirDiasHoras($subthrsprog,$posicionx,$alturaX,$ha,$ancho,$alinea,$pintast);
						$pdf->ImprimirTablaArea($tothrs,$posicionx2, $alturaX, $ha, $wst,'C',2,1);
			$alturaX = $alturaX + $ha;			
    
	}
		
	}
	
	//total de hrs ordinarias
	$totalhrs = array();
	for ($p=1;$p<=$numeroDeDias;$p++){
							$sqlaskhrt = "select sum(b.h_horanum) as numhrs from tb_horaeje a inner join tb_horario b on a.h_id = b.h_id where a.j_id='$idj' and a.s_id='$ids' and a.uap_mes='$mm' and a.uap_anno='$anno' and a.he_dia='$p' and a.tp_id='$idtp' and a.he_idserva='$idso' and a.he_tipohora=0 and a.ug_id='$ugid'";
							//echo $sqlaskhrsga."<br>";
							$resultaskhrt = mysql_query($sqlaskhrt);
							if(mysql_num_rows($resultaskhrt)!=0){
							while($rownh= mysql_fetch_array($resultaskhrt)){
							$numhrs = $rownh['numhrs'];
							$totalhrs[$p-1]= $numhrs;
							}
							}else{
							//echo $sqlaskhrsga."<br>";
							$totalhrs[$a-1]= 0;
							}
						}
						$sqlsumath="select sum(b.h_horanum) as tothrs from tb_horaeje a inner join tb_horario b on a.h_id = b.h_id where a.j_id='$idj' and a.s_id='$ids' and a.uap_mes='$mm' and a.uap_anno='$anno' and a.tp_id='$idtp' and a.he_idserva='$idso' and a.he_tipohora=0 and a.ug_id='$ugid'";
						$resultsumatr = mysql_query($sqlsumath);
						while($rowth= mysql_fetch_array($resultsumatr)){
									$tothrs = $rowth['tothrs'];
						}
					
						$wast = $sumat*0.2855;
						$wst= $sumat - ($sumat*0.12 + $sumat*0.165 + $suma);
						$txtst = 'TOTAL DE HORAS ORDINARIAS';
						$pdf->ImprimirTablaArea($txtst,25,$alturaX,$ha,$wast,'C',2,1);		
					    $pdf->ImprimirDiasHoras($totalhrs,$posicionx,$alturaX,$ha,$ancho,$alinea,$pintat);
						$pdf->ImprimirTablaArea($tothrs,$posicionx2, $alturaX, $ha, $wst,'C',2,1);
						$alturaX = $alturaX + $ha;
	//final de horas ordinarias
	
	}
	}

///HORAS EXTRAS DE APOYO
			
$eee= 0;
			for($i=0;$i<count($serv)-1;$i++){
			$idso = $serv[$i+1];
			$sqlask="select * from tb_horaeje where ug_id='$ugid' and uap_anno='$anno' and uap_mes='$mm' and s_id='$ids' and he_idserva='$idso' and he_idserva not in ('$ids') and tp_id='$idtp' and j_id='$idj' and he_tipohora='1'";
			//echo $sqlask."<br>";
			$resultask = mysql_query($sqlask);
				if(mysql_num_rows($resultask)!=0){
				
						$nomservicio = $nomserv[$i+1];
						$nomservicio = "APOYO AL ".$nomservicio;
						if($eee==0 && $bbb==0){
						$pdf->AddPage();
						$alturaX = 25;
						$ha = 3.7;
						$pdf->SetFont('Helvetica','B',12);
						$pdf->Image('../img/logoincor.jpg', 10, 10, 45, 16,'jpg');
						$pdf->Image('../img/logoessalud.jpg', 243, 12, 40, 11,'jpg');
						$pdf->Text(75,$alturaX,$texto);
						$pdf->SetFont('Arial','',6);
						$alturaX = $alturaX+$ha;
						$alturaX = $alturaX + $ha -3.5;
						$pdf->ImprimirTabla($dato1cab,25,$alturaX,$ha,$w1, $alig);
						$alturaX = $alturaX + $ha + $ha;
						$pdf->ImprimirTabla($dato2cab,25,$alturaX,$ha,$w2, $alig);
						$alturaX = $alturaX + $ha;
						$pdf->ImprimirTabla($dato3cab,25,$alturaX,$ha,$w3, $alig);
						$alturaX = $alturaX + $ha;
						$pdf->ImprimirTabla($dato4cab,25,$alturaX,$ha,$w4, $alig);
						$pdf->SetFont('Arial','',4.5);
						$pdf->ImprimirTablaJustificada($dato5cab,$posicionx2,$alturaX,3*$ha,$w5,'C',3);
						$pdf->SetFont('Arial','',6);
						$alturaX = $alturaX + $ha;
						$pdf->ImprimirTablaSinColor($dato6cab,25,$alturaX,$ha,$w6, $alig6);
						$alturaX = $alturaX - $ha;
						$pdf->SetFont('Arial','',5.5);
						$pdf->ImprimirDias($header2,$posicionx,$alturaX,$ha,$ancho,$alinea,$pinta);
						$alturaX = $alturaX + $ha;
						$pdf->ImprimirDias($header3,$posicionx,$alturaX,$ha,$ancho,$alinea,$pinta);
						$alturaX = $alturaX + $ha;
						$pdf->SetFont('Arial','',6);
						$aw= $sumat*0.12 + $sumat*0.32 + $sumat*0.12 + $sumat*0.44;
						//$pdf->ImprimirTablaTitulo($cabeceraho,25,$alturaX,$ha,$aw,'L',true);
						
						$pdf->ImprimirTablaTitulo($cabecerahea,25,$alturaX,$ha,$aw,'L',true);
						$alturaX = $alturaX + $ha;
						$eee=1;$bbb=1;
						}elseif($eee==0){
						$pdf->ImprimirTablaTitulo($cabecerahea,25,$alturaX,$ha,$aw,'L',true);
						$alturaX = $alturaX + $ha;
						$eee=1;
						}
						$pdf->ImprimirTablaTitulo($nomservicio,25,$alturaX,$ha,$aw,'L',false);
						$alturaX = $alturaX + $ha;
					//pregunta por el grupo area
						$sqlgarea="select distinct(a.ga_id) as idga, (select ga_desc from tb_garea where ga_id=a.ga_id) as garea from tb_horaeje a where a.tp_id='$idtp' and a.uap_anno='$anno' and a.uap_mes='$mm' and a.j_id='$idj' and a.s_id='$ids' and a.he_idserva='$idso' and a.ug_id='$ugid' and a.he_tipohora='1' order by idga asc";
						//echo $sqlgarea."<br>";
						$resultga = mysql_query($sqlgarea);
						if(mysql_num_rows($resultga)!=0){
						while ($rowga= mysql_fetch_array($resultga)){
						$idga= $rowga['idga'];
						$pdf->ImprimirTablaTitulo($rowga['garea'],25,$alturaX,$ha,$aw,'L',false);
						$alturaX = $alturaX + $ha;
								//pregunta por las areas
									$sqlarea ="select distinct(a_id) as ida from tb_horaeje where ga_id='$idga' and tp_id='$idtp' and uap_anno='$anno' and uap_mes='$mm' and j_id='$idj' and he_idserva='$idso' and s_id='$ids' and he_tipohora='1' order by a_id";
									$resulta = mysql_query($sqlarea);
									//echo $sqlarea."<br>";
									if(mysql_num_rows($resulta)!=0){
									while ($row= mysql_fetch_array($resulta)){
									$ida=$row['ida'];
									$sqlcantturno = "select a.a_id as codarea, (select a_desc from tb_area where a_id=a.a_id and ga_id=a.ga_id) as area, count(distinct(a.h_id)) as idhora from tb_horaeje a where a.j_id='$idj' and a.s_id='$ids' and a.he_idserva='$idso' and a.uap_anno='$anno' and a.uap_mes='$mm' and a.tp_id='$idtp' and a.a_id='$ida' and a.ga_id='$idga' and a.he_tipohora='1' group by a.a_id";
									//echo $sqlcantturno."<br>";
									$resultcantturno = mysql_query($sqlcantturno);
									//echo $sqlcantturno."<br><br>";
									while ($rownt= mysql_fetch_array($resultcantturno)){
									$area= $rownt['area'];
									$cantreg = $rownt['idhora'];
									$hp = $ha*$cantreg;
									$wa = $sumat*0.12;
									$pdf->ImprimirTablaArea($area,25,$alturaX,$hp,$wa,'C',2,$cantreg);
									//pregunta por el horario
									//$sqlhora="select distinct(a.h_id), b.h_horaturn as horaturn, (select o_idturn from tb_ordena where o_turn=b.h_horaturn) as tt as idhora from tb_horaeje a inner join tb_horario b on a.h_id = b.h_id where a.j_id='$idj' and a.s_id='$ids' and a.he_idserva='$idso' and a.uap_anno='$anno' and a.uap_mes='$mm' and a.tp_id='$idtp' and a.a_id='$ida' and a.ga_id='$idga' and a.he_tipohora='1' order by tt";
									$sqlhora="select distinct(h_id) as idhora from tb_horaeje where j_id='$idj' and s_id='$ids' and he_idserva='$idso' and uap_anno='$anno' and uap_mes='$mm' and tp_id='$idtp' and a_id='$ida' and ga_id='$idga' and he_tipohora='1'";
									$resulthora=mysql_query($sqlhora);
									//echo $sqlhora."<br><br>";
									$alturaXH = $alturaX;
									$alturaXT = $alturaX;
									while ($rowh= mysql_fetch_array($resulthora)){
									$idh=$rowh['idhora'];
									//pregunta por el turno
									$sqlturno = "select h_id, concat(date_format(h_horaini,'%k:%i %p'),' - ',date_format(h_horafin,'%k:%i %p')) as hora, h_horaturn as turno, h_horanum as numhora from tb_horario where h_id='$idh'";
									$resultturno = mysql_query($sqlturno);
									//echo $sqlturno."<br><br>";
									while ($rowtt= mysql_fetch_array($resultturno)){
									$horario = array($rowtt['hora'], $rowtt['turno'],$rowtt['numhora']);
									$wh= array($sumat*0.095, $sumat*0.025, $sumat*0.0455);
									$pdf->ImprimirTablaHorario($horario,25+$wa,$alturaXH ,$ha,$wh,'C');	
									$alturaXH = $alturaXH + $ha;
									}
									$diaprogea = array();
									for ($i=1;$i<=$numeroDeDias;$i++){
									$sqlconsultaturno="select (select h_horanum from tb_horario where h_id=a.h_id) as hora  from tb_horaeje a where a.j_id='$idj' and a.s_id='$ids' and a.uap_mes='$mm' and a.uap_anno='$anno' and a.he_dia='$i' and a.h_id='$idh' and a.a_id='$ida' and a.ga_id='$idga' and a.tp_id='$idtp' and a.he_idserva='$idso' and a.he_tipohora=1 and a.ug_id='$ugid'";
									//echo $sqlconsultaturno."<br>";
									//echo $sqlconsultaturno."<br>";
									$resultcontur = mysql_query($sqlconsultaturno);
									$dia= date("w",mktime( 0, 0, 0, $mm, $i, $anno )); 
									if(mysql_num_rows($resultcontur)==0){
									switch ($dia) {
									    case 0: $diaprogea[$i-1]=" "; break;
									    case 1: 
									    case 2:
									    case 3:
									    case 4:
									    case 5:
									    case 6:
									        $diaprogea[$i-1]=" "; break;
									}

									}else{
									while($rowt= mysql_fetch_array($resultcontur)){
									$hrord = $rowt['hora'];
										switch ($dia) {
									    case 0: $diaprogea[$i-1]=$hrord; break;
									    case 1: 
									    case 2:
									    case 3:
									    case 4:
									    case 5:
									    case 6:
									        $diaprogea[$i-1]=$hrord; break;
									}}
									}
									}
									$pdf->ImprimirDiasHoras($diaprogea,$posicionx,$alturaXT,$ha,$ancho,$alinea,$pintap);
					//horas por turno
					$askhrsturno = "select sum(b.h_horanum) as sumhrs from tb_horaeje a inner join tb_horario b on a.h_id=b.h_id where a.j_id='$idj' and a.s_id='$ids' and a.uap_mes='$mm' and a.uap_anno='$anno' and a.h_id='$idh' and a.a_id='$ida' and a.ga_id='$idga' and a.tp_id='$idtp' and a.he_idserva='$idso' and a.he_tipohora=1 and a.ug_id='$ugid' group by a.h_id";
					$resultaskhrst = mysql_query($askhrsturno);
					$wst= $sumat - ($sumat*0.12 + $sumat*0.165 + $suma);
					if(mysql_num_rows($resultaskhrst)==0){
						$pdf->ImprimirTablaArea(0,$posicionx2, $alturaXT, $ha, $wst,'C',2,1);
					}else{
						while($rowht= mysql_fetch_array($resultaskhrst)){
						$totalhorasturno = $rowht['sumhrs'];
						$pdf->ImprimirTablaArea($totalhorasturno,$posicionx2, $alturaXT, $ha, $wst,'C',2,1);
						}
					}
					$alturaXT = $alturaXT + $ha;
				}	
					$alturaX = $alturaX + $ha*$cantreg; 
				}
					}
				}	
				
				//sub cantidades de los grupos de areas
									$subthrsprog = array();
									for ($i=1;$i<=$numeroDeDias;$i++){
										$sqlaskhrsga = "select sum(b.h_horanum) as numhrs from tb_horaeje a inner join tb_horario b on a.h_id = b.h_id where a.j_id='$idj' and a.s_id='$ids' and a.uap_mes='$mm' and a.uap_anno='$anno' and a.he_dia='$i' and a.ga_id='$idga' and a.tp_id='$idtp' and a.he_idserva='$idso' and a.he_tipohora=1 and a.ug_id='$ugid'";
										//echo $sqlaskhrsga."<br>";
										$resultaskhrstga = mysql_query($sqlaskhrsga);
										if(mysql_num_rows($resultaskhrstga)!=0){
										while($rownh= mysql_fetch_array($resultaskhrstga)){
										$numhrs = $rownh['numhrs'];
										$subthrsprog[$i-1] = $rownh['numhrs'];
										}
										}else{
										//echo $sqlaskhrsga."<br>";
										$subthrsprog[$i-1] = 0;
										}
									}
									$sqlsumahrs="select sum(b.h_horanum) as tothrs from tb_horaeje a inner join tb_horario b on a.h_id = b.h_id where a.j_id='$idj' and a.s_id='$ids' and a.uap_mes='$mm' and a.uap_anno='$anno' and a.ga_id='$idga' and a.tp_id='$idtp' and a.he_idserva='$idso' and a.he_tipohora=1 and a.ug_id='$ugid'";
									$resultsumahrs = mysql_query($sqlsumahrs);
									while($rowth= mysql_fetch_array($resultsumahrs)){
												$tothrs = $rowth['tothrs'];
									}
									$wast = $sumat*0.2855;
									$wst= $sumat - ($sumat*0.12 + $sumat*0.165 + $suma);
									$txtst = 'SUB TOTAL DE HORAS';
									$pdf->ImprimirTablaArea($txtst,25,$alturaX,$ha,$wast,'C',2,1);		
								    $pdf->ImprimirDiasHoras($subthrsprog,$posicionx,$alturaX,$ha,$ancho,$alinea,$pintast);
									$pdf->ImprimirTablaArea($tothrs,$posicionx2, $alturaX, $ha, $wst,'C',2,1);
									$alturaX = $alturaX + $ha;	
			    
								
				}}
					//total de hrs extras
				$totalhrs = array();
				for ($i=1;$i<=$numeroDeDias;$i++){
										$sqlaskhrt = "select sum(b.h_horanum) as numhrs from tb_horaeje a inner join tb_horario b on a.h_id = b.h_id where a.j_id='$idj' and a.s_id='$ids' and a.uap_mes='$mm' and a.uap_anno='$anno' and a.he_dia='$i' and a.tp_id='$idtp' and a.he_idserva='$idso' and a.he_tipohora=1 and a.ug_id='$ugid'";
										//echo $sqlaskhrsga."<br>";
										$resultaskhrt = mysql_query($sqlaskhrt);
										if(mysql_num_rows($resultaskhrt)!=0){
										while($rownh= mysql_fetch_array($resultaskhrt)){
										$numhrs = $rownh['numhrs'];
										$totalhrs[$i-1]= $numhrs;
										}
										}else{
										//echo $sqlaskhrsga."<br>";
										$totalhrs[$i-1]= 0;
										}
									}
									$sqlsumath="select sum(b.h_horanum) as tothrs from tb_horaeje a inner join tb_horario b on a.h_id = b.h_id where a.j_id='$idj' and a.s_id='$ids' and a.uap_mes='$mm' and a.uap_anno='$anno' and a.tp_id='$idtp' and a.he_idserva='$idso' and a.he_tipohora=1 and a.ug_id='$ugid'";
									$resultsumatr = mysql_query($sqlsumath);
									while($rowth= mysql_fetch_array($resultsumatr)){
												$tothrs = $rowth['tothrs'];
									}
									
						$wast = $sumat*0.2855;
						$wst= $sumat - ($sumat*0.12 + $sumat*0.165 + $suma);
						$txtst = 'TOTAL DE HORAS EXTRAS';
						$pdf->ImprimirTablaArea($txtst,25,$alturaX,$ha,$wast,'C',2,1);		
					    $pdf->ImprimirDiasHoras($totalhrs,$posicionx,$alturaX,$ha,$ancho,$alinea,$pintat);
						$pdf->ImprimirTablaArea($tothrs,$posicionx2, $alturaX, $ha, $wst,'C',2,1);
						$alturaX = $alturaX + $ha;
	
	
	
	//////termina las horas extras
	}
			
	}
	if(($aaa==1 && $bbb==1) || ($eee==1 && $bbb==1)){
			$dato7cab=array('OBSERVACIONES:','');
			$dato8cab=array('','Firma del Jefe del Servicio','','Firma del Jefe del Departamento','');
			$w7=array($sumat*0.2855,$sumat*0.7145);
			$alig7=array('C','C');
			$w8=array($sumat*0.15,$sumat*0.25,$sumat*0.15,$sumat*0.25,$sumat*0.15);
			$alig8=array('C','C','C','C','C');
			$hh = $ha*2.3;
			$pdf->ImprimirTablaSinColorLineal($dato7cab,25,$alturaX,$hh,$w7, $alig7);
			$alturaX = $alturaX + 3.5*$ha + $hh;
			$dibu =array(0,'T',0,'T',0);
			$pdf->ImprimirTablaSinColorFirma($dato8cab,25,$alturaX,$ha,$w8, $alig8,$dibu);
	}
////////////////
$pdf->Output();

?>
