<?php

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

//class Horario extends Conectar
class Horario 
{
	
	private $lis_hr=array();
	private $lis_hr_prog =array();
	private $bu_hr =array();
	private $bu_hr_det =array();
	private $lis_hr_dep =array();
	private $lis_hr_all =array();
	private $lis_hr_prog_a =array();
	private $lis_hr_reprog_a =array();
	private $num_hr_prog_all;
	private $num_hr_prog;
	private $num_hr_reprog;
	private $num_hrs_per=0;
	private $num_hrs_per_reprog=0;
	private $sum_hrs_per_t;
	private $sum_hrs_per_t_reprog;
	private $sum_hrs_per_d;
	private $sum_hrs_per_ga;
	private $sum_hrs_per_ga_reprog;
	private $sum_hrs_per_ga_dia;
	private $sum_hrs_per_ga_dia_reprog;
	private $sum_hrs_per_to;
	private $sum_hrs_per_to_reprog;
	private $to_hrs_per;
	private $to_hrs_per2;
	
	
	public function buscar_horario($con,$idh)
	{
		$sql="select h_id as id, concat(date_format(h_horaini,'%k:%i %p'),' - ',date_format(h_horafin,'%k:%i %p')) as hora, h_horaturn as turno, h_horanum as numhora from tb_horario where h_id='$idh'";
		//echo $sql."<br>";
		$res=mysqli_query($con, $sql);
		while ($reg=mysqli_fetch_assoc($res))
		{
			$this->bu_hr[]=$reg;
		}
			return $this->bu_hr;
	}
	
	public function buscar_horario_det($con,$idh)
	{
		$sql="select h_horaini as hori, h_horafin as horf, h_horaturn as hort, h_horanum as horn from tb_horario where h_id='$idh'";
		//echo $sql."<br>";
		$res=mysqli_query($con, $sql);
		if($res){
		while ($reg=mysqli_fetch_assoc($res))
		{
			$this->bu_hr_det[]=$reg;
		}
			return $this->bu_hr_det;
		}
	}
	
	public function lis_horario_dep($con,$idj,$ids,$idga,$ida,$est)
	{
		$sql="select a.h_id as idh, concat(date_format(b.h_horaini,'%k:%i %p'), ' - ',date_format(b.h_horafin,'%k:%i %p')) as hora, h_horaturn as turno, h_horanum as numhora from areahora a inner join tb_horario b on a.h_id=b.h_id where a.s_id='$ids' and a.j_id='$idj' and a.ga_id='$idga' and a.a_id='$ida' and a.ah_estado='$est'";
		//echo $sql."<br>";
		$res=mysqli_query($con, $sql);
		while ($reg=mysqli_fetch_assoc($res))
		{
			$this->lis_hr_dep[]=$reg;
		}
			return $this->lis_hr_dep;
	}
	
	//lista los horario que estan programados dentro de un area
	public function lis_horario_per($con,$anno,$mm,$idj,$ids,$idtp,$dia,$codprog)
	{
		$sql="SELECT a.ut_codprog as cod, a.ga_id as idga, (select h_horaini from tb_horario where h_id=a.h_id) as hori, (select h_horafin from tb_horario where h_id=a.h_id) as horf, (select h_horaturn from tb_horario where h_id=a.h_id) as hort, (select h_horanum from tb_horario where h_id=a.h_id) as horn, a.ga_id as idga, a.a_id as ida, a.h_id as idh FROM tb_horaprog".$anno." a   where a.uap_anno='$anno' and a.uap_mes='$mm' and a.j_id='$idj' and a.hp_idserva='$ids' and a.tp_id='$idtp' and a.hp_dia='$dia' and a.ut_codprog='$codprog'";
		//echo $sql."<br>";
		$res=mysqli_query($con, $sql);
		while ($reg=mysqli_fetch_assoc($res))
		{
			$this->lis_hr[]=$reg;
		}
			return $this->lis_hr;
	}
	
	//lista los horario que estan reprogramados dentro de un area
	public function lis_horario_per_repro($con,$anno,$mm,$idj,$ids,$idtp,$dia,$codprog)
	{
		$sql="SELECT a.ut_codprog as cod, a.ga_id as idga, (select h_horaini from tb_horario where h_id=a.h_id) as hori, (select h_horafin from tb_horario where h_id=a.h_id) as horf, (select h_horaturn from tb_horario where h_id=a.h_id) as hort, (select h_horanum from tb_horario where h_id=a.h_id) as horn, a.ga_id as idga, a.a_id as ida, a.h_id as idh FROM tb_horareprog".$anno." a  where a.uap_anno='$anno' and a.uap_mes='$mm' and a.j_id='$idj' and a.hr_idserva='$ids' and a.tp_id='$idtp' and a.hr_dia='$dia' and a.ut_codprog='$codprog'";
		//echo $sql."<br>";
		$res=mysqli_query($con, $sql);
		while ($reg=mysqli_fetch_assoc($res))
		{
			$this->lis_hr[]=$reg;
		}
			return $this->lis_hr;
	}
	
	//lista todos los horarios programados en todos los servicios
	public function lis_horario_per_all($con,$anno,$mm,$idj,$idtp,$dia,$codper)
	{
		$sql="SELECT a.hp_idserva as serva, a.ut_codprog as cod, a.ga_id as idga, (select h_horaini from tb_horario where h_id=a.h_id) as hori, (select h_horafin from tb_horario where h_id=a.h_id) as horf, (select h_horaturn from tb_horario where h_id=a.h_id) as hort, (select h_horanum from tb_horario where h_id=a.h_id) as horn, a.ga_id as idga, a.a_id as ida, a.h_id as idh FROM tb_horaprog".$anno." a   where a.uap_anno='$anno' and a.uap_mes='$mm' and a.j_id='$idj' and a.tp_id='$idtp' and a.hp_dia='$dia' and a.ug_id='$codper'";
		//echo $sql."<br>";
		$res=mysqli_query($con, $sql);
		while ($reg=mysqli_fetch_assoc($res))
		{
			$this->lis_hr_all[]=$reg;
		}
			return $this->lis_hr_all;
	}
	
	//lista todos los horarios programados en todos los servicios
	public function lis_horario_per_all_repro($con,$anno,$mm,$idj,$idtp,$dia,$codper)
	{
		$sql="SELECT a.hr_idserva as serva, a.ut_codprog as cod, a.ga_id as idga, (select h_horaini from tb_horario where h_id=a.h_id) as hori, (select h_horafin from tb_horario where h_id=a.h_id) as horf, (select h_horaturn from tb_horario where h_id=a.h_id) as hort, (select h_horanum from tb_horario where h_id=a.h_id) as horn, a.ga_id as idga, a.a_id as ida, a.h_id as idh FROM tb_horareprog".$anno." a   where a.uap_anno='$anno' and a.uap_mes='$mm' and a.j_id='$idj' and a.tp_id='$idtp' and a.hr_dia='$dia' and a.ug_id='$codper'";
		//echo $sql."<br>";
		$res=mysqli_query($con, $sql);
		while ($reg=mysqli_fetch_assoc($res))
		{
			$this->lis_hr_all[]=$reg;
		}
			return $this->lis_hr_all;
	}
	
	public function cont_horario_prog_area($con,$anno,$mm,$idj,$ids,$idso,$idtp,$ugid,$thora,$idga,$ida)
	{
		$sql="select count(distinct(a.h_id)) as numhora from tb_horaprog".$anno." a inner join tb_subhoraprog".$anno." b on a.ug_id=b.ug_id and a.uap_anno=b.uap_anno and a.uap_mes=b.uap_mes and a.s_id=b.s_id and a.j_id=b.j_id and a.hp_idserva=b.hp_idserva and a.a_id=b.a_id and a.ga_id=b.ga_id and a.tp_id=b.tp_id and a.hp_tipohora=b.shp_tipohora where a.j_id='$idj' and a.s_id='$ids' and a.hp_idserva='$idso' and a.uap_anno='$anno' and a.uap_mes='$mm' and a.tp_id='$idtp' and a.a_id='$ida' and a.ug_id='$ugid' and a.ga_id='$idga' and a.hp_tipohora='$thora' group by a.uap_anno,a.uap_mes, a.s_id, a.j_id, a.hp_idserva, a.a_id, a.ga_id, a.tp_id";
		$res=mysqli_query($con, $sql);
		while ($reg=mysqli_fetch_assoc($res))
		{
			$this->num_hr_prog=$reg['numhora'];
		}
			return $this->num_hr_prog;
	}
	
	public function cont_horario_reprog_area($con,$anno,$mm,$idj,$ids,$idso,$idtp,$ugid,$thora,$idga,$ida)
	{
		$sql="select count(distinct(a.h_id)) as numhora from tb_horareprog".$anno." a inner join tb_subhorareprog".$anno." b on a.ug_id=b.ug_id and a.uap_anno=b.uap_anno and a.uap_mes=b.uap_mes and a.s_id=b.s_id and a.j_id=b.j_id and a.hr_idserva=b.hr_idserva and a.a_id=b.a_id and a.ga_id=b.ga_id and a.tp_id=b.tp_id and a.hr_tipohora=b.shr_tipohora where a.j_id='$idj' and a.s_id='$ids' and a.hr_idserva='$idso' and a.uap_anno='$anno' and a.uap_mes='$mm' and a.tp_id='$idtp' and a.a_id='$ida' and a.ug_id='$ugid' and a.ga_id='$idga' and a.hr_tipohora='$thora' group by a.uap_anno,a.uap_mes, a.s_id, a.j_id, a.hr_idserva, a.a_id, a.ga_id, a.tp_id";
		$res=mysqli_query($con, $sql);
		while ($reg=mysqli_fetch_assoc($res))
		{
			$this->num_hr_reprog=$reg['numhora'];
		}
			return $this->num_hr_reprog;
	}
	
		public function cont_horario_eje_area($con,$anno,$mm,$idj,$ids,$idso,$idtp,$ugid,$thora,$idga,$ida)
	{
		$sql="select count(distinct(a.h_id)) as numhora from tb_horaeje".$anno." a inner join tb_subhoraeje".$anno." b on a.ug_id=b.ug_id and a.uap_anno=b.uap_anno and a.uap_mes=b.uap_mes and a.s_id=b.s_id and a.j_id=b.j_id and a.he_idserva=b.he_idserva and a.a_id=b.a_id and a.ga_id=b.ga_id and a.tp_id=b.tp_id and a.he_tipohora=b.she_tipohora where a.j_id='$idj' and a.s_id='$ids' and a.he_idserva='$idso' and a.uap_anno='$anno' and a.uap_mes='$mm' and a.tp_id='$idtp' and a.a_id='$ida' and a.ug_id='$ugid' and a.ga_id='$idga' and a.he_tipohora='$thora' group by a.uap_anno,a.uap_mes, a.s_id, a.j_id, a.he_idserva, a.a_id, a.ga_id, a.tp_id";
		$res=mysqli_query($con, $sql);
		while ($reg=mysqli_fetch_assoc($res))
		{
			$this->num_hr_reprog=$reg['numhora'];
		}
			return $this->num_hr_reprog;
	}
	
	public function cont_horario_prog_area_all($con,$anno,$mm,$idj,$ids,$idtp,$idga,$ida)
	{
		//$sql="select count(distinct(a.h_id)) as numhora from tb_horaprog a inner join tb_subhoraprog b on a.ug_id=b.ug_id and a.uap_anno=b.uap_anno and a.uap_mes=b.uap_mes and a.s_id=b.s_id and a.j_id=b.j_id and a.hp_idserva=b.hp_idserva and a.a_id=b.a_id and a.ga_id=b.ga_id and a.tp_id=b.tp_id and a.hp_tipohora=b.shp_tipohora where a.j_id='$idj' and a.hp_idserva='$ids' and a.uap_anno='$anno' and a.uap_mes='$mm' and a.tp_id='$idtp' and a.a_id='$ida' and a.ga_id='$idga' group by a.uap_anno,a.uap_mes, a.s_id, a.j_id, a.hp_idserva, a.a_id, a.ga_id, a.tp_id";
		$sql="SELECT count(*) as numhora FROM tb_horarioprog".$anno." where j_id='$idj' and s_id='$ids' and uap_anno='$anno' and uap_mes='$mm' and tp_id='$idtp' and a_id='$ida' and ga_id='$idga'";
		//echo $sql."<br>";
		$res=mysqli_query($con, $sql);
		while ($reg=mysqli_fetch_assoc($res))
		{
			$this->num_hr_prog_all=$reg['numhora'];
		}
			return $this->num_hr_prog_all;
	}
	
		public function cont_horario_reprog_area_all($con,$anno,$mm,$idj,$ids,$idtp,$idga,$ida)
	{
		$sql="SELECT count(*) as numhora FROM tb_horarioreprog".$anno." where j_id='$idj' and s_id='$ids' and uap_anno='$anno' and uap_mes='$mm' and tp_id='$idtp' and a_id='$ida' and ga_id='$idga'";
		//echo $sql."<br>";
		$res=mysqli_query($con, $sql);
		while ($reg=mysqli_fetch_assoc($res))
		{
			$this->num_hr_prog_all=$reg['numhora'];
		}
			return $this->num_hr_prog_all;
	}
	
	public function lis_horario_prog_area($con,$anno,$mm,$idj,$ids,$idso,$idtp,$ugid,$thora,$idga,$ida)
	{
		$sql="select distinct(a.h_id) as idhora, (select h_horaturn from tb_horario where h_id = a.h_id) as horaturn, (select case h_horaturn when 'D' then 1 when 'N' then 2 when 'M' then 3 when 'T' then 4 end from tb_horario where h_id = a.h_id) as fila  from tb_horaprog".$anno." a where a.j_id='$idj' and a.s_id='$ids' and a.hp_idserva='$idso' and a.uap_anno='$anno' and a.uap_mes='$mm' and a.tp_id='$idtp' and a.a_id='$ida' and a.ga_id='$idga' and a.ug_id='$ugid' and a.hp_tipohora='$thora' order by fila asc";
		//echo $sql."<br>";
		$res=mysqli_query($con, $sql);
		while ($reg=mysqli_fetch_assoc($res))
		{
			$this->lis_hr_prog_a[]=$reg;
		}
			return $this->lis_hr_prog_a;
	}
	
		public function lis_horario_reprog_area($con,$anno,$mm,$idj,$ids,$idso,$idtp,$ugid,$thora,$idga,$ida)
	{
		$sql="select distinct(a.h_id) as idhora, (select h_horaturn from tb_horario where h_id = a.h_id) as horaturn, (select case h_horaturn when 'D' then 1 when 'N' then 2 when 'M' then 3 when 'T' then 4 end from tb_horario where h_id = a.h_id) as fila  from tb_horareprog".$anno." a where a.j_id='$idj' and a.s_id='$ids' and a.hr_idserva='$idso' and a.uap_anno='$anno' and a.uap_mes='$mm' and a.tp_id='$idtp' and a.a_id='$ida' and a.ga_id='$idga' and a.ug_id='$ugid' and a.hr_tipohora='$thora' order by fila asc";
		//echo $sql."<br>";
		$res=mysqli_query($con, $sql);
		while ($reg=mysqli_fetch_assoc($res))
		{
			$this->lis_hr_reprog_a[]=$reg;
		}
			return $this->lis_hr_reprog_a;
	}
	
	public function lis_horario_eje_area($con,$anno,$mm,$idj,$ids,$idso,$idtp,$ugid,$thora,$idga,$ida)
	{
		$sql="select distinct(a.h_id) as idhora, (select h_horaturn from tb_horario where h_id = a.h_id) as horaturn, (select case h_horaturn when 'D' then 1 when 'N' then 2 when 'M' then 3 when 'T' then 4 end from tb_horario where h_id = a.h_id) as fila  from tb_horaeje".$anno." a where a.j_id='$idj' and a.s_id='$ids' and a.he_idserva='$idso' and a.uap_anno='$anno' and a.uap_mes='$mm' and a.tp_id='$idtp' and a.a_id='$ida' and a.ga_id='$idga' and a.ug_id='$ugid' and a.he_tipohora='$thora' order by fila asc";
		//echo $sql."<br>";
		$res=mysqli_query($con, $sql);
		while ($reg=mysqli_fetch_assoc($res))
		{
			$this->lis_hr_reprog_a[]=$reg;
		}
			return $this->lis_hr_reprog_a;
	}
	
	
	public function lis_horario_prog_area_all($con,$anno,$mm,$idj,$ids,$idtp,$idga,$ida)
	{
		$sql="SELECT a.h_id as idhora, b.h_horaturn as horaturn, (select o_idturn from tb_ordena where o_turn=b.h_horaturn) as tt  FROM tb_horarioprog".$anno." a inner join tb_horario b on a.h_id = b.h_id where j_id='$idj' and s_id='$ids' and uap_anno='$anno' and uap_mes='$mm' and tp_id='$idtp' and a_id='$ida' and ga_id='$idga' order by tt";
		
		//$sql2="select distinct(a.h_id) as idhora, b.h_horaturn as horaturn, (select o_idturn from tb_ordena where o_turn=b.h_horaturn) as tt from tb_horaprog a inner join tb_horario b on a.h_id = b.h_id where a.j_id='$idj' and a.hp_idserva='$ids' and a.uap_anno='$anno' and a.uap_mes='$mm' and a.tp_id='$idtp' and a.a_id='$ida' and a.ga_id='$idga' order by tt";
		//$sql1="select distinct(a.h_id) as idhora, (select h_horaturn from tb_horario where h_id = a.h_id) as horaturn, (select case h_horaturn when 'D' then 1 when 'N' then 2 when 'M' then 3 when 'T' then 4 end from tb_horario where h_id = a.h_id) as fila  from tb_horaprog a where a.j_id='$idj' and a.hp_idserva='$ids' and a.uap_anno='$anno' and a.uap_mes='$mm' and a.tp_id='$idtp' and a.a_id='$ida' and a.ga_id='$idga' order by fila asc";
		//echo $sql."<br>";
		$res=mysqli_query($con, $sql);
		while ($reg=mysqli_fetch_assoc($res))
		{
			$this->lis_hr_prog[]=$reg;
		}
			return $this->lis_hr_prog;
	}
	
	public function lis_horario_reprog_area_all($con,$anno,$mm,$idj,$ids,$idtp,$idga,$ida)
	{
		$sql="SELECT a.h_id as idhora, b.h_horaturn as horaturn, (select o_idturn from tb_ordena where o_turn=b.h_horaturn) as tt  FROM tb_horarioreprog".$anno." a inner join tb_horario b on a.h_id = b.h_id where j_id='$idj' and s_id='$ids' and uap_anno='$anno' and uap_mes='$mm' and tp_id='$idtp' and a_id='$ida' and ga_id='$idga' order by tt";
		
		$res=mysqli_query($con, $sql);
		while ($reg=mysqli_fetch_assoc($res))
		{
			$this->lis_hr_prog[]=$reg;
		}
			return $this->lis_hr_prog;
	}
		
		public function prog_hrs_persona($con,$dia,$anno,$mm,$idj,$ids,$idso,$idtp,$ugid,$thora,$idga,$ida,$idh)
	{
		$sql="select (select h_horanum from tb_horario where h_id=a.h_id) as numhrs  from tb_horaprog".$anno." a where a.j_id='$idj' and a.s_id='$ids' and a.uap_mes='$mm' and a.uap_anno='$anno' and a.hp_dia='$dia' and a.h_id='$idh' and a.a_id='$ida' and a.ga_id='$idga' and a.tp_id='$idtp' and a.hp_idserva='$idso' and a.hp_tipohora='$thora' and a.ug_id='$ugid'";
		//echo $sql."<br>";
		$res=mysqli_query($con, $sql);
		while ($reg=mysqli_fetch_assoc($res))
		{
			$this->num_hrs_per=$reg['numhrs'];
		}
			return $this->num_hrs_per;
	}
	
		public function reprog_hrs_persona($con,$dia,$anno,$mm,$idj,$ids,$idso,$idtp,$ugid,$thora,$idga,$ida,$idh)
	{
		$sql="select (select h_horanum from tb_horario where h_id=a.h_id) as numhrs  from tb_horareprog".$anno." a where a.j_id='$idj' and a.s_id='$ids' and a.uap_mes='$mm' and a.uap_anno='$anno' and a.hr_dia='$dia' and a.h_id='$idh' and a.a_id='$ida' and a.ga_id='$idga' and a.tp_id='$idtp' and a.hr_idserva='$idso' and a.hr_tipohora='$thora' and a.ug_id='$ugid'";
		//echo $sql."<br>";
		$res=mysqli_query($con, $sql);
		while ($reg=mysqli_fetch_assoc($res))
		{
			$this->num_hrs_per_reprog=$reg['numhrs'];
		}
			return $this->num_hrs_per_reprog;
	}
	
		public function eje_hrs_persona($con,$dia,$anno,$mm,$idj,$ids,$idso,$idtp,$ugid,$thora,$idga,$ida,$idh)
	{
		$sql="select (select h_horanum from tb_horario where h_id=a.h_id) as numhrs  from tb_horaeje".$anno." a where a.j_id='$idj' and a.s_id='$ids' and a.uap_mes='$mm' and a.uap_anno='$anno' and a.he_dia='$dia' and a.h_id='$idh' and a.a_id='$ida' and a.ga_id='$idga' and a.tp_id='$idtp' and a.he_idserva='$idso' and a.he_tipohora='$thora' and a.ug_id='$ugid'";
		//echo $sql."<br>";
		$res=mysqli_query($con, $sql);
		while ($reg=mysqli_fetch_assoc($res))
		{
			$this->num_hrs_per_reprog=$reg['numhrs'];
		}
			return $this->num_hrs_per_reprog;
	}
	
	public function sum_hrs_persona_turno($con,$anno,$mm,$idj,$ids,$idso,$idtp,$ugid,$thora,$idga,$ida,$idh)
	{
		$sql="select case when a.a_id=9 and a.ga_id=18 then 0 else sum(b.h_horanum) end as sumhrs from tb_horaprog".$anno." a inner join tb_horario b on a.h_id=b.h_id where a.j_id='$idj' and a.s_id='$ids' and a.uap_mes='$mm' and a.uap_anno='$anno' and a.h_id='$idh' and a.a_id='$ida' and a.ga_id='$idga' and a.tp_id='$idtp' and a.hp_idserva='$idso' and a.hp_tipohora='$thora' and a.ug_id='$ugid' group by a.h_id";
        //echo $sql."<br>";
		$res=mysqli_query($con, $sql);
		while ($reg=mysqli_fetch_assoc($res))
		{
			$this->sum_hrs_per_t=$reg['sumhrs'];
		}
			return $this->sum_hrs_per_t;
	}
	
	public function sum_hrs_persona_turno_reprog($con,$anno,$mm,$idj,$ids,$idso,$idtp,$ugid,$thora,$idga,$ida,$idh)
	{
		$sql="select sum(b.h_horanum) as sumhrs from tb_horareprog".$anno." a inner join tb_horario b on a.h_id=b.h_id where a.j_id='$idj' and a.s_id='$ids' and a.uap_mes='$mm' and a.uap_anno='$anno' and a.h_id='$idh' and a.a_id='$ida' and a.ga_id='$idga' and a.tp_id='$idtp' and a.hr_idserva='$idso' and a.hr_tipohora='$thora' and a.ug_id='$ugid' group by a.h_id";
		$res=mysqli_query($con, $sql);
		while ($reg=mysqli_fetch_assoc($res))
		{
			$this->sum_hrs_per_t_reprog=$reg['sumhrs'];
		}
			return $this->sum_hrs_per_t_reprog;
	}
	
	public function sum_hrs_persona_turno_eje($con,$anno,$mm,$idj,$ids,$idso,$idtp,$ugid,$thora,$idga,$ida,$idh)
	{
		$sql="select sum(b.h_horanum) as sumhrs from tb_horaeje".$anno." a inner join tb_horario b on a.h_id=b.h_id where a.j_id='$idj' and a.s_id='$ids' and a.uap_mes='$mm' and a.uap_anno='$anno' and a.h_id='$idh' and a.a_id='$ida' and a.ga_id='$idga' and a.tp_id='$idtp' and a.he_idserva='$idso' and a.he_tipohora='$thora' and a.ug_id='$ugid' group by a.h_id";
		$res=mysqli_query($con, $sql);
		while ($reg=mysqli_fetch_assoc($res))
		{
			$this->sum_hrs_per_t_reprog=$reg['sumhrs'];
		}
			return $this->sum_hrs_per_t_reprog;
	}
	
	public function sum_hrs_persona_dia($con,$anno,$mm,$idj,$ids,$idso,$idtp,$ugid,$thora,$idga,$ida,$idh)
	{
		$sql="select sum(b.h_horanum) as sumhrs from tb_horaprog".$anno." a inner join tb_horario b on a.h_id=b.h_id where a.j_id='$idj' and a.s_id='$ids' and a.uap_mes='$mm' and a.uap_anno='$anno' and a.h_id='$idh' and a.a_id='$ida' and a.ga_id='$idga' and a.tp_id='$idtp' and a.hp_idserva='$idso' and a.hp_tipohora='$thora' and a.ug_id='$ugid' group by a.h_id";
		$res=mysqli_query($con, $sql);
		while ($reg=mysqli_fetch_assoc($res))
		{
			$this->sum_hrs_per_d=$reg['sumhrs'];
		}
			return $this->sum_hrs_per_d;
	}
	
	public function sum_hrs_per_garea_dia($con,$dia,$anno,$mm,$idj,$ids,$idso,$idtp,$ugid,$thora,$idga)
	{
		$sql="select sum(b.h_horanum) as numhrs from tb_horaprog".$anno." a inner join tb_horario b on a.h_id = b.h_id where a.j_id='$idj' and a.s_id='$ids' and a.uap_mes='$mm' and a.uap_anno='$anno' and a.hp_dia='$dia' and a.ga_id='$idga' and a.tp_id='$idtp'  and a.hp_idserva='$idso' and a.hp_tipohora='$thora' and a.ug_id='$ugid' and b.h_horatipo <> 0";
		//echo $sql."<br>";
		$res=mysqli_query($con, $sql);
		while ($reg=mysqli_fetch_assoc($res))
		{
			$this->sum_hrs_per_ga_dia=$reg['numhrs'];
		}
			return $this->sum_hrs_per_ga_dia;
	}
	
	public function sum_hrs_per_garea_dia_reprog($con,$dia,$anno,$mm,$idj,$ids,$idso,$idtp,$ugid,$thora,$idga)
	{
		$sql="select sum(b.h_horanum) as numhrs from tb_horareprog".$anno." a inner join tb_horario b on a.h_id = b.h_id where a.j_id='$idj' and a.s_id='$ids' and a.uap_mes='$mm' and a.uap_anno='$anno' and a.hr_dia='$dia' and a.ga_id='$idga' and a.tp_id='$idtp'  and a.hr_idserva='$idso' and a.hr_tipohora='$thora' and a.ug_id='$ugid' and b.h_horatipo <> 0";
		//echo $sql."<br>";
		$res=mysqli_query($con, $sql);
		while ($reg=mysqli_fetch_assoc($res))
		{
			$this->sum_hrs_per_ga_dia_reprog=$reg['numhrs'];
		}
			return $this->sum_hrs_per_ga_dia_reprog;
	}
	
	
	public function sum_hrs_per_garea_dia_eje($con,$dia,$anno,$mm,$idj,$ids,$idso,$idtp,$ugid,$thora,$idga)
	{
		$sql="select sum(b.h_horanum) as numhrs from tb_horaeje".$anno." a inner join tb_horario b on a.h_id = b.h_id where a.j_id='$idj' and a.s_id='$ids' and a.uap_mes='$mm' and a.uap_anno='$anno' and a.he_dia='$dia' and a.ga_id='$idga' and a.tp_id='$idtp'  and a.he_idserva='$idso' and a.he_tipohora='$thora' and a.ug_id='$ugid' and b.h_horatipo <> 0";
		//echo $sql."<br>";
		$res=mysqli_query($con, $sql);
		while ($reg=mysqli_fetch_assoc($res))
		{
			$this->sum_hrs_per_ga_dia_reprog=$reg['numhrs'];
		}
			return $this->sum_hrs_per_ga_dia_reprog;
	}
	
	
		public function sum_hrs_per_garea($con,$dia,$anno,$mm,$idj,$ids,$idso,$idtp,$ugid,$thora)
	{
		$sql="select sum(b.h_horanum) as numhrs from tb_horaprog".$anno." a inner join tb_horario b on a.h_id = b.h_id where a.j_id='$idj' and a.s_id='$ids' and a.uap_mes='$mm' and a.uap_anno='$anno' and a.hp_dia='$dia' and a.tp_id='$idtp' and a.hp_idserva='$idso' and a.hp_tipohora='$thora' and a.ug_id='$ugid' and b.h_horatipo <> 0";
		$res=mysqli_query($con, $sql);
		while ($reg=mysqli_fetch_assoc($res))
		{
			$this->sum_hrs_per_ga=$reg['numhrs'];
		}
			return $this->sum_hrs_per_ga;
	}
	
	public function sum_hrs_per_garea_reprog($con,$dia,$anno,$mm,$idj,$ids,$idso,$idtp,$ugid,$thora)
	{
		$sql="select sum(b.h_horanum) as numhrs from tb_horareprog".$anno." a inner join tb_horario b on a.h_id = b.h_id where a.j_id='$idj' and a.s_id='$ids' and a.uap_mes='$mm' and a.uap_anno='$anno' and a.hr_dia='$dia' and a.tp_id='$idtp' and a.hr_idserva='$idso' and a.hr_tipohora='$thora' and a.ug_id='$ugid' and b.h_horatipo <> 0";
		//echo $sql."<br>";
		$res=mysqli_query($con, $sql);
		while ($reg=mysqli_fetch_assoc($res))
		{
			$this->sum_hrs_per_ga_reprog=$reg['numhrs'];
		}
			return $this->sum_hrs_per_ga_reprog;
	}
	
	public function sum_hrs_per_garea_eje($con,$dia,$anno,$mm,$idj,$ids,$idso,$idtp,$ugid,$thora)
	{
		$sql="select sum(b.h_horanum) as numhrs from tb_horaeje".$anno." a inner join tb_horario b on a.h_id = b.h_id where a.j_id='$idj' and a.s_id='$ids' and a.uap_mes='$mm' and a.uap_anno='$anno' and a.he_dia='$dia' and a.tp_id='$idtp' and a.he_idserva='$idso' and a.he_tipohora='$thora' and a.ug_id='$ugid' and b.h_horatipo <> 0";
		//echo $sql."<br>";
		$res=mysqli_query($con, $sql);
		while ($reg=mysqli_fetch_assoc($res))
		{
			$this->sum_hrs_per_ga_reprog=$reg['numhrs'];
		}
			return $this->sum_hrs_per_ga_reprog;
	}
	
	public function sum_hrs_per_total($con,$anno,$mm,$idj,$ids,$idso,$idtp,$ugid,$thora,$idga)
	{
		$sql="select sum(b.h_horanum) as tothrs from tb_horaprog".$anno." a inner join tb_horario b on a.h_id = b.h_id where a.j_id='$idj' and a.s_id='$ids' and a.uap_mes='$mm' and a.uap_anno='$anno' and a.ga_id='$idga' and a.tp_id='$idtp' and a.hp_idserva='$idso' and a.hp_tipohora='$thora' and a.ug_id='$ugid' and b.h_horatipo <> 0";
		$res=mysqli_query($con, $sql);
		while ($reg=mysqli_fetch_assoc($res))
		{
			$this->sum_hrs_per_to=$reg['tothrs'];
		}
			return $this->sum_hrs_per_to;
	}
	
		public function sum_hrs_per_total_reprog($con,$anno,$mm,$idj,$ids,$idso,$idtp,$ugid,$thora,$idga)
	{
		$sql="select sum(b.h_horanum) as tothrs from tb_horareprog".$anno." a inner join tb_horario b on a.h_id = b.h_id where a.j_id='$idj' and a.s_id='$ids' and a.uap_mes='$mm' and a.uap_anno='$anno' and a.ga_id='$idga' and a.tp_id='$idtp' and a.hr_idserva='$idso' and a.hr_tipohora='$thora' and a.ug_id='$ugid' and b.h_horatipo <> 0";
		//echo $sql."<br>";
		$res=mysqli_query($con, $sql);
		while ($reg=mysqli_fetch_assoc($res))
		{
			$this->sum_hrs_per_to_reprog=$reg['tothrs'];
		}
			return $this->sum_hrs_per_to_reprog;
	}
	
		public function sum_hrs_per_total_eje($con,$anno,$mm,$idj,$ids,$idso,$idtp,$ugid,$thora,$idga)
	{
		$sql="select sum(b.h_horanum) as tothrs from tb_horaeje".$anno." a inner join tb_horario b on a.h_id = b.h_id where a.j_id='$idj' and a.s_id='$ids' and a.uap_mes='$mm' and a.uap_anno='$anno' and a.ga_id='$idga' and a.tp_id='$idtp' and a.he_idserva='$idso' and a.he_tipohora='$thora' and a.ug_id='$ugid' and b.h_horatipo <> 0";
		$res=mysqli_query($con, $sql);
		while ($reg=mysqli_fetch_assoc($res))
		{
			$this->sum_hrs_per_to_reprog=$reg['tothrs'];
		}
			return $this->sum_hrs_per_to_reprog;
	}
	
	public function sum_per_total($con,$anno,$mm,$idj,$ids,$idso,$idtp,$ugid,$thora)
	{
		$sql="select sum(b.h_horanum) as tothrs from tb_horaprog".$anno." a inner join tb_horario b on a.h_id = b.h_id where a.j_id='$idj' and a.s_id='$ids' and a.uap_mes='$mm' and a.uap_anno='$anno' and a.tp_id='$idtp' and a.hp_idserva='$idso' and a.hp_tipohora='$thora' and a.ug_id='$ugid' and b.h_horatipo <> 0";
		//echo $sql."<br>";
		$res=mysqli_query($con, $sql);
		while ($reg=mysqli_fetch_assoc($res))
		{
			$this->to_hrs_per=$reg['tothrs'];
		}
			return $this->to_hrs_per;
	}
	
	public function sum_per_total_sin_serv($con,$anno,$mm,$idj,$idso,$idtp,$ugid,$thora)
	{
		$sql="select sum(b.h_horanum) as tothrs from tb_horaprog".$anno." a inner join tb_horario b on a.h_id = b.h_id where a.j_id='$idj' and a.uap_mes='$mm' and a.uap_anno='$anno' and a.tp_id='$idtp' and a.hp_idserva='$idso' and a.hp_tipohora='$thora' and a.ug_id='$ugid' and b.h_horatipo <> 0";
		//echo $sql."<br>";
		$res=mysqli_query($con, $sql);
		while ($reg=mysqli_fetch_assoc($res))
		{
			$this->to_hrs_per2=$reg['tothrs'];
		}
			return $this->to_hrs_per2;
	}
	
		public function sum_per_total_reprog($con,$anno,$mm,$idj,$ids,$idso,$idtp,$ugid,$thora)
	{
		$sql="select sum(b.h_horanum) as tothrs from tb_horareprog".$anno." a inner join tb_horario b on a.h_id = b.h_id where a.j_id='$idj' and a.s_id='$ids' and a.uap_mes='$mm' and a.uap_anno='$anno' and a.tp_id='$idtp' and a.hr_idserva='$idso' and a.hr_tipohora='$thora' and a.ug_id='$ugid' and b.h_horatipo <> 0";
		
		$res=mysqli_query($con, $sql);
		while ($reg=mysqli_fetch_assoc($res))
		{
			$this->to_hrs_per_reprog=$reg['tothrs'];
		}
			return $this->to_hrs_per_reprog;
	}
	
	public function sum_per_total_eje($con,$anno,$mm,$idj,$ids,$idso,$idtp,$ugid,$thora)
	{
		$sql="select sum(b.h_horanum) as tothrs from tb_horaeje".$anno." a inner join tb_horario b on a.h_id = b.h_id where a.j_id='$idj' and a.s_id='$ids' and a.uap_mes='$mm' and a.uap_anno='$anno' and a.tp_id='$idtp' and a.he_idserva='$idso' and a.he_tipohora='$thora' and a.ug_id='$ugid' and b.h_horatipo <> 0";
		
		$res=mysqli_query($con, $sql);
		while ($reg=mysqli_fetch_assoc($res))
		{
			$this->to_hrs_per_reprog=$reg['tothrs'];
		}
			return $this->to_hrs_per_reprog;
	}
	
}
?>