Exemple #1
0
        public ActionResult GetListadoSearch(string busqueda, int pagina, int numreg, string estado)
        {
            List <OportunidadCategoria> listaCategoria      = new List <OportunidadCategoria>();
            OportunidadConsulta         oportunidadConsulta = new OportunidadConsulta();
            OportunidadCategoria        categoria           = new OportunidadCategoria();

            List <int> listAgente = new List <int>();

            if (!this.TodosMisAgentes)
            {
                listAgente.Add(this.AgenteWork.IdAgente);
            }
            else
            {
                foreach (var agente in this.AgentesWork)
                {
                    listAgente.Add(agente.IdAgente);
                }
            }
            var data = DataBase.Oportunidades.GetListadoFullTextSearch(listAgente, busqueda, pagina, numreg, estado);

            categoria = new OportunidadCategoria();

            if (data.Count > 0)
            {
                if (data[0].TotalPages > 1)
                {
                    categoria.Nombre = data[0].CurrentPage.ToString() + "/" + data[0].TotalPages.ToString() + " " + Rp3.AgendaComercial.Resources.LabelFor.Paginas + " [" + data[0].TotalRows.ToString() + " " + Rp3.AgendaComercial.Resources.LabelFor.Registros + "]";
                }
                else
                {
                    categoria.Nombre = "[" + data[0].TotalRows.ToString() + " " + Rp3.AgendaComercial.Resources.LabelFor.Registros + "]";
                }
            }
            else
            {
                categoria.Nombre = data.Count.ToString() + " " + Rp3.AgendaComercial.Resources.LabelFor.Registros;
            }

            categoria.isBusqueda = true;

            if (data.Count > 0)
            {
                categoria.FechaInicio = DateTime.Today;
                categoria.FechaFin    = DateTime.Today;
                categoria.Oportunidad = data.ToList();
            }
            listaCategoria.Add(categoria);

            oportunidadConsulta.OportunidadCategorias = listaCategoria;

            return(PartialView("_OportunidadListaDetalle", oportunidadConsulta));
        }
Exemple #2
0
        public ActionResult GetListado(DateTime fechaInicial, DateTime fechaFinal, string estado, string sortField, int sortMode, int?diasInactividad, int?tipo, string groupMode = Rp3.AgendaComercial.Models.Constantes.OportunidadGroupMode.Calendario)
        {
            fechaInicial = fechaInicial.Date;
            fechaFinal   = fechaFinal.Date.AddHours(23).AddMinutes(59).AddSeconds(59);;

            /*
             * 1 = Next Few Days
             * 2 = Next Weeks (Until last Week of Month)
             * 3 = Next Month
             */
            //Modelo
            List <OportunidadCategoria> listaOportunidad    = new List <OportunidadCategoria>();
            OportunidadConsulta         oportunidadConsulta = new OportunidadConsulta();
            OportunidadCategoria        categoria           = new OportunidadCategoria();

            //Current Day
            DateTime currentDay = DateTime.Now;
            //Find Remainder Sundays
            int remainderSundays = GetRemainderSundays(fechaInicial); // (currentDay);
            //First Sunday
            DateTime beginDate = GetNextSunday(fechaInicial);         // (currentDay);

            //Range of Search
            int dayRange = (fechaFinal - fechaInicial).Days;
            //Days Left Until End of Week
            int daysLeft = (GetNextSunday(fechaInicial) - fechaInicial).Days;

            List <int> listAgente = new List <int>();

            if (!this.TodosMisAgentes)
            {
                listAgente.Add(this.AgenteWork.IdAgente);
            }
            else
            {
                foreach (var agente in this.AgentesWork)
                {
                    listAgente.Add(agente.IdAgente);
                }
            }

            var data = DataBase.Oportunidades.GetOportunidadListado(listAgente, fechaInicial, fechaFinal, estado);

            if (diasInactividad != null)
            {
                data = data.Where(p => p.DiasInactividad > diasInactividad.Value).ToList();
            }

            if (tipo.HasValue)
            {
                data = data.Where(p => p.IdOportunidadTipo == tipo.Value).ToList();
            }

            switch (groupMode)
            {
            case Rp3.AgendaComercial.Models.Constantes.OportunidadGroupMode.Calendario:

                bool exit = false;

                if (dayRange <= 7)
                {
                    for (int x = 0; x <= 7; x++)
                    {
                        if (!exit)
                        {
                            categoria            = new OportunidadCategoria();
                            categoria.isBusqueda = false;

                            if (fechaInicial.Date == currentDay.Date)
                            {
                                if (x == 0)
                                {
                                    categoria.Nombre = Rp3.AgendaComercial.Resources.LabelFor.Hoy;
                                }
                                else if (x == 1)
                                {
                                    categoria.Nombre = Rp3.AgendaComercial.Resources.LabelFor.Maniana;
                                }
                                else
                                {
                                    categoria.Nombre = fechaInicial.AddDays(x).ToString("dddd").First().ToString().ToUpper() +
                                                       String.Join("", fechaInicial.AddDays(x).ToString("dddd").Skip(1))
                                                       + " " + fechaInicial.AddDays(x).Day.ToString() + ", " +
                                                       fechaInicial.ToString("MMMM").First().ToString().ToUpper() +
                                                       String.Join("", fechaInicial.ToString("MMMM").Skip(1));
                                }
                            }
                            else
                            {
                                categoria.Nombre = /*currentDay*/ fechaInicial.AddDays(x).ToString("dddd").First().ToString().ToUpper() +
                                                   String.Join("", /*currentDay*/ fechaInicial.AddDays(x).ToString("dddd").Skip(1))
                                                   + " " + /*currentDay*/ fechaInicial.AddDays(x).Day.ToString() + ", " +
                                                   fechaInicial.ToString("MMMM").First().ToString().ToUpper() +
                                                   String.Join("", fechaInicial.ToString("MMMM").Skip(1));
                            }

                            categoria.FechaInicio = /*currentDay*/ fechaInicial.AddDays(x);
                            categoria.FechaFin    = /*currentDay*/ fechaInicial.AddDays(x);
                            categoria.Oportunidad = data.Where(p => p.FechaInicio.Date == /*currentDay*/ fechaInicial.AddDays(x).Date).OrderBy(p => p.FechaInicio).Distinct().ToList();

                            listaOportunidad.Add(categoria);

                            if (fechaInicial.AddDays(x) >= fechaFinal)
                            {
                                exit = true;
                            }
                        }
                    }
                }

                if (dayRange > 7 && dayRange <= 29)
                {
                    for (int x = 0; x < 5; x++)
                    {
                        if (!exit)
                        {
                            int daysInWeek = 7;

                            DateTime CalFechaInicial = beginDate.AddDays((daysInWeek * (x - 1) + 1));
                            DateTime CalFechaFinal   = beginDate.AddDays(daysInWeek * (x));

                            if (x == 0)
                            {
                                CalFechaInicial = fechaInicial;
                                CalFechaFinal   = beginDate;
                            }
                            if (CalFechaFinal.Date > fechaFinal.Date)
                            {
                                CalFechaFinal = fechaFinal;
                                exit          = true;
                            }

                            string beginWeekDay = CalFechaInicial.ToString("dddd").First().ToString().ToUpper() +
                                                  String.Join("", CalFechaInicial.ToString("dddd").Skip(1));

                            string beginMontName = String.Empty;
                            if (CalFechaInicial.Year * 100 + CalFechaInicial.Month != CalFechaFinal.Year * 100 + CalFechaFinal.Month)
                            {
                                beginMontName = CalFechaInicial.ToString("MMMM").First().ToString().ToUpper() + String.Join("", CalFechaInicial.ToString("MMMM").Skip(1));
                            }

                            string endWeekDay = CalFechaFinal.ToString("dddd").First().ToString().ToUpper() +
                                                String.Join("", CalFechaFinal.ToString("dddd").Skip(1));

                            string textoEndMonth = CalFechaFinal.ToString("MMMM").First().ToString().ToUpper() +
                                                   String.Join("", CalFechaFinal.ToString("MMMM").Skip(1));

                            categoria            = new OportunidadCategoria();
                            categoria.isBusqueda = false;

                            //categoria.Nombre = beginWeekDay + " " + CalFechaInicial.Day.ToString() + " - " + endWeekDay + " " + CalFechaFinal.Day.ToString() + ", " + textoEndMonth;

                            if (String.IsNullOrEmpty(beginMontName))
                            {
                                if (beginWeekDay + " " + CalFechaInicial.Day.ToString() != endWeekDay + " " + CalFechaFinal.Day.ToString())
                                {
                                    categoria.Nombre = beginWeekDay + " " + CalFechaInicial.Day.ToString() + " - " + endWeekDay + " " + CalFechaFinal.Day.ToString() + ", " + textoEndMonth;
                                }
                                else
                                {
                                    categoria.Nombre = beginWeekDay + " " + CalFechaInicial.Day.ToString() + ", " + textoEndMonth;
                                }
                            }
                            else
                            {
                                categoria.Nombre = beginWeekDay + " " + CalFechaInicial.Day.ToString() + ", " + beginMontName + " - " + endWeekDay + " " + CalFechaFinal.Day.ToString() + ", " + textoEndMonth;
                            }

                            categoria.FechaInicio = CalFechaInicial.AddDays(1);
                            categoria.FechaFin    = CalFechaFinal;
                            categoria.Oportunidad = data.Where(p => (p.FechaInicio.Date >= CalFechaInicial.Date) &&
                                                               (p.FechaInicio.Date <= CalFechaFinal.Date))
                                                    .OrderBy(p => p.FechaInicio).Distinct().ToList();

                            listaOportunidad.Add(categoria);
                        }
                    }
                }

                if (dayRange > 29)
                {
                    for (int x = 1; x < 20; x++)
                    {
                        if (!exit)
                        {
                            DateTime CalFechaInicial = fechaInicial.AddDays(-(fechaInicial.Day - 1)).AddMonths(x - 1);
                            DateTime CalFechaFinal   = new DateTime(CalFechaInicial.Year, CalFechaInicial.Month, DateTime.DaysInMonth(CalFechaInicial.Year, CalFechaInicial.Month));

                            if (CalFechaFinal.Date > fechaFinal.Date)
                            {
                                CalFechaFinal = fechaFinal;
                                exit          = true;
                            }

                            categoria            = new OportunidadCategoria();
                            categoria.isBusqueda = false;

                            categoria.Nombre = CalFechaInicial.ToString("MMMM").First().ToString().ToUpper() + String.Join("", CalFechaInicial.ToString("MMMM").Skip(1));
                            if (x == 1)
                            {
                                categoria.FechaInicio = CalFechaInicial;
                            }
                            else
                            {
                                categoria.FechaInicio = CalFechaInicial.AddDays(1);
                            }

                            categoria.FechaFin    = CalFechaFinal;
                            categoria.Oportunidad = data.Where(p => (p.FechaInicio.Date >= CalFechaInicial.Date) &&
                                                               (p.FechaInicio.Date <= CalFechaFinal.Date))
                                                    .OrderBy(p => p.FechaInicio).Distinct().ToList();

                            listaOportunidad.Add(categoria);
                        }
                    }
                }

                break;

            case Rp3.AgendaComercial.Models.Constantes.OportunidadGroupMode.Estado:

                var estados = data.Select(p => p.EstadoDescripcion).Distinct().OrderBy(p => p);

                foreach (var estadolabel in estados)
                {
                    categoria            = new OportunidadCategoria();
                    categoria.isBusqueda = false;
                    categoria.Nombre     = estadolabel;

                    categoria.Oportunidad = data.Where(p => p.EstadoDescripcion == estadolabel).OrderBy(p => p.FechaInicio).ToList();

                    listaOportunidad.Add(categoria);
                }

                break;

            case Rp3.AgendaComercial.Models.Constantes.OportunidadGroupMode.Agente:

                var agentes = data.Select(p => p.Agente).Distinct().OrderBy(p => p);

                foreach (var agente in agentes)
                {
                    categoria            = new OportunidadCategoria();
                    categoria.isBusqueda = false;
                    categoria.Nombre     = agente;

                    categoria.Oportunidad = data.Where(p => p.Agente == agente).OrderBy(p => p.FechaInicio).ToList();

                    listaOportunidad.Add(categoria);
                }

                break;

            case Rp3.AgendaComercial.Models.Constantes.OportunidadGroupMode.Listado:

                categoria            = new OportunidadCategoria();
                categoria.isBusqueda = false;
                categoria.Nombre     = String.Empty;

                categoria.Oportunidad = data.OrderBy(p => p.FechaInicio).ToList();

                listaOportunidad.Add(categoria);

                break;
            }

            //if (fechaInicial < DateTime.Now.Date)
            //{
            //    if (groupMode == Rp3.AgendaComercial.Models.Constantes.OportunidadGroupMode.Calendario)
            //        listaOportunidad = listaOportunidad.OrderByDescending(p => p.FechaInicio).ToList();
            //}

            if (String.IsNullOrEmpty(sortField))
            {
                foreach (var cat in listaOportunidad)
                {
                    cat.Oportunidad = cat.Oportunidad.OrderByDescending(p => p.Calificacion).ThenByDescending(p => p.Importe).ToList();
                }
            }
            else
            {
                Sort(listaOportunidad, sortField, sortMode);
            }

            oportunidadConsulta.OportunidadCategorias = listaOportunidad;

            return(PartialView("_OportunidadListaDetalle", oportunidadConsulta));
        }