<?php
class Xhc_model extends CI_Model{
	public function __construct(){
		parent::__construct();
	}

	public function listar($texto = '', $xecl = 0){
		$where 	= ($xecl>0)?" AND hc.estc_id > 0":"";
		$where .= ($texto!='')?" AND hc.hc_apenombres LIKE '%{$texto}%'":"";
		$query 	= "	SELECT
						hc.hc_id,
						hc.hc_apellidos,
						hc.hc_nombres,
						hc.hc_apenombres,
						hc.hc_dni,
						hc.hc_direccion,
						hc.hc_fecha_nac,
						hc.hc_correo,
						hc.hc_correo2,
						hc.hc_celular,
						hc.hc_celular2,
						hc.hc_telefono,
						hc.hc_telefono2,
						hc.estc_id,
						hc.hc_estado,
						estado_civil.estc_descripcion
					FROM
						hc
					LEFT JOIN estado_civil ON hc.estc_id = estado_civil.estc_id
					WHERE hc.hc_estado = 0 {$where}
					ORDER BY hc.hc_apenombres ASC";
		return 	$this->db->query($query);
	}

	public function validar($dni){
		$query 	= "SELECT hc_id FROM hc WHERE hc_dni = $dni AND hc_estado = 0";
		$query 	= $this->db->query($query);
		return 	$query->row();
	}

	public function ver($id){
		$query 	= "	SELECT
						hc.hc_id,
						hc.hc_apellidos,
						hc.hc_nombres,
						hc.hc_apenombres,
						hc.hc_dni,
						hc.hc_direccion,
						hc.hc_fecha_nac,
						hc.hc_correo,
						hc.hc_correo2,
						hc.hc_celular,
						hc.hc_celular2,
						hc.hc_telefono,
						hc.hc_telefono2,
						hc.estc_id,
						hc.hc_estado
					FROM
						hc
					WHERE hc.hc_id = $id";
		$query 	= $this->db->query($query);
		return 	$query->row();
	}

	public function insertar($data){
		$this->db->insert('hc', $data);
	}

	public function editar($id, $data){
		$this->db->where('hc_id', $id);
		$this->db->update('hc', $data);
	}
}