Exemple #1
0
        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));
        }
Exemple #2
0
        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));
        }