コード例 #1
0
ファイル: HomeController.cs プロジェクト: adulenzy/JustFood
 private int CreateSale(int inHandCash)
 {
     DB.Sale today = GetToday();
     if (today == null)
     {
         var sale = new DB.Sale {
             Date      = DateTime.Now,
             TotalSold = 0,
             IsDividedAmongPartners = false,
             OtherExpenses          = 0,
             TotalAcheived          = 0,
             Discount                        = 0,
             TotalLess                       = 0,
             TotalWastages                   = 0,
             TotalDiscountNumber             = 0,
             InHandCashChange                = inHandCash,
             ActualAcheivedFromEmployee      = 0,
             ActualLossProfitAfterCollection = 0,
             IsInventorySet                  = false
         };
         db.Sales.Add(sale);
         db.SaveChanges();
         return(sale.SaleID);
     }
     else
     {
         return(today.SaleID);
     }
 }
コード例 #2
0
ファイル: HomeController.cs プロジェクト: adulenzy/JustFood
        private ActionResult DetermineSaleDay(DB.Sale sale, DB.SaleDayView saleView)
        {
            if (sale != null)
            {
                if (!sale.IsInventorySet)
                {
                    return(RedirectToActionPermanent("InventorySetter"));
                }
                if (saleView == null)
                {
                    saleView = new DB.SaleDayView(sale.SaleID)
                    {
                        Sale      = sale,
                        SaleDated = sale.Date
                    };
                }
                saleView.DiscountView = new DB.DiscountView {
                    SaleID = saleView.SaleID
                };

                ViewBag.SaleID = sale.SaleID;
                GenerateDropDowns();
                return(View("Day", saleView));
            }
            var ex = new Exception("Sale is invalid.");

            return(View("Error2", ex));
        }
コード例 #3
0
ファイル: HomeController.cs プロジェクト: adulenzy/JustFood
 /// <summary>
 /// checks null and return the value.
 /// </summary>
 /// <param name="sale"></param>
 /// <returns></returns>
 bool IsToday(DB.Sale sale)
 {
     if (sale != null)
     {
         if (sale.Date.Date == DateTime.Now.Date)
         {
             return(true);
         }
     }
     return(false);
 }
コード例 #4
0
ファイル: HomeController.cs プロジェクト: adulenzy/JustFood
 public ActionResult Today()
 {
     DB.Sale today = GetToday();
     if (today == null)
     {
         //create date.
         return(RedirectToAction("Create"));
     }
     else if (!today.IsInventorySet)
     {
         return(RedirectToActionPermanent("InventorySetter"));
     }
     return(DetermineSaleDay(today));
 }
コード例 #5
0
ファイル: HomeController.cs プロジェクト: adulenzy/JustFood
 /// <summary>
 /// Will be added with the context.
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 private DB.Sale GetDatedSale(int id)
 {
     DB.Sale sale = CacheSale;
     if (sale != null && IsToday(sale))
     {
         try {
             db.Entry(sale).State = EntityState.Modified;
         } catch (Exception ex) { }
         return(sale);
     }
     sale      = db.Sales.Find(id);
     CacheSale = sale;
     return(sale);
 }
コード例 #6
0
ファイル: HomeController.cs プロジェクト: adulenzy/JustFood
        bool IsTransactionRejected(DB.Sale sale)
        {
            var user = userinfo.GetUserSession();

            if (user.IsAccessToAdmin)
            {
                return(false);
            }
            Session["Sale"] = sale;
            //if date is not valid to today or is already check then return true.
            if (sale.Date.Date != DateTime.Now.Date || sale.IsDiscardsChecked || sale.IsDividedAmongPartners)
            {
                return(false);
            }
            return(true);
        }
コード例 #7
0
ファイル: HomeController.cs プロジェクト: adulenzy/JustFood
        private DB.Sale GetDatedSale(DateTime date)
        {
            var dated = date.Date;

            DB.Sale sale = CacheSale;
            if (sale != null && IsToday(sale))
            {
                try {
                    db.Entry(sale).State = EntityState.Modified;
                } catch (Exception ex) { }
                return(sale);
            }
            sale      = db.Sales.FirstOrDefault(n => n.Date == dated);
            CacheSale = sale;
            return(sale);
        }
コード例 #8
0
ファイル: HomeController.cs プロジェクト: adulenzy/JustFood
        DB.Sale GetToday()
        {
            DB.Sale sale;
            sale = CacheSale;
            if (sale != null && IsToday(sale))
            {
                try {
                    db.Entry(sale).State = EntityState.Modified;
                } catch (Exception ex) { }
                return(sale);
            }
            DateTime date = DateTime.Now.Date;

            sale      = db.Sales.FirstOrDefault(n => n.Date == date);
            CacheSale = sale;
            return(sale);
        }
コード例 #9
0
ファイル: HomeController.cs プロジェクト: adulenzy/JustFood
 void InventoryOut(DB.Sale sale, DB.Inventory inventory)
 {
 }
コード例 #10
0
ファイル: HomeController.cs プロジェクト: adulenzy/JustFood
 private void InventoryIn(DB.Sale sale, DB.Inventory inventory)
 {
 }
コード例 #11
0
ファイル: HomeController.cs プロジェクト: adulenzy/JustFood
 private ActionResult DetermineSaleDay(DB.Sale sale)
 {
     return(DetermineSaleDay(sale, null));
 }
コード例 #12
0
ファイル: HomeController.cs プロジェクト: adulenzy/JustFood
        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.");
            }
        }
コード例 #13
0
ファイル: HomeController.cs プロジェクト: adulenzy/JustFood
        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"));
        }