public void Expense(PostgresContext postgresContext, int moneyWorkerId, decimal sum, PaymentType paymentType, int categoryId, string comment, int forId) { var createdInfoMoney = _infoMoneyService.Create(new InfoMoney() { MoneyWorkerId = moneyWorkerId, Sum = -sum, MoneyOperationType = MoneyOperationType.Expense, PaymentType = paymentType, Comment = comment }); var expense = _expenseService.Create(new Expense() { InfoMoneyId = createdInfoMoney.Id, ExpenseCategoryId = categoryId, }); postgresContext.ExpensesOld.Add(new ExpenseOld(expense.Id, forId)); postgresContext.SaveChanges(); }
public IActionResult BookingClose(int id, decimal cashSum, decimal cashlessSum, int moneyWorkerId, bool cashless) { var userName = HttpContext.User.Identity.Name; User user = _userService.All().First(u => u.Login == userName); if (user == null) { throw new Exception("Пользователь не найден"); } Booking booking = _bookingService.All().First(b => b.Id == id); booking.Debt -= (cashSum + cashlessSum); booking.Pay += (cashSum + cashlessSum); if (booking.Debt <= 0) { booking.Status = BookingStatus.Close; } _bookingService.Update(booking); if (cashSum > 0) { _infoMoneyService.Create(new InfoMoney() { PaymentType = PaymentType.Cash, MoneyWorkerId = user.ShopId, MoneyOperationType = MoneyOperationType.Booking, Sum = cashSum, BookingId = booking.Id }); } if (cashlessSum > 0) { _infoMoneyService.Create(new InfoMoney() { PaymentType = PaymentType.Cashless, MoneyWorkerId = moneyWorkerId, MoneyOperationType = MoneyOperationType.Booking, Sum = cashlessSum, BookingId = booking.Id }); } if (booking.Status != BookingStatus.Close) { return(RedirectToAction("CheckPrint", new { bookingId = booking.Id, operationSum = cashSum + cashlessSum })); } int createdSaleId = 0; if (booking.Status == BookingStatus.Close) { var b_products = _bookingProductService.All() .Where(bp => bp.BookingId == booking.Id) .ToList(); decimal primeCost = 0; var sale = new Sale() { Date = DateTime.Now.AddHours(3), ShopId = user.ShopId.Value, PartnerId = booking.PartnerId, Sum = booking.Sum, CashSum = _infoMoneyService.All() .Where(x => x.BookingId == booking.Id && x.PaymentType == PaymentType.Cash) .Sum(x => x.Sum), CashlessSum = _infoMoneyService.All() .Where(x => x.BookingId == booking.Id && x.PaymentType == PaymentType.Cashless) .Sum(x => x.Sum), Payment = true, SaleType = SaleType.Booking, Discount = booking.Discount, ForRussian = booking.forRussian }; var createdSale = _saleService.Create(sale); _infoMoneyService.All() .Where(x => x.BookingId == booking.Id) .ToList() .ForEach(x => { x.SaleId = sale.Id; _infoMoneyService.Update(x); }); _saleInformationService.Create(new SaleInformation { SaleId = createdSale.Id, SaleType = SaleType.Booking }); foreach (var p in b_products) { _saleProductService.Create(new SaleProduct() { Amount = p.Amount, ProductId = p.ProductId, SaleId = sale.Id, Additional = p.Additional, Cost = p.Cost }); primeCost += _productOperationService.RealizationProduct(_db, p.ProductId, p.Amount, createdSale.Id); } sale.PrimeCost = primeCost; sale.Margin = sale.Sum - sale.PrimeCost; createdSaleId = createdSale.Id; _saleService.Update(createdSale); } if (createdSaleId != 0) { var managerId = _postgresContext.BookingManagersOld .FirstOrDefault(x => x.BookingId == id).ManagerId; _postgresContext.SaleManagersOld.Add( new SaleManagerOld(managerId, createdSaleId, booking.Date)); _postgresContext.SaveChanges(); } return(RedirectToAction("CheckPrint", new { saleId = createdSaleId, operationSum = cashSum + cashlessSum })); }
public IActionResult Create(CalculatedScore calculatedScore) { _calculatedScoreService.Create(calculatedScore); return(RedirectToAction("Index")); }
public IActionResult Create(Partner obj) { _partnerService.Create(obj); return(RedirectToAction("Index")); }
public IActionResult Create(ExpenseCategory obj) { _expenseCategoryService.Create(obj); return(RedirectToAction("Index")); }
public void Supply(SupplyProductVM obj) { var product = _productService.All().FirstOrDefault(x => x.Title == obj.Name && x.ShopId == obj.ShopId); if (product == null) { var productForCopy = _productService.All().FirstOrDefault(x => x.Id == obj.ProductId); product = _productService.Create(new Product() { Title = productForCopy.Title, Code = productForCopy.Code, Reserv = productForCopy.Reserv, BookingAmount = 0, Cost = productForCopy.Cost, CategoryId = productForCopy.CategoryId, ShopId = obj.ShopId, }); } var supplyHistory = _supplyHistoryService.Create(new SupplyHistory()); InfoProduct info; if (obj.SupplierId != 0) { info = new InfoProduct() { Amount = obj.Amount, Date = DateTime.Now.AddHours(3), ProductId = product.Id, ShopId = product.ShopId, SupplierId = obj.SupplierId, Type = InfoProductType.Supply, SupplyHistoryId = supplyHistory.Id }; var supplyProduct = new SupplyProduct() { ProductId = product.Id, SupplierId = obj.SupplierId, TotalAmount = obj.Amount, RealizationAmount = obj.Realization == SupplyType.ForRealization ? obj.Amount : 0, AdditionalCost = obj.AdditionalCost / obj.Amount, ProcurementCost = obj.ProcurementCost / obj.Amount, FinalCost = (obj.ProcurementCost / obj.Amount) + (obj.AdditionalCost / obj.Amount), StockAmount = obj.Amount, SupplyHistoryId = supplyHistory.Id }; _postgresContext.ProductOperations.Add(new ProductOperation( product.Id, obj.Amount, DateTime.Now.AddHours(3), obj.ProcurementCost / obj.Amount, obj.Realization == SupplyType.ForRealization, obj.SupplierId, StorageType.Shop)); _postgresContext.SaveChanges(); _supplyProductService.Create(supplyProduct); if (obj.Realization == SupplyType.DeferredPayment) { _deferredSupplyProductService.Create(new DeferredSupplyProduct() { Date = obj.Date, SupplyProductId = supplyProduct.Id }); } } else { var supply = _supplyProductService.Create(new SupplyProduct() { ProductId = product.Id, TotalAmount = obj.Amount, RealizationAmount = obj.Realization == SupplyType.ForRealization ? obj.Amount : 0, AdditionalCost = obj.AdditionalCost / obj.Amount, ProcurementCost = obj.ProcurementCost / obj.Amount, FinalCost = (obj.ProcurementCost / obj.Amount) + (obj.AdditionalCost / obj.Amount), StockAmount = obj.Amount, SupplyHistoryId = supplyHistory.Id }); info = new InfoProduct() { Amount = obj.Amount, Date = DateTime.Now.AddHours(3), ProductId = product.Id, ShopId = product.ShopId, Type = InfoProductType.Supply, SupplyHistoryId = supplyHistory.Id, }; } _infoProductService.Create(info); }
public Booking Booking(BookingVM booking, int userId) { var shopId = _context.Users.First(x => x.Id == userId).ShopId; var productsIds = booking.Products.Select(x => x.Id); var products = _context.Products.Where(x => productsIds.Contains(x.Id)); Booking newBooking = new Booking() { Date = DateTime.Now.AddHours(3), ShopId = shopId, UserId = userId, CashSum = booking.CashSum, CashlessSum = booking.CashlessSum, Sum = booking.Sum, Discount = booking.Discount, Debt = booking.Sum - booking.CashSum - booking.CashlessSum, Pay = booking.CashSum + booking.CashlessSum, Status = BookingStatus.Open, PartnerId = booking.Buyer == "Обычный покупатель" ? null : _context.Partners.First(p => p.Title == booking.Buyer)?.Id, forRussian = booking.forRussian }; var createdBooking = _bookingService.Create(newBooking); foreach (var product in booking.Products) { _bookingProductService.Create(new BookingProduct() { Amount = product.Amount, BookingId = createdBooking.Id, ProductId = product.Id, Additional = product.Additional, Cost = product.Cost }); } if (booking.CashSum > 0) { _infoMoneyService.Create(new InfoMoney() { BookingId = newBooking.Id, PaymentType = PaymentType.Cash, MoneyWorkerId = shopId, Sum = booking.CashSum, MoneyOperationType = MoneyOperationType.Booking }); } if (booking.CashlessSum > 0) { _infoMoneyService.Create(new InfoMoney() { BookingId = newBooking.Id, PaymentType = PaymentType.Cashless, MoneyWorkerId = booking.MoneyWorkerId, Sum = booking.CashlessSum, MoneyOperationType = MoneyOperationType.Booking }); } return(createdBooking); }