require_once("sqlserver.class.php");
class ODBC_SQLServer extends SQLServer
{
var $tabelas, $nometabelas, $relacionamentos;
function ODBC_SQLServer($conn, $tablenames, $relations = null)
{ //construtor
$this->conn = $conn;
$this->nometabelas = array();
$this->nometabelas = $tablenames;
$this->relacionamentos = $relations;
//die($this->odbc_conn);
$this->tabelas = array();
foreach ($this->nometabelas as $nome){
$this->tabelas[$nome] = array();
}
}
//formata a data do pt_br para ingles
function formataDataEn($dt=''){
if($dt == '') return '';
list($dia,$mes,$ano)=split("/", $dt,3);
$retorno = "".$ano."-".$mes."-".$dia;
return $retorno;
}
// formata a data do odbc pro formato brasileiro
function formataDataPt($dt=''){
if($dt == '') return '';
list($ano,$mes,$dia)=split("-", $dt,3);
$retorno = "".$dia."/".$mes."/".$ano;
return $retorno;
}
function set($tabela, $campo, $val){
if($this->checkcampo($tabela, $campo)){
$this->tabelas[$tabela][$campo] = $val;
return true;
}
else return false;
}
function checkcampo($tabela, $campo){
$this->query="SP_COLUMNS ".$tabela;
$id = $this->execute($this->conn, $this->query);
while ($linha = odbc_fetch_array($id)){
if($campo == $linha['COLUMN_NAME']){
odbc_free_result($id);
return true;
}
}
odbc_free_result($id);
return false;
}
function get($tabela, $campo){
if(isset($this->tabelas[$tabela][$campo]))
return $this->tabelas[$tabela][$campo];
else
return null;
}
function insert($tipo_func){
die("
Inserção Desabilitada");
}
function update(){
die(" Update Desabilitado!");
}
function delete($tabelas, $sql){
if($this->TestDelete()){
$this->query = "DELETE * FROM $tabelas WHERE $sql";
return $this->execute($this->conn, $this->query);
}
//die(" Deleção desabilitada!");
}
function TestDelete(){
return true;
}
function TestInsert(){
return true;
}
function TestUpdate(){
return true;
}
function reset(){
unset($this->tabelas);
// EXECUTAR ESSE CÓDIGO PARA CADA TABELA
/*if(sizeof($this->tabela)){
foreach($this->tabela as $campo => $valor){
unset($this->tabela[$campo]);
}
}*/
}
function listar($campos = "*", $usatabelas = null, $orderby = null){
$this->query = "";
$first = true;
$usada = array();
foreach($this->nometabelas as $index => $nome){
$usada[$nome] = false;
}
$usada[$this->nometabelas[0]] = true;
if($usatabelas != null)
foreach ($usatabelas as $indtab => $nometab)
$usada[$nometab] = true;
//while(list($key,$val) = each($table))
// echo "\n$key=>$val";
//die("querie".$this->query);
$tables = array();
foreach ($usada as $nometab => $val){
if($usada[$nometab]) $tables[sizeof($tables)] = $nometab;
}
if(sizeof($this->tabelas)){
foreach ($this->tabelas as $nome => $tabela) {
foreach ($tabela as $campo => $valor){
if(!is_null($this->tabelas[$nome][$campo])){
if(!empty($this->tabelas[$nome][$campo])){
if($nome != $this->nometabelas[0]){
if(!$usada[$nome]){
$usada[$nome] = true;
$tables[sizeof($tables)] = $nome;
}
}
if($first){
$first = false;
$this->query .= " WHERE $nome.$campo = '".$valor."'";
}
else
$this->query .= " AND $nome.$campo = '".$valor."'";
}
}
}
}
}
for ($i=0; $inometabelas);$i++){
for ($j=$i+1; $jnometabelas);$j++){
if($usada[$this->nometabelas[$i]] && $usada[$this->nometabelas[$j]] && $this->relacionamentos[$this->nometabelas[$i]][$this->nometabelas[$j]] != null){
$this->query .= " AND ".$this->nometabelas[$i].".".$this->relacionamentos[$this->nometabelas[$j]][$this->nometabelas[$i]]." = ".$this->nometabelas[$j].".".$this->relacionamentos[$this->nometabelas[$i]][$this->nometabelas[$j]];
}
}
}
if(!is_null($orderby))
$this->query .= " ORDER BY ".$orderby;
//echo sizeof($tables).";;";
return $this->vt_recordset($campos, $tables, $this->query);
}
/**
* retorna o contracheque do mês num vetor com a estrutura
* $vt_retorno['cadastro'][..dados..] --dados fixos
* $vt_retorno['ficha'][..contas..][..dados..] -dados que variam mensalmente (a maior parte são contas)
*
* @param string $cpf
* @param date $competencia
* @return array[][][] (3D)
*/
function gera_declaracao_rendimentos($cpf = null, $ano = null){
if(is_null($cpf) || is_null($ano))
return null;
$campos = array('PESSOAL."AREA" AS "PESSOAL.AREA"',
'PESSOAL."CCUSTO" AS "PESSOAL.CCUSTO"',
'PESSOAL."CHAPA" AS "PESSOAL.CHAPA"',
'PESSOAL."CPF" AS "PESSOAL.CPF"',
'PESSOAL."DEMISSAO" AS "PESSOAL.DEMISSAO"',
'PESSOAL."EMPRESA" AS "PESSOAL.EMPRESA"',
'PESSOAL."ID" AS "PESSOAL.ID"',
'PESSOAL."LOCAL" AS "PESSOAL.LOCAL"',
'PESSOAL."NOME" AS "PESSOAL.NOME"',
'PESSOAL."RES_BAIRRO" AS "PESSOAL.RES_BAIRRO"',
'PESSOAL."RES_CEP" AS "PESSOAL.RES_CEP"',
'PESSOAL."RES_ENDEREC" AS "PESSOAL.RES_ENDEREC"',
'EMPRESAS."DESCRICAO" AS "EMPRESAS.DESCRICAO"',
'EMPRESAS."CGC" AS "EMPRESAS.CGC"',
'EMPRESAS."ENDERECO" AS "EMPRESAS.ENDERECO"',
'EMPRESAS."END_NUMERO" AS "EMPRESAS.END_NUMERO"',
'EMPRESAS."END_COMPL" AS "EMRPESAS.END_COMPL"',
'EMPRESAS."END_BAIRRO" AS "EMPRESAS.END_BAIRRO"',
'EMPRESAS."END_CIDADE" AS "EMPRESAS.END_CIDADE"',
'EMPRESAS."END_UF" AS "EMPRESAS.END_UF"',
'EMPRESAS."NOMEPESSOA" AS "EMPRESAS.NOMEPESSOA"',
'FICHA."CONTA" AS "FICHA.CONTA"',
'FICHA."VALOR" AS "FICHA.VALOR"',
'FICHA."COMPETENCIA" AS "FICHA.COMPETENCIA"',
'CCUSTO."DESCRICAO" AS "CCUSTO.DESCRICAO"',
'CIDADES."DESCRICAO" AS "CIDADES.DESCRICAO"',
'CIDADES."ESTADO" AS "CIDADES.ESTADO"');
$tabelas = array( 'pessoal',
'ficha',
'ccusto',
'cidades',
'empresas');
$this->query = "where PESSOAL.ID = FICHA.ID
and PESSOAL.CCUSTO = CCUSTO.CODIGO
and PESSOAL.RES_CIDADE = CIDADES.CODIGO
and PESSOAL.EMPRESA = EMPRESAS.CODIGO
and ficha.conta like 'DIRF%'
and YEAR(ficha.competencia) = '$ano'
and pessoal.cpf = '$cpf'";
$vt_result = $this->vt_recordset($campos, $tabelas, $this->query);
return $vt_result;
}
function gera_tempo_trabalho($cpf = null){
if(is_null($cpf))
return null;
$campos = array('PESSOAL."ADMISSAO" AS "PESSOAL.ADMISSAO"');
$tabelas = array( 'pessoal');
$this->query = "where pessoal.cpf = '$cpf'";
$vt_result = $this->vt_recordset($campos, $tabelas, $this->query);
return $vt_result;
}
//MODIFICADO - COLOCANDO DECLARAÇÃO DE RENDIMENTOS DE TODOS OS ANOS - FECHA
//MODIFICADO - GERANDO O ABONO PECUNIÁRIO DE FÉRIAS - ABRE
function gera_abono_pecuniario_ferias($id = null, $ano = null){
if(is_null($id) || is_null($ano))
return null;
$campos = array("VALOR");
$tabelas = array("FICHA");
$datahoje = getdate();
if($ano >= 2008){
$this->query = "WHERE ID = $id AND CONTA = 'DIRF_ABONOFER' AND COMPETENCIA LIKE '%".$ano."%'";
} else {
$this->query = "WHERE ID = $id AND CONTA LIKE '%ABONOCA%' AND COMPETENCIA LIKE '%".$ano."%'";
}
$vt_result = $this->vt_recordset($campos, $tabelas, $this->query);
return $vt_result;
}
function gera_abono_pecuniario_ferias3($id = null, $ano = null){
if(is_null($id) || is_null($ano))
return null;
$campos = array("VALOR");
$tabelas = array("FICHA");
$datahoje = getdate();
if($ano != $datahoje['year']-1){
$this->query = "WHERE ID = $id AND CONTA LIKE '%ABONO3CA%' AND COMPETENCIA LIKE '%".$ano."%'";
}
$vt_result = $this->vt_recordset($campos, $tabelas, $this->query);
return $vt_result;
}
//MODIFICADO - GERANDO O ABONO PECUNIÁRIO DE FÉRIAS - FECHA
function gera_pensionistas($id = null){
if(is_null($id))
return null;
$campos = array("NOME", "CPF");
$tabelas = array("PENSIONISTAS");
$this->query = "WHERE ID = $id";
$vt_result = $this->vt_recordset($campos, $tabelas, $this->query);
return $vt_result;
}
function gera_contracheque($cpf = null, $ano = null, $mes = null){
if(is_null($cpf) || is_null($ano) || is_null($mes))
return null;
$is_13sal = false;
if ($mes == "13a")
$mes = "6";
if ($mes == "13b")
$mes = "12";
$competencia = $ano."-".str_pad($mes, 2, '0', STR_PAD_LEFT)."-01";
$vt_retorno = array();
$vt_retorno['cadastro'] = array();
$vt_retorno['ficha'] = array();
//recuperando os dados do funcionário
$campos = array("PESSOAL.ID"
, "HORARIO.HORASMES"
, "CARGOS.DESCRICAO AS 'CARGO'"
, "CARGOS.CODIGO AS 'CARGO_CODIGO'"
, "FUNCAOGRAT.DESCRICAO AS 'FUNCAO'"
, "FUNCAOGRAT.CODIGO AS 'FUNCAO_CODIGO'"
, "PESSOAL.CHAPA AS 'MATRICULA'"
, "ESTR_EMPR.DESCRICAO AS 'AREA'"
, "PESSOAL.NOME"
, "PESSOAL.PAG_BANCO"
, "PESSOAL.PAG_AGENCIA"
, "PESSOAL.PAG_CONTA"
, "PESSOAL.RG"
, "PESSOAL.RG_ORGAO"
, "PESSOAL.ADMISSAO"
, "PESSOAL.PIS"
, "PESSOAL.CTPS"
, "PESSOAL.CTPS_DATA"
, "PESSOAL.CTPS_SERIE"
, "PESSOAL.EMPRESA AS 'CODIGO_EMPRESA'"
, "PESSOAL.NIVEL AS 'NIVEL'"
, "PESSOAL.FUNCAO_NIVEL AS 'FUNCAO_NIVEL'"
, "PESSOAL.CARGO_CLASSE AS 'CLASSE'"
, "PESSOAL.FUNCAO_CLASSE AS 'FUNCAO_CLASSE'"
, "PESSOAL.PREVIND_OPCAO AS 'PREVIND_OPCAO'"
, "PESSOAL.ASSIMED AS 'ASSIMED'"
, "PESSOAL.DATA_NASC AS 'DATA_NASC'"
, "EMPRESAS.DESCRICAO AS 'EMPRESA'");
$tables = array("HORARIO"
, "CARGOS"
, "FUNCAOGRAT"
, "ESTR_EMPR"
, "EMPRESAS"
, "PESSOAL");
$this->query = " WHERE
PESSOAL.FUNCAO = FUNCAOGRAT.CODIGO
AND HORARIO.CODIGO = PESSOAL.HORARIO
AND PESSOAL.CARGO = CARGOS.CODIGO
AND ESTR_EMPR.CODIGO = PESSOAL.AREA
AND EMPRESAS.CODIGO = PESSOAL.EMPRESA
AND EMPRESAS.DESCRICAO NOT LIKE '%INSS%'
AND PESSOAL.DEMISSAO IS NULL
AND PESSOAL.CPF = '$cpf'";
$vt_cadastro = $this->vt_recordset($campos, $tables, $this->query);
//print_r($vt_cadastro);
//die();
for($i=0; $i $val){
$vt_retorno['cadastro'][$i][$field] = $val;
}
}
unset($tables, $campos);
//recuperando as contas da ficha para o mês de competência
$campos = array("PESSOAL.ID", "FICHA.*", "CONTAS.*", "TIPO_CONTAS.DESCRICAO AS 'TIPO_CONTAS_DESCRICAO'", "PESSOAL.EMPRESA AS 'CODIGO_EMPRESA'");
$tables = array("FICHA", "CONTAS", "PESSOAL", "TIPO_CONTAS", "EMPRESAS");
$this->query = " WHERE ";
$this->query .=" CONTAS.DESCRICAO NOT LIKE '% CA'
AND FICHA.VALOR <> 0
AND CONTAS.DESCRICAO NOT LIKE '% (CA)'
AND TIPO_CONTAS.CODIGO = CONTAS.TIPO
AND CONTAS.INATIVA = 0
AND FICHA.CONTA = CONTAS.CONTA
AND FICHA.ID = PESSOAL.ID
AND PESSOAL.EMPRESA = EMPRESAS.CODIGO
AND EMPRESAS.DESCRICAO NOT LIKE '%INSS%'
AND PESSOAL.DEMISSAO IS NULL
AND PESSOAL.CPF = '$cpf'
AND DATEDIFF(DD, FICHA.COMPETENCIA, '$competencia') = 0
ORDER BY
PESSOAL.EMPRESA, TIPO_CONTAS_DESCRICAO";//MODIFICADO --> AND FICHA.CONTA = 'DIRF_ABONOFER'
$vt_ficha = array();
$vt_ficha = $this->vt_recordset($campos, $tables, $this->query);
//--tratar o vt_ficha antes de jogar no $vt_retorno
$cod_empresa = $vt_ficha[0]['CODIGO_EMPRESA'];
$vt_retorno['ficha'][0] = array();
$i = 0;
foreach ($vt_ficha as $row){
if($row['CODIGO_EMPRESA'] != $cod_empresa){
$i++;
$vt_retorno['ficha'][$i] = array();
$cod_empresa = $row['CODIGO_EMPRESA'];
}
$vt_retorno['ficha'][$i][$row['CONTA']] = array();
$vt_retorno['ficha'][$i][$row['CONTA']] = $row;
}
//print_r($vt_ficha);
unset($vt_ficha, $vt_cadastro, $campos, $tables);
return $vt_retorno;
}
//ADICIONADO - PROPOSTA DE CONTRACHEQUE - ABRE
function gera_proposta_contracheque($codigo = null, $cargo = null, $faixa = null){ //PROCURA SAL DE FUNCIONARIO
if(is_null($codigo) || is_null($cargo) || is_null($faixa))
return null;
/*echo "";*/
$campos = array("CARGOS.DESCRICAO AS 'CARGO'"
, "CARGO_SAL.DESCRICAO AS 'CLASSE'"
, "CARGO_SAL.$faixa AS 'FAIXA'");
$tables = array("CARGO_SAL"
, "CARGOS");
$this->query = " WHERE
CARGOS.CODIGO = '$cargo'
AND CARGOS.CLASSESALARIAL = '$codigo'
AND CARGO_SAL.CODIGO = '$codigo'";
$vt_proposta = $this->vt_recordset($campos, $tables, $this->query);
return $vt_proposta;
}
function gera_proposta_contracheque_comissionado($codigo = null, $cargo = null, $faixa = null){ //PROCURA SAL DE CARGO COMISSIONADO
if(is_null($codigo) || is_null($cargo) || is_null($faixa))
return null;
/*echo "";*/
$campos = array("FUNCAOGRAT.DESCRICAO AS 'CARGO'"
, "FUNCAO_SAL.DESCRICAO AS 'CLASSE'"
, "FUNCAO_SAL.$faixa AS 'FAIXA'");
$tables = array("FUNCAO_SAL"
, "FUNCAOGRAT");
$this->query = " WHERE
FUNCAOGRAT.CODIGO = '$cargo'
AND FUNCAOGRAT.FUNCAO_CLASSE = '$codigo'
AND FUNCAO_SAL.CODIGO = '$codigo'";
$vt_proposta = $this->vt_recordset($campos, $tables, $this->query);
return $vt_proposta;
}
function gera_proposta_contracheque_salario($cpf = null){ //PROCURA SAL CORRETO
if(is_null($cpf))
return null;
/*echo "";*/
$campos = array("FICHA.VALOR AS 'SALARIO'"
, "PESSOAL.ID AS 'ID'"
, "PESSOAL.EMPRESA AS 'EMPRESA'");
$tables = array("FICHA"
, "PESSOAL");
$this->query = " WHERE
FICHA.ID = PESSOAL.ID
AND PESSOAL.CPF = '$cpf'
AND FICHA.CONTA = 'SALBAS'
ORDER BY FICHA.COMPETENCIA DESC";
$vt_salario = $this->vt_recordset($campos, $tables, $this->query);
return $vt_salario;
}
function gera_proposta_cargo_comissionado($cpf = null){ //PROCURA SAL DE CARGO COMISSIONADO CORRETO
if(is_null($cpf))
return null;
/*echo "";*/
$campos = array("FICHA.VALOR AS 'COMISSIONADO'"
, "PESSOAL.ID AS 'ID'"
, "PESSOAL.EMPRESA AS 'EMPRESA'");
$tables = array("FICHA"
, "PESSOAL");
$this->query = " WHERE
FICHA.ID = PESSOAL.ID
AND PESSOAL.CPF = '$cpf'
AND FICHA.CONTA = 'CARGOCOMISBAS'
AND PESSOAL.DEMISSAO IS NULL
ORDER BY FICHA.COMPETENCIA DESC";
$vt_salario = $this->vt_recordset($campos, $tables, $this->query);
return $vt_salario;
}
//ADICIONADO - PROPOSTA DE CONTRACHEQUE - FECHA
//ADICIONADO - GERENCIAR HORARIOS - ABRE
function procura_unidade_horarios($cpf = null){
if(is_null($cpf))
return null;
/*echo "";*/
$campos = array("LOCAL");
$tables = array("PESSOAL");
$this->query = " WHERE
DEMISSAO IS NULL
AND CPF = '$cpf'";
$vt_local = $this->vt_recordset($campos, $tables, $this->query);
return $vt_local;
}
function gera_funcionarios_horarios_ci($cpf = null, $horario_cadastro = null){
if((is_null($cpf)) || (is_null($horario_cadastro)))
return null;
$campos = array("AREA"
, "CCUSTO");
$tables = array("PESSOAL");
$this->query = " WHERE
CPF = '$cpf'
AND DEMISSAO IS NULL";
$vt_pessoa = $this->vt_recordset($campos, $tables, $this->query);
foreach($vt_pessoa as $index => $registro){
$area = substr($registro['AREA'], -3);
/*$ccusto1 = substr($registro['CCUSTO'], -4);
$ccusto2 = substr($registro['CCUSTO'], 0, 9);*/
break;
}
/*echo "";*/
unset($tables, $campos);
$campos = array("NOME"
, "CPF"
, "LOCAL");
$tables = array("PESSOAL");
//if($horario_cadastro == 1){
$this->query = " WHERE DEMISSAO IS NULL
AND CPF != '00000000000'
AND CPF != '$cpf'
AND (LOCAL like '%101' OR LOCAL like '%201' OR LOCAL like '%301' OR LOCAL like '%401')
ORDER BY NOME";
/*} else
if($horario_cadastro == 2){
$this->query = " WHERE AREA like '%".$area."'
AND DEMISSAO IS NULL
AND CPF != '00000000000'
AND CCUSTO like '".$ccusto2."%'
AND CPF != '$cpf'
AND (LOCAL like '%101' OR LOCAL like '%201' OR LOCAL like '%301' OR LOCAL like '%401')
ORDER BY NOME";
} else
if($horario_cadastro == 3){
$this->query = " WHERE AREA like '%".$area."'
AND DEMISSAO IS NULL
AND CPF != '00000000000'
AND CPF != '$cpf'
AND (LOCAL like '%101' OR LOCAL like '%201' OR LOCAL like '%301' OR LOCAL like '%401')
ORDER BY NOME";
}*/
$vt_pessoas = $this->vt_recordset($campos, $tables, $this->query);
return $vt_pessoas;
}
/*function gera_funcionarios_horarios_ctgas($cpf = null, $local = null, $horario_cadastro = null){
if((is_null($cpf)) || (is_null($local)) || (is_null($horario_cadastro)))
return null;
$campos = array("AREA"
, "CCUSTO");
$tables = array("PESSOAL");
$this->query = " WHERE
CPF = '$cpf'
AND DEMISSAO IS NULL";
$vt_pessoa = $this->vt_recordset($campos, $tables, $this->query);
foreach($vt_pessoa as $index => $registro){
$area = substr($registro['AREA'], -3);
$ccusto1 = substr($registro['CCUSTO'], -4);
$ccusto2 = substr($registro['CCUSTO'], 0, 9);
break;
}
unset($tables, $campos);
$campos = array("NOME"
, "CPF");
$tables = array("PESSOAL");
if($horario_cadastro == 1){
$this->query = " WHERE LOCAL = ".$local."
AND CPF != '00000000000'
AND CCUSTO like '%".$ccusto1."'
AND CCUSTO like '".$ccusto2."%'
AND AREA like '%".$area."'
AND CPF != '$cpf'
AND DEMISSAO IS NULL
ORDER BY NOME";
} else
if($horario_cadastro == 2){
$this->query = " WHERE LOCAL = ".$local."
AND CPF != '00000000000'
AND CCUSTO like '".$ccusto2."%'
AND AREA like '%".$area."'
AND CPF != '$cpf'
AND DEMISSAO IS NULL
ORDER BY NOME";
} else
if($horario_cadastro == 3){
$this->query = " WHERE LOCAL = ".$local."
AND CPF != '00000000000'
AND AREA like '%".$area."'
AND CPF != '$cpf'
AND DEMISSAO IS NULL
ORDER BY NOME";
}
$vt_pessoas = $this->vt_recordset($campos, $tables, $this->query);
return $vt_pessoas;
}*/
function gera_funcionarios_horarios_unidades($cpf = null, $local = null){
if((is_null($cpf)) || (is_null($cpf)))
return null;
$campos = array("NOME"
, "CPF"
, "LOCAL");
$tables = array("PESSOAL");
$this->query = " WHERE LOCAL like '%".$local."'
AND DEMISSAO IS NULL
AND CPF != '00000000000'
AND CPF != '$cpf'
ORDER BY NOME";
$vt_pessoas = $this->vt_recordset($campos, $tables, $this->query);
return $vt_pessoas;
}
function gera_funcionarios_horarios_casas($cpf = null, $horario_fiern = null, $horario_sesi = null, $horario_senai = null, $horario_iel = null, $horario_sistemafiern = null){
if((is_null($cpf)) || (is_null($horario_fiern)) || (is_null($horario_sesi)) || (is_null($horario_senai)) || (is_null($horario_iel)) || (is_null($horario_sistemafiern)))
return null;
/*echo "";*/
$sql = "AND (";
if($horario_fiern == 1)
$sql .= "EMPRESA like '%122'";
if($horario_sesi == 1){
if($horario_fiern == 1) $sql .= " OR ";
$sql .= "EMPRESA like '%222'";
}
if($horario_senai == 1){
if(($horario_fiern == 1) or ($horario_sesi == 1)) $sql .= " OR ";
$sql .= "EMPRESA like '%322'";
}
if($horario_iel == 1){
if(($horario_fiern == 1) or ($horario_sesi == 1) or ($horario_senai == 1)) $sql .= " OR ";
$sql .= "EMPRESA like '%422'";
}
$sql .= ")";
if($horario_sistemafiern == 1)
$sql = "";
$campos = array("NOME"
, "CPF"
, "LOCAL");
$tables = array("PESSOAL");
$this->query = " WHERE DEMISSAO IS NULL
AND CPF != '00000000000'
AND CPF != '$cpf'
".$sql."
ORDER BY NOME";
$vt_pessoas = $this->vt_recordset($campos, $tables, $this->query);
return $vt_pessoas;
}
//ADICIONADO - GERENCIAR HORARIOS - FECHA
//ADICIONADO - GERANDO FICHA ENCARGOS DE FAMILIA - ABRE
function gera_encargos_familia($cpf = null){
if((is_null($cpf)) || (is_null($cpf)))
return null;
$campos = array("e.DESCRICAO as 'EMP_G'"
, "e.NOMERESP as 'EMP_P'"
, "p.CHAPA as 'MAT'"
, "p.NOME as 'NOME'"
, "p.RES_FONE as 'FONE'"
, "c.DESCRICAO as 'CARGO'"
, "f.DESCRICAO as 'COMIS'"
, "p.RES_ENDEREC as 'END'"
, "p.RES_COMPL as 'COMPL'"
, "p.RES_BAIRRO as 'BAIRRO'"
, "cd.DESCRICAO as 'CIDADE'"
, "p.RES_CEP as 'CEP'"
, "p.RES_ESTADO as 'UF'"
, "cv.DESCRICAO as 'CIVIL'"
, "p.CTPS as 'CTPS'"
, "p.CTPS_SERIE as 'CTPS_SERIE'"
, "p.CTPS_DATA as 'CTPS_DATA'");
$tables = array("PESSOAL as p"
, "FUNCAOGRAT as f"
, "CARGOS as c"
, "CIDADES as cd"
, "CIVIL as cv"
, "EMPRESAS as e");
$this->query = " WHERE p.CPF = '".$cpf."'
AND p.CPF != '00000000000'
AND p.[CARGO] = c.[CODIGO]
AND p.CARGO_CLASSE = c.CLASSESALARIAL
AND p.FUNCAO = f.CODIGO
AND p.FUNCAO_CLASSE = f.FUNCAO_CLASSE
AND p.RES_CIDADE = cd.CODIGO
AND p.EST_CIVIL = cv.CODIGO
AND p.EMPRESA = e.CODIGO
AND p.DEMISSAO IS NULL";
$vt_pessoas = $this->vt_recordset($campos, $tables, $this->query);
foreach($vt_pessoas as $index => $registro){
$comiss = $registro['COMIS'];
break;
}
if($comiss != "NÃO SE APLICA"){
unset($tables, $campos);
$campos = array("e.DESCRICAO as 'EMP_G'"
, "e.NOMERESP as 'EMP_P'"
, "p.CHAPA as 'MAT'"
, "p.NOME as 'NOME'"
, "p.RES_FONE as 'FONE'"
, "f.DESCRICAO as 'COMIS'"
, "p.RES_ENDEREC as 'END'"
, "p.RES_COMPL as 'COMPL'"
, "p.RES_BAIRRO as 'BAIRRO'"
, "cd.DESCRICAO as 'CIDADE'"
, "p.RES_CEP as 'CEP'"
, "p.RES_ESTADO as 'UF'"
, "cv.DESCRICAO as 'CIVIL'"
, "p.CTPS as 'CTPS'"
, "p.CTPS_SERIE as 'CTPS_SERIE'"
, "p.CTPS_DATA as 'CTPS_DATA'");
$tables = array("PESSOAL as p"
, "FUNCAOGRAT as f"
, "CIDADES as cd"
, "CIVIL as cv"
, "EMPRESAS as e");
$this->query = " WHERE p.CPF = '".$cpf."'
AND p.CPF != '00000000000'
AND p.FUNCAO = f.CODIGO
AND p.FUNCAO_CLASSE = f.FUNCAO_CLASSE
AND p.RES_CIDADE = cd.CODIGO
AND p.EST_CIVIL = cv.CODIGO
AND p.EMPRESA = e.CODIGO
AND p.DEMISSAO IS NULL";
$vt_pessoa = $this->vt_recordset($campos, $tables, $this->query);
return $vt_pessoa;
}
return $vt_pessoas;
}
//ADICIONADO - GERANDO FICHA ENCARGOS DE FAMILIA - FECHA
//CALCULAR IDADE - ABRE
function calcula_idade($nascimento) {
$hoje = date("d-m-Y"); //pega a data d ehoje
$aniv = explode("-", $nascimento); //separa a data de nascimento em array, utilizando o símbolo de - como separador
$atual = explode("-", $hoje); //separa a data de hoje em array
$idade = $atual[2] - $aniv[2];
if($aniv[1] > $atual[1]){ //verifica se o mês de nascimento é maior que o mês atual
$idade--; //tira um ano, já que ele não fez aniversário ainda
} else
if($aniv[1] == $atual[1] && $aniv[0] > $atual[0]){ //verifica se o dia de hoje é maior que o dia do aniversário
$idade--; //tira um ano se não fez aniversário ainda
}
return $idade; //retorna a idade da pessoa em anos
}
//CALCULAR IDADE - FECHA
function consultar() {
$this->query = "";
$first = true;
$usada = array();
foreach($this->nometabelas as $index => $nome){
$usada[$nome] = false;
}
//while(list($key,$val) = each($table))
// echo "\n$key=>$val";
//die("querie".$this->query);
$tables = array();
//$tables[0] = $this->nometabelas[0];
//$usada[$this->nometabelas[0]] = true;
if(sizeof($this->tabelas)){
foreach ($this->tabelas as $nome => $tabela) {
foreach ($tabela as $campo => $valor){
if(!is_null($this->tabelas[$nome][$campo])){
if(!empty($this->tabelas[$nome][$campo])){
if(!$usada[$nome]){
$usada[$nome] = true;
$tables[sizeof($tables)] = $nome;
}
if($first){
$first = false;
$this->query .= " WHERE $nome.$campo = '".$valor."'";
}
else
$this->query .= " AND $nome.$campo = '".$valor."'";
}
}
}
}
}
for ($i=0; $inometabelas);$i++){
for ($j=$i+1; $jnometabelas);$j++){
if($usada[$this->nometabelas[$i]] && $usada[$this->nometabelas[$j]]){
$this->query .= " AND ".$this->nometabelas[$i].".".$this->relacionamentos[$this->nometabelas[$j]][$this->nometabelas[$i]]." = ".$this->nometabelas[$j].".".$this->relacionamentos[$this->nometabelas[$i]][$this->nometabelas[$j]];
}
}
}
$qry = $this->query;
$qry2 = "";
foreach($this->nometabelas as $index => $nome){
if($usada[$nome]){
$this->query = "SP_COLUMNS $nome";
$rs = $this->execute();
while($row=odbc_fetch_array($rs)){
if($qry2 == "")
$qry2 = "$nome.".$row['COLUMN_NAME']." AS '$nome::".$row['COLUMN_NAME']."'";
else
$qry2 .= ", $nome.".$row['COLUMN_NAME']." AS '$nome::".$row['COLUMN_NAME']."'";
}
}
}
$this->query = "SELECT $qry2 FROM ";
for($i=0; $i< sizeof($tables); $i++){
$this->query .= $tables[$i];
if($i < sizeof($tables)-1) $this->query .= ",";
}
$this->query .= $qry;
//die($this->query);
$rs = $this->execute($showerror=true, $debug=true);
if($row_rs = odbc_fetch_array($rs))
$total_linhas = 1;
else
$total_linhas = 0;
$indexnomes = array_flip($this->nometabelas);
if ($total_linhas>0){
foreach ($row_rs as $campo => $valor){
$nomes = split("::", $campo);
$this->tabelas[$this->nometabelas[$indexnomes[$nomes[0]]]][$nomes[1]] = $valor;
}
$bl_aux = true;
}else $bl_aux = false;
odbc_free_result($rs);
return $bl_aux;
//die("função de consulta desabilitada.");
}
function show($tabela, $campo){
if(isset($this->tabelas[$tabela][$campo]))
return true;
else
return false;
}
}
?>