<?php 


class DaoRecibo extends conexao {

public function Atualizar(recibo $recibo) {

try {

if ($recibo->getRec_cd() != '') {

$sql = " UPDATE recibo SET
rec_cliente = ?,
rec_dt_emissao = ?,
rec_descricao = ?,
rec_valor = ?,
rec_situacao = ?
WHERE rec_cd = ? ";

$stmt = self::conectar()->prepare($sql);
$stmt->bindValue(1, $recibo->getRec_cliente());
$stmt->bindValue(2, $recibo->getRec_dt_emissao());
$stmt->bindValue(3, $recibo->getRec_descricao());
$stmt->bindValue(4, $recibo->getRec_valor());
$stmt->bindValue(5, $recibo->getRec_situacao());
$stmt->bindValue(6, $recibo->getRec_cd());


} else {

$sql = " INSERT INTO recibo (rec_cliente,rec_dt_emissao,rec_descricao,rec_valor,rec_situacao)
VALUES (?,?,?,?,?)";


$stmt = self::conectar()->prepare($sql);
$stmt->bindValue(1, $recibo->getRec_cliente());
$stmt->bindValue(2, $recibo->getRec_dt_emissao());
$stmt->bindValue(3, $recibo->getRec_descricao());
$stmt->bindValue(4, $recibo->getRec_valor());
$stmt->bindValue(5, $recibo->getRec_situacao());


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

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

}

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

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




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

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

 
}
