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

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

$idj=$_GET['idj'];
$ids=$_GET['ids'];
//$idtp=1;
//$anno=2011;
//$mm=1;
$ugid=$_GET['ugid'];
$fecha=$_GET['fecha'];
//$ugid=$_GET['ugid'];
//$idj=$_GET['idj'];
//$ids=$_GET['ids'];
//$fecha=$_GET['fecha'];
//$ugid=$_GET['ugid'];
$diap=substr($fecha, 0, 2);
$mm=substr($fecha, 3, 2);
$anno=substr($fecha, 6, 4);


require_once("../class/class.conectar.php");

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

//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 = mysqli_query($conex,$sqldepa);
$resultserv = mysqli_query($conex,$sqlserv);
$a=0;
$cad="";
$serv[] = array();
$nomserv[] = array();
while ($rows= mysqli_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= mysqli_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, ";
$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'];
$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'=>'SEPTIEMBRE');
$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('APELLIDOS Y NOMBRES','GRUPO OCUPACIONAL','DNI','GUARDIA DIRUNA','GUARDIA NOCTURNA');

$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;
}
}

function fechadia($i,$mm, $anno){

$dia= date("w",mktime( 0, 0, 0, $mm, $i, $anno )); 
switch ($dia) {
    case 0:
        $diafecha= 'DOMINGO';
		break;
    case 1:
        $diafecha= 'LUNES';
        break;
    case 2:
        $diafecha= 'MARTES';
        break;
	case 3:
        $diafecha= 'MIERCOLES';
        break;
	case 4:
        $diafecha= 'JUEVES';
        break;
	case 5:
        $diafecha= 'VIERNES';
        break;
	case 6:
        $diafecha= 'SABADO';
        break;
}
$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'=>'SEPTIEMBRE');
$arraymes[] = array('idmes'=>'10','mes'=>'OCTUBRE');
$arraymes[] = array('idmes'=>'11','mes'=>'NOVIEMBRE');
$arraymes[] = array('idmes'=>'12','mes'=>'DICIEMBRE');

$diafecha = $diafecha.", ".$i." DE ".$arraymes[$mm-1]['mes']." DEL ".$anno;

return $diafecha;
}

$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 ImprimirTablaTitulo2($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
	  	
	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 ImprimirTablaDisminuirTitulo($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',5);
	$this->SetXY($x,$y);
    //Datos
	  	
	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);
        }
	$this->SetFont('','B',7);
}

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 ImprimirTablaSinColorTitulo($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,$h,$data,$dibuja,0,$alig,$dib);
		//$dib = !$dib;
//    }
		//$y = $y + $h;
		//$this->SetXY($x,$y);
		
    //}

}
function ImprimirTablaConColorTitulo($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=true;
   	//for($i=0;$i<count($data);$i++)
    //{
	        $this->Cell($w,$h,$data,$dibuja,0,$alig,$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[$j],$dib);
		//$dib = !$dib;
		$x = $x + $w[$j];
		$this->SetXY($x,$y);
        }
}

function ImprimirTablaHorario2($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',5);
	$this->SetXY($x,$y);
	//$pdf->SetFont('Helvetica','B',9);
    //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);
        }
	$this->SetFont('','B',7);
}

function ImprimirTablaSinColorTitulo2($data,$x, $y, $h, $w,$alig,$dibuja)
{
    $this->SetFillColor(254,259,152);
    $this->SetTextColor(0);
    $this->SetDrawColor(128,0,0);
    $this->SetLineWidth(.3);	
    $this->SetFont('','B');
	$this->SetXY($x,$y);
    //Datos
	$dib=true;
   	//for($i=0;$i<count($data);$i++)
    //{
	        $this->Cell($w,$h,$data,$dibuja,0,$alig,$dib);
		//$dib = !$dib;
//    }
		//$y = $y + $h;
		//$this->SetXY($x,$y);
		
    //}

}
function ImprimirTablaPersonal($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[$j],$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 ImprimirTablaJustificada2($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($j=0;$j<count($w);$j++)
		{
		$this->MultiCell($w[$j],$h,$data[$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 = 5.5;

$pdf=new PDF();
//$pdf->FPDF('L');
$pdf->__construct('L');

$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;
$posicionx2 = ($sumat - ($posicionx + $suma)) - 14.75;

$alig6 = array('L','C','C');
$w6 = array($sumat*0.12,$sumat*0.12, $sumat*0.0455);


//if(mysql_num_rows($resultcontur)!=0){
////AREA
$mes = mktime( 0, 0, 0, $mm, 1, $anno ); 
$numeroDeDias = intval(date("t",$mes)); 
/*
//$sqla = "select a.ga_id as idga, a.a_id as ida, b.a_desc as adesc, b.a_tipo as atipo  from tb_areaservicio a inner join tb_area b on a.ga_id=b.ga_id and a.a_id=b.a_id where a.s_id='$ids' and a.j_id='$idj' and a.ga_id='$idga'";
$sqlar = "select b.ga_id as id, (select ga_desc from tb_garea where ga_id=a.ga_id) as garea from tb_areaservicio a inner join tb_area b on a.a_id=b.a_id and a.ga_id=b.ga_id where a.s_id='$ids' and a.j_id='$idj' and a.ga_id='$idga' group by b.ga_id";
//echo $sqlar."<br>";
// busca el nombre del area
$resultar = mysqli_query($conex,$sqlar);
//echo $sqlar."<br>";
if ($resultar == false){
echo 'PROVOCO UN ERROR EN LA CONSULTA 2';
}else{
while ($rowar= mysqli_fetch_array($resultar)){
$garea = $rowar['garea'];
}}
*/
///////////////////////////////////////
//nombre de la jefatura
$sqljefatura = "select j_desc as nom from tb_jefatura where j_id='$idj'";
$resultjefatura = mysqli_query($conex,$sqljefatura);
while ($rowj= mysqli_fetch_array($resultjefatura)){
$nomjefatura = $rowj['nom']; 
}
//nombre de servicio
$sqlserv = "select s_desc as nom from tb_servicio where j_id='$idj' and s_id='$ids'";
$resultserv = mysqli_query($conex,$sqlserv);
while ($rows= mysqli_fetch_array($resultserv)){
$nomservicio = $rows['nom']; 
}

////////////////////////////////////
//////PROGRAMACION DEL DIA

setlocale(LC_TIME,"spanish"); 
$cadenafecha = strftime("Hoy es %A, %d de %B del %Y." ,time());

$pdf->AddPage('P');
$pdf->SetTextColor(0);
$sumat = 295;
$pdf->SetFont('Helvetica','B',9);
$pdf->Image('../img/logoincor.jpg', 10, 4, 41, 14,'jpg');
$pdf->Image('../img/logoessalud.jpg', 160, 6, 36, 9,'jpg');
$texto = "CONSOLIDADOS DE HORAS PROGRAMADOS DEL PERSONAL ASISTENCIAL";
$ini = 16;
$pdf->ImprimirTablaSinColorTitulo("LISTA DE PROVICION DE ALIMENTOS DEL ".$nomjefatura,11,$ini,$ha,$sumat*0.65,'C',0);
$ini = $ini + $ha;
$pdf->ImprimirTablaSinColorTitulo($nomservicio,11,$ini,$ha,$sumat*0.65,'C',0);
$ini = $ini + $ha*1.9;
$pdf->SetFont('Helvetica','B',9);
$fechad = fechadia($diap,$mm,$anno);
$pdf->ImprimirTablaSinColorTitulo($fechad,11,$ini,$ha,$sumat*0.65,'C',0);
$ini = $ini + 1.3*$ha;
$pdf->SetFont('Arial','B',7);
						//$subtitulo = array('APELLIDOS Y NOMBRES','GRUPO OCUPACIONAL','DNI','GUARDIA DIURNA','GUARDIA NOCTURNA');
					    $subtitulo = array('APELLIDOS Y NOMBRES','GRUPO OCUPACIONAL','DNI');
						$subtitulo2 = array('GUARDIA DIURNA','GUARDIA NOCTURNA');
						$wh= array($sumat*0.20, $sumat*0.13, $sumat*0.08);
						
											
						$xx = $sumat*0.20 + $sumat*0.13 + $sumat*0.08;
						$wh2= array($sumat*0.07,$sumat*0.07);
						$pdf->ImprimirTablaTitulo2($subtitulo,25,$ini,$ha,$wh,'C',1);	
						$pdf->ImprimirTablaDisminuirTitulo($subtitulo2,25+$xx,$ini,$ha,$wh2,'C',1);				
						$ini = $ini + $ha;

//pregunta por personal programado en la manana o diurno
$personalman="select a.ug_id as ugid, a.ut_codprog as codprog, (select ua_dni from tb_usuasist where ug_id=a.ug_id) as dni, (select concat(ua_apepat,' ',ua_apemat,' ',ua_nom) from tb_usuasist where ug_id=a.ug_id) as nombre, c.h_id as idh, concat(date_format(c.h_horaini,'%k:%i %p'), ' - ',date_format(c.h_horafin,'%k:%i %p')) as hora,c.h_horaturn as turno, a.hr_tipohora as thora, (select tp_desc from tb_tipoperson where tp_id = a.tp_id) as grupoocup from tb_horareprog".$anno." a inner join tb_horario c on a.h_id = c.h_id where a.hr_dia='$diap' and a.uap_anno='$anno' and a.uap_mes='$mm' and a.hr_idserva='$ids' and a.j_id='$idj' and c.h_horaturn in ('D','N') and c.h_horatipo=1 and a.hr_tipohora=0 and a.ug_id not in (select ug_id from tb_usudep where tc_idcont='8' and ua_estado !=0) order by nombre";

//echo $personalman."<br>";
$resultperprogman = mysqli_query($conex,$personalman);

//1 D,M - 2 M - 3 T - 4 N
if(mysqli_num_rows($resultperprogman)>0){

while ($rowp= mysqli_fetch_array($resultperprogman)){
$datos = array();
$nombre=utf8_decode($rowp['nombre']);
$go=$rowp['grupoocup'];
$dni=$rowp['dni'];
$turno = $rowp['turno'];
if($turno == 'D')
$datos = array($nombre,$go,$dni,'X','');
if($turno == 'N')
$datos = array($nombre,$go,$dni,'','X');

$wh3= array($sumat*0.20, $sumat*0.13, $sumat*0.08,$sumat*0.07,$sumat*0.07);
$alinear = array('L','C','C','C','C');	
$pdf->ImprimirTablaHorario($datos,25,$ini,$ha,$wh3,$alinear);
$ini = $ini + $ha;	
}
}//fin del bucle del personal

$ini = $ini + 35;	
$titulofin1="Firma y Sello del Responsable";
$titulofin2="Fecha y Hora de Entrega:";
$pdf->Text(40,$ini,$titulofin1);
$pdf->Text(135,$ini,$titulofin2);


///////////////////
$pdf->Output();

?>
