Ejemplo n.º 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));
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 3
0
        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));
        }
Ejemplo n.º 4
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"));
        }