$clrhemitecontracheque->rh85_horaemissao = db_hora();
 $clrhemitecontracheque->rh85_ip = $sIp;
 $clrhemitecontracheque->rh85_externo = 'true';
 $clrhemitecontracheque->incluir($iSequencial);
 if ($clrhemitecontracheque->erro_status == 0) {
     db_redireciona('db_erros.php?fechar=true&db_erro=' . $clrhemitecontracheque->erro_msg);
 }
 if ($lin == 1) {
     $lin = 0;
     $pdf1->seq = 0;
 } else {
     $lin = 1;
     $pdf1->seq = 1;
 }
 $sql = "\n  select " . $sigla . "rubric as rubrica,\n       round(" . $sigla . "valor,2) as valor,\n       round(" . $sigla . "quant,2) as quant, \n       rh27_descr, \n       " . $xtipo . " as tipo , \n       case when " . $sigla . "pd = 3 then 'B' \n            else case when " . $sigla . "pd = 1 then 'P' \n\t         else 'D' \n\t    end \n       end as provdesc\n \n  from " . $arquivo . " \n     inner join rhrubricas on rh27_rubric = " . $sigla . "rubric \n                          and rh27_instit = {$institservidor}\n  where " . $sigla . "regist = {$regist}\n    and " . $sigla . "anousu = {$ano} \n    and " . $sigla . "mesusu = {$mes}\n    and " . $sigla . "instit = {$institservidor}\n    {$wheresemest}\n  order by " . $sigla . "rubric  ";
 if (cl_cfpess::verificarUtilizacaoEstruturaSuplementar() && ($opcao == 'salario' || $opcao == 'suplementar' || $opcao == 'complementar')) {
     $sql = "select rh143_rubrica              as rubrica,                             ";
     $sql .= "       round(sum(rh143_valor), 2) as valor,                               ";
     $sql .= "       round(rh143_quantidade, 2) as quant,                               ";
     $sql .= "       rh27_descr                 ,                                       ";
     $sql .= "       {$xtipo}                   as tipo ,                               ";
     $sql .= "       case                                                               ";
     $sql .= "         when rh143_tipoevento = 3 then 'B'                               ";
     $sql .= "         else                                                             ";
     $sql .= "           case                                                           ";
     $sql .= "             when rh143_tipoevento = 1 then 'P'                           ";
     $sql .= "             else 'D'                                                     ";
     $sql .= "           end                                                            ";
     $sql .= "       end as provdesc                                                    ";
     $sql .= "  from rhfolhapagamento                                                   ";
     $sql .= " inner join rhhistoricocalculo on rh143_folhapagamento = rh141_sequencial ";
    var sOpcoes = '';

    $(idObj).innerHTML = '';
    
    if ( iLinhas > 0 ) {
     
      for ( var iInd=0; iInd < iLinhas; iInd++ ) {
        
        oCombos = aLista[iInd];
        with ( aLista[iInd] ) {

          $(idObj).options[iInd]            = new Option();
          $(idObj).options[iInd].value      = codigo; 

          <?php 
if (cl_cfpess::verificarUtilizacaoEstruturaSuplementar()) {
    ?>
            if ( idObj == "selTipoCalc" ) {
              $(idObj).options[iInd].sequencial = sequencial; 
              $(idObj).options[iInd].numero     = numero; 
            }
          <?php 
}
?>
          
          $(idObj).options[iInd].text       = descr.urlDecode();
        }        
      }
      
      $(idObj).options[0].selected = true;
      
				              <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                         ";
    $sSqlRubricas .= "                                     and rh27_instit = rh141_instit                           ";
    $sSqlRubricas .= "  where rh141_sequencial = {$iSequencial}                                                     ";
    $sSqlRubricas .= "    and rh143_regist = {$iMatric}                                                             ";
    $sSqlRubricas .= "  group by rh143_rubrica, rh143_quantidade, rh27_descr, rh143_tipoevento                      ";
    $sSqlRubricas .= "  order by rh143_tipoevento,                                                                  ";