Esempio n. 1
0
        public static bool LogarCredenciado(string codacesso, string senha, out int cred_id)
        {
            bool r = false;

            cred_id = 0;
            BD             BD = new BD();
            SafeDataReader dr = BD.GetDataReader("SELECT senha, cred_id FROM Credenciados WHERE codacesso = " + codacesso, null);

            try
            {
                if (dr.Read())
                {
                    netUtil.Funcoes f = new netUtil.Funcoes();
                    if (f.Crypt("D", dr.GetString(0), "BIGCOMPRAS") == senha)
                    {
                        r       = true;
                        cred_id = dr.GetInt32(1);
                    }
                }
            }
            finally
            {
                dr.Close();
            }

            return(r);
        }
Esempio n. 2
0
        //Alterado para SqlServer
        public static DataTable GetFechamentos(bool vzerado, bool baixados, string tipoext, string nfentreg,
                                             string datafecha, string dataini, string datafim, int empres_id,
                                             string chapa, string cartao, string nome, string status, string grupo, string setor)
        {
            int band_id = DALConveniado.GetEmpresBandId(empres_id);
             int qtdLimites = DALConveniado.GetQtdLimites(empres_id);
             string sql = " select CONV.CONV_ID, CONV.CHAPA, CONV.TITULAR, CONV.GRUPO_CONV_EMP, ";
             sql += " CONTACORRENTE.DATA_FECHA_EMP, ";
             sql += " CONTACORRENTE.DATA_VENC_EMP, ";
             sql += " coalesce(sum(CONTACORRENTE.DEBITO - CONTACORRENTE.CREDITO),0) as VALOR "; //<-- ISSO AQUI ERA OQ TAVA ANTES... FOI ALTERADO PRA PODER ADICIONAR OS OUTROS VALORES DOS SALDOS (01/12/2012)
             if (band_id != 999)
             {
               if (qtdLimites >= 1)
               {
               sql += ", (select coalesce(sum (debito - credito),0)" +
                      " from contacorrente cc" +
                      " join credenciados cred on cred.cred_id = cc.cred_id" +
                      " where conv_id = conv.conv_id" +
                      " and receita = 'S'" +
                      " and data_fecha_emp = CONTACORRENTE.DATA_FECHA_EMP" +
                      " and coalesce(cc.entreg_nf,'N') = 'S'" +
                      " and cred.seg_id in (select seg_id" +
                      "        from bandeiras_segmentos bs" +
                      "            where bs.band_id = " + band_id +
                      "               and bs.cod_limite = 1)" +
                      " ) as SALDO_COM_RECEITA_LIM_1," +
                      " (select coalesce(sum (debito - credito),0)" +
                      " from contacorrente cc" +
                      " join credenciados cred on cred.cred_id = cc.cred_id" +
                      " where conv_id = conv.conv_id" +
                      " and receita = 'N'" +
                      " and data_fecha_emp = CONTACORRENTE.DATA_FECHA_EMP" +
                      " and coalesce(cc.entreg_nf, 'N') = 'S' and" +
                      " cred.seg_id in (select seg_id" +
                      "              from bandeiras_segmentos bs" +
                      "             where bs.band_id = " + band_id +
                      "               and bs.cod_limite = 1)" +
                      " ) as SALDO_SEM_RECEITA_LIM_1," +
                      " (select coalesce(sum (debito - credito),0)" +
                      " from contacorrente cc" +
                      " join credenciados cred on cred.cred_id = cc.cred_id" +
                      " where conv_id = conv.conv_id" +
                      " and receita = 'S'" +
                      " and data_fecha_emp = CONTACORRENTE.DATA_FECHA_EMP" +
                      " and coalesce(cc.entreg_nf, 'N') = 'N' and" +
                      " cred.seg_id in (select seg_id" +
                      "				from bandeiras_segmentos bs" +
                      "             where bs.band_id = " + band_id +
                      "              and bs.cod_limite = 1)" +
                      " ) as SALDO_COM_RECEITA_N_CONF_LIM_1," +
                      " (select coalesce(sum (debito - credito),0)" +
                      " from contacorrente cc" +
                      " join credenciados cred on cred.cred_id = cc.cred_id" +
                      " where conv_id = conv.conv_id" +
                      " and receita = 'N'" +
                      " and data_fecha_emp = CONTACORRENTE.DATA_FECHA_EMP" +
                      " and coalesce(cc.entreg_nf, 'N') = 'N' and" +
                      " cred.seg_id in (select seg_id" +
                      "             from bandeiras_segmentos bs" +
                      "             where bs.band_id = " + band_id +
                      "               and bs.cod_limite = 1)" +
                      " ) as SALDO_SEM_RECEITA_N_CONF_LIM_1 ";
               }
               if (qtdLimites >= 2)
               {
               sql += ", (select coalesce(sum (debito - credito),0)" +
                     " from contacorrente cc" +
                     " join credenciados cred on cred.cred_id = cc.cred_id" +
                     " where conv_id = conv.conv_id" +
                     " and receita = 'S'" +
                     " and data_fecha_emp = CONTACORRENTE.DATA_FECHA_EMP" +
                     " and coalesce(cc.entreg_nf,'N') = 'S'" +
                     " and cred.seg_id in (select seg_id" +
                     "        from bandeiras_segmentos bs" +
                     "            where bs.band_id = " + band_id +
                     "               and bs.cod_limite = 2)" +
                     " ) as SALDO_COM_RECEITA_LIM_2," +
                     " (select coalesce(sum (debito - credito),0)" +
                     " from contacorrente cc" +
                     " join credenciados cred on cred.cred_id = cc.cred_id" +
                     " where conv_id = conv.conv_id" +
                     " and receita = 'N'" +
                     " and data_fecha_emp = CONTACORRENTE.DATA_FECHA_EMP" +
                     " and coalesce(cc.entreg_nf, 'N') = 'S' and" +
                     " cred.seg_id in (select seg_id" +
                     "              from bandeiras_segmentos bs" +
                     "             where bs.band_id = " + band_id +
                     "               and bs.cod_limite = 2)" +
                     " ) as SALDO_SEM_RECEITA_LIM_2," +
                     " (select coalesce(sum (debito - credito),0)" +
                     " from contacorrente cc" +
                     " join credenciados cred on cred.cred_id = cc.cred_id" +
                     " where conv_id = conv.conv_id" +
                     " and receita = 'S'" +
                     " and data_fecha_emp = CONTACORRENTE.DATA_FECHA_EMP" +
                     " and coalesce(cc.entreg_nf, 'N') = 'N' and" +
                     " cred.seg_id in (select seg_id" +
                     "				from bandeiras_segmentos bs" +
                     "             where bs.band_id = " + band_id +
                     "              and bs.cod_limite = 2)" +
                     " ) as SALDO_COM_RECEITA_N_CONF_LIM_2," +
                     " (select coalesce(sum (debito - credito),0)" +
                     " from contacorrente cc" +
                     " join credenciados cred on cred.cred_id = cc.cred_id" +
                     " where conv_id = conv.conv_id" +
                     " and receita = 'N'" +
                     " and data_fecha_emp = CONTACORRENTE.DATA_FECHA_EMP" +
                     " and coalesce(cc.entreg_nf, 'N') = 'N' and" +
                     " cred.seg_id in (select seg_id" +
                     "             from bandeiras_segmentos bs" +
                     "             where bs.band_id = " + band_id +
                     "               and bs.cod_limite = 2)" +
                     " ) as SALDO_SEM_RECEITA_N_CONF_LIM_2 ";
               }
               if (qtdLimites >= 3)
               {
               sql += ", (select coalesce(sum (debito - credito),0)" +
                     " from contacorrente cc" +
                     " join credenciados cred on cred.cred_id = cc.cred_id" +
                     " where conv_id = conv.conv_id" +
                     " and receita = 'S'" +
                     " and data_fecha_emp = CONTACORRENTE.DATA_FECHA_EMP" +
                     " and coalesce(cc.entreg_nf,'N') = 'S'" +
                     " and cred.seg_id in (select seg_id" +
                     "        from bandeiras_segmentos bs" +
                     "            where bs.band_id = " + band_id +
                     "               and bs.cod_limite = 3)" +
                     " ) as SALDO_COM_RECEITA_LIM_3," +
                     " (select coalesce(sum (debito - credito),0)" +
                     " from contacorrente cc" +
                     " join credenciados cred on cred.cred_id = cc.cred_id" +
                     " where conv_id = conv.conv_id" +
                     " and receita = 'N'" +
                     " and data_fecha_emp = CONTACORRENTE.DATA_FECHA_EMP" +
                     " and coalesce(cc.entreg_nf, 'N') = 'S' and" +
                     " cred.seg_id in (select seg_id" +
                     "              from bandeiras_segmentos bs" +
                     "             where bs.band_id = " + band_id +
                     "               and bs.cod_limite = 3)" +
                     " ) as SALDO_SEM_RECEITA_LIM_3," +
                     " (select coalesce(sum (debito - credito),0)" +
                     " from contacorrente cc" +
                     " join credenciados cred on cred.cred_id = cc.cred_id" +
                     " where conv_id = conv.conv_id" +
                     " and receita = 'S'" +
                     " and data_fecha_emp = CONTACORRENTE.DATA_FECHA_EMP" +
                     " and coalesce(cc.entreg_nf, 'N') = 'N' and" +
                     " cred.seg_id in (select seg_id" +
                     "				from bandeiras_segmentos bs" +
                     "             where bs.band_id = " + band_id +
                     "              and bs.cod_limite = 3)" +
                     " ) as SALDO_COM_RECEITA_N_CONF_LIM_3," +
                     " (select coalesce(sum (debito - credito),0)" +
                     " from contacorrente cc" +
                     " join credenciados cred on cred.cred_id = cc.cred_id" +
                     " where conv_id = conv.conv_id" +
                     " and receita = 'N'" +
                     " and data_fecha_emp = CONTACORRENTE.DATA_FECHA_EMP" +
                     " and coalesce(cc.entreg_nf, 'N') = 'N' and" +
                     " cred.seg_id in (select seg_id" +
                     "             from bandeiras_segmentos bs" +
                     "             where bs.band_id = " + band_id +
                     "               and bs.cod_limite = 3)" +
                     " ) as SALDO_SEM_RECEITA_N_CONF_LIM_3 ";
               }
               if (qtdLimites >= 4)
               {
               sql += ", (select coalesce(sum (debito - credito),0)" +
                     " from contacorrente cc" +
                     " join credenciados cred on cred.cred_id = cc.cred_id" +
                     " where conv_id = conv.conv_id" +
                     " and receita = 'S'" +
                     " and data_fecha_emp = CONTACORRENTE.DATA_FECHA_EMP" +
                     " and coalesce(cc.entreg_nf,'N') = 'S'" +
                     " and cred.seg_id in (select seg_id" +
                     "        from bandeiras_segmentos bs" +
                     "            where bs.band_id = " + band_id +
                     "               and bs.cod_limite = 4)" +
                     " ) as SALDO_COM_RECEITA_LIM_4," +
                     " (select coalesce(sum (debito - credito),0)" +
                     " from contacorrente cc" +
                     " join credenciados cred on cred.cred_id = cc.cred_id" +
                     " where conv_id = conv.conv_id" +
                     " and receita = 'N'" +
                     " and data_fecha_emp = CONTACORRENTE.DATA_FECHA_EMP" +
                     " and coalesce(cc.entreg_nf, 'N') = 'S' and" +
                     " cred.seg_id in (select seg_id" +
                     "              from bandeiras_segmentos bs" +
                     "             where bs.band_id = " + band_id +
                     "               and bs.cod_limite = 4)" +
                     " ) as SALDO_SEM_RECEITA_LIM_4," +
                     " (select coalesce(sum (debito - credito),0)" +
                     " from contacorrente cc" +
                     " join credenciados cred on cred.cred_id = cc.cred_id" +
                     " where conv_id = conv.conv_id" +
                     " and receita = 'S'" +
                     " and data_fecha_emp = CONTACORRENTE.DATA_FECHA_EMP" +
                     " and coalesce(cc.entreg_nf, 'N') = 'N' and" +
                     " cred.seg_id in (select seg_id" +
                     "				from bandeiras_segmentos bs" +
                     "             where bs.band_id = " + band_id +
                     "              and bs.cod_limite = 4)" +
                     " ) as SALDO_COM_RECEITA_N_CONF_LIM_4," +
                     " (select coalesce(sum (debito - credito),0)" +
                     " from contacorrente cc" +
                     " join credenciados cred on cred.cred_id = cc.cred_id" +
                     " where conv_id = conv.conv_id" +
                     " and receita = 'N'" +
                     " and data_fecha_emp = CONTACORRENTE.DATA_FECHA_EMP" +
                     " and coalesce(cc.entreg_nf, 'N') = 'N' and" +
                     " cred.seg_id in (select seg_id" +
                     "             from bandeiras_segmentos bs" +
                     "             where bs.band_id = " + band_id +
                     "               and bs.cod_limite = 4)" +
                     " ) as SALDO_SEM_RECEITA_N_CONF_LIM_4 ";
               }
               sql += " from CONVENIADOS CONV ";
               sql += (vzerado ? " left " : "") + "join CONTACORRENTE on ( CONV.CONV_ID = CONTACORRENTE.CONV_ID ) ";

               #region Valores Pagos
               if (!baixados)
             sql += " and (COALESCE(CONTACORRENTE.BAIXA_CONVENIADO,'N') <> 'S')";
               #endregion

               #region Tipo de Autorizacao
               switch (nfentreg)
               {
             case "S": sql += " and (COALESCE(CONTACORRENTE.ENTREG_NF,'N') = 'S') "; break;
             case "N": sql += " and (COALESCE(CONTACORRENTE.ENTREG_NF,'N') = 'N') "; break;
               }
               #endregion

               #region Tipo Extrato
               if (tipoext == "F") //Fechamento
             sql += " and (CONTACORRENTE.DATA_FECHA_EMP = '" + Convert.ToDateTime(datafecha).ToString("dd/MM/yyyy") + "')";
               else if (tipoext == "P") //extrato periodo
             sql += " and (CONTACORRENTE.DATA between '" + Convert.ToDateTime(dataini).ToString("dd/MM/yyyy") + "' and '" + Convert.ToDateTime(datafim).ToString("dd/MM/yyyy") + "')";
               #endregion

               sql += " join empresas emp on conv.empres_id = emp.empres_id ";
               sql += " join bandeiras b on b.band_id = emp.band_id ";
               sql += " left join bandeiras_conv bc on conv.conv_id = bc.conv_id ";
             }
             else
             {
               //sql += " coalesce(sum(CONTACORRENTE.DEBITO - CONTACORRENTE.CREDITO),0) as VALOR "; //<-- ISSO AQUI ERA OQ TAVA ANTES... FOI ALTERADO PRA PODER ADICIONAR OS OUTROS VALORES DOS SALDOS (01/12/2012)
               sql += " from CONVENIADOS CONV ";
               sql += (vzerado ? " left " : "") + "join CONTACORRENTE on ( CONV.CONV_ID = CONTACORRENTE.CONV_ID ) ";

               #region Valores Pagos
               if (!baixados)
             sql += " and (COALESCE(CONTACORRENTE.BAIXA_CONVENIADO,'N') <> 'S')";
               #endregion

               #region Tipo de Autorizacao
               switch (nfentreg)
               {
             case "S": sql += " and (COALESCE(CONTACORRENTE.ENTREG_NF,'N') = 'S') "; break;
             case "N": sql += " and (COALESCE(CONTACORRENTE.ENTREG_NF,'N') = 'N') "; break;
               }
               #endregion

               #region Tipo Extrato

               if (tipoext == "F") //Fechamento
             sql += " and (CONTACORRENTE.DATA_FECHA_EMP = '" + Convert.ToDateTime(datafecha).ToString("dd/MM/yyyy") + "')";
               else if (tipoext == "P") //extrato periodo
             sql += " and (CONTACORRENTE.DATA between '" + Convert.ToDateTime(dataini).ToString("dd/MM/yyyy") + "' and '" + Convert.ToDateTime(datafim).ToString("dd/MM/yyyy") + "')";
               #endregion

             }
             sql += " where (CONV.APAGADO <> 'S')";
             sql += " and (CONV.EMPRES_ID = " + empres_id + ")";
             #region Conveniado

             netUtil.Funcoes funcoes = new netUtil.Funcoes();

             if (grupo != "0")
            sql += " and conv.grupo_conv_emp=" + grupo;
             if (setor != "0")
            sql += " and conv.setor = '" + setor + "'";
             if (funcoes.SoNumero(chapa) != "")
            sql += " and conv.chapa = " + funcoes.SoNumero(chapa);
             else
            if (funcoes.SoNumero(cartao) != "") //procura pelo cartao
            {
               if ((cartao.Length == 11) && (Convert.ToInt32(cartao.Substring(9, 2)) == funcoes.DigitoCartao(Convert.ToInt32(cartao.Substring(0, 9)))))
                  sql += " and conv.conv_id = (SELECT conv_id FROM cartoes WHERE codigo = " + cartao.Substring(0, 9) + ")";
               else //cartao de importação
                  sql += " and conv.conv_id = (SELECT top 1 conv_id FROM cartoes WHERE apagado <> 'S' AND titular = 'S' AND codcartimp = '" + cartao + "')";
            }
            else
               if (nome != "")//procura pelo Nome
               {
                  sql += " and (titular like '" + (nome.Length > 3 ? "%" : "") + nome.ToUpper() + "%')";
               }
             #endregion

             #region Status do Conveniado
             switch (status)
             {
            case "L": sql += " and conv.liberado = 'S' "; break;
            case "B": sql += " and conv.liberado <> 'S' "; break;
             }
             #endregion

             //if (band_id != 999)
             //{
             //  string campos = "";
             //  if (qtdLimites >= 1)
             //     campos = ", SALDO_COM_RECEITA_LIM_1, SALDO_SEM_RECEITA_LIM_1, SALDO_COM_RECEITA_N_CONF_LIM_1, SALDO_SEM_RECEITA_N_CONF_LIM_1 ";
             //  if (qtdLimites >= 2)
             //    campos += ", SALDO_COM_RECEITA_LIM_2, SALDO_SEM_RECEITA_LIM_2, SALDO_COM_RECEITA_N_CONF_LIM_2, SALDO_SEM_RECEITA_N_CONF_LIM_2 ";
             //  if (qtdLimites >= 3)
             //    campos += ", SALDO_COM_RECEITA_LIM_3, SALDO_SEM_RECEITA_LIM_3, SALDO_COM_RECEITA_N_CONF_LIM_3, SALDO_SEM_RECEITA_N_CONF_LIM_3 ";
             //  if (qtdLimites >= 4)
             //    campos += ", SALDO_COM_RECEITA_LIM_4, SALDO_SEM_RECEITA_LIM_4, SALDO_COM_RECEITA_N_CONF_LIM_4, SALDO_SEM_RECEITA_N_CONF_LIM_4 ";
             //  sql += " group by CONTACORRENTE.DATA_FECHA_EMP, CONV.TITULAR, CONV.CHAPA, CONTACORRENTE.DATA_VENC_EMP, CONV.CONV_ID, CONV.GRUPO_CONV_EMP " + campos;
             //}
             //else
               sql += " group by CONTACORRENTE.DATA_FECHA_EMP, CONV.TITULAR, CONV.CHAPA, CONTACORRENTE.DATA_VENC_EMP, CONV.CONV_ID, CONV.GRUPO_CONV_EMP ";
             sql += "order by CONV.TITULAR";

             BD BD = new BD();
             return BD.GetDataTable(sql, null);
        }
Esempio n. 3
0
        //Alterado para SqlServer
        public Cartoes IncluiCartao(int conv_id, string nome, double limite_mes, string liberado, string operador, string titular, int num_dep, int cred_id, string ativo, string DtNascimento, string codigoImportacao, int nProtocolo)
        {
            BD         BD                     = new BD();
            int        cartao_id              = Convert.ToInt32(BD.ExecuteScalar("SELECT NEXT VALUE FOR SCARTAO_ID AS CARTAO_ID", null).ToString());
            TipoCartao cartao                 = titular == "S" ? TipoCartao.Titular : TipoCartao.Dependente;
            string     codCartImp             = string.Empty;
            double     codcartao              = Convert.ToDouble(BD.ExecuteScalar("SELECT NEXT VALUE FOR SCARTAO_NUM ", null));
            int        empres_id              = DALConveniado.GetConvEmpresID(conv_id);
            bool       naoGeraCartaoParaMenor = DALEmpresa.GetNaoGerarCartaoParaMenor(empres_id);
            bool       maiorDeIdade           = (!DtNascimento.Equals("")? MaiorDeIdade(Convert.ToDateTime(DtNascimento)):false);
            string     jaEmitido              = (titular == "N"?"S":"N");

            if (((naoGeraCartaoParaMenor && maiorDeIdade) || (!naoGeraCartaoParaMenor)) || titular == "S")
            {
                jaEmitido = "N";
                if (!string.IsNullOrEmpty(codigoImportacao))
                {
                    codCartImp = codigoImportacao;
                }
                else
                {
                    bool    encontrado;
                    Cartoes c = new Cartoes();
                    if (UsaCodImportacao(conv_id))
                    {
                        do
                        {
                            codCartImp = c.geraCartaoCom8primeirosDig(Int32.Parse(BuscarNumBase()));
                            encontrado = codCardTimpExiste(codCartImp);
                        } while (encontrado);
                    }
                    else if (INICIALCODCARTIMP())
                    {
                        int    i = (int)BD.ExecuteScalar("SELECT NEXT VALUE FOR SINICODCARTIMP", null);
                        string a = BD.ExecuteScalar("select INICIALCODCARTIMP from config ", null).ToString();
                        codCartImp = a + i.ToString("00000000");
                    }
                    else if (ConfigMoveCartao())
                    {
                        codCartImp = codcartao.ToString();
                    }
                    else if (ConfigIncrementoCartao(cartao))
                    {
                        codCartImp = ConfigCodigoIncremento;
                    }
                    else if (ConfigMascaraCartao())
                    {
                        Conveniados conv = DALConveniado.GetConveniado(conv_id);
                        int         seq  = ((int)BD.ExecuteScalar("select coalesce(count(*),1) as total from cartoes where conv_id = " + conv_id, null) + 1);
                        codCartImp = (conv.Empresa.Empres_id.ToString("0000") + conv.Chapa.ToString("000000") + seq.ToString("00"));
                    }
                }
            }
            netUtil.Funcoes func   = new netUtil.Funcoes();
            int             digito = func.DigitoCartao(codcartao);

            MontadorSql mont = new MontadorSql("cartoes", MontadorType.Insert);

            mont.AddField("cartao_id", cartao_id);
            mont.AddField("codigo", codcartao);
            mont.AddField("digito", digito);
            mont.AddField("conv_id", conv_id);
            mont.AddField("nome", Utils.TirarAcento(nome.ToUpper()));
            mont.AddField("limite_mes", limite_mes);
            mont.AddField("dtcadastro", System.DateTime.Now);
            mont.AddField("liberado", liberado);
            mont.AddField("operador", operador);
            mont.AddField("jaemitido", jaEmitido);
            mont.AddField("apagado", 'N');
            mont.AddField("titular", titular.ToUpper());
            if (!DtNascimento.Equals(""))
            {
                mont.AddField("data_nasc", DtNascimento);
            }
            mont.AddField("num_dep", (num_dep > 0 ? num_dep : 0));
            if (((naoGeraCartaoParaMenor && maiorDeIdade) || (!naoGeraCartaoParaMenor)) || titular == "S")
            {
                mont.AddField("codcartimp", codCartImp == string.Empty ? null : codCartImp);
            }
            if (cred_id != 0)
            {
                mont.AddField("cred_id", cred_id);
            }
            mont.AddField("ativo", ativo);
            mont.AddField("empres_id", empres_id);

            Cartoes cart = new Cartoes();

            if (BD.ExecuteNoQuery(mont.GetSqlString(), mont.GetParams()) == 1)
            {
                int logID = Log.GeraLogID();
                Log.GravaLog(logID, "FCadCartoes", "cartao_id", "", cartao_id.ToString(), operador, "Inclusão", "Cadastro de Cartões", cartao_id.ToString(), "Cartão ID: " + cartao_id.ToString(), "", nProtocolo);

                cart.Cartao_id    = cartao_id;
                cart.Codigo       = codcartao;
                cart.Digito       = digito;
                cart.Codigodigito = cart.Codigo.ToString() + cart.Digito.ToString("00");
                cart.CodImp       = codCartImp;
            }
            else
            {
                cart.Cartao_id = 0;
            }

            return(cart);
        }
Esempio n. 4
0
        //Alterado para SqlServer
        public static DataTable GetFechamentos(bool vzerado, bool baixados, string tipoext, string nfentreg,
                                               string datafecha, string dataini, string datafim, int empres_id,
                                               string chapa, string cartao, string nome, string status, string grupo, string setor)
        {
            int    band_id    = DALConveniado.GetEmpresBandId(empres_id);
            int    qtdLimites = DALConveniado.GetQtdLimites(empres_id);
            string sql        = " select CONV.CONV_ID, CONV.CHAPA, CONV.TITULAR, CONV.GRUPO_CONV_EMP, ";

            sql += " CONTACORRENTE.DATA_FECHA_EMP, ";
            sql += " CONTACORRENTE.DATA_VENC_EMP, ";
            sql += " coalesce(sum(CONTACORRENTE.DEBITO - CONTACORRENTE.CREDITO),0) as VALOR "; //<-- ISSO AQUI ERA OQ TAVA ANTES... FOI ALTERADO PRA PODER ADICIONAR OS OUTROS VALORES DOS SALDOS (01/12/2012)
            if (band_id != 999)
            {
                if (qtdLimites >= 1)
                {
                    sql += ", (select coalesce(sum (debito - credito),0)" +
                           " from contacorrente cc" +
                           " join credenciados cred on cred.cred_id = cc.cred_id" +
                           " where conv_id = conv.conv_id" +
                           " and receita = 'S'" +
                           " and data_fecha_emp = CONTACORRENTE.DATA_FECHA_EMP" +
                           " and coalesce(cc.entreg_nf,'N') = 'S'" +
                           " and cred.seg_id in (select seg_id" +
                           "        from bandeiras_segmentos bs" +
                           "            where bs.band_id = " + band_id +
                           "               and bs.cod_limite = 1)" +
                           " ) as SALDO_COM_RECEITA_LIM_1," +
                           " (select coalesce(sum (debito - credito),0)" +
                           " from contacorrente cc" +
                           " join credenciados cred on cred.cred_id = cc.cred_id" +
                           " where conv_id = conv.conv_id" +
                           " and receita = 'N'" +
                           " and data_fecha_emp = CONTACORRENTE.DATA_FECHA_EMP" +
                           " and coalesce(cc.entreg_nf, 'N') = 'S' and" +
                           " cred.seg_id in (select seg_id" +
                           "              from bandeiras_segmentos bs" +
                           "             where bs.band_id = " + band_id +
                           "               and bs.cod_limite = 1)" +
                           " ) as SALDO_SEM_RECEITA_LIM_1," +
                           " (select coalesce(sum (debito - credito),0)" +
                           " from contacorrente cc" +
                           " join credenciados cred on cred.cred_id = cc.cred_id" +
                           " where conv_id = conv.conv_id" +
                           " and receita = 'S'" +
                           " and data_fecha_emp = CONTACORRENTE.DATA_FECHA_EMP" +
                           " and coalesce(cc.entreg_nf, 'N') = 'N' and" +
                           " cred.seg_id in (select seg_id" +
                           "				from bandeiras_segmentos bs"+
                           "             where bs.band_id = " + band_id +
                           "              and bs.cod_limite = 1)" +
                           " ) as SALDO_COM_RECEITA_N_CONF_LIM_1," +
                           " (select coalesce(sum (debito - credito),0)" +
                           " from contacorrente cc" +
                           " join credenciados cred on cred.cred_id = cc.cred_id" +
                           " where conv_id = conv.conv_id" +
                           " and receita = 'N'" +
                           " and data_fecha_emp = CONTACORRENTE.DATA_FECHA_EMP" +
                           " and coalesce(cc.entreg_nf, 'N') = 'N' and" +
                           " cred.seg_id in (select seg_id" +
                           "             from bandeiras_segmentos bs" +
                           "             where bs.band_id = " + band_id +
                           "               and bs.cod_limite = 1)" +
                           " ) as SALDO_SEM_RECEITA_N_CONF_LIM_1 ";
                }
                if (qtdLimites >= 2)
                {
                    sql += ", (select coalesce(sum (debito - credito),0)" +
                           " from contacorrente cc" +
                           " join credenciados cred on cred.cred_id = cc.cred_id" +
                           " where conv_id = conv.conv_id" +
                           " and receita = 'S'" +
                           " and data_fecha_emp = CONTACORRENTE.DATA_FECHA_EMP" +
                           " and coalesce(cc.entreg_nf,'N') = 'S'" +
                           " and cred.seg_id in (select seg_id" +
                           "        from bandeiras_segmentos bs" +
                           "            where bs.band_id = " + band_id +
                           "               and bs.cod_limite = 2)" +
                           " ) as SALDO_COM_RECEITA_LIM_2," +
                           " (select coalesce(sum (debito - credito),0)" +
                           " from contacorrente cc" +
                           " join credenciados cred on cred.cred_id = cc.cred_id" +
                           " where conv_id = conv.conv_id" +
                           " and receita = 'N'" +
                           " and data_fecha_emp = CONTACORRENTE.DATA_FECHA_EMP" +
                           " and coalesce(cc.entreg_nf, 'N') = 'S' and" +
                           " cred.seg_id in (select seg_id" +
                           "              from bandeiras_segmentos bs" +
                           "             where bs.band_id = " + band_id +
                           "               and bs.cod_limite = 2)" +
                           " ) as SALDO_SEM_RECEITA_LIM_2," +
                           " (select coalesce(sum (debito - credito),0)" +
                           " from contacorrente cc" +
                           " join credenciados cred on cred.cred_id = cc.cred_id" +
                           " where conv_id = conv.conv_id" +
                           " and receita = 'S'" +
                           " and data_fecha_emp = CONTACORRENTE.DATA_FECHA_EMP" +
                           " and coalesce(cc.entreg_nf, 'N') = 'N' and" +
                           " cred.seg_id in (select seg_id" +
                           "				from bandeiras_segmentos bs"+
                           "             where bs.band_id = " + band_id +
                           "              and bs.cod_limite = 2)" +
                           " ) as SALDO_COM_RECEITA_N_CONF_LIM_2," +
                           " (select coalesce(sum (debito - credito),0)" +
                           " from contacorrente cc" +
                           " join credenciados cred on cred.cred_id = cc.cred_id" +
                           " where conv_id = conv.conv_id" +
                           " and receita = 'N'" +
                           " and data_fecha_emp = CONTACORRENTE.DATA_FECHA_EMP" +
                           " and coalesce(cc.entreg_nf, 'N') = 'N' and" +
                           " cred.seg_id in (select seg_id" +
                           "             from bandeiras_segmentos bs" +
                           "             where bs.band_id = " + band_id +
                           "               and bs.cod_limite = 2)" +
                           " ) as SALDO_SEM_RECEITA_N_CONF_LIM_2 ";
                }
                if (qtdLimites >= 3)
                {
                    sql += ", (select coalesce(sum (debito - credito),0)" +
                           " from contacorrente cc" +
                           " join credenciados cred on cred.cred_id = cc.cred_id" +
                           " where conv_id = conv.conv_id" +
                           " and receita = 'S'" +
                           " and data_fecha_emp = CONTACORRENTE.DATA_FECHA_EMP" +
                           " and coalesce(cc.entreg_nf,'N') = 'S'" +
                           " and cred.seg_id in (select seg_id" +
                           "        from bandeiras_segmentos bs" +
                           "            where bs.band_id = " + band_id +
                           "               and bs.cod_limite = 3)" +
                           " ) as SALDO_COM_RECEITA_LIM_3," +
                           " (select coalesce(sum (debito - credito),0)" +
                           " from contacorrente cc" +
                           " join credenciados cred on cred.cred_id = cc.cred_id" +
                           " where conv_id = conv.conv_id" +
                           " and receita = 'N'" +
                           " and data_fecha_emp = CONTACORRENTE.DATA_FECHA_EMP" +
                           " and coalesce(cc.entreg_nf, 'N') = 'S' and" +
                           " cred.seg_id in (select seg_id" +
                           "              from bandeiras_segmentos bs" +
                           "             where bs.band_id = " + band_id +
                           "               and bs.cod_limite = 3)" +
                           " ) as SALDO_SEM_RECEITA_LIM_3," +
                           " (select coalesce(sum (debito - credito),0)" +
                           " from contacorrente cc" +
                           " join credenciados cred on cred.cred_id = cc.cred_id" +
                           " where conv_id = conv.conv_id" +
                           " and receita = 'S'" +
                           " and data_fecha_emp = CONTACORRENTE.DATA_FECHA_EMP" +
                           " and coalesce(cc.entreg_nf, 'N') = 'N' and" +
                           " cred.seg_id in (select seg_id" +
                           "				from bandeiras_segmentos bs"+
                           "             where bs.band_id = " + band_id +
                           "              and bs.cod_limite = 3)" +
                           " ) as SALDO_COM_RECEITA_N_CONF_LIM_3," +
                           " (select coalesce(sum (debito - credito),0)" +
                           " from contacorrente cc" +
                           " join credenciados cred on cred.cred_id = cc.cred_id" +
                           " where conv_id = conv.conv_id" +
                           " and receita = 'N'" +
                           " and data_fecha_emp = CONTACORRENTE.DATA_FECHA_EMP" +
                           " and coalesce(cc.entreg_nf, 'N') = 'N' and" +
                           " cred.seg_id in (select seg_id" +
                           "             from bandeiras_segmentos bs" +
                           "             where bs.band_id = " + band_id +
                           "               and bs.cod_limite = 3)" +
                           " ) as SALDO_SEM_RECEITA_N_CONF_LIM_3 ";
                }
                if (qtdLimites >= 4)
                {
                    sql += ", (select coalesce(sum (debito - credito),0)" +
                           " from contacorrente cc" +
                           " join credenciados cred on cred.cred_id = cc.cred_id" +
                           " where conv_id = conv.conv_id" +
                           " and receita = 'S'" +
                           " and data_fecha_emp = CONTACORRENTE.DATA_FECHA_EMP" +
                           " and coalesce(cc.entreg_nf,'N') = 'S'" +
                           " and cred.seg_id in (select seg_id" +
                           "        from bandeiras_segmentos bs" +
                           "            where bs.band_id = " + band_id +
                           "               and bs.cod_limite = 4)" +
                           " ) as SALDO_COM_RECEITA_LIM_4," +
                           " (select coalesce(sum (debito - credito),0)" +
                           " from contacorrente cc" +
                           " join credenciados cred on cred.cred_id = cc.cred_id" +
                           " where conv_id = conv.conv_id" +
                           " and receita = 'N'" +
                           " and data_fecha_emp = CONTACORRENTE.DATA_FECHA_EMP" +
                           " and coalesce(cc.entreg_nf, 'N') = 'S' and" +
                           " cred.seg_id in (select seg_id" +
                           "              from bandeiras_segmentos bs" +
                           "             where bs.band_id = " + band_id +
                           "               and bs.cod_limite = 4)" +
                           " ) as SALDO_SEM_RECEITA_LIM_4," +
                           " (select coalesce(sum (debito - credito),0)" +
                           " from contacorrente cc" +
                           " join credenciados cred on cred.cred_id = cc.cred_id" +
                           " where conv_id = conv.conv_id" +
                           " and receita = 'S'" +
                           " and data_fecha_emp = CONTACORRENTE.DATA_FECHA_EMP" +
                           " and coalesce(cc.entreg_nf, 'N') = 'N' and" +
                           " cred.seg_id in (select seg_id" +
                           "				from bandeiras_segmentos bs"+
                           "             where bs.band_id = " + band_id +
                           "              and bs.cod_limite = 4)" +
                           " ) as SALDO_COM_RECEITA_N_CONF_LIM_4," +
                           " (select coalesce(sum (debito - credito),0)" +
                           " from contacorrente cc" +
                           " join credenciados cred on cred.cred_id = cc.cred_id" +
                           " where conv_id = conv.conv_id" +
                           " and receita = 'N'" +
                           " and data_fecha_emp = CONTACORRENTE.DATA_FECHA_EMP" +
                           " and coalesce(cc.entreg_nf, 'N') = 'N' and" +
                           " cred.seg_id in (select seg_id" +
                           "             from bandeiras_segmentos bs" +
                           "             where bs.band_id = " + band_id +
                           "               and bs.cod_limite = 4)" +
                           " ) as SALDO_SEM_RECEITA_N_CONF_LIM_4 ";
                }
                sql += " from CONVENIADOS CONV ";
                sql += (vzerado ? " left " : "") + "join CONTACORRENTE on ( CONV.CONV_ID = CONTACORRENTE.CONV_ID ) ";

                #region Valores Pagos
                if (!baixados)
                {
                    sql += " and (COALESCE(CONTACORRENTE.BAIXA_CONVENIADO,'N') <> 'S')";
                }
                #endregion

                #region Tipo de Autorizacao
                switch (nfentreg)
                {
                case "S": sql += " and (COALESCE(CONTACORRENTE.ENTREG_NF,'N') = 'S') "; break;

                case "N": sql += " and (COALESCE(CONTACORRENTE.ENTREG_NF,'N') = 'N') "; break;
                }
                #endregion

                #region Tipo Extrato
                if (tipoext == "F") //Fechamento
                {
                    sql += " and (CONTACORRENTE.DATA_FECHA_EMP = '" + Convert.ToDateTime(datafecha).ToString("dd/MM/yyyy") + "')";
                }
                else if (tipoext == "P") //extrato periodo
                {
                    sql += " and (CONTACORRENTE.DATA between '" + Convert.ToDateTime(dataini).ToString("dd/MM/yyyy") + "' and '" + Convert.ToDateTime(datafim).ToString("dd/MM/yyyy") + "')";
                }
                #endregion

                sql += " join empresas emp on conv.empres_id = emp.empres_id ";
                sql += " join bandeiras b on b.band_id = emp.band_id ";
                sql += " left join bandeiras_conv bc on conv.conv_id = bc.conv_id ";
            }
            else
            {
                //sql += " coalesce(sum(CONTACORRENTE.DEBITO - CONTACORRENTE.CREDITO),0) as VALOR "; //<-- ISSO AQUI ERA OQ TAVA ANTES... FOI ALTERADO PRA PODER ADICIONAR OS OUTROS VALORES DOS SALDOS (01/12/2012)
                sql += " from CONVENIADOS CONV ";
                sql += (vzerado ? " left " : "") + "join CONTACORRENTE on ( CONV.CONV_ID = CONTACORRENTE.CONV_ID ) ";

                #region Valores Pagos
                if (!baixados)
                {
                    sql += " and (COALESCE(CONTACORRENTE.BAIXA_CONVENIADO,'N') <> 'S')";
                }
                #endregion

                #region Tipo de Autorizacao
                switch (nfentreg)
                {
                case "S": sql += " and (COALESCE(CONTACORRENTE.ENTREG_NF,'N') = 'S') "; break;

                case "N": sql += " and (COALESCE(CONTACORRENTE.ENTREG_NF,'N') = 'N') "; break;
                }
                #endregion

                #region Tipo Extrato

                if (tipoext == "F") //Fechamento
                {
                    sql += " and (CONTACORRENTE.DATA_FECHA_EMP = '" + Convert.ToDateTime(datafecha).ToString("dd/MM/yyyy") + "')";
                }
                else if (tipoext == "P") //extrato periodo
                {
                    sql += " and (CONTACORRENTE.DATA between '" + Convert.ToDateTime(dataini).ToString("dd/MM/yyyy") + "' and '" + Convert.ToDateTime(datafim).ToString("dd/MM/yyyy") + "')";
                }
                #endregion
            }
            sql += " where (CONV.APAGADO <> 'S')";
            sql += " and (CONV.EMPRES_ID = " + empres_id + ")";
            #region Conveniado

            netUtil.Funcoes funcoes = new netUtil.Funcoes();

            if (grupo != "0")
            {
                sql += " and conv.grupo_conv_emp=" + grupo;
            }
            if (setor != "0")
            {
                sql += " and conv.setor = '" + setor + "'";
            }
            if (funcoes.SoNumero(chapa) != "")
            {
                sql += " and conv.chapa = " + funcoes.SoNumero(chapa);
            }
            else
            if (funcoes.SoNumero(cartao) != "") //procura pelo cartao
            {
                if ((cartao.Length == 11) && (Convert.ToInt32(cartao.Substring(9, 2)) == funcoes.DigitoCartao(Convert.ToInt32(cartao.Substring(0, 9)))))
                {
                    sql += " and conv.conv_id = (SELECT conv_id FROM cartoes WHERE codigo = " + cartao.Substring(0, 9) + ")";
                }
                else //cartao de importação
                {
                    sql += " and conv.conv_id = (SELECT top 1 conv_id FROM cartoes WHERE apagado <> 'S' AND titular = 'S' AND codcartimp = '" + cartao + "')";
                }
            }
            else
            if (nome != "")   //procura pelo Nome
            {
                sql += " and (titular like '" + (nome.Length > 3 ? "%" : "") + nome.ToUpper() + "%')";
            }
            #endregion

            #region Status do Conveniado
            switch (status)
            {
            case "L": sql += " and conv.liberado = 'S' "; break;

            case "B": sql += " and conv.liberado <> 'S' "; break;
            }
            #endregion

            //if (band_id != 999)
            //{
            //  string campos = "";
            //  if (qtdLimites >= 1)
            //     campos = ", SALDO_COM_RECEITA_LIM_1, SALDO_SEM_RECEITA_LIM_1, SALDO_COM_RECEITA_N_CONF_LIM_1, SALDO_SEM_RECEITA_N_CONF_LIM_1 ";
            //  if (qtdLimites >= 2)
            //    campos += ", SALDO_COM_RECEITA_LIM_2, SALDO_SEM_RECEITA_LIM_2, SALDO_COM_RECEITA_N_CONF_LIM_2, SALDO_SEM_RECEITA_N_CONF_LIM_2 ";
            //  if (qtdLimites >= 3)
            //    campos += ", SALDO_COM_RECEITA_LIM_3, SALDO_SEM_RECEITA_LIM_3, SALDO_COM_RECEITA_N_CONF_LIM_3, SALDO_SEM_RECEITA_N_CONF_LIM_3 ";
            //  if (qtdLimites >= 4)
            //    campos += ", SALDO_COM_RECEITA_LIM_4, SALDO_SEM_RECEITA_LIM_4, SALDO_COM_RECEITA_N_CONF_LIM_4, SALDO_SEM_RECEITA_N_CONF_LIM_4 ";
            //  sql += " group by CONTACORRENTE.DATA_FECHA_EMP, CONV.TITULAR, CONV.CHAPA, CONTACORRENTE.DATA_VENC_EMP, CONV.CONV_ID, CONV.GRUPO_CONV_EMP " + campos;
            //}
            //else
            sql += " group by CONTACORRENTE.DATA_FECHA_EMP, CONV.TITULAR, CONV.CHAPA, CONTACORRENTE.DATA_VENC_EMP, CONV.CONV_ID, CONV.GRUPO_CONV_EMP ";
            sql += "order by CONV.TITULAR";

            BD BD = new BD();
            return(BD.GetDataTable(sql, null));
        }
Esempio n. 5
0
        public static DataTable GetFechamentos(bool vzerado, bool baixados, string tipoext, string nfentreg,
                                             string datafecha, string dataini, string datafim, int empres_id,
                                             string chapa, string cartao, string nome, string status, string grupo)
        {
            string sql = " select CONVENIADOS.CONV_ID, CONVENIADOS.CHAPA, CONVENIADOS.TITULAR, CONVENIADOS.GRUPO_CONV_EMP, ";
             sql += " CONTACORRENTE.DATA_FECHA_EMP, ";
             sql += " CONTACORRENTE.DATA_VENC_EMP, ";
             sql += " coalesce(CONTACORRENTE.RECEITA,'N') AS RECEITA, ";
             sql += " coalesce(sum(CONTACORRENTE.DEBITO - CONTACORRENTE.CREDITO),0) as VALOR ";
             sql += " from CONVENIADOS  ";
             sql += (vzerado ? " left " : "") + "join CONTACORRENTE on ( CONVENIADOS.CONV_ID = CONTACORRENTE.CONV_ID ) ";

             #region Valores Pagos
             if (!baixados)
            sql += " and (COALESCE(CONTACORRENTE.BAIXA_CONVENIADO,'N') <> 'S')";
             #endregion

             #region Tipo de Autorizacao
             switch (nfentreg)
             {
            case "S": sql += " and (COALESCE(CONTACORRENTE.ENTREG_NF,'N') = 'S') "; break;
            case "N": sql += " and (COALESCE(CONTACORRENTE.ENTREG_NF,'N') = 'N') "; break;
             }
             #endregion

             #region Tipo Extrato

             if (tipoext == "F") //Fechamento
            sql += " and (CONTACORRENTE.DATA_FECHA_EMP = '" + Convert.ToDateTime(datafecha).ToString("MM/dd/yyyy") + "')";
             else if (tipoext == "P") //extrato periodo
            sql += " and (CONTACORRENTE.DATA between '" + Convert.ToDateTime(dataini).ToString("MM/dd/yyyy") + "' and '" + Convert.ToDateTime(datafim).ToString("MM/dd/yyyy") + "')";
             #endregion

             sql += " where (CONVENIADOS.APAGADO <> 'S')";
             sql += " and (CONVENIADOS.EMPRES_ID = " + empres_id + ")";

             #region Conveniado

             netUtil.Funcoes funcoes = new netUtil.Funcoes();

             if (grupo != "0")
            sql += " and conveniados.grupo_conv_emp=" + grupo;

             if (funcoes.SoNumero(chapa) != "")
            sql += " and conveniados.chapa = " + funcoes.SoNumero(chapa);
             else
            if (funcoes.SoNumero(cartao) != "") //procura pelo cartao
            {
               if ((cartao.Length == 11) && (Convert.ToInt32(cartao.Substring(9, 2)) == funcoes.DigitoCartao(Convert.ToInt32(cartao.Substring(0, 9)))))
                  sql += " and conveniados.conv_id = (SELECT conv_id FROM cartoes WHERE codigo = " + cartao.Substring(0, 9) + ")";
               else //cartao de importação
                  sql += " and conveniados.conv_id = (SELECT FIRST 1 conv_id FROM cartoes WHERE apagado <> 'S' AND titular = 'S' AND codcartimp = '" + cartao + "')";
            }
            else
               if (nome != "")//procura pelo Nome
               {
                  sql += " and (titular like '" + (nome.Length > 3 ? "%" : "") + nome.ToUpper() + "%')";
               }
             #endregion

             #region Status do Conveniado
             switch (status)
             {
            case "L": sql += " and conveniados.liberado = 'S' "; break;
            case "B": sql += " and conveniados.liberado <> 'S' "; break;
             }
             #endregion

             sql += " group by CONTACORRENTE.DATA_FECHA_EMP, CONVENIADOS.TITULAR, CONVENIADOS.CHAPA, CONTACORRENTE.DATA_VENC_EMP, CONVENIADOS.CONV_ID, CONVENIADOS.GRUPO_CONV_EMP, CONTACORRENTE.RECEITA ";
             sql += "order by CONVENIADOS.TITULAR";

             BD BD = new BD();
             return BD.GetDataTable(sql, null);
        }
Esempio n. 6
0
        public static bool LogarCredenciado(string codacesso, string senha, out int cred_id)
        {
            bool r = false;
            cred_id = 0;
            BD BD = new BD();
            SafeDataReader dr = BD.GetDataReader("SELECT senha, cred_id FROM Credenciados WHERE codacesso = " + codacesso, null);
            try
            {
                if (dr.Read())
                {
                    netUtil.Funcoes f = new netUtil.Funcoes();
                    if (f.Crypt("D", dr.GetString(0), "BIGCOMPRAS") == senha)
                    {
                        r = true;
                        cred_id = dr.GetInt32(1);
                    }
                }
            }
            finally
            {
                dr.Close();
            }

            return r;
        }
Esempio n. 7
0
        public static DataTable GetFechamentos(bool vzerado, bool baixados, string tipoext, string nfentreg,
                                               string datafecha, string dataini, string datafim, int empres_id,
                                               string chapa, string cartao, string nome, string status, string grupo)
        {
            string sql = " select CONVENIADOS.CONV_ID, CONVENIADOS.CHAPA, CONVENIADOS.TITULAR, CONVENIADOS.GRUPO_CONV_EMP, ";

            sql += " CONTACORRENTE.DATA_FECHA_EMP, ";
            sql += " CONTACORRENTE.DATA_VENC_EMP, ";
            sql += " coalesce(CONTACORRENTE.RECEITA,'N') AS RECEITA, ";
            sql += " coalesce(sum(CONTACORRENTE.DEBITO - CONTACORRENTE.CREDITO),0) as VALOR ";
            sql += " from CONVENIADOS  ";
            sql += (vzerado ? " left " : "") + "join CONTACORRENTE on ( CONVENIADOS.CONV_ID = CONTACORRENTE.CONV_ID ) ";

            #region Valores Pagos
            if (!baixados)
            {
                sql += " and (COALESCE(CONTACORRENTE.BAIXA_CONVENIADO,'N') <> 'S')";
            }
            #endregion

            #region Tipo de Autorizacao
            switch (nfentreg)
            {
            case "S": sql += " and (COALESCE(CONTACORRENTE.ENTREG_NF,'N') = 'S') "; break;

            case "N": sql += " and (COALESCE(CONTACORRENTE.ENTREG_NF,'N') = 'N') "; break;
            }
            #endregion

            #region Tipo Extrato

            if (tipoext == "F") //Fechamento
            {
                sql += " and (CONTACORRENTE.DATA_FECHA_EMP = '" + Convert.ToDateTime(datafecha).ToString("MM/dd/yyyy") + "')";
            }
            else if (tipoext == "P") //extrato periodo
            {
                sql += " and (CONTACORRENTE.DATA between '" + Convert.ToDateTime(dataini).ToString("MM/dd/yyyy") + "' and '" + Convert.ToDateTime(datafim).ToString("MM/dd/yyyy") + "')";
            }
            #endregion

            sql += " where (CONVENIADOS.APAGADO <> 'S')";
            sql += " and (CONVENIADOS.EMPRES_ID = " + empres_id + ")";

            #region Conveniado

            netUtil.Funcoes funcoes = new netUtil.Funcoes();

            if (grupo != "0")
            {
                sql += " and conveniados.grupo_conv_emp=" + grupo;
            }

            if (funcoes.SoNumero(chapa) != "")
            {
                sql += " and conveniados.chapa = " + funcoes.SoNumero(chapa);
            }
            else
            if (funcoes.SoNumero(cartao) != "") //procura pelo cartao
            {
                if ((cartao.Length == 11) && (Convert.ToInt32(cartao.Substring(9, 2)) == funcoes.DigitoCartao(Convert.ToInt32(cartao.Substring(0, 9)))))
                {
                    sql += " and conveniados.conv_id = (SELECT conv_id FROM cartoes WHERE codigo = " + cartao.Substring(0, 9) + ")";
                }
                else //cartao de importação
                {
                    sql += " and conveniados.conv_id = (SELECT FIRST 1 conv_id FROM cartoes WHERE apagado <> 'S' AND titular = 'S' AND codcartimp = '" + cartao + "')";
                }
            }
            else
            if (nome != "")   //procura pelo Nome
            {
                sql += " and (titular like '" + (nome.Length > 3 ? "%" : "") + nome.ToUpper() + "%')";
            }
            #endregion

            #region Status do Conveniado
            switch (status)
            {
            case "L": sql += " and conveniados.liberado = 'S' "; break;

            case "B": sql += " and conveniados.liberado <> 'S' "; break;
            }
            #endregion

            sql += " group by CONTACORRENTE.DATA_FECHA_EMP, CONVENIADOS.TITULAR, CONVENIADOS.CHAPA, CONTACORRENTE.DATA_VENC_EMP, CONVENIADOS.CONV_ID, CONVENIADOS.GRUPO_CONV_EMP, CONTACORRENTE.RECEITA ";
            sql += "order by CONVENIADOS.TITULAR";

            BD BD = new BD();
            return(BD.GetDataTable(sql, null));
        }