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 string MontaRelatorioAReceber()
        {
            string retorno = "";

            using (Th2_Report r = new Th2_Report(ExpertPdf.HtmlToPdf.PdfPageSize.A4, ExpertPdf.HtmlToPdf.PDFPageOrientation.Portrait))
            {
                r.ID_EMPRESA = ID_EMPRESA;

                r.DefineCabecalho("Relat&oacute;rio de T&iacute;tulos a Receber Vencidos", 60);

                DateTime dataLimite = Doran_TitulosVencidos.DataLimiteParaVencimento();

                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_CLIENTE > 0
                                && linha.HISTORICO.Contains(cliente_fornecedor) &&
                                linha.CODIGO_EMITENTE == ID_EMPRESA

                                select new
                    {
                        linha.NUMERO_FINANCEIRO,
                        linha.NUMERO_SEQ_NF_SAIDA,
                        linha.NUMERO_NF_SAIDA,
                        linha.NUMERO_SEQ_NF_ENTRADA,
                        linha.HISTORICO,
                        linha.DATA_LANCAMENTO,
                        linha.DATA_VENCIMENTO,
                        CLIENTE         = linha.TB_NOTA_SAIDA == null ? "" : linha.TB_NOTA_SAIDA.TB_CLIENTE.NOMEFANTASIA_CLIENTE,
                        VENDEDOR        = linha.TB_NOTA_SAIDA == null ? "" : linha.TB_NOTA_SAIDA.NOME_VENDEDOR_NF,
                        CODIGO_VENDEDOR = linha.TB_NOTA_SAIDA == null ? 0 : linha.TB_NOTA_SAIDA.CODIGO_VENDEDOR_NF,
                        VALOR_TOTAL     = (linha.VALOR + linha.VALOR_ACRESCIMO + linha.VALOR_MULTA) - linha.VALOR_DESCONTO,
                        linha.VALOR_APROXIMADO
                    };

                    if (VENDEDOR > 0)
                    {
                        query = query.Where(_ => _.CODIGO_VENDEDOR == VENDEDOR);
                    }

                    string _conteudo = "<table style='width: 70%; font-family: tahoma; font-size: 8pt;'>";

                    _conteudo += @"<tr>
                                    <td style='BORDER-BOTTOM: 1px solid; border-color:#C0C0C0;'>NF / Duplicata</td>
                                    <td style='BORDER-BOTTOM: 1px solid; border-color:#C0C0C0;'>Lan&ccedil;amento</td>
                                    <td style='BORDER-BOTTOM: 1px solid; border-color:#C0C0C0;'>Vencimento</td>
                                    <td style='BORDER-BOTTOM: 1px solid; border-color:#C0C0C0;'>Cliente</td>
                                    <td style='BORDER-BOTTOM: 1px solid;  border-color:#C0C0C0;'>Vendedor</td>
                                    <td style='BORDER-BOTTOM: 1px solid; text-align: right; border-color:#C0C0C0;'>Valor</td>
                                    <td style='BORDER-BOTTOM: 1px solid; text-align: right; border-color:#C0C0C0;'>Valor Aproximado?</td>
                                  </tr>";

                    decimal Total = 0;

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

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

                        DateTime _limite = DateTime.Now;

                        if (_limite.DayOfWeek == DayOfWeek.Saturday)
                        {
                            _limite = _limite.AddDays(-2);
                        }

                        if (_limite.DayOfWeek == DayOfWeek.Sunday)
                        {
                            _limite = _limite.AddDays(-3);
                        }

                        decimal valor = (decimal)item.VALOR_TOTAL - Doran_TitulosVencidos.PagoParcialmente(item.NUMERO_FINANCEIRO);

                        if (_vencimento < _limite)
                        {
                            _conteudo += string.Format(@"<tr>
                                        <td style='BORDER-LEFT: 1px solid; BORDER-RIGHT: 1px solid; border-color:#C0C0C0;'>{0}</td>
                                        <td style='BORDER-RIGHT: 1px solid; border-color:#C0C0C0;'>{1}</td>
                                        <td style='BORDER-RIGHT: 1px solid; border-color:#C0C0C0;'>{2}</td>
                                        <td style='BORDER-RIGHT: 1px solid; border-color:#C0C0C0;'>{3}</td>
                                        <td style='BORDER-RIGHT: 1px solid; border-color:#C0C0C0;'>{4}</td>
                                        <td style='BORDER-RIGHT: 1px solid; border-color:#C0C0C0; text-align: right;'>{5}</td>
                                        <td style='BORDER-RIGHT: 1px solid; border-color:#C0C0C0;'>{6}</td>
                                      </tr>", item.NUMERO_NF_SAIDA.ToString() + "/" + ApoioXML.LetrasDuplicatas_ERP_Servicos(item.NUMERO_SEQ_NF_SAIDA, item.NUMERO_SEQ_NF_ENTRADA, item.DATA_VENCIMENTO),
                                                       ApoioXML.Data((DateTime)item.DATA_LANCAMENTO),
                                                       ApoioXML.Data((DateTime)item.DATA_VENCIMENTO),
                                                       string.IsNullOrEmpty(item.CLIENTE) ? item.HISTORICO : item.CLIENTE.Trim(),
                                                       string.IsNullOrEmpty(item.VENDEDOR) ? "" : item.VENDEDOR.Trim(),
                                                       ((decimal)valor).ToString("c"),
                                                       item.VALOR_APROXIMADO == 1 ? "S" : "");

                            Total += valor;
                        }
                    }

                    _conteudo += string.Format(@"<tr>
                                        <td style='BORDER-TOP: 1px solid; text-align: right; border-color:#C0C0C0;'>&nbsp;</td>
                                        <td style='BORDER-TOP: 1px solid; text-align: right; border-color:#C0C0C0;'>&nbsp;</td>
                                        <td style='BORDER-TOP: 1px solid; text-align: right; border-color:#C0C0C0;'>&nbsp;</td>
                                        <td style='BORDER-TOP: 1px solid; text-align: right; border-color:#C0C0C0;'>&nbsp;</td>
                                        <td style='BORDER-TOP: 1px solid; text-align: right; border-color:#C0C0C0;'>{0}</td>
                                        <td style='BORDER-TOP: 1px solid; text-align: right; border-color:#C0C0C0;'>{1}</td>
                                        <td style='BORDER-TOP: 1px solid; text-align: right; border-color:#C0C0C0;'>&nbsp;</td>
                                      </tr></table>", "Total..:", ((decimal)Total).ToString("c"));

                    r.InsereConteudo(_conteudo);

                    retorno = r.SalvaDocumento("Doran_Titulos_Receber_Vencidos");
                }

                return(retorno);
            }
        }
Esempio n. 3
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);
        }
Esempio n. 4
0
        public string Faturamento_Inadimplencia(DateTime dt1, DateTime dt2, decimal _ID_EMPRESA)
        {
            ID_EMPRESA = _ID_EMPRESA;

            using (Doran_ERP_Servicos_DadosDataContext ctx = new Doran_ERP_Servicos_DadosDataContext())
            {
                int monthsApart = 12 * (dt1.Year - dt2.Year) + dt1.Month - dt2.Month;
                monthsApart = Math.Abs(monthsApart);

                dt2 = dt2.AddDays(1);
                dt2 = dt2.AddMonths(-monthsApart);

                List <decimal?> TotalFaturamento = new List <decimal?>();
                List <decimal?> TotalVencido     = new List <decimal?>();
                List <string>   Periodo          = new List <string>();
                decimal?        _totalVencido    = 0;

                for (int i = 0; i <= monthsApart; i++)
                {
                    var query = from linha in ctx.TB_FINANCEIROs
                                where (linha.DATA_VENCIMENTO >= dt1 &&
                                       linha.DATA_VENCIMENTO < dt2) &&
                                linha.CREDITO_DEBITO == 0 &&
                                linha.CODIGO_EMITENTE == ID_EMPRESA
                                select linha;

                    decimal?_total = query.Sum(tf => tf.VALOR_TOTAL);

                    if (!_total.HasValue)
                    {
                        TotalFaturamento.Add(0);
                    }
                    else
                    {
                        TotalFaturamento.Add(_total);
                    }

                    DateTime _vencido = dt1.Month == DateTime.Now.Month ?
                                        Doran_TitulosVencidos.DataLimiteParaVencimento() :
                                        dt2;

                    var query1 = from linha in ctx.TB_FINANCEIROs
                                 where (linha.DATA_VENCIMENTO >= dt1 &&
                                        linha.DATA_VENCIMENTO < _vencido) &&
                                 linha.DATA_PAGAMENTO == new DateTime(1901, 01, 01) &&
                                 linha.CREDITO_DEBITO == 0 &&
                                 linha.CODIGO_EMITENTE == ID_EMPRESA
                                 select linha;

                    decimal tv = 0;

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

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

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

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

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

                    _totalVencido += tv;

                    TotalVencido.Add(_totalVencido);

                    Periodo.Add(dt1.Month.ToString().PadLeft(2, '0') + "/" + dt1.Year.ToString());

                    dt1 = dt1.AddMonths(1);
                    dt2 = dt1;
                    dt2 = dt2.AddMonths(1);
                    dt2 = dt2.AddSeconds(-1);
                }

                string retorno = "[";

                for (int i = 0; i < TotalFaturamento.Count; i++)
                {
                    string _totalFaturamento = TotalFaturamento[i].ToString();
                    _totalFaturamento = _totalFaturamento.Replace(",", ".");

                    string totalVencido = TotalVencido[i].ToString();
                    totalVencido = totalVencido.Replace(",", ".");

                    retorno += "{ periodo: '" + Periodo[i] + "', total_faturamento: " + _totalFaturamento + ", total_vencido: " + totalVencido + " },";
                }

                retorno = retorno.Substring(0, retorno.Length - 1) + "]";

                return(retorno);
            }
        }