Exemplo n.º 1
0
        private void Limite_Excedido()
        {
            using (Doran_ERP_Servicos_DadosDataContext ctx = new Doran_ERP_Servicos_DadosDataContext())
            {
                var emAberto = (from linha in ctx.TB_FINANCEIROs
                                where linha.CREDITO_DEBITO == 0 &&
                                linha.CODIGO_CLIENTE == CODIGO_CLIENTE &&
                                linha.DATA_PAGAMENTO == new DateTime(1901, 01, 01)
                                select linha.VALOR_TOTAL).Sum();

                if (!emAberto.HasValue)
                {
                    emAberto = 0;
                }

                if (emAberto > 0)
                {
                    var pagoParcial = (from linha in ctx.TB_PAGTO_PARCIALs
                                       where linha.TB_FINANCEIRO.CREDITO_DEBITO == 0 &&
                                       linha.TB_FINANCEIRO.CODIGO_CLIENTE == CODIGO_CLIENTE &&
                                       linha.TB_FINANCEIRO.DATA_PAGAMENTO == new DateTime(1901, 01, 01)
                                       select linha).Sum(pp => pp.VALOR_PAGTO);

                    if (pagoParcial.HasValue)
                    {
                        emAberto -= pagoParcial;
                    }
                }

                if (emAberto < (decimal)0.00)
                {
                    emAberto = 0;
                }

                emAberto += Doran_Limite_Credito_Cliente.Limite_Excedido_Cliente(CODIGO_CLIENTE);

                if (emAberto > (decimal)0.00)
                {
                    using (Doran_ERP_Servicos_DadosDataContext ctx1 = new Doran_ERP_Servicos_DadosDataContext())
                    {
                        var limite = (from linha in ctx1.TB_CLIENTEs
                                      where linha.ID_CLIENTE == CODIGO_CLIENTE
                                      select linha).ToList().First().TB_LIMITE.VALOR_LIMITE;

                        if ((emAberto - limite) > limite)
                        {
                            AdicionaRestricao(CRITERIOS_DE_ANALISE.Limite_Excedido, string.Concat(@"Limite de Cr&eacute;dito excedido para este cliente. <br />
                                Limite de Cr&eacute;dito cadastrado = ", ((double)limite).ToString("c"), "<br />",
                                                                                                  "Valor em aberto deste cliente = <span style='color: red;'>", ((double)(emAberto - limite)).ToString("c"), "</span>"));
                        }
                    }
                }
                // falta adicionar os pedidos já aprovados e ainda não faturados.
            }
        }
Exemplo n.º 2
0
        public string ListaClientesComLimiteExcedido(Dictionary <string, object> dados)
        {
            using (Doran_ERP_Servicos_DadosDataContext ctx = new Doran_ERP_Servicos_DadosDataContext())
            {
                var query = from linha in ctx.TB_FINANCEIROs

                            where linha.DATA_PAGAMENTO == new DateTime(1901, 01, 01) &&
                            linha.CREDITO_DEBITO == 0 && linha.CODIGO_CLIENTE > 0 &&
                            (linha.TB_CLIENTE.NOME_CLIENTE.Contains(dados["pesquisa"].ToString()) ||
                             linha.TB_CLIENTE.NOMEFANTASIA_CLIENTE.Contains(dados["pesquisa"].ToString()))

                            group linha by new
                {
                    linha.CODIGO_CLIENTE,
                    linha.TB_CLIENTE.NOMEFANTASIA_CLIENTE,
                    linha.TB_CLIENTE.TB_MUNICIPIO.NOME_MUNICIPIO,
                    linha.TB_CLIENTE.TB_MUNICIPIO1.TB_UF.SIGLA_UF,
                    linha.TB_CLIENTE.TELEFONE_FATURA,
                    linha.TB_CLIENTE.TB_LIMITE.VALOR_LIMITE
                }
                into grupo

                    select new
                {
                    CODIGO_CLIENTE       = grupo.Key.CODIGO_CLIENTE,
                    NOMEFANTASIA_CLIENTE = grupo.Key.NOMEFANTASIA_CLIENTE,
                    CIDADE       = grupo.Key.NOME_MUNICIPIO,
                    UF           = grupo.Key.SIGLA_UF,
                    TELEFONE     = grupo.Key.TELEFONE_FATURA,
                    VALOR_LIMITE = grupo.Key.VALOR_LIMITE,

                    VALOR_EM_ABERTO = grupo.Sum(linha => linha.VALOR_TOTAL)
                };

                query = query.Where(m => m.VALOR_EM_ABERTO > 0);

                int rowCount = query.Count();

                query = query.Skip(Convert.ToInt32(dados["start"])).Take(Convert.ToInt32(dados["limit"]));

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

                dt.Columns["VALOR_EM_ABERTO"].ReadOnly = false;

                foreach (DataRow dr in dt.Rows)
                {
                    decimal valorEmAberto = Convert.ToDecimal(dr["VALOR_EM_ABERTO"]);

                    valorEmAberto += Doran_Limite_Credito_Cliente.Limite_Excedido_Cliente(Convert.ToDecimal(dr["CODIGO_CLIENTE"]));

                    valorEmAberto -= Convert.ToDecimal(dr["VALOR_LIMITE"]);

                    if (valorEmAberto < (decimal)0.00)
                    {
                        valorEmAberto = 0;
                    }

                    dr["VALOR_EM_ABERTO"] = valorEmAberto;
                }

                return(ClientesInadimplentes(dt, rowCount, ID_EMPRESA));
            }
        }
Exemplo n.º 3
0
        public static Dictionary <string, string> Creditos_do_Cliente(decimal CODIGO_CLIENTE, string DataInicial, string DataFinal, decimal ID_EMPRESA)
        {
            DateTime dt1 = Convert.ToDateTime(DataInicial);
            DateTime dt2 = Convert.ToDateTime(DataFinal);

            dt2 = dt2.AddDays(1);

            Dictionary <string, string> retorno = new Dictionary <string, string>();

            using (Doran_ERP_Servicos_DadosDataContext ctx = new Doran_ERP_Servicos_DadosDataContext())
            {
                var faturamento = (from linha in ctx.TB_NOTA_SAIDAs
                                   where linha.CODIGO_CLIENTE_NF == CODIGO_CLIENTE &&
                                   (linha.DATA_EMISSAO_NF >= dt1 &&
                                    linha.DATA_EMISSAO_NF < dt2) &&
                                   (linha.STATUS_NF == 2 || linha.STATUS_NF == 4)

                                   select linha).Sum(fat => fat.TOTAL_NF);

                if (faturamento.HasValue)
                {
                    retorno.Add("Faturamento", ((decimal)faturamento).ToString("c", CultureInfo.CurrentCulture));
                }
                else
                {
                    retorno.Add("Faturamento", 0.ToString("c", CultureInfo.CurrentCulture));
                }

                DateTime amanha = DateTime.Today;
                amanha = amanha.AddDays(1);

                var aReceber = (from linha in ctx.TB_FINANCEIROs
                                where linha.CODIGO_CLIENTE == CODIGO_CLIENTE &&
                                linha.DATA_VENCIMENTO >= amanha &&
                                linha.DATA_PAGAMENTO == new DateTime(1901, 01, 01) &&
                                linha.CREDITO_DEBITO == 0

                                select linha).Sum(ar => ar.VALOR_TOTAL);

                if (aReceber.HasValue)
                {
                    retorno.Add("aReceber", ((decimal)aReceber).ToString("c", CultureInfo.CurrentCulture));
                }
                else
                {
                    retorno.Add("aReceber", 0.ToString("c", CultureInfo.CurrentCulture));
                }


                var Recebido = (from linha in ctx.TB_FINANCEIROs
                                where linha.CODIGO_CLIENTE == CODIGO_CLIENTE &&
                                (linha.DATA_PAGAMENTO >= dt1 &&
                                 linha.DATA_PAGAMENTO < dt2) &&
                                linha.CREDITO_DEBITO == 0

                                select linha).Sum(pa => pa.VALOR_TOTAL);

                if (Recebido.HasValue)
                {
                    retorno.Add("Recebido", ((decimal)Recebido).ToString("c", CultureInfo.CurrentCulture));
                }
                else
                {
                    retorno.Add("Recebido", 0.ToString("c", CultureInfo.CurrentCulture));
                }

                decimal Inadimplente = Doran_TitulosVencidos.TotalVencidos(Vencidos.RECEBER, CODIGO_CLIENTE, ID_EMPRESA);

                if (Inadimplente > (decimal)0.00)
                {
                    retorno.Add("Inadimplente", "<span style='color: red;'>" + Inadimplente.ToString("c", CultureInfo.CurrentCulture) + "</span>");
                }
                else
                {
                    retorno.Add("Inadimplente", "<span>" + Inadimplente.ToString("c", CultureInfo.CurrentCulture) + "</span>");
                }

                var limiteCliente = (from linha in ctx.TB_CLIENTEs
                                     where linha.ID_CLIENTE == CODIGO_CLIENTE
                                     select new
                {
                    linha.TB_LIMITE.VALOR_LIMITE
                }).ToList();

                decimal _limiteCliente = 0;

                foreach (var item in limiteCliente)
                {
                    _limiteCliente = (decimal)item.VALOR_LIMITE;
                }

                var EmAberto = (from linha in ctx.TB_FINANCEIROs
                                where linha.CODIGO_CLIENTE == CODIGO_CLIENTE &&
                                linha.DATA_PAGAMENTO == new DateTime(1901, 01, 01) &&
                                linha.CREDITO_DEBITO == 0

                                select linha).Sum(ab => ab.VALOR_TOTAL);

                if (EmAberto > _limiteCliente)
                {
                    EmAberto = EmAberto - _limiteCliente;
                }
                else
                {
                    EmAberto = 0;
                }

                EmAberto += Doran_Limite_Credito_Cliente.Limite_Excedido_Cliente(CODIGO_CLIENTE);

                if (EmAberto > (decimal)0.00)
                {
                    retorno.Add("Excedido", "<span style='color: red;'>" + ((decimal)EmAberto).ToString("c", CultureInfo.CurrentCulture) + "</span>");
                }
                else
                {
                    retorno.Add("Excedido", ((decimal)EmAberto).ToString("c", CultureInfo.CurrentCulture));
                }

                var Abatimentos = (from linha in ctx.GetTable <TB_SALDO_CLIENTE_FORNECEDOR>()
                                   orderby linha.CODIGO_CLIENTE, linha.SALDO_RESTANTE

                                   where linha.CODIGO_CLIENTE == CODIGO_CLIENTE &&
                                   linha.SALDO_RESTANTE > (decimal)0.00

                                   select linha).Sum(a => a.SALDO_RESTANTE);

                if (Abatimentos.HasValue)
                {
                    retorno.Add("Abatimentos", "<span style='color: navy;'>" + ((decimal)Abatimentos).ToString("c", CultureInfo.CurrentCulture) + "</span>");
                }
                else
                {
                    retorno.Add("Abatimentos", ((decimal)0.00).ToString("c", CultureInfo.CurrentCulture));
                }

                // Data e Valor da Ultima Compra

                var ultimaCompra = (from linha in ctx.TB_NOTA_SAIDAs
                                    orderby linha.CODIGO_CLIENTE_NF, linha.DATA_EMISSAO_NF descending
                                    where linha.CODIGO_CLIENTE_NF == CODIGO_CLIENTE &&
                                    linha.STATUS_NF == 4
                                    select new { linha.DATA_EMISSAO_NF, linha.TOTAL_SERVICOS_NF }).Take(1).ToList();

                if (ultimaCompra.Any())
                {
                    foreach (var item in ultimaCompra)
                    {
                        retorno.Add("data_ultima_compra", ApoioXML.TrataData2(item.DATA_EMISSAO_NF));
                        retorno.Add("valor_ultima_compra", ((decimal)item.TOTAL_SERVICOS_NF).ToString("c"));
                    }
                }
                else
                {
                    retorno.Add("data_ultima_compra", "");
                    retorno.Add("valor_ultima_compra", ((decimal)0.00).ToString("c"));
                }

                // Maior compra

                var maiorCompra = (from linha in ctx.TB_NOTA_SAIDAs
                                   orderby linha.CODIGO_CLIENTE_NF, linha.DATA_EMISSAO_NF
                                   where linha.CODIGO_CLIENTE_NF == CODIGO_CLIENTE &&
                                   linha.STATUS_NF == 4
                                   select linha).Max(m => m.TOTAL_SERVICOS_NF);

                retorno.Add("maior_compra", maiorCompra.HasValue ? ((decimal)maiorCompra).ToString("c") : ((decimal)0.00).ToString("c"));

                return(retorno);
            }
        }
Exemplo n.º 4
0
        public List <string> GraficoCreditoCliente(decimal CODIGO_CLIENTE)
        {
            using (Doran_ERP_Servicos_DadosDataContext ctx = new Doran_ERP_Servicos_DadosDataContext())
            {
                DateTime amanha = DateTime.Today;
                amanha = amanha.AddDays(1);

                var aReceber = (from linha in ctx.TB_FINANCEIROs
                                where linha.CODIGO_CLIENTE == CODIGO_CLIENTE &&
                                linha.DATA_VENCIMENTO >= amanha &&
                                linha.DATA_PAGAMENTO == new DateTime(1901, 01, 01) &&
                                linha.CREDITO_DEBITO == 0

                                select linha).Sum(ar => ar.VALOR_TOTAL);

                if (!aReceber.HasValue)
                {
                    aReceber = 0;
                }

                decimal Inadimplente = Doran_TitulosVencidos.TotalVencidos(Vencidos.RECEBER, CODIGO_CLIENTE, ID_EMPRESA);

                var limiteCliente = (from linha in ctx.TB_CLIENTEs
                                     where linha.ID_CLIENTE == CODIGO_CLIENTE
                                     select new
                {
                    linha.TB_LIMITE.VALOR_LIMITE
                }).ToList();

                decimal _limiteCliente = 0;

                foreach (var item in limiteCliente)
                {
                    _limiteCliente = (decimal)item.VALOR_LIMITE;
                }

                var EmAberto = (from linha in ctx.TB_FINANCEIROs
                                where linha.CODIGO_CLIENTE == CODIGO_CLIENTE &&
                                linha.DATA_PAGAMENTO == new DateTime(1901, 01, 01) &&
                                linha.CREDITO_DEBITO == 0

                                select linha).Sum(ab => ab.VALOR_TOTAL);

                EmAberto += Doran_Limite_Credito_Cliente.Limite_Excedido_Cliente(CODIGO_CLIENTE);

                if (EmAberto > _limiteCliente)
                {
                    EmAberto = EmAberto - _limiteCliente;
                }
                else
                {
                    EmAberto = 0;
                }

                var Abatimentos = (from linha in ctx.GetTable <TB_SALDO_CLIENTE_FORNECEDOR>()
                                   orderby linha.CODIGO_CLIENTE, linha.SALDO_RESTANTE

                                   where linha.CODIGO_CLIENTE == CODIGO_CLIENTE &&
                                   linha.SALDO_RESTANTE > (decimal)0.00

                                   select linha).Sum(a => a.SALDO_RESTANTE);

                string _aReceber = aReceber.ToString();
                _aReceber = _aReceber.Replace(",", ".");

                string _Inadimplente = Inadimplente.ToString();
                _Inadimplente = _Inadimplente.Replace(",", ".");

                string _emAberto = EmAberto.ToString();
                _emAberto = _emAberto.Replace(",", ".");

                string _Abatimentos = Abatimentos.HasValue ? Abatimentos.ToString() : "";
                _Abatimentos = _Abatimentos.Replace(",", ".");

                List <string> retorno = new List <string>();

                retorno.Add("['Total a Receber', " + _aReceber + "]");
                retorno.Add("['Total Inadimplente', " + _Inadimplente + "]");
                retorno.Add("['Limite de Crédito Excedido', " + _emAberto + " ]");
                retorno.Add("['Abatimento(s)', " + _Abatimentos + " ]");

                return(retorno);
            }
        }