<?php
$sNomeIdJan1 = 'iJan_Fli_RsmGer';
$sCorBarraInf = '#E8E3CE';
$sTipoLocal = SQLVarConfig('NOME_LOCAIS_SVC');
$sPulaLinha = CHR(13).CHR(10);
// Carrega sessão para á variável
$aSessaoLocal = @$aSessao[$sNomeAcesso.'_S'];
//
//
//  ** TELA PRINCIPAL **
If ( EMPTY($sSubModulo) ) {
    //
    // Criar objeto Janela
    $oJanelaPrinc = New R_Janela();
    $oJanelaPrinc->sIdObj  = $sNomeIdJan1; 
    $oJanelaPrinc->nTop    = 5;
    $oJanelaPrinc->nLeft   = 5;
    $oJanelaPrinc->nWidth  = 1360;   // Largura
    $oJanelaPrinc->nHeight = 0;     // Altura
	  $oJanelaPrinc->nLeft   += ($nTela_W/2)-($oJanelaPrinc->nWidth/2);
    $oJanelaPrinc->sTitulo = 'Resumo Gerencial';
    $oJanelaPrinc->sJavKeyDown = "return Car_".$sNomeAcesso."1.Teclas_F(this,event);";
	//
	$sJavaTravarJ = "document.getElementById('".$oJanelaPrinc->sIdObj."_Travar').style.visibility='visible'; parent.Disabled_In_Elems('".$oJanelaPrinc->sIdObj."',true);";
    $oJanelaPrinc->sJavOnClickF =
       $sJavaTravarJ.
       "document.forms.fmRsmGer.acao.value='FECHAR'; ".
       "document.forms.fmRsmGer.submod.value=''; ".
       "document.forms.fmRsmGer.submit();";
    //
    $oJanelaPrinc->aIdsObjList =
       ARRAY(
         'sl_RsmGer_Filial', 'in_RsmGer_DatIni', 'in_RsmGer_DatFim'
       );
    //
    // JANELA TELA PRINCIPAL
    If ( EMPTY($sAcao) ) {
	   //
       MYSQL_SELECT_DB(DBSql_Bank) or die(MYSQL_ERROR());
       $sSQLQuery = "SELECT * FROM cad_acesso";
       $aCad_Acesso = MYSQL_QUERY($sSQLQuery);
       $aCad_Acesso = SQL_Extrair_Cmp( $aCad_Acesso );
       MYSQL_SELECT_DB( $aSessao['BD_APONTADO_ACESSO'] );
      //  $sHTML_ComboFil = '<option selected value="0">** Todas as filiais **</option>';
       $sHTML_ComboFil = "";
       ForEach( $aCad_Acesso As $aItem ) {
          $sHTML_ComboFil .=
            '<option value="'.$aItem['ACS_CODIGOI'].'">'.
             Str_Zero($aItem['ACS_CODIGOI'],3).' - '.$aItem['ACS_APELID'].
            '</option>';
       }
       //
       // Tela HTML

       $onClickMontar = 
        "document.forms.fmRsmGer.acao.value='MONTAR'; document.forms.fmRsmGer.submit();".
        "document.getElementById('RsmGer_BT_Imp').style.display = 'none';".
        "document.getElementById('RsmGer_BT_Xls').style.display = 'none';"
      ;

      $onClickImprimir = 
       "Car_".$sNomeAcesso."1.oPrt.window.print();"
      ;

      $onClickGerarCsv = 
        "document.forms.fmRsmGer.acao.value='GERAR_CSV';".
        "document.forms.fmRsmGer.submit();"
      ;

       $sRet_TelaJ_HTML =
         $oJanelaPrinc->MontaJanHTML(True).
         '<div class="row">'.
          '<div style="padding:5px; padding-left: 50px; padding-right:50px" class="col-xs-3">'.
            '<form name="fmRsmGer" accept-charset="utf-8" method="post" action="./car_js.php" target="car_'.$sNomeAcesso.'2">'.
              '<input name="mod" type="hidden" value="'.$sModulo.'">'.
              '<input name="submod" type="hidden" value="">'.
              '<input name="acao" type="hidden" value="">'.
              '<input name="nomeacs" type="hidden" value="'.$sNomeAcesso.'">'.
              '<div class="row">'.
                '<div class="col-xs-12">'.
                  '<img onclick="'."sIdHasFocus='in_RsmGer_DatIni';".'" src="images/bimg_calendario.png" border="0" id="bt_RsmGer_DatIni" style="cursor:pointer;"> Data Inicial'.
                  '<input class="form-control" value="'.date('d/m/Y').'" id="in_RsmGer_DatIni" name="Fil_DataIni" type="text" maxlength="10">'.
                '</div>'.
                '<div class="col-xs-12">'.
                  '<img onclick="'."sIdHasFocus='in_RsmGer_DatFim';".'" src="images/bimg_calendario.png" border="0" id="bt_RsmGer_DatFim" style="cursor:pointer;"> Data Final'.
                  '<input class="form-control" value="'.date('d/m/Y').'" id="in_RsmGer_DatFim" name="Fil_DataFim" type="text" maxlength="10">'.
                  '<br/>'.
                '</div>'.
                '<div class="checkbox">'.
                     '<label>'.
                        '<input id="chkTodas" onClick="Car_'.$sNomeAcesso.'1.selecionarTodas()" type="checkbox" value="">'.
                        'Selecionar todas as filiais'.
                     '</label>'.
                  '</div>'.
                '<div class="col-xs-12">'.
                  '<label>Filial:</label>'.
                  '<select required onChange="Car_'.$sNomeAcesso.'1.mudarSelect(this.value)" style="white-space:normal" id="sl_RsmGer_Filial" name="RsmGer_Filial[]" class="form-control select2" multiple="multiple" data-placeholder="Selecione uma filial">'.
                  // '<select style="white-space:normal; width:100%" class="form-control select2" multiple="multiple" data-placeholder="Selecione uma filial" id="sl_RsmGer_Filial" name="RsmGer_Filial[]">'.
                    $sHTML_ComboFil.
                  '</select>'.
                '</div>'.
              '</div>'.
            '</form>'.       
          '</div>'.
          '<div class="col-xs-9">'.
            '<div id="dv_RsmGer_Resultado" style="width:100%; height:460px; background:#FFFFFF; overflow:auto;">'.
            '</div>'.
            '<iframe name="RsmGer_Print"></iframe>'.
          '</div>'.
        '</div>'.
         //
         
         //
        //  '<table width="100%" style="background-color:'.$sCorBarraInf.';" border="0" cellspacing="0" cellpadding="0"></tr>'.
        //   '<td width="4px" height="40px" align="left">&nbsp;</td>'.
        //   // '<td width="130px" align="left">'.
        //   //  HTML_Botao( 3, 'RsmGer_BT_Mnt', "document.getElementById('RsmGer_BT_Imp').style.display = 'none';".
        //   //                                  "document.getElementById('RsmGer_BT_Xls').style.display = 'none';".
        //   //                                  "document.forms.fmRsmGer.acao.value='MONTAR';".
        //   //                                  "document.forms.fmRsmGer.submit();"
        //   //               , 'Montar (F9)','images/btimg_lupa.png').
        //   // '</td>'.
        //   '<td width="140px" align="left">'.
        //    HTML_Botao( 3, 'RsmGer_BT_Imp' , 'Car_'.$sNomeAcesso.'1.oPrt.window.print();'
        //                 , 'Imprimir (F10)','images/btimg_imp.png', 130).
        //   '</td>'.
        //   '<td width="120px" align="right">'.
        //    HTML_Botao( 3, 'RsmGer_BT_Xls' , "document.forms.fmRsmGer.acao.value='GERAR_CSV';".
        //                                     "document.forms.fmRsmGer.submit();"
        //                 , 'Excel (F11)','images/btimg_exportar_excel.png', 100).
        //   '</td>'.
        //   '<td>'.
        //     '&nbsp;'.
        //   '</td>'.
        //   '<td width="120px" align="right">'.
        //    HTML_Botao( 3, 'RsmGer_BT_Fch', $oJanelaPrinc->sJavOnClickF
        //                 , 'Sair (ESC)' ,'images/btimg_fechar.png').
        //   '</td>'.
        //   '<td width="4px" height="40px" align="left">&nbsp;</td>'.
        //  '</tr></table>'.
         '<div class="row">'.
          '<div class="col-xs-12">'.
            '<div class="row">'.
              '<div class="col-xs-2">'.
                '<button '.
                     'onClick="'.$onClickMontar.'"'.
                     'id="RsmGer_BT_Mnt" '.
                     'style="display:block"'.
                     'class="btn btn-default btn-block"'.
                '>'.
                  '<img src="images/btimg_lupa.png">'.
                  ' Montar (F9)'.
                '</button>'.
              '</div>'.
              
              '<div class="col-xs-2">'.
                '<button '.
                     'onClick="'.$onClickImprimir.'"'.
                     'id="RsmGer_BT_Imp" '.
                     'class="btn btn-default btn-block"'.
                '>'.
                  '<img src="images/btimg_imp.png">'.
                  ' Imprimir (F10)'.
                '</button>'.
              '</div>'.

              '<div class="col-xs-2">'.
                '<button '.
                     'onClick="'.$onClickGerarCsv.'"'.
                     'id="RsmGer_BT_Xls" '.
                     'class="btn btn-default btn-block"'.
                '>'.
                  '<img src="images/btimg_exportar_excel.png">'.
                  ' Excel (F11)'.
                '</button>'.
              '</div>'.

              '<div class="col-xs-2 pull-right">'.
                '<button onClick="'.$oJanelaPrinc->sJavOnClickF.'" id="RsmGer_BT_Fch" style="display:block" class="btn btn-default btn-block"><img src="images/btimg_fechar.png"> Sair (ESC)</button>'.
              '</div>'.
            '</div>'.
          '</div>'.
         '</div>'.
         //
         $oJanelaPrinc->MontaJanHTML(False);
       //
	    // Java anterior
      $sRet_Javs .=
      'parent.document.getElementById("dv_MenuL_Barra").style.visibility="hidden";'.
        //
        "function Teclas_F( Objeto, Evento ) {".
          "vNumTecla = parent.Tecla_Apertada(Evento);".
          "sAntFocus = parent.sIdHasFocus;".
          "if ( vNumTecla==120) {".          // ** [F9] **
              "if (parent.document.getElementById('RsmGer_BT_Mnt').style.display!='none') {".           // (Visualizar)
                "setTimeout( parent.document.getElementById('RsmGer_BT_Mnt').onclick , 10);".
              "}".
          "} else if ( vNumTecla==121) {".   // ** [F10] **
              "if (parent.document.getElementById('RsmGer_BT_Imp').style.display!='none') {".           // (Imprimir)
                "setTimeout( parent.document.getElementById('RsmGer_BT_Imp').onclick , 10);".
              "}".
          "} else if ( vNumTecla==122) {".   // ** [F11] **
              "if (parent.document.getElementById('RsmGer_BT_Xls').style.display!='none') {".           // (Exportar CSV)
                "setTimeout( parent.document.getElementById('RsmGer_BT_Xls').onclick , 10);".
              "}".
          "} else if ( vNumTecla==116) {".   // ** [F5] **     Não atualizar
              //
          "} else if ( vNumTecla==27 ) {".   // ** [ESC] **    Fechar da janela
              "setTimeout( parent.document.getElementById('RsmGer_BT_Fch').onclick , 10);".
          "} else if ( vNumTecla==13) {".    // ** [ENTER] **
            "while (true) {".
                "sTempId = parent.Proximo_TabObj(parent.document.getElementById('".$oJanelaPrinc->sIdObj."'),sAntFocus);".
                "if ( sTempId.length>0 ) {".
                    "parent.document.getElementById(sTempId).focus();".
                    "if (sTempId == parent.sIdHasFocus ) {".
                        'parent.document.getElementById(sTempId).select();'.
                        "break;".
                    "}".
                    "sAntFocus=sTempId;".
                "} else {".
                    "parent.document.getElementById('sl_RsmGer_Filial').focus();".
                    'break;'.
                "}".
            "}".
          "} else {".
            "return true;".
          "} ".
          "return false;".
        "}".
        '';
      // Java posterior
      $sRet_JavsPos .=
        "parent.document.getElementById('sl_RsmGer_Filial').focus();".
        "parent.document.getElementById('RsmGer_BT_Imp').style.display = 'none';".
        "parent.document.getElementById('RsmGer_BT_Xls').style.display = 'none';".
        "var oPrt = parent.frames['RsmGer_Print'];".
        //
        'parent.Calendar.setup({ '.
          'inputField : "in_RsmGer_DatIni", '.
          'trigger    : "bt_RsmGer_DatIni", '.
          'onSelect   : function() { this.hide(); parent.sIdHasFocus=""; },'.
          'showTime   : 0, '.
          'dateFormat : "%d/%m/%Y" '.
        '});'.
        'parent.Calendar.setup({ '.
          'inputField : "in_RsmGer_DatFim", '.
          'trigger    : "bt_RsmGer_DatFim", '.
          'onSelect   : function() { this.hide(); parent.sIdHasFocus=""; },'.
          'showTime   : 0, '.
          'dateFormat : "%d/%m/%Y" '.
        '});'.
        'parent.$("#sl_RsmGer_Filial").select2();'.
        //
        'function selecionarTodas(){'.
          'var chk = parent.$("chkTodas");'.
          'if(! parent.$("#chkTodas").is(":checked")){'.
             'parent.$("#sl_RsmGer_Filial option").removeAttr("selected");'.
          '} else {'.
             'parent.$("#sl_RsmGer_Filial option").attr("selected", "selected");'.
          '}'.
          'parent.$("#sl_RsmGer_Filial").select2();'.
       '}'.

       'function mudarSelect(valor){'.
          'if(valor.length > 0) {'.
             'if(parent.$("#chkTodas").is(":checked")) { '.
                'parent.$("#chkTodas").attr("checked", false);'.
             '}'.
             'parent.$("#sl_RsmGer_Filial option[value=0]").removeAttr("selected");'.
             'parent.$("#sl_RsmGer_Filial").select2();'.
          '}'.
       '}'.
        '';
	   //
    //
    // Montar resumo
    } ElseIf ( $sAcao=="MONTAR" ) {
      //
      //  $nCod_Filial  = @$_POST['RsmGer_Filial']+0;
      $aCod_Filial  = $_POST['RsmGer_Filial']; // Variável que recebe o array de filiais
      foreach ( $aCod_Filial As $nIndice => $nCod_Filial ) {
        $aCod_Filial_Tmp[$nCod_Filial] = 1;
      }
      $aCod_Filial = $aCod_Filial_Tmp;

      // var_dump($aCod_Filial_Tmp);
      $sFil_DataIni = @$_POST['Fil_DataIni'];
      $sFil_DataFim = @$_POST['Fil_DataFim'];
      $nFil_DataIni = ConvertDataSTR(ConvertDataBRUS($sFil_DataIni));
      $nFil_DataFim = ConvertDataSTR(ConvertDataBRUS($sFil_DataFim));
      //
      If ( $nFil_DataIni < MKTIME(0,0,0,1,1,2000) AND $nFil_DataFim < MKTIME(0,0,0,1,1,2000) ) {
        $nFil_DataFim = MKTIME(0,0,0);
        //$nFil_DataIni = $nFil_DataFim-(90*24*60*60);
        $nFil_DataIni = $nFil_DataFim;
      }
      If ( $nFil_DataIni < MKTIME(0,0,0,1,1,2000) ) {
        $nFil_DataIni = MKTIME(0,0,0);
      }
      If ( $nFil_DataIni > $nFil_DataFim ) {
        $nFil_DataFim = $nFil_DataIni;
      }
      If ( $nFil_DataFim > ($nFil_DataIni)+(365*24*60*60) ) {
        //$nFil_DataFim = ($nFil_DataIni)+(365*24*60*60);
      }
      $sFil_DataIni = DATE("d/m/Y",$nFil_DataIni);
      $sFil_DataFim = DATE("d/m/Y",$nFil_DataFim);
      //
      MYSQL_SELECT_DB(DBSql_Bank) OR DIE(MYSQL_ERROR());
      $sSQLQuery = "SELECT * FROM cad_acesso ORDER BY ACS_CODIGOI ASC";
      $aCads_Acesso = MYSQL_QUERY($sSQLQuery);
      $aCads_Acesso = SQL_Extrair_Cmp( $aCads_Acesso );
      $sHTML_Rel = '';
      $sCsv_Rel  = '';
      $aDados_Filiais = ARRAY();
      RsmGer_Montar_Rel_CSS();
      ForEach( $aCads_Acesso As $aCad_Acesso ) {
        //
        // If ( $nCod_Filial>0 AND $aCad_Acesso['ACS_CODIGOI']<>$nCod_Filial ) {
        If ( ! ISSET($aCod_Filial[0]) ) {
            If ( ! ISSET($aCod_Filial[$aCad_Acesso['ACS_CODIGOI']]) ) {
                CONTINUE;
            }
         }
            // CONTINUE;
        // }
        MYSQL_SELECT_DB( $aCad_Acesso['ACS_NOMEBD'] );
        RsmGer_Montar_Rel();
        //
        // If ( $nCod_Filial>0 ) {
        //     BREAK;
        // }
      }
      MYSQL_SELECT_DB( $aSessao['BD_APONTADO_ACESSO'] );
      If ( COUNT($aDados_Filiais)>1 ) {
        RsmGer_Montar_Rel(True);
      }
      //
      $aSessaoLocal['CSV_REL'] = $sCsv_Rel;
      //
      // Java anterior
      $sRet_Javs .=
        "var oRsm = parent.document.getElementById('dv_RsmGer_Resultado');".
        "var oPrt = parent.frames['RsmGer_Print'];".
        "oPrt.location.href = 'about:blank';".
        'parent.document.getElementById("in_RsmGer_DatIni").value = "'.$sFil_DataIni.'";'.
        'parent.document.getElementById("in_RsmGer_DatFim").value = "'.$sFil_DataFim.'";'.
      'oRsm.innerHTML='.JAVA_CharCode(UTF8_DECODE($sHTML_Rel)).';'.
        "setTimeout(".
          "function () {".
            "oPrt.document.write('<html><head><title>Resumo Gerencial</title></head><body>');".
            "oPrt.document.write(oRsm.innerHTML);".
            "oPrt.document.write('</body></html>');".
            "parent.document.getElementById('RsmGer_BT_Imp').style.display = 'inline-block';".
            "parent.document.getElementById('RsmGer_BT_Xls').style.display = 'inline-block';".
          "}".
          ",1500".
        ");".
        '';
    //
    // >> Gerar CSV para download
    } ElseIf ( $sAcao=="GERAR_CSV" ) {
       OB_CLEAN();
       $sArquivo = "Relatorio_Gerencial_".DATE("d-m-Y_H-i-s").".csv";
       $sConteudo = UTF8_DECODE(@$aSessaoLocal['CSV_REL']);
       HEADER("Content-Type: text/csv");
       HEADER("Content-Length: ".STRLEN($sConteudo));
       HEADER("Content-Disposition: attachment; filename=".$sArquivo);
       ECHO $sConteudo;
       EXIT;
    //
    // FECHAR
    } ElseIf ( $sAcao=="FECHAR" ) {
       $sRet_Javs .=
         'parent.document.getElementById("dv_MenuL_Barra").style.visibility="visible";'.
         "parent.RmElem('".$oJanelaPrinc->sIdObj."');".
         "";
	   //
       UNSET( $aSessaoLocal );
    }
    //
    //
}
// Tratamento da variável de sessão
If ( ISSET($aSessaoLocal) ) {
   $aSessao[$sNomeAcesso.'_S'] = $aSessaoLocal;
} Else {
   UNSET( $aSessao[$sNomeAcesso.'_S'] );
}
//
//
//
Function RsmGer_Montar_Rel( $bRelatorioTotalGeral=False ) {
   Global $sHTML_Rel, $sCsv_Rel, $aDados_Filiais, $aCad_Acesso, $nFil_DataIni, $nFil_DataFim, $sTipoLocal, $sPulaLinha;
   //
   $aDados_Filial = ARRAY();
   $aTipos_Grupo =
     ARRAY(
       "LOCAL"       => ARRAY( $sTipoLocal, "AND FAT_TIP_LOC=0" ),
       "BALCAO"      => ARRAY( "Balcão"   , "AND FAT_TIP_LOC=1" ),
       "DELIVERY"    => ARRAY( "Delivery" , "AND FAT_TIP_LOC=2" ),
       "TOTAL"       => ARRAY( "Total" , "" )
     );
   $sTituloRsm = "";
   //

   If ( $bRelatorioTotalGeral ) {
      $sTituloRsm = "** TOTAL GERAL **";
      ForEach ( $aDados_Filiais As $nAcs_CodigoI => $aDados_Filial_P ) {
        ForEach ( $aDados_Filial_P As $sIndice => $aDados_Grupo ) {
          ForEach ( $aDados_Grupo As $sIndice_D => $aDados ) {
            $aTmp = @$aDados_Filial[$sIndice][$sIndice_D];
            ForEach ( $aDados As $sIndice_I => $nItem ) {
              $aTmp[$sIndice_I]  = @$aTmp[$sIndice_I] +$aDados[$sIndice_I];
            }
            $aDados_Filial[$sIndice][$sIndice_D] = $aTmp;
          }
        }
      }
      //
   } Else {
      $sTituloRsm = Str_Zero($aCad_Acesso['ACS_CODIGOI'],3).' - '.utf8_encode($aCad_Acesso['ACS_APELID']);
      $sSQLQuery_Padrao =
        "SELECT ".
          "COUNT(*)         AS QUANTIDADE ,".
          "SUM(FAT_TOT_VAL) AS FAT_TOT_VAL,".
          "SUM(FAT_TAXASVR) AS FAT_TAXASVR,".
          "SUM(FAT_TAXACVR) AS FAT_TAXACVR,".
          "SUM(FAT_DESCONT) AS FAT_DESCONT ".
        "FROM fat_geral ".
        "WHERE FAT_DATAINI >= '".DATE("Y-m-d",$nFil_DataIni)."' ".
          "AND FAT_DATAINI <= '".DATE("Y-m-d",$nFil_DataFim)."' ".
        "";
      //
      ForEach( $aTipos_Grupo As $sIndice => $aGrupo ) {
        $aTmpGrupo = ARRAY();
        $sSQLWhere = $aGrupo[1];
        If ( EMPTY($sSQLWhere) ) { CONTINUE; }
        // Recebidas
        $sSQLQuery =
          $sSQLQuery_Padrao.$sSQLWhere." ".
          "AND FAT_RCFORMA=1 AND FAT_CAN_DAT=0".
          ";";
        $aTmp = MYSQL_QUERY($sSQLQuery);
        $aTmp = SQL_Extrair( $aTmp );
        $aTmpGrupo['RECEBIDAS'] = $aTmp;
        // Não recebidas
        $sSQLQuery =
          $sSQLQuery_Padrao.$sSQLWhere." ".
          "AND FAT_RCFORMA=0 AND FAT_CAN_DAT=0".
          ";";
        $aTmp = MYSQL_QUERY($sSQLQuery);
        $aTmp = SQL_Extrair( $aTmp );
        $aTmpGrupo['NAO_RECEBIDAS'] = $aTmp;
        // Canceladas
        $sSQLQuery =
          $sSQLQuery_Padrao.$sSQLWhere." ".
          "AND FAT_CAN_DAT>0".
          ";";
        $aTmp = MYSQL_QUERY($sSQLQuery);
        $aTmp = SQL_Extrair( $aTmp );
        $aTmpGrupo['CANCELADAS'] = $aTmp;
        $aDados_Filial[$sIndice] = $aTmpGrupo;
      }
      //
      $aTmpFilial_T = ARRAY();
      ForEach ( $aDados_Filial As $sIndice => $aDados_Grupo ) {
        ForEach ( $aDados_Grupo As $sIndice_D => $aDados ) {
          $aTmp = @$aTmpFilial_T[$sIndice_D];
          ForEach ( $aDados As $sIndice_I => $nItem ) {
            $aTmp[$sIndice_I]  = @$aTmp[$sIndice_I] +$aDados[$sIndice_I];
          }
          $aTmpFilial_T[$sIndice_D] = $aTmp;
        }
      }
      $aDados_Filial['TOTAL'] = $aTmpFilial_T;
      //
      $nAcs_CodigoI = $aCad_Acesso['ACS_CODIGOI']+0;
      $aDados_Filiais[$nAcs_CodigoI] = $aDados_Filial;
      //
      //$sHTML_Rel .= "FILIAL => ".VAR_EXPORT($aDados_Filial,True)."<br>";
      //$sHTML_Rel .= "FILIAL => ".VAR_EXPORT($aDados_Filiais,True)."<br>";
   }
   $sHTML_Rel .= '<div class="table-responsive">';
   //
   $sHTML_Rel .=
     '<table class="RsmGer_Tabela table table-bordered">'.
      '<tr>'.
       '<td class="RsmGer_Tabela_td_T" colspan="16" align="center" valign="middle">'.
        $sTituloRsm.
       '</td>'.
      '</tr>'.
      '<tr>'.
       '<td class="RsmGer_Tabela_td_Dd">'.
       '</td>'.
       '<td class="RsmGer_Tabela_td_G recebidas" colspan="5" align="center">'.
        'Recebidas'.
       '</td>'.
       '<td class="RsmGer_Tabela_td_G nao_recebidas" colspan="5" align="center">'.
        'Não recebidas'.
       '</td>'.
       '<td class="RsmGer_Tabela_td_G" colspan="5" align="center">'.
        'Canceladas'.
       '</td>'.
      '</tr>'.
      '<tr>'.
       '<td class="RsmGer_Tabela_td_Dd">'.
       '</td>';
   //
   $sCsv_Rel .=
     ';;'.$sTituloRsm.$sPulaLinha.
     ';Recebidas;;;;'.
     ';Não recebidas;;;;'.
     ';Canceladas'.$sPulaLinha.
     '';
   //
   For ( $nContador=1; $nContador<=3; $nContador++ ) {
     if ( $nContador == 1 ) {
       $bgColor = "#e6ffe6";
     } else if ( $nContador == 2) { 
       $bgColor = "#ffebe6";
     } else {
       $bgColor = "#fff";
     }
     $sHTML_Rel .=
       '<td class="table-header" style="background: '.$bgColor.'" width="90px" align="right">'.
        'Qtd de comandas'.
       '</td>'.
       '<td class="table-header" style="background: '.$bgColor.'" width="90px" align="right">'.
        'Produtos'.
       '</td>'.
       '<td class="table-header" style="background: '.$bgColor.'" width="90px" align="right">'.
        'Taxa de serviço'.
       '</td>'.
       '<td class="table-header" style="background: '.$bgColor.'" width="90px" align="right">'.
        'Taxa de couver'.
       '</td>'.
       '<td class="table-header" style="background: '.$bgColor.'" width="70px" align="right">'.
        'Desconto'.
       '</td>';
     //
     $sCsv_Rel .=
       ';Qtd de comandas'.
       ';Produtos'.
       ';Taxa de serviço'.
       ';Taxa de couver'.
       ';Desconto'.
       '';
   }
   //
   $countLinhas = 0;
   $classe = "";
   ForEach ( $aDados_Filial As $sIndice => $aDados_Grupo ) {

    if ( $countLinhas % 2 != 0 ) {
      $classe = "cinza";
    }

    $countLinhas++;

     $sHTML_Rel .=
       '</tr>'.
       '<tr class="'.$aTipos_Grupo[$sIndice][0].'">'.
        '<td class="RsmGer_Tabela_td_Dd">'.
         $aTipos_Grupo[$sIndice][0].
        '</td>'.
       '';
     $sCsv_Rel .=
       $sPulaLinha.
       $aTipos_Grupo[$sIndice][0].';'.
       '';
     //
     $contador = 0;
     ForEach ( $aDados_Grupo As $sIndice_D => $aDados ) {
       $classe = "";
      
      if($countLinhas % 2 == 0) {
        if ( $contador == 0 ) { 
          $classe = "recebidas";
        } else if ( $contador == 1) {
          $classe = "nao_recebidas";
        } else { 
          $classe = "";
        }
      }
      

        

       $contador++;
       
       $sHTML_Rel .=
         '<td class="'.$classe.'" width="90px" align="right">'.
          $aDados['QUANTIDADE'].
         '</td>'.
         '<td class="'.$classe.'" align="right">'.
          FormatoMoeda_Mil($aDados['FAT_TOT_VAL']).
         '</td>'.
         '<td class="'.$classe.'" align="right">'.
          FormatoMoeda_Mil($aDados['FAT_TAXASVR']).
         '</td>'.
         '<td class="'.$classe.'" align="right">'.
          FormatoMoeda_Mil($aDados['FAT_TAXACVR']).
         '</td>'.
         '<td class="'.$classe.'" align="right">'.
          FormatoMoeda_Mil($aDados['FAT_DESCONT']).
         '</td>';
       $sCsv_Rel .=
         $aDados['QUANTIDADE'].';'.
         'R$ '.FormatoMoeda_Mil($aDados['FAT_TOT_VAL']).';'.
         'R$ '.FormatoMoeda_Mil($aDados['FAT_TAXASVR']).';'.
         'R$ '.FormatoMoeda_Mil($aDados['FAT_TAXACVR']).';'.
         'R$ '.FormatoMoeda_Mil($aDados['FAT_DESCONT']).';'.
         '';
     }

     
   }
   $sHTML_Rel .=
      '</tr>'.
     '</table>';
    //
    $sHTML_Rel .= '</div>';

    $sCsv_Rel .=
     $sPulaLinha.
     $sPulaLinha.
     '';
    //
}
//
Function RsmGer_Montar_Rel_CSS() {
   Global $sHTML_Rel;
   $sCSS_Rel =
     '.RsmGer_Tabela {'.
       'font-family: arial'.
     '}'.
     '.RsmGer_Tabela_td_T {'.
      //  'border-top: 1px solid #666666;'.
      //  'border-right: 1px solid #666666;'.
      //  'border-left: 1px solid #666666;'.
       'height:26px;'.
       'font-size: 14px;'.
       'font-weight: bold;'.
     '}'.
     '.RsmGer_Tabela_td_G {'.
      //  'border-top: 1px solid #666666;'.
      //  'border-right: 1px solid #666666;'.
       'height:26px;'.
       'font-size: 12px;'.
       'font-weight: bold;'.
     '}'.
     '.RsmGer_Tabela_td_D {'.
      //  'border-top: 1px solid #666666;'.
      //  'border-right: 1px solid #666666;'.
       'height:22px;'.
       'padding-right: 3px;'.
       'font-size: 11px;'.
     '}'.
     '.RsmGer_Tabela_td_Dd {'.
      //  'border-top: 1px solid #666666;'.
      //  'border-left: 1px solid #666666;'.
      //  'border-right: 1px solid #666666;'.
       'height:22px;'.
       'padding-right: 3px;'.
       'font-size: 11px;'.
     '}'.
     '.RsmGer_Tabela_td_DV {'.
       'font-weight: bold;'.
     '}'.
     '.RsmGer_Tabela_td_TF {'.
      //  'border-top: 1px solid #666666;'.
     '}'.
     '.table tr:nth-child(even) { '.
      'background: #FFFFFF;'.
     '}'.
     '.table tr:nth-child(odd) { '.
      'background: #b3ecff;'.
     '}'.
     '.TOTAL td { '.
        'font-size: 16px;'.
        'font-weight: bolder;'.
     '}'.
     '.recebidas { '.
      'background-color: #e6ffe6;'.
     '}'.
     '.nao_recebidas { '.
      'background-color: #ffebe6;'.
     '}'.
     '';
   $sHTML_Rel .= '<style type="text/css" rel="stylesheet">'.$sCSS_Rel.'</style>';
   //
}
//
//
//
?>