Viewing file: mensalidade_class_bkp_19.03.2015.php (6.9 KB) -rwxr-xr-x Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php
require_once("valores_class.php");
require_once("boletos_class.php");
class Mensalidades{
var $tabela, $campos, $qtd_campos, $campos_data;
var $conexao;
/*
Autor: Rodrigo J Polette
Empresa: NetNigro
Data: 12/05/2009
*/
function Mensalidades(){
$this->tabela = "irp_servicos_mensalidades";
$this->campos = array("SRM_RowID","SRM_Oficio_DR","SRM_Valor","SRM_AtivoSN","SRM_MesReferencia","SRM_AnoReferencia","SRM_CanceladoSN");
$this->qtd_campos = count($this->campos);
$this->campos_data = array();
global $conexao;
$this->conexao = $conexao;
}
function get($nome) {
return stripslashes($this->$nome);
}
function set($nome,$valor) {
$this->$nome = $valor;
}
function limpar() {
for ($i=0;$i<$this->qtd_campos;$i++) {
$campo = $this->campos[$i];
unset($this->$campo);
}
}
function carrega($dados) {
reset($dados);
while (list($campo,$valor) = each($dados)) {
if (in_array($campo,$this->campos_data))
$this->$campo = FormataData($valor,'SCREEN');
else
$this->$campo = stripslashes($valor);
}
}
function verNotNull(){
if (strlen($this->get("SRM_AtivoSN"))==0)
$this->set("SRM_AtivoSN",'S');
if (strlen($this->get("SRM_CanceladoSN"))==0)
$this->set("SRM_CanceladoSN",'S');
if (
(strlen($this->get("SRM_Oficio_DR"))==0) or
(strlen($this->get("SRM_Valor"))==0) or
(strlen($this->get("SRM_AtivoSN"))==0) or
(strlen($this->get("SRM_MesReferencia"))==0) or
(strlen($this->get("SRM_AnoReferencia"))==0)
) {
return false;
}
else
return true;
}
function inserir() {
if (!$this->verNotNull())
return false;
$nomes = "(";
$valores = "(";
for ($i=0;$i<$this->qtd_campos;$i++) {
$campo = $this->campos[$i];
$valor = $this->get($campo);
if (strlen($valor)==0)
$valor = "NULL";
else {
if (in_array($campo,$this->campos_data))
$valor = FormataData($valor,"BD");
$valor = "'$valor'";
}
$nomes .= "$campo,";
$valores .= "$valor,";
}
$nomes = substr($nomes,0,-1).")";
$valores = substr($valores,0,-1).")";
$sql = "INSERT INTO $this->tabela $nomes VALUES $valores";
/*echo "$sql<br />";
$this->set("SRM_RowID",10000);
return true;*/
if (mysqli_query($this->conexao,$sql)) {
$this->set("SRM_RowID",mysqli_insert_id($this->conexao));
return true;
}
else {
$this->set("SRM_RowID","");
return false;
}
}
function alterar($id) {
if (!is_numeric($id)) return false;
if (!$this->verNotNUll())
return false;
$this->set("SRM_RowID",$id);
$sets = "";
for ($i=0;$i<$this->qtd_campos;$i++) {
$campo = $this->campos[$i];
$valor = $this->get($campo);
if (strlen($valor)==0)
$valor = "NULL";
else {
if (in_array($campo,$this->campos_data))
$valor = FormataData($valor,"BD");
$valor = "'$valor'";
}
$sets .= "$campo = $valor,";
}
$sets = substr($sets,0,-1);
$sql = "UPDATE $this->tabela SET $sets WHERE SRM_RowID=$id";
if (mysqli_query($this->conexao,$sql))
return true;
else
return false;
}
function deletar($id) {
if (!$this->buscar($id)) return false;
return mysqli_query($this->conexao,"DELETE FROM $this->tabela WHERE SRM_RowID=$id");
}
function buscar($id) {
if (!is_numeric($id)) return false;
$dados = mysqli_fetch_assoc(mysqli_query($this->conexao,"SELECT * FROM $this->tabela WHERE SRM_RowID=$id"));
if (is_array($dados)) {
$this->carrega($dados);
return true;
}
else
return false;
}
function listar($where="",$orderby="",$inicio="",$qtd="") {
$sql = "SELECT * FROM $this->tabela";
if ($where) $sql = $sql." WHERE ".$where;
if ($orderby) $sql = $sql." ORDER BY ".$orderby;
if (is_numeric($inicio) and is_numeric($qtd))
$sql = $sql." LIMIT $inicio,$qtd";
return mysqli_query($this->conexao,$sql);
}
function lista_oficios() {
$sql = "SELECT oficios.*, cidades.CID_Entrancia FROM oficios left join cidades ON (oficios.OFI_Cidades_DR = cidades.CID_RowID)";
/*$sql = "
SELECT * FROM irp_servicos_boletos
INNER JOIN irp_servicos_mensalidades ON SVB_Mensalidade_DR = SRM_RowID
INNER JOIN oficios ON SRM_Oficio_DR = OFI_RowID
WHERE SVB_DataPagamento >= '2012-12-01'
AND SVB_DataPagamento <= '2013-01-22'
AND SVB_PagoSN = 'S'
AND SVB_AtivoSN = 'S'
LIMIT 0, 2000
";*/
return mysqli_query($this->conexao,$sql);
}
function gerarMensalidadesBoletos($data_vencto,$mes_referencia,$ano_referencia,$id_texto_usar=0) {
if ($id_texto_usar == 0)
$id_texto_usar = "";
list($dia,$mes,$ano) = explode("/",$data_vencto);
if ((!checkdate($mes,$dia,$ano)) or ($mes_referencia < 1 and $mes_referencia > 12) or (!is_numeric($ano_referencia)))
return false;
//Verifica o status de autocommit
$antes = mysqli_fetch_row(mysqli_query($this->conexao,"SELECT @@autocommit"));
$antes = $antes[0];
mysqli_autocommit($this->conexao,true);
$ok = true;
$valores = new Valores();
$boletos = new Boletos();
$valores_entrancia = $valores->retorna_array();
$ok = is_array($valores_entrancia);
//$ok = true;
if ($ok) {
$res_oficios = $this->lista_oficios();
while ($oficio = mysqli_fetch_assoc($res_oficios)) {
$this->limpar();
$boletos->limpar();
//Gera a mensalidade
$this->set('SRM_Oficio_DR',$oficio['OFI_RowID']);
$this->set('SRM_Valor',$valores_entrancia[$oficio['CID_Entrancia']]['SRV_Valor']);
//$this->set('SRM_Valor',100.000);
$this->set('SRM_MesReferencia',$mes_referencia);
$this->set('SRM_AnoReferencia',$ano_referencia);
if (!$this->inserir()) {
$ok = false;
break;
}
//Gera o boleto
$boletos->set('SVB_Mensalidade_DR', $this->get('SRM_RowID'));
$boletos->set('SVB_DataVencimento', $data_vencto);
$boletos->set('SVB_Valor', $valores_entrancia[$oficio['CID_Entrancia']]['SRV_Valor']);
//$boletos->set('SVB_Valor', 100.000);
if (is_numeric($id_texto_usar)) {
$boletos->set('SVB_MensagemBoleto_DR',$id_texto_usar);
}
if (!$boletos->inserir()) {
$ok = false;
break;
}
}
}
if ($ok)
mysqli_commit($this->conexao);
else
mysqli_rollback($this->conexao);
if ($antes==1)
mysqli_autocommit($this->conexao,true);
else
mysqli_autocommit($this->conexao,false);
return $ok;
}
function Fetch($resultado) {
$dados = mysql_fetch_assoc($resultado);
if ($dados) {
$this->carrega($dados);
return true;
}
else
return false;
}
}
?>
|