Esempio n. 1
0
        public static decimal TotalVencidos(Vencidos recepberPagar, decimal CODIGO_CLIENTE_FORNECEDOR, DataContext ctx, decimal ID_EMPRESA)
        {
            DateTime dataLimite = Doran_TitulosVencidos.DataLimiteParaVencimento(ctx);

            decimal?retorno = 0;

            if (recepberPagar == Vencidos.RECEBER)
            {
                var query = from linha in ctx.GetTable <TB_FINANCEIRO>()
                            where linha.DATA_PAGAMENTO == new DateTime(1901, 01, 01) &&
                            linha.DATA_VENCIMENTO < dataLimite &&
                            linha.CREDITO_DEBITO == 0 &&
                            linha.CODIGO_EMITENTE == ID_EMPRESA

                            && (linha.CODIGO_CLIENTE == CODIGO_CLIENTE_FORNECEDOR || CODIGO_CLIENTE_FORNECEDOR == 0)

                            select new TABELA_DATA_VENCIMENTO()
                {
                    NUMERO_FINANCEIRO = linha.NUMERO_FINANCEIRO,
                    DATA_VENCIMENTO   = linha.DATA_VENCIMENTO,
                    VALOR_TOTAL       = (linha.VALOR + linha.VALOR_ACRESCIMO + linha.VALOR_MULTA) - linha.VALOR_DESCONTO
                };

                foreach (var item in query)
                {
                    DateTime _vencimento = Convert.ToDateTime(item.DATA_VENCIMENTO);

                    while (Doran_TitulosVencidos.Feriado_FimDeSemana(_vencimento, ctx))
                    {
                        _vencimento = _vencimento.AddDays(1);
                    }

                    if (_vencimento < DateTime.Now)
                    {
                        retorno += item.VALOR_TOTAL;
                    }
                }

                DataTable dt = ApoioXML.ToTable <TABELA_DATA_VENCIMENTO>(query);

                foreach (DataRow dr in dt.Rows)
                {
                    retorno -= Doran_TitulosVencidos.PagoParcialmente(Convert.ToDecimal(dr["NUMERO_FINANCEIRO"]), ctx);

                    if (retorno < (decimal)0.00)
                    {
                        retorno = 0;
                    }
                }
            }
            else
            {
                var query = (from linha in ctx.GetTable <TB_FINANCEIRO>()
                             where linha.DATA_PAGAMENTO == new DateTime(1901, 01, 01) &&
                             linha.DATA_VENCIMENTO < dataLimite &&
                             linha.CREDITO_DEBITO == 1 &&
                             linha.CODIGO_EMITENTE == ID_EMPRESA

                             && (linha.CODIGO_FORNECEDOR == CODIGO_CLIENTE_FORNECEDOR || CODIGO_CLIENTE_FORNECEDOR == 0)

                             select new TABELA_DATA_VENCIMENTO()
                {
                    NUMERO_FINANCEIRO = linha.NUMERO_FINANCEIRO,
                    DATA_VENCIMENTO = linha.DATA_VENCIMENTO,
                    VALOR_TOTAL = (linha.VALOR + linha.VALOR_ACRESCIMO + linha.VALOR_MULTA) - linha.VALOR_DESCONTO
                }).ToList();

                foreach (var item in query)
                {
                    DateTime _vencimento = Convert.ToDateTime(item.DATA_VENCIMENTO);

                    while (Doran_TitulosVencidos.Feriado_FimDeSemana(_vencimento, ctx))
                    {
                        _vencimento = _vencimento.AddDays(1);
                    }

                    if (_vencimento < DateTime.Now)
                    {
                        retorno += (decimal)item.VALOR_TOTAL;
                    }
                }

                DataTable dt = ApoioXML.ToTable <TABELA_DATA_VENCIMENTO>(query);

                foreach (DataRow dr in dt.Rows)
                {
                    retorno -= Doran_TitulosVencidos.PagoParcialmente(Convert.ToDecimal(dr["NUMERO_FINANCEIRO"]), ctx);
                }
            }

            return(retorno.HasValue ? (decimal)retorno : 0);
        }
Esempio n. 2
0
        public static decimal TotalVencidos(Vencidos recepberPagar, decimal CODIGO_CLIENTE_FORNECEDOR, decimal ID_EMPRESA)
        {
            DateTime dataLimite = Doran_TitulosVencidos.DataLimiteParaVencimento();
            decimal? retorno    = 0;

            if (recepberPagar == Vencidos.RECEBER)
            {
                using (Doran_ERP_Servicos_DadosDataContext ctx = new Doran_ERP_Servicos_DadosDataContext())
                {
                    ctx.Connection.Open();
                    ctx.ExecuteCommand("SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;");

                    var query = from linha in ctx.TB_FINANCEIROs
                                where linha.DATA_PAGAMENTO == new DateTime(1901, 01, 01) &&
                                linha.DATA_VENCIMENTO < dataLimite &&
                                linha.CREDITO_DEBITO == 0 &&
                                linha.CODIGO_EMITENTE == ID_EMPRESA

                                select linha;

                    if (CODIGO_CLIENTE_FORNECEDOR > 0)
                    {
                        query = query.Where(c => c.CODIGO_CLIENTE == CODIGO_CLIENTE_FORNECEDOR);
                    }
                    else
                    {
                        query = query.Where(c => c.CODIGO_CLIENTE > 0);
                    }

                    foreach (var item in query)
                    {
                        DateTime _vencimento = Convert.ToDateTime(item.DATA_VENCIMENTO);

                        while (Doran_TitulosVencidos.Feriado_FimDeSemana(_vencimento))
                        {
                            _vencimento = _vencimento.AddDays(1);
                        }

                        if (_vencimento < DateTime.Now)
                        {
                            retorno += (item.VALOR + item.VALOR_ACRESCIMO + item.VALOR_MULTA) - item.VALOR_DESCONTO;
                        }
                    }

                    DataTable dt = ApoioXML.ToDataTable(ctx, query);

                    foreach (DataRow dr in dt.Rows)
                    {
                        retorno -= Doran_TitulosVencidos.PagoParcialmente(Convert.ToDecimal(dr["NUMERO_FINANCEIRO"]));

                        if (retorno < (decimal)0.00)
                        {
                            retorno = 0;
                        }
                    }
                }
            }
            else
            {
                using (Doran_ERP_Servicos_DadosDataContext ctx = new Doran_ERP_Servicos_DadosDataContext())
                {
                    ctx.Connection.Open();
                    ctx.ExecuteCommand("SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;");

                    var query = from linha in ctx.TB_FINANCEIROs
                                where linha.DATA_PAGAMENTO == new DateTime(1901, 01, 01) &&
                                linha.DATA_VENCIMENTO < dataLimite &&
                                linha.CREDITO_DEBITO == 1 &&
                                linha.CODIGO_EMITENTE == ID_EMPRESA

                                && (linha.CODIGO_FORNECEDOR == CODIGO_CLIENTE_FORNECEDOR || CODIGO_CLIENTE_FORNECEDOR == 0)
                                select linha;

                    foreach (var item in query)
                    {
                        DateTime _vencimento = Convert.ToDateTime(item.DATA_VENCIMENTO);

                        while (Doran_TitulosVencidos.Feriado_FimDeSemana(_vencimento))
                        {
                            _vencimento = _vencimento.AddDays(1);
                        }

                        if (_vencimento < DateTime.Now)
                        {
                            retorno += (item.VALOR + item.VALOR_ACRESCIMO + item.VALOR_MULTA) - item.VALOR_DESCONTO;
                        }
                    }

                    DataTable dt = ApoioXML.ToDataTable(ctx, query);

                    foreach (DataRow dr in dt.Rows)
                    {
                        retorno -= Doran_TitulosVencidos.PagoParcialmente(Convert.ToDecimal(dr["NUMERO_FINANCEIRO"]));
                    }
                }
            }

            return(retorno.HasValue ? (decimal)retorno : 0);
        }