<?php

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

//class DescansoMedico extends Conectar
class DescansoMedico
{
	//private $visitas=array();
	private $lis_dm=array();
	private $cod_dm;
	private $num_hrs_dm;
	private $num_hrs_dm_mes=array();
	
	//busca el id del ultimo descanso medico registrado
	public function buscar_id_descmed($con,$ugid)
	{
		$sql="select v_id from tb_desmed where ug_id='$ugid' order by v_id desc limit 1";
		$res=mysqli_query($con, $sql);
		while ($reg=mysqli_fetch_assoc($res))
		{
			$this->cod_dm=$reg['v_id'];
		}
			return $this->cod_dm;
	}
	
	//consulta si una fecha esta dentro del rango del descanso medico
	public function consultar_descmed_fecha($con,$codper,$fecha) 
	{
		$sql="SELECT ug_id FROM tb_descmed where ug_id='$codper' and date('$fecha') between date(dm_fechaini) and date(dm_fechafin)";
			//echo $sql;
		$res=mysqli_query($con, $sql);
		while ($reg=mysqli_fetch_assoc($res))
		{
			$this->lis_dm[]=$reg;
		}
			return $this->lis_dm;
	}
	
	//contabiliza la cantidad de hrs suspendidas por descanso medico
	public function consultar_descmed_hrssuspen($con,$codper,$idtp,$anno,$mm,$thora) 
	{
		$sql="SELECT sum(b.h_horanum) as numhrs FROM tb_horasusp_dm a inner join tb_horario b on a.h_id=b.h_id where a.tp_id='$idtp' and a.ug_id='$codper' and a.uap_anno='$anno' and a.uap_mes='$mm' and a.hs_tipohora='0'";
			//echo $sql."<br>";
		$res=mysqli_query($con, $sql);
		while ($reg=mysqli_fetch_assoc($res))
		{
			$this->num_hrs_dm=$reg['numhrs'];
		}
			return $this->num_hrs_dm;
	}

		public function consultar_descmed_anno_mes($con,$codper,$anno,$mm) 
	{
		$sql="select dm_id as id, concat(date_format(dm_fechaini,'%d/%m/%Y'),' AL ', date_format(dm_fechafin,'%d/%m/%Y')) as fecha from tb_descmed where ((year(dm_fechaini)='$anno' and month(dm_fechaini)='$mm') or (year(dm_fechafin)='$anno' and month(dm_fechafin)='$mm')) and ug_id='$codper'";
			//echo $sql;
		$res=mysqli_query($con, $sql);
		while ($reg=mysqli_fetch_assoc($res))
		{
			$this->num_hrs_dm_mes[]=$reg;
		}
			return $this->num_hrs_dm_mes;
	}
	
}
?>