<?php
require_once('DataManager.Class.php');

class ClienteProveedor {

    public $conn;

    function __construct($c) {
        
        if(isset($c)){
                $this->conn = $c;
        } else {
                $this->conn = DataManager::getInstance();
        }
    }

	public function informacionPersonaLimit($cliente, $provSils, $provcliente, $estado, $rut, $razonSocial, $inicio, $cantidad ) 
	{
		$stmt = $this->conn->prepare("{CALL agenda.SP_persona_informacion_limit (?, ?, ?, ?, ?, ?, ?, ?)}");
		$stmt->execute(array($cliente, $provSils, $provcliente, $estado, $rut, $razonSocial, $inicio, $cantidad ));

		return $stmt->fetchAll();	
	}

	public function informacionPersona($persID, $estado, $tipo_retorno)
	{
	
		$stmt = $this->conn->prepare("{CALL agenda.SP_persona_informacion (?, ?)}");
		$stmt->bindValue(1, $persID, PDO::PARAM_INT);
		$stmt->bindValue(2, $estado, PDO::PARAM_INT);
		$stmt->execute();

		if($tipo_retorno == 0) {
			return $stmt->fetch();
		} else {
			return $stmt->fetchAll();
		}

	}

	public function ingresarPersona($rut, $cliente, $provSils, $provcliente, $razonSocial, $nombFantasia, $web, $contacto, $email,
										$telfFijo, $telfCel, $comunaId, $direccion, $formaPagoId, $catalogoId, $estado, $usuaId, $pass, $verif  ) 
	{
		$stmt = $this->conn->prepare("{CALL agenda.SP_persona_adm_ingresa (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)}");
		$stmt->execute(array($rut, $cliente, $provSils, $provcliente, $razonSocial, $nombFantasia, $web, $contacto, $email,
								$telfFijo, $telfCel, $comunaId, $direccion, $formaPagoId,  $catalogoId, $estado, $usuaId, $pass, $verif ));

        return $stmt->fetch();	
    }
	
	public function modificarPersona($persID, $rut, $cliente, $provSils, $provcliente, $razonSocial, $nombFantasia, $web, $contacto, $email,
										$telfFijo, $telfCel, $comunaId, $direccion, $formaPagoId, $catalogoId, $estado  ) 
	{
		$stmt = $this->conn->prepare("{CALL agenda.SP_persona_adm_modifica (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)}");
		$stmt->execute(array($persID, $rut, $cliente, $provSils, $provcliente, $razonSocial, $nombFantasia, $web, $contacto, $email,
								$telfFijo, $telfCel, $comunaId, $direccion, $formaPagoId,  $catalogoId, $estado ));

        return $stmt->fetch();	
    }

	public function eliminarPersona($persID ) 
	{
		$stmt = $this->conn->prepare("{CALL agenda.SP_persona_eliminar (?)}");
		$stmt->execute(array($persID ));

        return $stmt->fetch();	
    }

	public function aprobarPersona($persID, $usrID, $pass, $verif ) 
	{
		$stmt = $this->conn->prepare("{CALL agenda.SP_persona_activar (?, ?, ?, ?)}");
		$stmt->execute(array($persID, $usrID, $pass, $verif ));

        return $stmt->fetch();	
    }

	public function rechazarPersona($persID, $motivo, $usrID ) 
	{
		$stmt = $this->conn->prepare("{CALL agenda.SP_persona_rechazar (?, ?, ?)}");
		$stmt->execute(array($persID, $motivo, $usrID ));

        return $stmt->fetch();	
    }

	public function habilitarPersona($persID, $motivo, $usrID, $pass, $verif ) 
	{
		$stmt = $this->conn->prepare("{CALL agenda.SP_persona_habilitar (?, ?, ?, ?, ?)}");
		$stmt->execute(array($persID, $motivo, $usrID, $pass, $verif ));

        return $stmt->fetch();	
    }

	 
	public function informacionTipoPersona($persId) {
		$stmt = $this->conn->prepare("{CALL agenda.SP_persona_tipo_informacion (?)}");
		$stmt->bindValue(1, $persId, PDO::PARAM_INT);
		$stmt->execute();
	
		return $stmt->fetchAll();		

	}


    function Close() {
        
        $this->conn = null;
        
    }

}
?>