Exemplo n.º 1
0
        public async Task <List <ReporteMercadoDTO> > FiltroAdmin(int ano, int mes)
        {
            DateTime actual = DateTime.Now;

            if (mes == 0)
            {
                mes = actual.Month;
            }
            if (ano == 0)
            {
                ano = actual.Year;
            }
            var repor = await AdminxProductoxTiempo();

            var listareporte = repor.Value;


            List <ReporteMercadoDTO> reporte = new List <ReporteMercadoDTO>();

            var queryablemer = context.Mercados.AsQueryable();
            var mercadoDB    = await queryablemer.ToListAsync();

            foreach (var mer in mercadoDB)
            {
                //rompe por cada mercado
                List <ReporteMercadoDTO> reportemercado = new List <ReporteMercadoDTO>();
                List <string>            producto       = new List <string>();
                foreach (var rep in listareporte)
                {
                    if (rep.nombre.Equals(mer.Nombre))
                    {
                        if (rep.fechaAno == ano)
                        {
                            if (rep.fechaMes == mes)
                            {
                                if (reportemercado.Count != 0)
                                {
                                    if (producto.Contains(rep.producto))
                                    {
                                        int id = producto.IndexOf(rep.producto);
                                        reportemercado.ElementAt(id).ventatotal    = reportemercado.ElementAt(id).ventatotal + rep.cantidad;
                                        reportemercado.ElementAt(id).gananciatotal = reportemercado.ElementAt(id).gananciatotal + rep.precio;
                                    }
                                    else
                                    {
                                        ReporteMercadoDTO parcial = new ReporteMercadoDTO();
                                        parcial.nombre        = rep.nombre;
                                        parcial.producto      = rep.producto;
                                        parcial.ventatotal    = rep.cantidad;
                                        parcial.gananciatotal = rep.precio;
                                        producto.Add(rep.producto);
                                        reportemercado.Add(parcial);
                                    }
                                }
                                else
                                {
                                    ReporteMercadoDTO parcial = new ReporteMercadoDTO();
                                    parcial.nombre        = rep.nombre;
                                    parcial.producto      = rep.producto;
                                    parcial.ventatotal    = rep.cantidad;
                                    parcial.gananciatotal = rep.precio;
                                    producto.Add(rep.producto);
                                    reportemercado.Add(parcial);
                                }
                            }
                        }
                    }
                }

                string nommer    = "";
                double gantotmer = 0;
                foreach (var y in reportemercado)
                {
                    nommer    = y.nombre;
                    gantotmer = gantotmer + y.gananciatotal;
                }
                if (nommer != "" && gantotmer != 0)
                {
                    ReporteMercadoDTO parcial = new ReporteMercadoDTO();
                    parcial.nombre        = nommer;
                    parcial.gananciatotal = gantotmer;
                    reporte.Add(parcial);
                }
            }
            var bakaa = "bakka";

            return(reporte);
        }
Exemplo n.º 2
0
        public async Task <List <ReporteMercadoDTO> > FiltroAdmins(int ano, int mes)
        {
            DateTime actual = DateTime.Now;

            if (mes == 0)
            {
                mes = actual.Month;
            }
            if (ano == 0)
            {
                ano = actual.Year;
            }
            var repor = await AdminxProductoxTiempo();

            var listareporte = repor.Value;


            List <ReporteMercadoDTO> reporte  = new List <ReporteMercadoDTO>();
            List <string>            producto = new List <string>();

            foreach (var rep in listareporte)
            {
                if (rep.fechaAno == ano)
                {
                    if (rep.fechaMes == mes)
                    {
                        if (reporte.Count != 0)
                        {
                            if (producto.Contains(rep.producto))
                            {
                                int id = producto.IndexOf(rep.producto);
                                reporte.ElementAt(id).ventatotal    = reporte.ElementAt(id).ventatotal + rep.cantidad;
                                reporte.ElementAt(id).gananciatotal = reporte.ElementAt(id).gananciatotal + rep.precio;
                            }
                            else
                            {
                                ReporteMercadoDTO parcial = new ReporteMercadoDTO();
                                parcial.nombre        = rep.nombre;
                                parcial.producto      = rep.producto;
                                parcial.ventatotal    = rep.cantidad;
                                parcial.gananciatotal = rep.precio;
                                producto.Add(rep.producto);
                                reporte.Add(parcial);
                            }
                        }
                        else
                        {
                            ReporteMercadoDTO parcial = new ReporteMercadoDTO();
                            parcial.nombre        = rep.nombre;
                            parcial.producto      = rep.producto;
                            parcial.ventatotal    = rep.cantidad;
                            parcial.gananciatotal = rep.precio;
                            producto.Add(rep.producto);
                            reporte.Add(parcial);
                        }
                    }
                }
            }

            var bakaa = "bakka";

            return(reporte);
        }
Exemplo n.º 3
0
        public async Task <ActionResult <List <ReporteMercadoDTO> > > AdminxProductoxTiempo()
        {
            var usuarioid = HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier);

            //join
            //Lista para mercado
            var consulta = await context.Ordenes.Where(x => x.Estado == 4)
                           .Join(
                context.Detalles,
                ord => ord.Id,
                det => det.OrdenID,
                (ord, det) => new
            {
                orderid = ord.Id,
                merid   = det.MercadoId,
                proid   = det.ProductoId,
                amount  = det.Cantidad,
                price   = det.Precio,
                date    = ord.FechaCreacion
            }
                )//obetenemos todos los pedidos hechos x cada dia
                           .Join(
                context.Mercados,
                ord => ord.merid,
                mer => mer.Id,
                (ord, mer) => new
            {
                ord.orderid,
                ord.proid,
                ord.amount,
                ord.price,
                ord.date,
                mername = mer.Nombre,
            }
                )//otenemos todos los detalles con su precio y producto
                           .Join(
                context.Productos,
                ord => ord.proid,
                product => product.Id,
                (ord, product) => new
            {
                ord.orderid,
                ord.mername,
                ord.amount,
                ord.price,
                ord.date,
                productname = product.Titulo,
            }
                )//obtenemos el nombre del producto
                           .ToListAsync();

            List <ReporteMercadoDTO> listareporte = new List <ReporteMercadoDTO>();

            //transformacion al DTO
            foreach (var report in consulta)
            {
                ReporteMercadoDTO merchreport = new ReporteMercadoDTO();
                merchreport.nombre   = report.mername;
                merchreport.producto = report.productname;
                merchreport.cantidad = report.amount;
                merchreport.precio   = report.price;
                merchreport.fecha    = (DateTime)report.date;
                merchreport.fechaDia = report.date.Value.Day;
                merchreport.fechaMes = report.date.Value.Month;
                merchreport.fechaAno = report.date.Value.Year;

                listareporte.Add(merchreport);
            }
            var bakaa = "bakka";

            return(listareporte);
        }