示例#1
0
        public IActionResult GetList()
        {
            var suppliers = SupplierHandlers.Get(_postgresContext, _shopContext)
                            .Select(x => new SupplierVM()
            {
                Id    = x.Id,
                Title = x.Title
            }).ToList();

            var shops = _shopContext.Shops
                        .Select(x => new ShopVM()
            {
                Title = x.Title,
                Id    = x.Id
            }).ToList();

            var moneyWorkers = _shopContext.MoneyWorkers
                               .Select(x => new
            {
                Id    = x.Id,
                Title = x.Title
            }).ToList();

            var payments = _postgresContext.ScheduledDeliveryPayments
                           .ToList();

            var scheduledSupplies = _postgresContext.ScheduledDeliveries
                                    .Include(x => x.Products)
                                    .ToList()
                                    .Select(x => new ScheduledDeliveryVM()
            {
                Id               = x.Id,
                Date             = x.CreatedDate.ToString("dd.MM.yyyy"),
                Payment          = x.DepositedSum,
                ProductsExpected = x.Products
                                   .Where(z => z.SupplyProductId == 0 || z.SupplyProductId == null)
                                   .Select(z => z.Amount)
                                   .Sum(),
                ShopsTitles = x.Products
                              .Where(z => z.ShopId > 0)
                              .Select(z => shops.FirstOrDefault(s => s.Id == z.ShopId)?.Title ?? "")
                              .Distinct()
                              .Aggregate(new StringBuilder(), (cur, next) => cur.Append(cur.Length == 0 ? "" : ", ").Append(next))
                              .ToString(),
                SupplierId         = x.SupplierId,
                Supplier           = suppliers.FirstOrDefault(z => z.Id == x.SupplierId)?.Title ?? "",
                ProcurementCost    = x.Products.Sum(z => z.ProcurementCost * z.Amount),
                MoneyWorkersTitles = payments.Where(z => z.ScheduledDeliveryId == x.Id)
                                     .Select(z => z.MoneyWorkerId)
                                     .Distinct()
                                     .Select(z => moneyWorkers.FirstOrDefault(m => m.Id == z)?.Title ?? "")
                                     .Aggregate(new StringBuilder(), (cur, next) => cur.Append(cur.Length == 0 ? "" : ", ").Append(next))
                                     .ToString()
            })
                                    .Where(x => x.ProductsExpected > 0)
                                    .OrderByDescending(x => x.Id)
                                    .ToList();

            return(Ok(new { scheduledSupplies, suppliers }));
        }
示例#2
0
        public IActionResult CreateByManager()
        {
            var products = _shopContext.Products
                           .Select(x => new ProductVM()
            {
                Id    = x.Id,
                Title = x.Title
            }).ToList();

            var suppliers = SupplierHandlers.Get(_postgresContext, _shopContext)
                            .Select(x => new SupplierVM()
            {
                Id    = x.Id,
                Title = x.Title
            }).ToList();

            var categories = _shopContext.Categories
                             .Select(x => new CategoryVM()
            {
                Id    = x.Id,
                Title = x.Title
            }).ToList();

            ViewBag.Products   = products;
            ViewBag.Suppliers  = suppliers;
            ViewBag.Categories = categories;

            return(View());
        }
示例#3
0
        public IActionResult GetAll()
        {
            var result = SupplierHandlers.Get(_postgresContext, _shopContext)
                         .Select(x => new SupplierVM()
            {
                Id    = x.Id,
                Title = x.Title
            }).ToList();

            return(Ok(result));
        }
示例#4
0
        public IActionResult GetProductsList()
        {
            var productsTitles = _shopContext.Products
                                 .Select(x => new ProductVM()
            {
                Id    = x.Id,
                Title = x.Title
            }).ToList();

            var shops = _shopContext.Shops
                        .Select(x => new ShopVM()
            {
                Id    = x.Id,
                Title = x.Title
            }).ToList();

            var suppliers = SupplierHandlers.Get(_postgresContext, _shopContext)
                            .Select(x => new SupplierVM()
            {
                Id    = x.Id,
                Title = x.Title
            }).ToList();

            var scheduledProductsDeliveries = _postgresContext.ScheduledProductDeliveries
                                              .Where(x => x.DeliveryType != ScheduledProductDeliveryType.Delivered)
                                              .ToList()
                                              .Select(x => new ScheduledProductDeliveryVM()
            {
                Id              = x.Id,
                Title           = productsTitles.FirstOrDefault(z => z.Id == x.ProductId).Title,
                Amount          = x.Amount,
                ProcurementCost = x.ProcurementCost,
                Shop            = x.ShopId == 0
                        ? "Магазин не выбран"
                        : shops.FirstOrDefault(z => z.Id == x.ShopId).Title,
                Supplier   = suppliers.FirstOrDefault(z => z.Id == x.SupplierId).Title,
                ShopId     = x.ShopId,
                SupplierId = x.SupplierId
            }).ToList();

            return(Ok(scheduledProductsDeliveries));
        }
示例#5
0
        public IActionResult GetFilters()
        {
            var shops = _shopContext.Shops
                        .Select(x => new ShopVM()
            {
                Id    = x.Id,
                Title = x.Title
            }).ToList();

            var suppliers = SupplierHandlers.Get(_postgresContext, _shopContext)
                            .Select(x => new SupplierVM()
            {
                Id    = x.Id,
                Title = x.Title
            }).ToList();

            return(Ok(new
            {
                suppliers = suppliers,
                shops = shops
            }));
        }
示例#6
0
        public IActionResult Index()
        {
            var suppliersInfoInit = _postgresContext.SupplierInfoInits.ToList();

            var operations = _postgresContext.ProductOperations
                             // .Where(x => a.Contains(x.ProductId))
                             .ToList()
                             .GroupBy(x => x.SupplierId)
                             .Select(x => new
            {
                SupplierId = x.Key,
                Debt       = x.Where(z => z.ForRealization && z.Amount < 0)
                             .Sum(z => z.Cost * z.Amount * -1),
                OnStockForRealization = x.Where(z => z.ForRealization &&
                                                z.StorageType == StorageType.Shop)
                                        .Sum(z => z.Amount * z.Cost),
                OnStock = x.Where(z => z.StorageType == StorageType.Shop)
                          .Sum(z => z.Amount * z.Cost)
            }).ToList();

            var repayments = _postgresContext.SupplierPayments.ToList()
                             .GroupBy(x => x.SupplierId)
                             .Select(x => new
            {
                SupplierId    = x.Key,
                RepaymentsSum = x.Sum(z => z.Sum)
            }).ToList();

            var result = SupplierHandlers.Get(_postgresContext, _shopContext);

            foreach (var supplierVm in result)
            {
                var supplierInfoInit = suppliersInfoInit
                                       .FirstOrDefault(x => x.SupplierId == supplierVm.Id);
                if (supplierInfoInit != null)
                {
                    supplierVm.Debt += supplierInfoInit.Debt;
                    supplierVm.CostProductOnStock            += supplierInfoInit.PriceProducts;
                    supplierVm.CostRealizationProductOnStock += supplierInfoInit.PriceProductsForRealization;
                }

                var operation = operations
                                .FirstOrDefault(x => x.SupplierId == supplierVm.Id);
                if (operation != null)
                {
                    supplierVm.Debt += operation.Debt;
                    supplierVm.CostProductOnStock            += operation.OnStock;
                    supplierVm.CostRealizationProductOnStock += operation.OnStockForRealization;
                }

                var repayment = repayments
                                .FirstOrDefault(x => x.SupplierId == supplierVm.Id);
                if (repayment != null)
                {
                    supplierVm.Debt -= repayment.RepaymentsSum;
                }
            }

            ViewBag.Debt               = Math.Round(result.Sum(x => x.Debt), 2);
            ViewBag.RealizationCost    = Math.Round(result.Sum(x => x.CostRealizationProductOnStock), 2);
            ViewBag.CostProductOnStock = Math.Round(result.Sum(x => x.CostProductOnStock), 2);

            return(View(result));
        }