Exemple #1
0
        public IQueryable <SaleListVM> SaleList(ShopContext db)
        {
            var infoMoneys = db.InfoMonies.ToList();

            var query = db.Sales
                        .Where(x => x.Payment)
                        .Include(x => x.SalesProducts).ThenInclude(x => x.Product)
                        .Include(x => x.Partner)
                        .OrderByDescending(x => x.Date)
                        .Take(100)
                        .Select(x => new SaleListVM()
            {
                Id           = x.Id,
                Date         = x.Date.ToString("dd.MM.yyyy"),
                Sum          = db.InfoMonies.Where(z => z.SaleId == x.Id).Sum(z => z.Sum),
                ShopTitle    = x.Shop.Title,
                PrimeCost    = x.PrimeCost,
                ProductTitle = x.SalesProducts.FirstOrDefault().Product.Title,
                BuyerTitle   = x.PartnerId != null
                        ? x.Partner.Title
                        : "Обычный покупатель",
                HasAdditionalProduct = x.SalesProducts.Any(x => x.Additional),
                MarginPercent        = Math.Round((x.Margin == 0 || x.Sum == 0) ? 0 : x.Margin / (x.Sum / 100))
            })
                        .ToList()
                        .Select(x => new SaleListVM()
            {
                Id                   = x.Id,
                Date                 = x.Date,
                Sum                  = x.Sum,
                PrimeCost            = x.PrimeCost,
                ShopTitle            = x.ShopTitle,
                HasAdditionalProduct = x.HasAdditionalProduct,
                BuyerTitle           = x.BuyerTitle,
                ProductTitle         = x.ProductTitle,
                PaymentType          = _saleInfoService.PaymentType(x.Id, infoMoneys),
                MarginPercent        = Math.Round(x.MarginPercent)
            }).AsQueryable();

            return(query);
        }
Exemple #2
0
        public IActionResult Detail(int id)
        {
            var userName = HttpContext.User.Identity.Name;
            var user     = _userService.All().First(u => u.Login == userName).Role.ToString();

            ViewBag.Role = user;

            var infoMoneys = _db.InfoMonies.ToList();

            Sale sale = _saleService.All()
                        .Select(x => new Sale()
            {
                Id    = x.Id,
                Title = x.Title,
                Date  = x.Date,
                //Sum = infoMoneys.Where(z => z.SaleId == x.Id).Sum(z => z.Sum),
                Discount   = x.Discount,
                Margin     = x.Margin,
                Partner    = x.Partner,
                PrimeCost  = x.PrimeCost,
                Shop       = x.Shop,
                SaleType   = x.SaleType,
                ForRussian = x.ForRussian
            }).First(p => p.Id == id);

            sale.Sum = infoMoneys.Where(z => z.SaleId == sale.Id)
                       .Sum(z => z.Sum);

            ViewBag.SalesProducts = _saleProductService.All().Select(sp => new SaleProduct
            {
                SaleId     = sp.SaleId,
                Product    = sp.Product,
                Amount     = sp.Amount,
                Additional = sp.Additional,
                Cost       = sp.Cost
            }).Where(sp => sp.SaleId == sale.Id).ToList();

            ViewBag.PaymentType = _saleInfoService.PaymentType(sale.Id, infoMoneys);

            var scores = _infoMoneyService.All().Where(x => x.SaleId == id);

            ViewBag.SaleFinanceDetail = new SaleDetailFinanceVM
            {
                CashScores = scores.Where(x => x.PaymentType == PaymentType.Cash)
                             .Select(x => new SaleDetailFinanceItemVM
                {
                    MoneyWorkerTitle = x.MoneyWorker.Title,
                    Sum = x.Sum.ToString()
                }),
                CashlessScores = scores.Where(x => x.PaymentType == PaymentType.Cashless)
                                 .Select(x => new SaleDetailFinanceItemVM
                {
                    MoneyWorkerTitle = x.MoneyWorker.Title,
                    Sum = x.Sum.ToString()
                })
            };

            var managerId = _postgresContext.SaleManagersOld
                            .FirstOrDefault(x => x.SaleId == id)?.ManagerId;

            if (managerId != null)
            {
                ViewBag.Manager = _postgresContext.Managers
                                  .FirstOrDefault(x => x.Id == managerId)?.Name ??
                                  "Менеджер не указан или не найден";
            }
            else
            {
                ViewBag.Manager = "Менеджер не указан или не найден";
            }

            return(View(sale));
        }