<?php

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

//class Personal extends Conectar
class Personal 
{
	
	private $lis_per=array();
	private $lis_fing=array();
	private $lis_datos_per=array();
	private $lis_datos_per2=array();
	private $lis_datos_per_campo=array();
	private $hrsprog;
	private $dia_cumple=array();
	private $dia_cumple2=array();
	
		
	public function buscar_nombre($con,$ugid)
	{
		$sql="select concat(ua_apepat,' ',ua_apemat,' ',ua_nom) as nombre from tb_usuasist where ug_id='$ugid'";
		$res=mysqli_query($con, $sql);
		while ($reg=mysqli_fetch_assoc($res))
		{
			$this->lis_per[]=$reg;
		}
			return $this->lis_per;
	}
	
	public function buscar_fechaing($con,$ugid)
	{
		$sql="select date_format(ud_fechaing,'%d/%m/%Y') as fechaing from tb_usudep where ug_id='$ugid'";
		$res=mysqli_query($con, $sql);
		while ($reg=mysqli_fetch_assoc($res))
		{
			$this->lis_fing[]=$reg;
		}
			return $this->lis_fing;
	}
	
	
	public function buscar_datos_per($con,$ugid)
	{
	$sql="select a.ug_id as codigo, CONCAT(a.ua_apepat,' ',a.ua_apemat,' ',a.ua_nom) as nombre, a.ua_dni as dni,  ";
	$sql= $sql." (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,";
	$sql= $sql." (select c_desc from tb_cargo where c_id=b.c_id) as cargo, (select esp_desc from tb_especialidad where ua_idespec=b.ua_idespec) as especialidad,";
	$sql= $sql." a.ua_numplanilla as planilla, a.ua_numcoleg as numcoleg,a.ua_numesp as numesp,b.tc_idcont as idcont from tb_usuasist a inner join tb_usudep b on a.ug_id=b.ug_id where a.ug_id='$ugid' and b.ua_estado not in (0)";
	//echo $sql."<br>";
	$res=mysqli_query($con, $sql);
		while ($reg=mysqli_fetch_assoc($res))
		{
			$this->lis_datos_per[]=$reg;
		}
			return $this->lis_datos_per;
	}
	
	public function buscar_datos_per2($con,$ugid)
	{
	$sql="select a.ug_id as codigo, CONCAT(a.ua_apepat,' ',a.ua_apemat,' ',a.ua_nom) as nombre, a.ua_dni as dni,  ";
	$sql= $sql." (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,";
	$sql= $sql." (select c_desc from tb_cargo where c_id=b.c_id) as cargo, (select esp_desc from tb_especialidad where ua_idespec=b.ua_idespec) as especialidad,";
	$sql= $sql." a.ua_numplanilla as planilla, a.ua_numcoleg as numcoleg,a.ua_numesp as numesp,b.tc_idcont as idcont from tb_usuasist a inner join tb_usudep b on a.ug_id=b.ug_id where a.ug_id='$ugid' and b.ua_estado not in (0)";
	//echo $sql."<br>";
	$res=mysqli_query($con, $sql);
		while ($reg=mysqli_fetch_assoc($res))
		{
			$this->lis_datos_per2[]=$reg;
		}
			return $this->lis_datos_per2;
	}
	
	public function buscar_datos_per_campo($con,$ugid)
	{
	$sql="select CONCAT(a.ua_apepat,' ',a.ua_apemat,' ',a.ua_nom) as nombre, a.ua_apepat as apepat, a.ua_apemat as apemat, a.ua_nom as nom, b.ua_idespec as idesp, b.tc_idcont as idcont, b.tp_id as idtp, date_format(b.ud_fechaing,'%d/%m/%Y') as fechaing,b.c_id as idc  from tb_usuasist a inner join tb_usudep b on a.ug_id = b.ug_id where a.ug_id='$ugid' and b.ua_estado not in ('0')";
	$res=mysqli_query($con, $sql);
		while ($reg=mysqli_fetch_assoc($res))
		{
			$this->lis_datos_per_campo[]=$reg;
		}
			return $this->lis_datos_per_campo;
	}
	
	public function contar_hrsprog($con,$ugid)
	{
		$sql="select b.tc_hrsprog as hora from tb_usudep a inner join tb_tipocont b on a.tc_idcont = b.tc_idcont where a.ug_id='$ugid' and a.ua_estado not in ('0')";
		$res=mysqli_query($con, $sql);
		while ($reg=mysqli_fetch_assoc($res))
		{
			$this->hrsprog=$reg['hora'];
		}
			return $this->hrsprog;
	}
	
	public function ask_cumple($con,$dia,$mm,$codper)
	{
		$sql="SELECT ug_id FROM tb_usuasist where day(ua_fechanac)='$dia' and month(ua_fechanac)='$mm' and ug_id='$codper'";
		//echo $sql."<br>";
		$res=mysqli_query($con, $sql);
		while ($reg=mysqli_fetch_assoc($res))
		{
			$this->dia_cumple[]=$reg;
		}
			return $this->dia_cumple;
	}
	public function ask_cumple_mes_per($con,$mm,$codper)
	{
		$sql="select day(ua_fechanac) as onomastico from tb_usuasist where ug_id='$codper' and month(ua_fechanac)='$mm'";
		//echo $sql."<br>";
		$res=mysqli_query($con, $sql);
		while ($reg=mysqli_fetch_assoc($res))
		{
			$this->dia_cumple2[]=$reg;
		}
			return $this->dia_cumple2;
	}
	
	public function modifcar_datos_per($con,$ugid,$apepat,$apemat,$nom)
	{
		$sql="update tb_usuasist set ua_apepat=upper('$apepat'), ua_apemat=upper('$apemat'), ua_nom=upper('$nom') where ug_id='$ugid'";
		//echo $sql."<br>";
		$res=mysqli_query($con, $sql);
		
	}
	
	public function modifcar_codprog_per($con,$codprog,$cod)
	{
		$sql="update tb_usuasist set ua_codprog='$codprog' where ug_id='$cod'";
		$res=mysqli_query($con, $sql);
		
	}
	
	public function registrar_datos_per_nuevo($con,$ugid,$cont,$apepat,$apemat,$nom)
	{
		$sql="insert into tb_usuasist (ug_id, contador, ua_apepat, ua_apemat, ua_nom) values ('$ugid','$cont',upper('$apepat'),upper('$apemat'),upper('$nom'))";
		//echo $sql."<br>";
		$res=mysqli_query($con, $sql);
		
	}
	
	
}
?>