<?php

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

//class Jefaturas extends Conectar
class Jefaturas
{
	
	private $lis_jef=array();
	private $dat_jef=array();
	private $lis_serv=array();
	private $dat_serv=array();
	private $num_cont;
	
		public function listar_jefatura($con)
	{
		$sql="select j_id as cod, j_desc as descripcion from tb_jefatura";
		$res=mysqli_query($con, $sql);
		while ($reg=mysqli_fetch_assoc($res))
		{
			$this->lis_jef[]=$reg;
		}
			return $this->lis_jef;
	}
	
		public function buscar_jefatura($con,$idj)
	{
		$sql="select j_id as idj, 0 as ids, j_abrev as abrev ,j_desc as nom  from tb_jefatura where j_id='$idj'";
		$res=mysqli_query($con, $sql);
		while ($reg=mysqli_fetch_assoc($res))
		{
			$this->dat_jef[]=$reg;
		}
			return $this->dat_jef;
	}
	
	public function listar_jefatura_servicio($con,$idj)
	{
	
		$sql="select j_id as idj, s_id as ids, s_abrev as abrev, s_desc as nom from tb_servicio where j_id='$idj'";
		$res=mysqli_query($con, $sql);
		while ($reg=mysqli_fetch_assoc($res))
		{
			$this->lis_serv[]=$reg;
		}
			return $this->lis_serv;
	}
	
	public function buscar_jefatura_servicio($con,$idj,$ids)
	{
		$sql="select s_id as cod, s_abrev as abrev, s_desc as nom from tb_servicio where j_id='$idj' and s_id='$ids'";
		$res=mysqli_query($con, $sql);
		while ($reg=mysqli_fetch_assoc($res))
		{
			$this->dat_serv[]=$reg;
		}
			return $this->dat_serv;
	}
	
	public function contador_per_servicio($con,$idj,$ids)
	{
		$sql="select a.contador as contador from tb_usuasist a inner join tb_usudep b on a.ug_id=b.ug_id where b.j_id='$idj' and b.s_id='$ids' order by a.contador desc limit 1";
		$res=mysqli_query($con, $sql);
		while ($reg=mysqli_fetch_assoc($res))
		{
			$this->num_cont=$reg['contador'];
		}
			return $this->num_cont;
	}
	
}
?>