<?php 

class DaoCliente extends conexao {

public function Atualizar(cliente $cliente) {

try {

if ($cliente->getCli_id() != '') {

$sql = " UPDATE cliente SET
cli_nm = ?,
cli_rg = ?,
cli_oe = ?,
cli_cpf = ?,
cli_fone = ?,
cli_cel = ?,
cli_fax = ?,
cli_email = ?,
cli_supervisor_cd = ?,
cli_end = ?,
cli_numero = ?,
cli_bairro = ?,
cli_cid_cd = ?,
cli_cep = ?,
cli_moradia = ?,
cli_situacao_moradia = ?,
cli_tempo_moradia = ?,
cli_conjugue = ?,
cli_rg_conj = ?,
cli_oe_conj = ?,
cli_cpf_conj = ?,
cli_pai = ?,
cli_mae = ?,
cli_foto = ?,
cli_nm_conhecido1 = ?,
cli_fone_conh1 = ?,
cli_cel_conh1 = ?,
cli_nm_conhecido2 = ?,
cli_fone_conh2 = ?,
cli_cel_conh2 = ?,
cli_lider_cd = ?,
cli_nivel = ?,
cli_cnpj = ?,
cli_cidade = ?,
cli_uf = ?
WHERE cli_id = ? ";

$stmt = self::conectar()->prepare($sql);
$stmt->bindValue(1, $cliente->getCli_nm());
$stmt->bindValue(2, $cliente->getCli_rg());
$stmt->bindValue(3, $cliente->getCli_oe());
$stmt->bindValue(4, $cliente->getCli_cpf());
$stmt->bindValue(5, $cliente->getCli_fone());
$stmt->bindValue(6, $cliente->getCli_cel());
$stmt->bindValue(7, $cliente->getCli_fax());
$stmt->bindValue(8, $cliente->getCli_email());
$stmt->bindValue(9, $cliente->getCli_supervisor_cd());
$stmt->bindValue(10, $cliente->getCli_end());
$stmt->bindValue(11, $cliente->getCli_numero());
$stmt->bindValue(12, $cliente->getCli_bairro());
$stmt->bindValue(13, $cliente->getCli_cid_cd());
$stmt->bindValue(14, $cliente->getCli_cep());
$stmt->bindValue(15, $cliente->getCli_moradia());
$stmt->bindValue(16, $cliente->getCli_situacao_moradia());
$stmt->bindValue(17, $cliente->getCli_tempo_moradia());
$stmt->bindValue(18, $cliente->getCli_conjugue());
$stmt->bindValue(19, $cliente->getCli_rg_conj());
$stmt->bindValue(20, $cliente->getCli_oe_conj());
$stmt->bindValue(21, $cliente->getCli_cpf_conj());
$stmt->bindValue(22, $cliente->getCli_pai());
$stmt->bindValue(23, $cliente->getCli_mae());
$stmt->bindValue(24, $cliente->getCli_foto());
$stmt->bindValue(25, $cliente->getCli_nm_conhecido1());
$stmt->bindValue(26, $cliente->getCli_fone_conh1());
$stmt->bindValue(27, $cliente->getCli_cel_conh1());
$stmt->bindValue(28, $cliente->getCli_nm_conhecido2());
$stmt->bindValue(29, $cliente->getCli_fone_conh2());
$stmt->bindValue(30, $cliente->getCli_cel_conh2());
$stmt->bindValue(31, $cliente->getCli_lider_cd());
$stmt->bindValue(32, $cliente->getCli_nivel());
$stmt->bindValue(33, $cliente->getCli_cnpj());
$stmt->bindValue(34, $cliente->getCli_cidade());
$stmt->bindValue(35, $cliente->getCli_uf());
$stmt->bindValue(36, $cliente->getCli_id());


} else {

$sql = " INSERT INTO cliente (cli_nm,cli_rg,cli_oe,cli_cpf,cli_fone,cli_cel,cli_fax,cli_email,cli_supervisor_cd,cli_end,cli_numero,cli_bairro,cli_cid_cd,cli_cep,cli_moradia,cli_situacao_moradia,cli_tempo_moradia,cli_conjugue,cli_rg_conj,cli_oe_conj,cli_cpf_conj,cli_pai,cli_mae,cli_foto,cli_nm_conhecido1,cli_fone_conh1,cli_cel_conh1,cli_nm_conhecido2,cli_fone_conh2,cli_cel_conh2,cli_lider_cd,cli_nivel,cli_cnpj,cli_cidade,cli_uf)
VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";


$stmt = self::conectar()->prepare($sql);
$stmt->bindValue(1, $cliente->getCli_nm());
$stmt->bindValue(2, $cliente->getCli_rg());
$stmt->bindValue(3, $cliente->getCli_oe());
$stmt->bindValue(4, $cliente->getCli_cpf());
$stmt->bindValue(5, $cliente->getCli_fone());
$stmt->bindValue(6, $cliente->getCli_cel());
$stmt->bindValue(7, $cliente->getCli_fax());
$stmt->bindValue(8, $cliente->getCli_email());
$stmt->bindValue(9, $cliente->getCli_supervisor_cd());
$stmt->bindValue(10, $cliente->getCli_end());
$stmt->bindValue(11, $cliente->getCli_numero());
$stmt->bindValue(12, $cliente->getCli_bairro());
$stmt->bindValue(13, $cliente->getCli_cid_cd());
$stmt->bindValue(14, $cliente->getCli_cep());
$stmt->bindValue(15, $cliente->getCli_moradia());
$stmt->bindValue(16, $cliente->getCli_situacao_moradia());
$stmt->bindValue(17, $cliente->getCli_tempo_moradia());
$stmt->bindValue(18, $cliente->getCli_conjugue());
$stmt->bindValue(19, $cliente->getCli_rg_conj());
$stmt->bindValue(20, $cliente->getCli_oe_conj());
$stmt->bindValue(21, $cliente->getCli_cpf_conj());
$stmt->bindValue(22, $cliente->getCli_pai());
$stmt->bindValue(23, $cliente->getCli_mae());
$stmt->bindValue(24, $cliente->getCli_foto());
$stmt->bindValue(25, $cliente->getCli_nm_conhecido1());
$stmt->bindValue(26, $cliente->getCli_fone_conh1());
$stmt->bindValue(27, $cliente->getCli_cel_conh1());
$stmt->bindValue(28, $cliente->getCli_nm_conhecido2());
$stmt->bindValue(29, $cliente->getCli_fone_conh2());
$stmt->bindValue(30, $cliente->getCli_cel_conh2());
$stmt->bindValue(31, $cliente->getCli_lider_cd());
$stmt->bindValue(32, $cliente->getCli_nivel());
$stmt->bindValue(33, $cliente->getCli_cnpj());
$stmt->bindValue(34, $cliente->getCli_cidade());
$stmt->bindValue(35, $cliente->getCli_uf());


}
if ($stmt->execute()){
return true;
} else
return false;

} catch (Exception $e) {
print "Erro ao tentar atualizar: ".$e;
}

}

public function PesquisarCliente($codigo){
$sql = " SELECT * FROM cliente WHERE cli_id = ? ";
$stmt = self::conectar()->prepare($sql);
$stmt->bindValue(1, $codigo);
$stmt->execute();
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
return $result;
}

public function ListarCliente(){
$sql = " SELECT * FROM cliente ORDER BY cli_id ";
$stmt = self::conectar()->prepare($sql);
$stmt->execute();
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
return $result;
}


public function Contar_qtd_cliente(){
	$sql = "SELECT COUNT(cli_id) AS qtd_cliente FROM cliente";
	$stmt = self::conectar()->prepare($sql);
	$stmt->execute();
	$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
	foreach($result as $row){
		return $row['qtd_cliente'];
	}
}



public function ProximoId(){
$sql = " SELECT COALESCE(MAX(cli_id), 0) + 1 AS PROXIMO_REGISTRO FROM cliente ";
$stmt = self::conectar()->prepare($sql);
$stmt->execute();
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
return $result;
}

	
public function deletar($cli_id){		
$sql = " DELETE FROM cliente WHERE cli_id = ? ";
$stmt = self::conectar()->prepare($sql);
$stmt->bindValue(1, $cli_id); 
$stmt->execute();
}

 
}
