public IActionResult Index() { return(View(_userService.All().Select(x => new UserVM() { Id = x.Id, Title = x.Login, Role = x.Role, Password = x.Password, Shop = x.Shop }))); }
public IActionResult ProductDetail(int id) { ProductVM product = _productService.All().Select(x => new ProductVM() { Id = x.Id, Category = x.Category, Code = x.Code, Cost = x.Cost, Title = x.Title, Shop = x.Shop }).ToList() .Select(x => new ProductVM() { Id = x.Id, Amount = _supplyProduct.All().Where(sp => sp.ProductId == x.Id) .Sum(sp => sp.StockAmount), Category = x.Category, Code = x.Code, Cost = x.Cost, Title = x.Title, Shop = x.Shop }).First(p => p.Id == id); //TODO: Сделать Join один поставщик - один SupplyProduct на отображение //Для таба с поставщиками ViewBag.SupplierProducts = _supplyProduct.All() .Where(x => x.ProductId == id && x.SupplierId != null) .Select(x => new SupplyProduct { Id = x.Id, Supplier = x.Supplier, Product = x.Product, TotalAmount = x.TotalAmount, RealizationAmount = x.RealizationAmount }); //Для таба со стоимостью товара ViewBag.SupplyProduct = _supplyProduct.All() .Where(x => x.ProductId == id) .Select(x => new SupplyProduct { Id = x.Id, Product = x.Product, TotalAmount = x.TotalAmount, StockAmount = x.StockAmount, AdditionalCost = x.AdditionalCost, ProcurementCost = x.ProcurementCost, FinalCost = x.FinalCost }); return(View(product)); }
public IActionResult Index() { var userName = HttpContext.User.Identity.Name; ViewBag.UserId = _userService.All().First(u => u.Login == userName).Id; ViewBag.Categories = _categoryService.All(); ViewBag.Shops = _shopService.All(); var result = ProductService.GetProductsInStock(_db, _postgresContext); return(View(result)); }
public IActionResult Index() { var archiveCalculatedScores = _postgresContext.ArchiveCalculatedScores .Select(x => x.CalculatedScoreId).ToList(); return(View(_calculatedScoreService.All() .Where(x => !archiveCalculatedScores.Contains(x.Id)) .Select(cs => new CalculatedScoreVM() { Id = cs.Id, Title = cs.Title, Balance = _infoMoneyService.GetMoneyWorkerBalance(_db, cs.Id) }) )); }
public IQueryable <SaleByCategoryVM> GetSalesByCategoriesStats() { var moscowShopId = 1; var petersburgShopId = 2; var saleCategories = _categoryService.All() .Select(x => new SaleByCategoryVM { Category = x, SalesByMoscow = _saleAmountService.GetClearSalesAmountShop(moscowShopId, x.Id), SalesByPetersburg = _saleAmountService.GetClearSalesAmountShop(petersburgShopId, x.Id), PartnerSales = _saleAmountService.GetSalesAmountPartners(x.Id), ForRussianFederation = _saleAmountService.GetSalesAmountRussian(x.Id), TurnOverMoscow = _turnOverService.GetClearTurnOverShop(moscowShopId, x.Id), TurnOverPetersburg = _turnOverService.GetClearTurnOverShop(petersburgShopId, x.Id), TurnOverPartner = _turnOverService.GetTurnOverPartners(x.Id), TurnOverRF = _turnOverService.GetTurnOverRussian(x.Id), TurnOver = _turnOverService.GetClearTurnOverShop(moscowShopId, x.Id) + _turnOverService.GetClearTurnOverShop(petersburgShopId, x.Id) + _turnOverService.GetTurnOverPartners(x.Id) + _turnOverService.GetTurnOverRussian(x.Id), MarginMoscow = _marginService.GetClearMarginShop(moscowShopId, x.Id), MarginPetersburg = _marginService.GetClearMarginShop(petersburgShopId, x.Id), MarginPartner = _marginService.GetMarginPartners(x.Id), MarginRF = _marginService.GetMarginRussian(x.Id), Margin = _marginService.GetClearMarginShop(moscowShopId, x.Id) + _marginService.GetClearMarginShop(petersburgShopId, x.Id) + _marginService.GetMarginPartners(x.Id) + _marginService.GetMarginRussian(x.Id) }); return(saleCategories); }
public void WriteOff(int productId, int supplyId, int amount) { var product = _productService.Get(productId); var supply = _supplyProductService.All().FirstOrDefault(x => x.Id == supplyId); var forRealization = supply.RealizationAmount > 0; supply = SupplyProductWriteOff(supply, amount); CreateHistory(new InfoProduct { Amount = amount, ProductId = product.Id, Date = DateTime.Now.AddHours(3), ShopId = product.ShopId, Type = InfoProductType.Writeoff, SupplyProductId = supply.Id }); _supplyProductService.Update(supply); _postgresContext.ProductOperations.Add(new ProductOperation( supply.ProductId, -amount, DateTime.Now.AddHours(3), supply.ProcurementCost, forRealization, supply.SupplierId ?? 0, StorageType.Shop)); _postgresContext.SaveChanges(); }
public IActionResult Index() { var userName = HttpContext.User.Identity.Name; ViewBag.UserId = _userService.All().First(u => u.Login == userName).Id; if (_userService.All().First(u => u.Login == userName).Role != Role.Administrator) { return(RedirectToAction("Login", "Account")); } ViewBag.Partners = _partnerService.All(); ViewBag.Shops = _shopService.All(); return(View(_saleStatisticService.SaleList(_db).ToList())); }
public IActionResult Index() { ViewBag.Sum = _supplyProductService.All() .Sum(x => x.FinalCost * x.StockAmount); return(View()); }
public IActionResult Detail(int id) { var userName = HttpContext.User.Identity.Name; ViewBag.UserRole = _userService.All().First(u => u.Login == userName).Role; ViewBag.SupplierProducts = _supplyProductService.All() .Where(x => x.ProductId == id && x.SupplierId != null) .Select(x => new SupplyProduct { Id = x.Id, Supplier = x.Supplier, Product = x.Product, TotalAmount = x.TotalAmount, RealizationAmount = x.RealizationAmount }); //Для таба со стоимостью товара ViewBag.SupplyProduct = _supplyProductService.All() .Where(x => x.ProductId == id) .Select(x => new SupplyProduct { Id = x.Id, Product = x.Product, TotalAmount = x.TotalAmount, StockAmount = x.StockAmount, AdditionalCost = x.AdditionalCost, ProcurementCost = x.ProcurementCost, FinalCost = x.FinalCost }); var shops = _db.Shops.ToList(); ViewBag.Shops = shops; ViewBag.IncompleteProducts = _postgresContext.IncompleteProducts .Where(x => x.ProductId == id) .ToList() .Select(x => new IncompleteProductDto() { Amount = x.Amount, Comment = x.Comment, Shop = shops.FirstOrDefault(s => s.Id == x.ShopId)?.Title ?? "" }); return(View(ProductService.GetProductDetail(_db, id))); }
public string BuyerTitle(int id) { var sale = _saleService.Get(id); var res = _parnterService.All().FirstOrDefault(x => x.Id == sale.PartnerId)?.Title ?? "Обычный покупатель"; return(res); }
private int GetSalesAmount(IQueryable <int> salesIds, int categoryId) { var salesProducts = _saleProductService.All() .Where(x => salesIds.Contains(x.SaleId) && x.Product.CategoryId == categoryId); var result = salesProducts.Sum(x => x.Amount); return(result); }
private decimal GetPrimeCost(IQueryable <int> salesIds, int categoryId) { var productsInformations = _productInformationService.All() .Where(x => salesIds.Contains(x.SaleId) && x.Product.CategoryId == categoryId); var result = productsInformations.Sum(x => x.FinalCost); return(result); }
public IActionResult CheckPrint(int?saleId, int?bookingId, decimal operationSum) { if (saleId != null) { var sale = _saleService.All().FirstOrDefault(x => x.Id == saleId); ViewBag.SaleProducts = _saleProductService.All() .Where(x => x.SaleId == sale.Id) .Include(x => x.Product); ViewBag.Sale = true; ViewBag.OperationSum = operationSum; if (sale.SaleType != SaleType.SaleFromStock) { ViewBag.TotalOperationSum = _infoMoneyService.All() .Where(x => x.SaleId == sale.Id) .Sum(x => x.Sum); } else { ViewBag.TotalOperationSum = operationSum; } return(View(sale)); } else { var booking = _bookingService.All().FirstOrDefault(x => x.Id == bookingId); ViewBag.SaleProducts = _bookingProductService.All() .Where(x => x.BookingId == bookingId) .Include(x => x.Product); ViewBag.OperationSum = operationSum; ViewBag.TotalOperationSum = _infoMoneyService.All() .Where(x => x.BookingId == booking.Id) .Sum(x => x.Sum); ViewBag.Sale = false; return(View(booking)); } }
public IActionResult Expense() { var userName = HttpContext.User.Identity.Name; User user = _userService.All().First(u => u.Login == userName); ViewBag.ShopId = _shopService.All().FirstOrDefault(s => s.Id == user.ShopId); ViewBag.CategoryExpense = _expenseCategoryService.All(); ViewBag.Shops = _db.Shops.ToList(); return(View()); }
public IActionResult Realization() { ViewBag.Partners = _partnerService.All(); var userName = HttpContext.User.Identity.Name; ViewBag.userId = _userService.All().First(u => u.Login == userName).Id; return(View()); }
private decimal GetTurnOver(IQueryable <int> saleIds, int categoryId) { var saleProducts = _saleProductService.All() .Where(x => saleIds.Contains(x.SaleId) && x.Product.CategoryId == categoryId) .Select(x => new SaleProduct { Id = x.Id, Amount = x.Amount, Additional = x.Additional, ProductId = x.ProductId, SaleId = x.SaleId, Cost = x.Cost * x.Amount - (x.Sale.Discount / x.Sale.SalesProducts.Sum(z => z.Amount)) }).ToList(); var result = saleProducts.Sum(x => x.Cost * x.Amount); return(Math.Round(result, 2)); }
public IActionResult CloseOpenSale(int id) { var sale = _saleService.All().FirstOrDefault(x => x.Id == id); sale.Payment = true; var saleInformation = _saleInformationService.All().FirstOrDefault(x => x.SaleId == sale.Id); var infoMoneys = _infoMoneyService.All().Where(x => x.SaleId == sale.Id); if (infoMoneys.Count() == 0) { if (sale.CashSum > 0) { _infoMoneyService.Create(new InfoMoney() { MoneyWorkerId = sale.ShopId, Sum = sale.CashSum, SaleId = sale.Id, PaymentType = PaymentType.Cash, MoneyOperationType = MoneyOperationType.Sale }); } if (sale.CashlessSum > 0) { _infoMoneyService.Create(new InfoMoney() { MoneyWorkerId = saleInformation.MoneyWorkerForIncomeId, Sum = sale.CashlessSum, SaleId = sale.Id, PaymentType = PaymentType.Cashless, MoneyOperationType = MoneyOperationType.Sale }); } } _db.SaleInformations.Remove(saleInformation); _db.SaveChanges(); return(RedirectToAction("Index")); }
public IActionResult SupplierInfoByDate(string date) { var filterDate = DateTime.Now.AddHours(3); if (date != null) { var buf = date.Split('.'); filterDate = new DateTime( Convert.ToInt32(buf[2]), Convert.ToInt32(buf[1]), Convert.ToInt32(buf[0])); } var suppliersInfoInit = _postgresContext.SupplierInfoInits.ToList(); var operations = _postgresContext.ProductOperations .Where(x => x.DateTime.Date <= filterDate.Date) .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) .Sum(z => z.Amount * z.Cost), OnStock = x.Sum(z => z.Amount * z.Cost) }).ToList(); var repayments = _postgresContext.SupplierPayments .Where(x => x.DateTime.Date <= filterDate.Date) .ToList() .GroupBy(x => x.SupplierId) .Select(x => new { SupplierId = x.Key, RepaymentsSum = x.Sum(z => z.Sum) }).ToList(); var supplierInfos = _postgresContext.SuppliersInfos .ToList(); var removedSuppliers = supplierInfos .Where(x => x.Removed) .Select(x => x.SupplierId) .ToList(); var result = _supplierService.All() .ToList() .Where(x => !removedSuppliers.Contains(x.Id)) .Join(supplierInfos, s => s.Id, i => i.SupplierId, (s, i) => new { Id = s.Id, Title = s.Title, Phone = s.Phone, Email = s.Email, Order = i.Order }) .OrderBy(x => x.Order) .Select(x => new SupplierVM() { Id = x.Id, Title = x.Title, Phone = x.Phone, Email = x.Email, Debt = 0, CostRealizationProductOnStock = 0, CostProductOnStock = 0, Order = x.Order }).ToList(); 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(PartialView(result)); }
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)); }
public IActionResult Delete(int id) { Sale sale = _db.Sales .Include(x => x.Partner) .Include(x => x.Shop) .FirstOrDefault(x => x.Id == id); var productInformations = _db.ProductInformations .Where(x => x.SaleId == sale.Id) .ToList(); var deletedSale = new DeletedSale() { Buyer = sale.Partner?.Title ?? "Обычный покупатель", Date = sale.Date, DeletedDate = DateTime.Now.AddHours(3), Discount = sale.Discount, Margin = sale.Margin, Number = sale.Id, ShopId = sale.ShopId, ShopTitle = sale.Shop.Title, Sum = sale.Sum, ProcurementCost = sale.PrimeCost, SaleType = sale.SaleType == SaleType.Sale ? "Обычная продажа" : sale.SaleType == SaleType.SaleFromStock ? "Продажа со склада" : sale.SaleType == SaleType.DefferedSale ? "Продажа с отложенным платежом" : sale.SaleType == SaleType.DefferedSaleFromStock ? "Отложенная продажа со склада поставщика" : sale.SaleType == SaleType.Booking ? "Бронирование" : "" }; foreach (var productInfo in productInformations) { var supplyProduct = _db.SupplyProducts .Include(x => x.Product) .Include(x => x.Supplier) .FirstOrDefault(x => x.Id == productInfo.SupplyProductId); var saleProduct = _db.SalesProducts .Include(x => x.Product) .AsNoTracking() .FirstOrDefault(x => x.SaleId == sale.Id && x.ProductId == productInfo.ProductId); deletedSale.Products.Add(new DeletedSaleProduct() { Title = saleProduct.Product.Title, Code = saleProduct.Product.Code, ProductId = saleProduct.ProductId, Amount = productInfo.Amount, Price = saleProduct.Cost, ProcurementCost = productInfo.ProcurementCost, SupplierId = supplyProduct?.SupplierId ?? 0, SupplierName = supplyProduct?.Supplier?.Title ?? "" }); if (productInfo.ForRealization == true && supplyProduct != null) { supplyProduct.StockAmount += productInfo.Amount; supplyProduct.RealizationAmount += productInfo.Amount; var supplier = _supplierService.All().FirstOrDefault(x => x.Id == supplyProduct.SupplierId); if (supplier == null) { throw new Exception("Поставщик не найден"); } supplier.Debt -= supplyProduct.ProcurementCost * productInfo.Amount; _supplierService.Update(supplier); } else if (productInfo.ForRealization == true && supplyProduct == null) { var supplierId = _postgresContext.SalesFromStockOld .FirstOrDefault(x => x.SaleId == sale.Id)?.SupplierId ?? 0; var supplier = _supplierService.All() .FirstOrDefault(x => x.Id == supplierId); if (supplier == null) { throw new Exception("Поставщик не найден"); } var product = deletedSale.Products .FirstOrDefault(x => x.ProductId == productInfo.ProductId); if (product != null) { product.SupplierId = supplier.Id; product.SupplierName = supplier.Title; } supplier.Debt -= productInfo.ProcurementCost * productInfo.Amount; _supplierService.Update(supplier); } else if (supplyProduct != null) { supplyProduct.StockAmount += productInfo.Amount; } if (supplyProduct != null) { _supplyProductService.Update(supplyProduct); } } var infoMoneys = _db.InfoMonies .Include(x => x.MoneyWorker) .Where(x => x.SaleId == sale.Id).ToList(); foreach (var infoMoney in infoMoneys) { deletedSale.Payments.Add(new DeletedPayment() { Sum = infoMoney.Sum, Account = infoMoney.MoneyWorker.Title, Comment = infoMoney.Comment, PaymentType = infoMoney.PaymentType == PaymentType.Cash ? "Наличный" : infoMoney.PaymentType == PaymentType.Cashless ? "Безналичный" : "Смешанный", Date = infoMoney.Date }); _db.InfoMonies.Remove(infoMoney); } var salesProducts = _saleProductService.All().Where(x => x.SaleId == sale.Id).ToList(); foreach (var saleProduct in salesProducts) { _db.SalesProducts.Remove(saleProduct); } _db.Sales.Remove(sale); _db.SaveChanges(); _postgresContext.DeletedSalesInfoOld.Add(new DeletedSaleInfoOld() { Sale = deletedSale }); _postgresContext.SaveChanges(); return(RedirectToAction("Index")); }
public IQueryable <BookingProduct> GetBookedProductsInShop(int shopId) { return(_bookingProductService.All() .Where(x => x.Booking.ShopId == shopId && x.Booking.Status == BookingStatus.Open)); }
public IActionResult Index() { return(View(_expenseCategoryService.All())); }
public bool HasAdditionalProduct(int id) { return(_saleProductService.All().Any(x => x.SaleId == id && x.Additional)); }