Example #1
0
        public bool AuditingInventoryOrder(string InventoryID)
        {
            bool flag = false;

            try
            {
                ProductsStock    stock;
                VInventory       inventory = new VInventory();
                ProductsStockDAL kdal      = new ProductsStockDAL();
                inventory = new InventoryDAL().getByID(InventoryID);
                if (kdal.isHaveEitity(inventory.HouseDetailID, inventory.ProductsID))
                {
                    stock = new ProductsStock();
                    stock.HouseDetailID = inventory.HouseDetailID;
                    stock.ProductsID    = inventory.ProductsID;
                    stock.Num           = inventory.AdjustNum;
                    kdal.updateEitityNum(stock);
                }
                else
                {
                    stock = new ProductsStock();
                    stock.HouseDetailID = inventory.HouseDetailID;
                    stock.ProductsID    = inventory.ProductsID;
                    stock.Num           = inventory.AdjustNum;
                    kdal.insertNewEitity(stock);
                }
                flag = true;
            }
            catch
            {
            }
            return(flag);
        }
Example #2
0
        public IActionResult BuyProduct(int id = 0)
        {
            if (id == 0)
            {
                ProductsStock prod = new ProductsStock();
                prod.available = true;
                return(View(prod));
            }
            else
            {
                var ProductListQuery = (from p in _context.Products
                                        join o in _context.TypeProduct on p.TypeProduct equals o.TypeProductID
                                        join s in _context.Stock on p.ProductID equals s.ProductID
                                        where p.ProductID == id
                                        select new ProductsStock
                {
                    ProductID = p.ProductID,
                    ProductName = p.ProductName,
                    Details = o.Details,
                    Price = p.Price,
                    quantity = s.Quantity,
                    available = s.Available,
                    Photo = p.Photo
                }).FirstOrDefault();


                return(View(ProductListQuery));
            }
        }
Example #3
0
        public bool insertNewEitity(ProductsStock p)
        {
            int rowsAffected = 0;

            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@HouseDetailID", SqlDbType.Int), new SqlParameter("@ProductsID", SqlDbType.Int), new SqlParameter("@Num", SqlDbType.Int) };
            parameters[0].Value = p.HouseDetailID;
            parameters[1].Value = p.ProductsID;
            parameters[2].Value = p.Num;
            SQLHelper.RunProcedure("p_ProductsStock_insertNewEitity", parameters, out rowsAffected);
            return(1 == rowsAffected);
        }
Example #4
0
        public bool AuditingTransferring(string ID)
        {
            bool flag = false;

            try
            {
                ProductsStockDAL   kdal  = new ProductsStockDAL();
                VTransferringOrder order = new TransferringOrderDAL().getByID(ID);
                if (order == null)
                {
                    return(false);
                }
                int           outHouseID = order.OutHouseID;
                int           inHouseID  = order.InHouseID;
                int           productsID = order.ProductsID;
                int           quantity   = order.Quantity;
                ProductsStock stock      = kdal.getByProductsIDStockID(productsID, outHouseID);
                ProductsStock stock2     = kdal.getByProductsIDStockID(productsID, inHouseID);
                if (stock == null)
                {
                    return(false);
                }
                if (quantity > stock.Num)
                {
                    return(false);
                }
                ProductsStock p = new ProductsStock();
                p.HouseDetailID = outHouseID;
                p.ProductsID    = productsID;
                p.Num           = quantity;
                ProductsStock stock4 = new ProductsStock();
                stock4.HouseDetailID = inHouseID;
                stock4.ProductsID    = productsID;
                stock4.Num           = quantity;
                if (kdal.updateCutNum(p))
                {
                    if (stock2 == null)
                    {
                        kdal.insertNewEitity(stock4);
                    }
                    else
                    {
                        kdal.updateAddNum(stock4);
                    }
                }
                flag = true;
            }
            catch
            {
            }
            return(flag);
        }
Example #5
0
        public async Task <IActionResult> BuyProducts([FromBody] ProductsStock prod)
        {
            if (prod.quantity < 1)
            {
                return(Json(new { success = false, message = "Please, type the amount of products to buy" }));
            }
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }



            var CurrProductStock = _context.Stock.Where(x => x.ProductID == prod.ProductID).FirstOrDefault();


            int quantity = 0, InStock = 0;

            InStock  = CurrProductStock.Quantity;
            quantity = prod.quantity;
            if (quantity > InStock)
            {
                return(Json(new { success = false, message = "There is not enough products in stock to this quantity" }));
            }

            quantity = InStock - quantity;
            CurrProductStock.Quantity = quantity;



            _context.Stock.Update(CurrProductStock);

            await _context.SaveChangesAsync();

            // Purchase log
            var          cookieValueUserID = Request.Cookies["UserLoggedID"];
            LogPurchases ProductsPurchased = new LogPurchases();

            ProductsPurchased.ProductID = prod.ProductID;
            ProductsPurchased.Quantity  = prod.quantity;
            ProductsPurchased.UserID    = Convert.ToInt32(cookieValueUserID);
            ProductsPurchased.Date      = DateTime.Now;
            _context.LogPurchases.Add(ProductsPurchased);
            await _context.SaveChangesAsync();

            return(Json(new { success = true, message = "You buy " + prod.quantity + " of " + prod.ProductName }));
        }
Example #6
0
        public bool AuditingBuyReturnOrder(string BuyReturnID)
        {
            bool flag = false;

            try
            {
                List <VBuyReturnDetail> list = new List <VBuyReturnDetail>();
                ProductsStockDAL        kdal = new ProductsStockDAL();
                BuyReturn return2            = new BuyReturnDAL().getByID(BuyReturnID);
                if (return2 == null)
                {
                    return(false);
                }
                list = new BuyReturnDetailDAL().getBuyReturnDetailByBuyReturnID(BuyReturnID);
                for (int i = 0; i < list.Count; i++)
                {
                    ProductsStock   stock;
                    BuyReturnDetail detail = list[i];
                    if (kdal.isHaveEitity(return2.HouseDetailID, detail.ProductsID))
                    {
                        stock = new ProductsStock();
                        stock.HouseDetailID = return2.HouseDetailID;
                        stock.ProductsID    = detail.ProductsID;
                        stock.Num           = detail.Quantity;
                        kdal.updateCutNum(stock);
                    }
                    else
                    {
                        stock = new ProductsStock();
                        stock.HouseDetailID = return2.HouseDetailID;
                        stock.ProductsID    = detail.ProductsID;
                        stock.Num           = -detail.Quantity;
                        kdal.insertNewEitity(stock);
                    }
                }
                flag = true;
            }
            catch
            {
            }
            return(flag);
        }
Example #7
0
        public bool AuditingSalesOutOrder(string SalesReturnID)
        {
            bool flag = false;

            try
            {
                VSalesReturn return2           = new VSalesReturn();
                List <VSalesReturnDetail> list = new List <VSalesReturnDetail>();
                ProductsStockDAL          kdal = new ProductsStockDAL();
                return2 = new SalesReturnDAL().getByID(SalesReturnID);
                list    = new SalesReturnDetailDAL().getBySalesReturnID(SalesReturnID);
                for (int i = 0; i < list.Count; i++)
                {
                    ProductsStock     stock;
                    SalesReturnDetail detail = list[i];
                    if (kdal.isHaveEitity(return2.HouseDetailID, detail.ProductsID))
                    {
                        stock = new ProductsStock();
                        stock.HouseDetailID = return2.HouseDetailID;
                        stock.ProductsID    = detail.ProductsID;
                        stock.Num           = detail.Quantity;
                        kdal.updateAddNum(stock);
                    }
                    else
                    {
                        stock = new ProductsStock();
                        stock.HouseDetailID = return2.HouseDetailID;
                        stock.ProductsID    = detail.ProductsID;
                        stock.Num           = detail.Quantity;
                        kdal.insertNewEitity(stock);
                    }
                }
                flag = true;
            }
            catch
            {
            }
            return(flag);
        }
Example #8
0
        public bool AuditingAppendStockOrder(string AppendID)
        {
            bool flag = false;

            try
            {
                VAppendStock stock             = new VAppendStock();
                List <VAppendStockDetail> list = new List <VAppendStockDetail>();
                ProductsStockDAL          kdal = new ProductsStockDAL();
                stock = new AppendStockDAL().getByID(AppendID);
                list  = new AppendStockDetailDAL().getListByAppendID(AppendID);
                for (int i = 0; i < list.Count; i++)
                {
                    ProductsStock     stock2;
                    AppendStockDetail detail = list[i];
                    if (kdal.isHaveEitity(stock.HouseDetailID, detail.ProductsID))
                    {
                        stock2 = new ProductsStock();
                        stock2.HouseDetailID = stock.HouseDetailID;
                        stock2.ProductsID    = detail.ProductsID;
                        stock2.Num           = detail.Quantity;
                        kdal.updateAddNum(stock2);
                    }
                    else
                    {
                        stock2 = new ProductsStock();
                        stock2.HouseDetailID = stock.HouseDetailID;
                        stock2.ProductsID    = detail.ProductsID;
                        stock2.Num           = detail.Quantity;
                        kdal.insertNewEitity(stock2);
                    }
                }
                flag = true;
            }
            catch
            {
            }
            return(flag);
        }
Example #9
0
        public bool AuditingBuyReceiptOrder(string ReceiptOrderID)
        {
            bool flag = false;

            try
            {
                BuyReceipt receipt            = new BuyReceipt();
                List <VBuyReceiptDetail> list = new List <VBuyReceiptDetail>();
                ProductsStockDAL         kdal = new ProductsStockDAL();
                receipt = new BuyReceiptDAL().getByID(ReceiptOrderID);
                list    = new BuyReceiptDetailDAL().getBuyReceiptDetailByReceiptOrderID(ReceiptOrderID);
                for (int i = 0; i < list.Count; i++)
                {
                    ProductsStock    stock;
                    BuyReceiptDetail detail = list[i];
                    if (kdal.isHaveEitity(receipt.HouseDetailID, detail.ProductsID))
                    {
                        stock = new ProductsStock();
                        stock.HouseDetailID = receipt.HouseDetailID;
                        stock.ProductsID    = detail.ProductsID;
                        stock.Num           = detail.Quantity;
                        kdal.updateAddNum(stock);
                    }
                    else
                    {
                        stock = new ProductsStock();
                        stock.HouseDetailID = receipt.HouseDetailID;
                        stock.ProductsID    = detail.ProductsID;
                        stock.Num           = detail.Quantity;
                        kdal.insertNewEitity(stock);
                    }
                }
                flag = true;
            }
            catch
            {
            }
            return(flag);
        }
Example #10
0
        public async Task <IActionResult> PostProduct([FromBody] ProductsStock prod)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (prod.ProductID == 0)
            {
                Products NewProduct = new Products();
                NewProduct.ProductName = prod.ProductName;
                NewProduct.Price       = prod.Price;
                NewProduct.TypeProduct = prod.ProductType;
                NewProduct.Photo       = prod.Photo;

                _context.Products.Add(NewProduct);
                await _context.SaveChangesAsync();

                Stock NewProductToStore = new Stock();
                NewProductToStore.Available = prod.available;
                NewProductToStore.Quantity  = prod.quantity;
                NewProductToStore.ProductID = NewProduct.ProductID;


                _context.Stock.Add(NewProductToStore);
                await _context.SaveChangesAsync();

                return(Json(new { success = true, message = "Product added successfully." }));
            }
            else
            {
                var ProductToEdit = _context.Products.Where(x => x.ProductID == prod.ProductID).FirstOrDefault();
                ProductToEdit.ProductID   = prod.ProductID;
                ProductToEdit.ProductName = prod.ProductName;
                if (prod.Price != ProductToEdit.Price)
                {
                    // Price changing log
                    var       cookieValueUserID = Request.Cookies["UserLoggedID"];
                    LogPrices PriceChanged      = new LogPrices();
                    PriceChanged.PrevPrice = ProductToEdit.Price;
                    PriceChanged.NewPrice  = prod.Price;
                    PriceChanged.ProductID = prod.ProductID;
                    PriceChanged.UserID    = Convert.ToInt32(cookieValueUserID);
                    PriceChanged.Date      = DateTime.Now;
                    _context.LogPrices.Update(PriceChanged);
                    await _context.SaveChangesAsync();
                }
                ProductToEdit.Price       = prod.Price;
                ProductToEdit.TypeProduct = prod.ProductType;
                ProductToEdit.Photo       = prod.Photo;

                _context.Products.Update(ProductToEdit);

                await _context.SaveChangesAsync();

                var CurrProductStock = _context.Stock.Where(x => x.ProductID == prod.ProductID).FirstOrDefault();

                CurrProductStock.Available = prod.available;
                CurrProductStock.Quantity  = prod.quantity;
                CurrProductStock.ProductID = prod.ProductID;


                _context.Stock.Update(CurrProductStock);

                await _context.SaveChangesAsync();

                return(Json(new { success = true, message = "Product edited successfully." }));
            }
        }