public ActionResult AddProduct(AddProductView addProduct, string time, int SaleID) { #region Check Cache var saleCache = CacheSale; if (IsCookieTimeEqual(time)) { MessageSetter.SetWarning("Sorry , previous transaction is not saved to the database."); if (saleCache != null) { if (IsToday(saleCache)) { // today return(RedirectToActionPermanent("Today")); } else { return(DetermineSaleDay(saleCache)); } } } #endregion if (addProduct.Cost < 0) { ModelState.AddModelError("Amount", "Amount can't be negative."); return(DetermineSaleDay(SaleID)); } var useraccExt = new UserAccountsExtension(); var accountOf = useraccExt.GetProductBoughtUser(); var accountBalance = new AccountBalance() { AccountOf = accountOf.UserID, AddBy = userinfo.GetUserID(), Amount = addProduct.Cost, AddedQuantity = addProduct.Quantity, QtyType = addProduct.QuantityType, Dated = DateTime.Now, CategoryProduct = addProduct.CategoryID, IsExpense = true, IsAddedMoney = false, IsBoughtProduct = true, IsVerified = false }; var inventoryEntension = new InventoryExtension(); if (inventoryEntension.InventoryAdd(db, accountBalance)) { db.SaveChanges(); MessageSetter.SetPositive("Product of " + addProduct.Cost + " successfully."); } else { MessageSetter.SetWarning("try again."); } return(DetermineSaleDay(SaleID)); }
public ActionResult Expense(ExpenseSalesView expense, string time) { #region Check Cache var saleCache = CacheSale; if (IsCookieTimeEqual(time)) { MessageSetter.SetWarning("Sorry , previous transaction is not saved to the database."); if (saleCache != null) { if (IsToday(saleCache)) { // today return(RedirectToActionPermanent("Today")); } else { return(DetermineSaleDay(saleCache)); } } } #endregion int SaleID = expense.SaleID; const string dailyExpense = "Daily Expense"; if (expense.Amount < 0) { ModelState.AddModelError("Amount", "Amount can't be negative."); return(DetermineSaleDay(SaleID)); } SaleDayView day = new SaleDayView(SaleID); var userAccExtention = new UserAccountsExtension(); var accountOf = userAccExtention.GetExpenseAccount(); var accountBalance = new AccountBalance() { AccountOf = accountOf.UserID, AddBy = userinfo.GetUserID(), Amount = expense.Amount * (-1), Dated = DateTime.Now, CategoryProduct = expense.ExpenseCategoryID, Note = expense.Note, IsExpense = true, IsAddedMoney = false, IsBoughtProduct = false, IsVerified = false }; db.AccountBalances.Add(accountBalance); MessageSetter.SetPositive("Expense of " + expense.Amount + " added successfully."); db.SaveChanges(); return(DetermineSaleDay(SaleID)); }
public ActionResult Requisition(Requisition requisition, string time, int SaleIDReq) { #region Check Cache var saleCache = CacheSale; if (IsCookieTimeEqual(time)) { MessageSetter.SetWarning("Sorry , previous transaction is not saved to the database."); if (saleCache != null) { if (IsToday(saleCache)) { // today return(RedirectToActionPermanent("Today")); } else { return(DetermineSaleDay(saleCache)); } } } #endregion var req = new Requisition() { AddedBy = userinfo.GetUserID(), QtyType = requisition.QtyType, Quantity = requisition.Quantity, CategoryID = requisition.CategoryID, IsAutoAdded = false, IsInProcess = false, IsDone = false }; var categoryFound = db.Categories.FirstOrDefault(n => n.CategoryID == requisition.CategoryID); string quantityType = ""; if (categoryFound != null) { var category = categoryFound.Category1; var quantityTypeObject = db.QuantityTypes.FirstOrDefault(n => n.QuantityTypeID == requisition.QtyType); if (quantityTypeObject != null) { quantityType = quantityTypeObject.QtyType; } else { MessageSetter.SetError("Requisition failed " + category); goto skip; } db.Requisitions.Add(req); db.SaveChanges(); MessageSetter.SetPositive("Requisition successfully " + category + " " + req.Quantity + " " + quantityType + " added."); } else { MessageSetter.SetError("Requisition failed."); } skip: return(DetermineSaleDay(SaleIDReq)); }
public ActionResult DiscardItem(int SaleID, int CategoryID, string time) { #region Check Cache var saleCache = CacheSale; if (IsCookieTimeEqual(time)) { if (saleCache != null) { if (IsToday(saleCache)) { // today return(RedirectToActionPermanent("Today")); } else { return(DetermineSaleDay(saleCache)); } } return(DetermineSaleDay(SaleID)); } #endregion var sale = GetDatedSale(SaleID); if (sale == null) { return(RedirectToActionPermanent("Today")); } if (IsTransactionRejected(sale)) { return(View("Error2", new Exception("Sorry you have no rights to change previous sales information."))); } var inventory = db.Inventories.Include(n => n.Category).FirstOrDefault(n => n.CategoryID == CategoryID); var lastSold = db.DetailedSales.OrderByDescending(n => n.Time) .FirstOrDefault(n => n.SaleID == SaleID && n.CategoryID == CategoryID && !n.IsDiscard && !n.IsMarkedDiscard); var existRecord = sale != null && inventory != null; var saleView = new SaleDayView(SaleID) { Sale = sale }; ///means item still sold and can be discarded bool soldOut = false; var summary = saleView.GetSummary(); var specificCategory = summary.FirstOrDefault(n => n.SaleID == SaleID && n.CategoryID == CategoryID); if (specificCategory != null) { // if any summary of that item exist. // if any item is still sold from this category. soldOut = !(specificCategory.SoldQuantity > 0); //if still one sold then it will be false. } if (existRecord && !soldOut) { //first check if one product is sold or not. //if not then can't discard. var saleItem = new DB.DetailedSale() { CategoryID = CategoryID, SaleID = SaleID, SellingPrice = (int)inventory.SoldPrice, SoldAt = lastSold.SoldAt * -1, Time = DateTime.Now, IsDiscard = true, UserID = userinfo.GetUserID() }; // do some inventory in // not implemented yet... InventoryIn(sale, inventory); sale.TotalAcheived += saleItem.SoldAt; //because sold at is - sale.TotalSold += saleItem.SoldAt; //fixing discount money if (lastSold.Discount != null && lastSold.Discount > 0) { sale.Discount -= lastSold.Discount; } //tracking discard sales sale.DiscardSales++; if (sale.DiscardSales > 20) { sale.AnyProblem = true; } lastSold.IsMarkedDiscard = true;//when discarded, marked it. db.DetailedSales.Add(saleItem); string categoryDisplay = inventory.Category.Category1; MessageSetter.SetPositive(categoryDisplay + " -1."); //decreasing quantity of sale DecreaseSaleQuantity(saleItem); //remove category wise sale RemoveCategoryWiseSellingInformation(saleItem); db.SaveChanges(); CacheSale = sale; return(DetermineSaleDay(sale)); } else if (existRecord && soldOut) { // do nothing , send to the view. if (IsToday(sale)) { return(RedirectToActionPermanent("Today")); } return(DetermineSaleDay(sale)); } else { throw new Exception("Information about discarding not found."); } }
public ActionResult Discount(DiscountView discountView, string time) { if (ModelState.IsValid) { #region Check Cache int SaleID = discountView.SaleID; var saleCache = CacheSale; if (IsCookieTimeEqual(time)) { MessageSetter.SetWarning("Sorry , previous transaction is not saved to the database. Because same transaction is placed before."); if (saleCache != null) { if (IsToday(saleCache)) { // today return(RedirectToActionPermanent("Today")); } else { return(DetermineSaleDay(saleCache)); } } return(DetermineSaleDay(SaleID)); } #endregion var sale = GetDatedSale(SaleID); if (IsTransactionRejected(sale)) { return(View("Error2", new Exception("Sorry you have no rights to change previous sales information."))); } var inventory = db.Inventories.Include(n => n.Category).FirstOrDefault(n => n.CategoryID == discountView.DiscountCategoryID); if (sale != null && inventory != null) { int soldAt = discountView.Amount; int discount = (int)inventory.SoldPrice - soldAt; var saleItem = new DB.DetailedSale { CategoryID = discountView.DiscountCategoryID, IsDiscard = false, SaleID = discountView.SaleID, SellingPrice = (int)inventory.SoldPrice, SoldAt = soldAt, Discount = discount, Time = DateTime.Now, IsMarkedDiscard = false, DiscountPerson = discountView.Name, DiscountNumber = discountView.Phone, Note = discountView.Notes, UserID = userinfo.GetUserID() }; // do some inventory out // not implemented yet... InventoryOut(sale, inventory); sale.TotalAcheived += soldAt; sale.TotalSold += soldAt; sale.TotalDiscountNumber++; if (sale.Discount == null) { sale.Discount = 0; } sale.Discount += discount; db.DetailedSales.Add(saleItem); //Increasing quantity of sale IncreaseSaleQuantity(saleItem); //add category wise sale AddCategoryWiseSellingInformation(saleItem); db.SaveChanges(); string categoryDisplay = inventory.Category.Category1; MessageSetter.SetPositive(categoryDisplay + " +1 , discount @" + discount + "."); CacheSale = sale; } else { throw new Exception("Sale or Inventory is not found."); } return(DetermineSaleDay(sale)); } return(View("Error")); }