function bb_condicaosubpesanterior($prefixo = null)
{
    $submes = db_mesfolha() - 1;
    $subano = db_anofolha();
    // $submes = 1-1;
    // $subano = 2006;
    if ($submes < 1) {
        $submes = 12;
        $subano -= 1;
    }
    $retorno = " where " . $prefixo . "anousu = " . $subano . " and " . $prefixo . "mesusu = " . $submes;
    if (db_at(strtoupper($prefixo), "R45_R61_R30_R51_R05_R12_R03_R27_R57_R42_R25_R28_R41_R52_R63_R17_R60_R64_R65_R37_R66_R67_") == 0) {
        $retorno .= "  and  " . $prefixo . "instit = " . DB_getsession("DB_instit");
    }
    return $retorno;
}
 *  
 *  Copia da licenca no diretorio licenca/licenca_en.txt 
 *                                licenca/licenca_pt.txt 
 */
error_reporting('** CONSULTA FUNCIONAL! **');
session_start();
include "libs/db_conecta.php";
include "libs/db_stdlib.php";
include "libs/db_sql.php";
include "libs/db_utils.php";
include "dbforms/db_funcoes.php";
parse_str(base64_decode($HTTP_SERVER_VARS["QUERY_STRING"]));
$oGet = db_utils::postMemory($_GET);
$numcgm = db_getsession("DB_login");
$anoFolha = db_anofolha();
$mesFolha = db_mesfolha();
db_logs("", "", 0, "Consulta Funcional.");
?>
<html>
<head>
<title><?php 
echo $w01_titulo;
?>
</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="config/estilos.css" rel="stylesheet" type="text/css">
<script language="JavaScript" src="scripts/db_script.js"></script>
</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" bgcolor="<?php 
echo $w01_corbody;
?>
 function sql_query_com_temporarios($rh01_regist = null, $campos = "*", $ordem = null, $dbwhere = "")
 {
     $sql = "select ";
     if ($campos != "*") {
         $campos_sql = split("#", $campos);
         $virgula = "";
         for ($i = 0; $i < sizeof($campos_sql); $i++) {
             $sql .= $virgula . $campos_sql[$i];
             $virgula = ",";
         }
     } else {
         $sql .= $campos;
     }
     $sql .= " from rhpessoal ";
     $sql .= "      left  join rhpessoalmov on  rh02_anousu = " . db_anofolha() . "\n                                           and  rh02_mesusu = " . db_mesfolha() . "\n                                           and  rh02_regist = rh01_regist\n                                           and  rh02_instit = " . db_getsession("DB_instit") . " ";
     $sql .= "      left  join rhlota       on  rhlota.r70_codigo = rhpessoalmov.rh02_lota\n                                           and  rhlota.r70_instit = rhpessoalmov.rh02_instit ";
     $sql .= "      inner join cgm  on  cgm.z01_numcgm = rhpessoal.rh01_numcgm";
     $sql .= "      inner join db_config    on  db_config.codigo = rhpessoal.rh01_instit";
     $sql .= "      inner join rhestcivil  on  rhestcivil.rh08_estciv = rhpessoal.rh01_estciv";
     $sql .= "      inner join rhraca  on  rhraca.rh18_raca = rhpessoal.rh01_raca";
     $sql .= "      left  join rhfuncao     on  rhfuncao.rh37_funcao = rhpessoalmov.rh02_funcao\n                                           and  rhfuncao.rh37_instit = rhpessoalmov.rh02_instit  ";
     $sql .= "      inner join rhinstrucao  on  rhinstrucao.rh21_instru = rhpessoal.rh01_instru";
     $sql .= "      inner join rhnacionalidade  on  rhnacionalidade.rh06_nacionalidade = rhpessoal.rh01_nacion";
     $sql .= "      left  join rhpesrescisao on rh02_seqpes = rh05_seqpes";
     $sql .= "      left  join rhsindicato   on rh01_rhsindicato = rh116_sequencial";
     $sql .= "      inner join rhreajusteparidade  on  rhreajusteparidade.rh148_sequencial = rhpessoal.rh01_reajusteparidade";
     $sql .= "      left  join rhcontratoemergencial on rh163_matricula = rh01_regist";
     $sql .= "      left  join rhcontratoemergencialrenovacao on rh164_contratoemergencial = rh163_sequencial";
     $sql2 = "";
     if ($dbwhere == "") {
         if ($rh01_regist != null) {
             $sql2 .= " where rhpessoal.rh01_regist = {$rh01_regist} ";
         }
     } else {
         if ($dbwhere != "") {
             $sql2 = " where {$dbwhere}";
         }
     }
     $sql .= $sql2;
     if ($ordem != null) {
         $sql .= " order by ";
         $campos_sql = split("#", $ordem);
         $virgula = "";
         for ($i = 0; $i < sizeof($campos_sql); $i++) {
             $sql .= $virgula . $campos_sql[$i];
             $virgula = ",";
         }
     }
     return $sql;
 }
require_once "fpdf151/impcarne.php";
require_once "fpdf151/scpdf.php";
require_once "libs/db_utils.php";
require_once "libs/db_libpessoal.php";
require_once "classes/db_cgm_classe.php";
require_once "classes/db_iptubase_classe.php";
require_once "classes/db_issbase_classe.php";
require_once "classes/db_rhemitecontracheque_classe.php";
require_once "classes/db_cfpess_classe.php";
$oPost = db_utils::postMemory($_POST);
$oDaoCfpess = new cl_cfpess();
/**
 * Modelo de impressão de relatório contra cheque
 * Retorna false caso der erro na consulta
 */
$iTipoRelatorio = $oDaoCfpess->buscaCodigoRelatorio('contracheque', db_anofolha(), db_mesfolha());
if (!$iTipoRelatorio) {
    db_redireciona('db_erros.php?fechar=true&db_erro=Modelo de impressão invalido, verifique parametros.');
}
validaUsuarioLogado();
db_postmemory($_POST);
parse_str($HTTP_SERVER_VARS['QUERY_STRING']);
$clrhemitecontracheque = new cl_rhemitecontracheque();
$filtro = 'M';
$msg = '';
$local = '';
$tipo_local = 's';
$num_vias = 1;
$ordem = 'M';
$sIp = $HTTP_SERVER_VARS['REMOTE_ADDR'];
$ano = $anocalc;
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA          
 *  02111-1307, USA.                                                  
 *  
 *  Copia da licenca no diretorio licenca/licenca_en.txt 
 *                                licenca/licenca_pt.txt 
 */
include "libs/db_conecta.php";
include "libs/db_stdlib.php";
include "libs/db_sql.php";
include "libs/db_utils.php";
validaUsuarioLogado();
$aRetorno = array();
parse_str(base64_decode($HTTP_SERVER_VARS["QUERY_STRING"]), $aRetorno);
$iMatric = $aRetorno['iMatric'];
$oRHPessoal = db_utils::getDao('rhpessoal');
$sSqlDadosServidor = "select *,\n                             substr((select * from  db_fxxx(rh02_regist,rh02_anousu,rh02_mesusu,rh02_instit)),210,25) as padraoatual\n\t\t\t\t\t\t\t\t\t\t\t  from rhpessoal\n\t\t\t\t\t\t\t\t\t\t\t       inner join rhpessoalmov    on rh02_anousu                        = " . db_anofolha() . " \n\t\t\t\t\t\t\t\t\t\t\t                                 and rh02_mesusu                        = " . db_mesfolha() . "\n\t\t\t\t\t\t\t\t\t\t\t                                 and rh02_regist                        = rh01_regist\n\t\t\t\t\t\t\t\t\t\t\t       left  join rhlota          on rhlota.r70_codigo                  = rhpessoalmov.rh02_lota\n\t\t\t\t\t\t\t\t\t\t\t                                 and rhlota.r70_instit                  = rhpessoalmov.rh02_instit\n\t\t\t\t\t\t\t\t\t\t\t       left  join rhpesbanco      on rh44_seqpes                        = rhpessoalmov.rh02_seqpes\n\t\t\t\t\t\t\t\t\t\t\t       inner join cgm             on cgm.z01_numcgm                     = rhpessoal.rh01_numcgm\n\t\t\t\t\t\t\t\t\t\t\t       left  join db_cgmruas      on db_cgmruas.z01_numcgm              = cgm.z01_numcgm\n\t\t\t\t\t\t\t\t\t\t\t       left  join ruas            on ruas.j14_codigo                    = db_cgmruas.j14_codigo\n\t\t\t\t\t\t\t\t\t\t\t       left  join ruastipo        on ruastipo.j88_codigo                = ruas.j14_tipo\n\t\t\t\t\t\t\t\t\t\t\t       inner join rhestcivil      on rhestcivil.rh08_estciv             = rhpessoal.rh01_estciv\n\t\t\t\t\t\t\t\t\t\t\t       left  join rhfuncao        on rhfuncao.rh37_funcao               = rhpessoal.rh01_funcao\n\t\t\t\t\t\t\t\t\t\t\t                                 and rhfuncao.rh37_instit               = rhpessoalmov.rh02_instit\n\t\t\t\t\t\t\t\t\t\t\t       left  join rhregime        on rhregime.rh30_codreg               = rhpessoalmov.rh02_codreg\n\t\t\t\t\t\t\t\t\t\t\t                                 and rhregime.rh30_instit               = rhpessoalmov.rh02_instit   \n\t\t\t\t\t\t\t\t\t\t\t       inner join rhinstrucao     on rhinstrucao.rh21_instru            = rhpessoal.rh01_instru\n\t\t\t\t\t\t\t\t\t\t\t       left  join rhpespadrao     on rhpespadrao.rh03_seqpes            = rhpessoalmov.rh02_seqpes \n\t\t\t\t\t\t\t\t\t\t\t       left  join rhpesrescisao   on rh02_seqpes = rh05_seqpes\n\t\t\t\t\t\t\t\t\t\t\t where rhpessoal.rh01_regist = {$iMatric}";
$rsDadosServidor = $oRHPessoal->sql_record($sSqlDadosServidor);
$oDadosServidor = db_utils::fieldsMemory($rsDadosServidor, 0);
?>
<html>
<head>
<title><?php 
echo $w01_titulo;
?>
</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="config/estilos.css"        rel="stylesheet" type="text/css">
<link href="config/portalservidor.css" rel="stylesheet" type="text/css">

<script language="JavaScript" src="scripts/scripts.js"></script>
<script language="JavaScript" src="scripts/db_script.js"></script>
 *  
 *  Copia da licenca no diretorio licenca/licenca_en.txt 
 *                                licenca/licenca_pt.txt 
 */
include "libs/db_conecta.php";
include "libs/db_stdlib.php";
include "libs/db_sql.php";
include "libs/db_utils.php";
validaUsuarioLogado();
$aRetorno = array();
parse_str(base64_decode($HTTP_SERVER_VARS["QUERY_STRING"]), $aRetorno);
$iMatric = $aRetorno['iMatric'];
$sSqlFeriasGozadas = " select *\n\t\t\t\t\t\t\t\t\t\t\t\t  from cadferia\n\t\t\t\t\t\t\t\t\t\t\t\t where r30_regist = {$iMatric}\n\t\t\t\t\t\t\t\t\t\t\t\t   and r30_anousu = " . db_anofolha() . "\n\t\t\t\t\t\t\t\t\t\t\t\t   and r30_mesusu = " . db_mesfolha() . "";
$rsFeriasGozadas = db_query($sSqlFeriasGozadas);
$iNroFeriasGozadas = pg_num_rows($rsFeriasGozadas);
$sSqlFeriasaGozar = " select * from (\n                        select to_char(max(ultimo_periodo) + cast('1 day'  as interval ),'yyyy-mm-dd')  as periodo_aquisitivo_inicial,\n                              to_char(max(ultimo_periodo) + cast('1 year' as interval ),'yyyy-mm-dd')  as periodo_aquisitivo_final\n\t\t\t\t\t\t\t\t\t  \t   from ( select case  \n\t\t\t\t\t\t\t\t\t\t\t                   when r30_peraf is not null then r30_peraf  \n\t\t\t\t\t\t\t\t\t\t\t                   else rh01_admiss \n\t\t\t\t\t\t\t\t\t\t\t                 end as ultimo_periodo \n\t\t\t\t\t\t\t\t\t\t\t            from rhpessoal\n\t\t\t\t\t\t\t\t\t\t\t                 inner join rhpessoalmov  on rh02_regist = rh01_regist\n\t\t\t\t\t\t\t\t\t\t\t                                         and rh02_anousu = " . db_anofolha() . "\n                                                               and rh02_mesusu = " . db_mesfolha() . "\n                                       left  join rhpesrescisao on rh05_seqpes = rh02_seqpes\t\t\t\t\t\t\t\t\t\t                                            \n\t\t\t\t\t\t\t\t\t\t\t                 left  join cadferia      on r30_regist  = rh02_regist  \n\t\t\t\t\t\t\t\t\t\t\t                                         and r30_anousu  = rh02_anousu \n\t\t\t\t\t\t\t\t\t\t\t                                         and r30_mesusu  = rh02_mesusu\n\t\t\t\t\t\t\t\t\t\t\t                  left join rhregime      on rh30_codreg = rh02_codreg                    \n\t\t\t\t\t\t\t\t\t\t\t           where rh01_regist = {$iMatric}\n\t\t\t\t\t\t\t\t\t\t\t             and rh05_seqpes is null \n\t\t\t\t\t\t\t\t\t\t\t             and  rh30_vinculo not in ('P','I'))  as x ) as y \n\t\t\t\t\t\t\t\t\t\twhere periodo_aquisitivo_inicial is not null \n\t\t\t\t\t\t\t\t\t\t  and periodo_aquisitivo_final   is not null ";
$rsFeriasaGozar = db_query($sSqlFeriasaGozar);
$iNroFeriasaGozar = pg_num_rows($rsFeriasaGozar);
?>
<html>
<head>
<title><?php 
echo $w01_titulo;
?>
</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="config/estilos.css"        rel="stylesheet" type="text/css">
<link href="config/portalservidor.css" rel="stylesheet" type="text/css">
<script language="JavaScript" src="scripts/scripts.js"></script>
<script language="JavaScript" src="scripts/db_script.js"></script>
</head>
     <tr>
       <td class="labelForm">
         Data de Nascimento:
       </td>
       <td class="dadosForm">
         <?php 
 echo db_formatar($oDependentes->rh31_dtnasc, 'd');
 ?>
       </td>
     
     <?php 
 $sSqlTipoDependente = " select *                                                 ";
 $sSqlTipoDependente .= "   from fc_tipo_dependente({$iMatric},                    ";
 $sSqlTipoDependente .= "                           {$oDependentes->rh31_codigo},  ";
 $sSqlTipoDependente .= "                           " . db_anofolha() . ",             ";
 $sSqlTipoDependente .= "                           " . db_mesfolha() . ",             ";
 $sSqlTipoDependente .= "                           " . db_getsession('DB_instit') . ")";
 $rsTipoDepend = db_query($sSqlTipoDependente);
 $oTipoDepend = db_utils::fieldsMemory($rsTipoDepend, 0);
 if ($oTipoDepend->rlirrf == 'f') {
     $sIRRF = 'Não';
 } else {
     $sIRRF = 'Sim';
 }
 if ($oTipoDepend->rlsalariofamilia == 'f') {
     $sSalarioFamilia = 'Não';
 } else {
     $sSalarioFamilia = 'Sim';
 }
 ?>
       <td class="labelForm">
            <tr>  
              <td>
                <table width="100%">
			            <thead>
				            <tr>
				              <th class="headerTableForm"> Rubrica       </th>
					            <th class="headerTableForm"> Descrição     </th>
					            <th class="headerTableForm"> Quantidade    </th>
			                <th class="headerTableForm" width='10%'>&nbsp;</th>
				              <th class="headerTableForm"> Proventos     </th>
				              <th class="headerTableForm"> Descontos     </th>
				            </tr>           
			            </thead> 
			            <tbody>
				            <?php 
$sSqlRubricas = " select {$sSigla}_rubric as rubric,\n\t\t\t\t                                        {$sSigla}_quant  as quant,\n\t\t\t\t                                        rh27_descr       as descr,\n\t\t\t                                                {$sSigla}_valor  as valor,\n                                                                        {$sSigla}_pd     as tipo,\n\t\t\t\t                                        case when {$sSigla}_pd = 1 then {$sSigla}_valor else 0 end as provento, \n\t\t\t\t                                        case when {$sSigla}_pd = 2 then {$sSigla}_valor else 0 end as desconto\n\t\t\t\t                                   from rhpessoal \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t        inner join rhpessoalmov  on rh02_regist      = rh01_regist     \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t                                and rh02_anousu      = " . db_anofolha() . "\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t                                and rh02_mesusu      = " . db_mesfolha() . "\t                                   \n\t\t\t\t                                        inner join {$sTabela}    on {$sSigla}_regist = rh01_regist \n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t                                        and {$sSigla}_anousu = {$iAnoUsu}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t                                    and {$sSigla}_mesusu = {$iMesUsu}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t                                    and {$sSigla}_instit = rh02_instit\n\t\t\t\t                                        inner join rhrubricas    on rh27_rubric      = {$sSigla}_rubric\n\t\t\t\t                                                                and rh27_instit      = rh02_instit  \n\t\t\t\t                                  where rh01_regist = {$iMatric}\n\t\t\t\t                                 order by {$sSigla}_pd,\n\t\t\t\t                                          {$sSigla}_rubric";
/**
 * Se o parâmetro da sessão "DB_COMPLEMENTAR" estiver ativado e a folha selecionada for salário, complementar ou suplementar, 
 * busca os dados das rubricas da tabela rhhistoricocalculo.
 */
if (cl_cfpess::verificarUtilizacaoEstruturaSuplementar() && ($sSigla == 'r48' || $sSigla == 'r14' || $sSigla == 'supl')) {
    $sSqlRubricas = "  select rh143_rubrica    as rubric,                                                          ";
    $sSqlRubricas .= "        rh143_quantidade as quant,                                                            ";
    $sSqlRubricas .= "        rh27_descr       as descr,                                                            ";
    $sSqlRubricas .= "        sum(rh143_valor) as valor,                                                            ";
    $sSqlRubricas .= "        rh143_tipoevento as tipo,                                                             ";
    $sSqlRubricas .= "        case when (rh143_tipoevento) = 1 then sum(rh143_valor) end as provento,               ";
    $sSqlRubricas .= "        case when (rh143_tipoevento) = 2 then sum(rh143_valor) end as desconto                ";
    $sSqlRubricas .= "   from rhfolhapagamento                                                                      ";
    $sSqlRubricas .= "        inner join rhhistoricocalculo on rh143_folhapagamento = rh141_sequencial              ";
    $sSqlRubricas .= "        inner join rhrubricas         on  rh27_rubric = rh143_rubrica                         ";
session_start();
include "libs/db_conecta.php";
include "libs/db_stdlib.php";
include "libs/db_sql.php";
include "libs/db_utils.php";
include "dbforms/db_funcoes.php";
include "classes/db_cfpess_classe.php";
validaUsuarioLogado();
$aRetorno = array();
parse_str(base64_decode($HTTP_SERVER_VARS["QUERY_STRING"]), $aRetorno);
$id_usuario = $aRetorno['id_usuario'];
$matricula = $aRetorno['matricula'];
$instituicao = $aRetorno['instituicao'];
$numcgm = db_getsession("DB_login");
$anoFolha = db_anofolha($instituicao);
$mesFolha = db_mesfolha($instituicao);
db_logs("", "", 0, "Consulta Funcional.");
$sUrl = base64_encode("iMatric=" . $matricula . "&iInstit=" . $instituicao);
$sUrlAverba = base64_encode("&averba");
/**
 * Caso o cliente seja Bage (codcli = 15) 
 * Então a variável lBloqueio passa a ser true e não mostrará os menus:
 * - Assentamento 
 * - Averbação do tempo de serviço 
 * - Férias
 * 
 * Do contrário todos os menus são mostrados normalmente.
 */
$lBloqueio = false;
$rsCodCli = db_query("select db21_codcli from db_config where prefeitura is true limit 1");
$iCodCli = db_utils::fieldsmemory($rsCodCli)->db21_codcli;