<?php

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

//class Area extends Conectar
class Area
{
	
	private $lis_area=array();
	private $ask_area=array();
	private $lis_garea_prog=array();
	private $lis_garea_reprog1=array();
	private $lis_garea_reprog2=array();
	private $lis_garea_prog_all=array();
	private $lis_garea_prog_all_r=array();
	private $lis_garea_prog_dep=array();
	
		
	public function listar_area($con,$idga)
	{
		$sql="select a_id as cod, a_desc as nom from tb_area where ga_id='$idga'";
		$res=mysqli_query($con, $sql);
		while ($reg=mysqli_fetch_assoc($res))
		{
			$this->lis_area[]=$reg;
		}
			return $this->lis_area;
	}
	
	public function ask_area_id($con,$idga,$ida)
	{
		$sql="select a_id as cod, a_desc as nom from tb_area where ga_id='$idga' and a_id='$ida'";
		$res=mysqli_query($con, $sql);
		while ($reg=mysqli_fetch_assoc($res))
		{
			$this->ask_area[]=$reg;
		}
			return $this->ask_area;
	}
	
		public function listar_area_prog($con,$anno,$mm,$idj,$ids,$idso,$idtp,$ugid,$idga,$thora)
	{
		$sql="select distinct(a.a_id) as ida,(select a_desc from tb_area where ga_id=a.ga_id and a_id=a.a_id) as area from tb_subhoraprog".$anno." a where a.ga_id='$idga' and a.tp_id='$idtp' and a.uap_anno='$anno' and a.uap_mes='$mm' and a.j_id='$idj' and a.hp_idserva='$idso' and a.s_id='$ids' and a.ug_id='$ugid' and a.shp_tipohora='$thora' and (((a.shp_numho + a.shp_numhe)>0) or (a.a_id = 9 and a.ga_id=18))";
		//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_area_reprog($con,$anno,$mm,$idj,$ids,$idso,$idtp,$ugid,$idga,$thora)
	{
		$sql="select distinct(a.a_id) as ida,(select a_desc from tb_area where ga_id=a.ga_id and a_id=a.a_id) as area from tb_subhorareprog".$anno." a where a.ga_id='$idga' and a.tp_id='$idtp' and a.uap_anno='$anno' and a.uap_mes='$mm' and a.j_id='$idj' and a.hr_idserva='$idso' and a.s_id='$ids' and a.ug_id='$ugid' and a.shr_tipohora='$thora' and (a.shr_numho + a.shr_numhe)>0";
		//echo $sql."<br>";
		$res=mysqli_query($con, $sql);
		while ($reg=mysqli_fetch_assoc($res))
		{
			$this->lis_garea_reprog1[]=$reg;
		}
			return $this->lis_garea_reprog1;
	
	
	}
	
		public function listar_area_eje($con,$anno,$mm,$idj,$ids,$idso,$idtp,$ugid,$idga,$thora)
	{
		$sql="select distinct(a.a_id) as ida,(select a_desc from tb_area where ga_id=a.ga_id and a_id=a.a_id) as area from tb_subhoraeje".$anno." a where a.ga_id='$idga' and a.tp_id='$idtp' and a.uap_anno='$anno' and a.uap_mes='$mm' and a.j_id='$idj' and a.he_idserva='$idso' and a.s_id='$ids' and a.ug_id='$ugid' and a.she_tipohora='$thora' and (a.she_numho + a.she_numhe)>0";
		//echo $sql."<br>";
		$res=mysqli_query($con, $sql);
		while ($reg=mysqli_fetch_assoc($res))
		{
			$this->lis_garea_reprog2[]=$reg;
		}
			return $this->lis_garea_reprog2;
	
	
	}
	
	public function listar_area_prog_all($con,$anno,$mm,$idj,$ids,$idtp,$idga)
	{
		$sql="select distinct(a.a_id) as ida,(select a_desc from tb_area where ga_id=a.ga_id and a_id=a.a_id) as area from tb_subhoraprog".$anno." a where a.ga_id='$idga' and a.tp_id='$idtp' and a.uap_anno='$anno' and a.uap_mes='$mm' and a.j_id='$idj' and a.hp_idserva='$ids'  and ((a.shp_numho+ a.shp_numhe)>0 or (a.a_id = 9 and a.ga_id=18)) order by a_id asc";
		//echo $sql."<br>";
		$res=mysqli_query($con, $sql);
		while ($reg=mysqli_fetch_assoc($res))
		{
			$this->lis_garea_prog_all[]=$reg;
		}
			return $this->lis_garea_prog_all;
	
	
	}
	
	//lista toda las areas en la reprograamcion
	public function listar_area_prog_all_repro($con,$anno,$mm,$idj,$ids,$idtp,$idga)
	{
		$sql="select distinct(a.a_id) as ida,(select a_desc from tb_area where ga_id=a.ga_id and a_id=a.a_id) as area from tb_subhorareprog".$anno." a where a.ga_id='$idga' and a.tp_id='$idtp' and a.uap_anno='$anno' and a.uap_mes='$mm' and a.j_id='$idj' and a.hr_idserva='$ids' and (a.shr_numho + a.shr_numhe>0) order by a_id asc";
		//echo $sql."<br>";
		$res=mysqli_query($con, $sql);
		while ($reg=mysqli_fetch_assoc($res))
		{
			$this->lis_garea_prog_all_r[]=$reg;
		}
			return $this->lis_garea_prog_all_r;
	
	
	}
	
	
	
		public function listar_area_dep_serv($con,$idj,$ids,$idtp,$idga)
	{
		$sql="select a.ga_id as idga, a.a_id as ida, b.a_desc as nom, 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' and a.tp_id='$idtp'";
		//echo $sql."<br>";
		$res=mysqli_query($con, $sql);
		while ($reg=mysqli_fetch_assoc($res))
		{
			$this->lis_garea_prog_dep[]=$reg;
		}
			return $this->lis_garea_prog_dep;
	
	
	}
		
	
}
?>