Exemplo n.º 1
0
        /// <summary>
        /// Remove category wise sold -= numberOfitemSold wheatear exist or not .
        /// However it doesn't perform SaveChanges()
        /// </summary>
        /// <param name="sale"></param>
        /// <param name="CategoryID"></param>
        /// <param name="numberOfitemSold"></param>
        void RemoveCategoryWiseSellingInformation(DB.DetailedSale dSale, int numberOfitemSold = 1)
        {
            var cat = db.CategoryWiseSolds
                      .FirstOrDefault(n => n.SaleID == dSale.SaleID && n.CategoryID == dSale.CategoryID);

            if (cat == null)
            {
                cat = new CategoryWiseSold()
                {
                    CategoryWiseSoldID = Guid.NewGuid(),
                    CategoryID         = dSale.CategoryID,
                    SaleID             = dSale.SaleID,
                    Quantity           = 0
                };
            }
            if (cat != null)
            {
                cat.Quantity -= numberOfitemSold;
            }
        }
Exemplo n.º 2
0
        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.");
            }
        }
Exemplo n.º 3
0
        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"));
        }
Exemplo n.º 4
0
 void DecreaseSaleQuantity(DB.DetailedSale dSale, short number = -1)
 {
     dSale.Qty = number;
 }