<?php

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

//class GrupoArea extends Conectar
class GrupoArea
{
	
	private $lis_garea=array();
	private $lis_garea_prog=array();
	private $lis_garea_reprog=array();
	
	
	public function listar_garea($con)
	{
		$sql="select ga_id as cod, ga_desc as descripcion from tb_garea";
		$res=mysqli_query($con, $sql);
		while ($reg=mysqli_fetch_assoc($res))
		{
			$this->lis_garea[]=$reg;
		}
			return $this->lis_garea;
	}
	
	public function listar_garea_dep($con,$idj,$ids,$idtp)
	{
		$sql="select a.ga_id as id, (select ga_desc from tb_garea where ga_id=a.ga_id) as area from tb_areaservicio a where a.s_id='$ids' and a.j_id='$idj' and a.tp_id='$idtp' group by a.ga_id";
		$res=mysqli_query($con, $sql);
		while ($reg=mysqli_fetch_assoc($res))
		{
			$this->lis_garea[]=$reg;
		}
			return $this->lis_garea;
	}
	
	public function listar_garea_prog($con,$anno,$mm,$idj,$ids,$idso,$idtp,$ugid,$thora)
	{
		$sql="select distinct(a.ga_id) as idga, b.ga_desc as garea from tb_subhoraprog".$anno." a inner join tb_garea b on a.ga_id=b.ga_id 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.hp_idserva='$idso' and a.ug_id='$ugid' and a.shp_tipohora='$thora' order by idga asc";
		//echo $sql."<br>";
		$res=mysqli_query($con, $sql);
		while ($reg=mysqli_fetch_assoc($res))
		{
			$this->lis_garea_prog[]=$reg;
		}
			return $this->lis_garea_prog;
	
	
	}
	
	public function listar_garea_reprog($con,$anno,$mm,$idj,$ids,$idso,$idtp,$ugid,$thora)
	{
		$sql="select distinct(a.ga_id) as idga, b.ga_desc as garea from tb_subhorareprog".$anno." a inner join tb_garea b on a.ga_id=b.ga_id 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.hr_idserva='$idso' and a.ug_id='$ugid' and a.shr_tipohora='$thora' order by idga asc";
		echo $sql."<br>";
		$res=mysqli_query($con, $sql);
		while ($reg=mysqli_fetch_assoc($res))
		{
			$this->lis_garea_reprog[]=$reg;
		}
			return $this->lis_garea_reprog;
	
	
	}
	
	public function listar_garea_eje($con,$anno,$mm,$idj,$ids,$idso,$idtp,$ugid,$thora)
	{
		$sql="select distinct(a.ga_id) as idga, b.ga_desc as garea from tb_subhoraeje".$anno." a inner join tb_garea b on a.ga_id=b.ga_id 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.she_tipohora='$thora' order by idga asc";
		//echo $sql."<br>";
		$res=mysqli_query($con, $sql);
		while ($reg=mysqli_fetch_assoc($res))
		{
			$this->lis_garea_reprog[]=$reg;
		}
			return $this->lis_garea_reprog;
	
	
	}
	
	public function buscar_garea_dep_serv($con,$idj,$ids,$idtp,$idga)
	{
		$sql="select b.ga_id as id, (select ga_desc from tb_garea where ga_id=a.ga_id) as nom 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' and a.tp_id='$idtp' group by b.ga_id";
		//echo $sql."<br>";
		$res=mysqli_query($con, $sql);
		while ($reg=mysqli_fetch_assoc($res))
		{
			$this->lis_garea_prog[]=$reg;
		}
			return $this->lis_garea_prog;
	
	
	}
	
		
	
}
?>