Ejemplo n.º 1
0
        public IActionResult UpdateChinaOrder(int Id)
        {
            ChinaOrder   chinaOrder   = _unitOfWork.ChinaOrder.GetAll().Where(a => a.Id == Id).FirstOrDefault();
            ChinaOrderVM chinaOrderVM = new ChinaOrderVM()
            {
                chinaOrder  = chinaOrder,
                ProductList = _unitOfWork.Product.GetAll().OrderBy(a => a.ProductName).
                              Select(i => new SelectListItem
                {
                    Text  = i.ProductName,
                    Value = i.Id.ToString()
                })
            };

            if (chinaOrder.IgnoreMissingQuantity)
            {
                ViewBag.Ignore = true;
            }
            else
            {
                ViewBag.Ignore = false;
            }
            if (chinaOrder.ReceivedAll)
            {
                ViewBag.Received = true;
            }
            else
            {
                ViewBag.Received = false;
            }
            ViewBag.QuantityZero = false;

            return(View(chinaOrderVM));
        }
Ejemplo n.º 2
0
        public IActionResult AddChinaOrder()
        {
            ChinaOrderVM chinaOrderVM;

            chinaOrderVM = new ChinaOrderVM()
            {
                chinaOrder  = new ChinaOrder(),
                ProductList = _unitOfWork.Product.GetAll().OrderBy(a => a.ProductName).
                              Select(i => new SelectListItem
                {
                    Text  = i.ProductName,
                    Value = i.Id.ToString()
                })
            };
            ViewBag.ShowMsg      = 0;
            ViewBag.failed       = false;
            ViewBag.QuantityZero = false;
            return(View(chinaOrderVM));
        }
Ejemplo n.º 3
0
        public IActionResult AddChinaOrder(ChinaOrderVM chinaOrderVM)
        {
            ViewBag.QuantityZero = false;
            ChinaOrderVM chinaOrderVM2 = new ChinaOrderVM()
            {
                chinaOrder  = new ChinaOrder(),
                ProductList = _unitOfWork.Product.GetAll().OrderBy(a => a.ProductName).
                              Select(i => new SelectListItem
                {
                    Text  = i.ProductName,
                    Value = i.Id.ToString()
                })
            };

            if (ModelState.IsValid)
            {
                if (chinaOrderVM.chinaOrder.Quantity <= 0)
                {
                    ViewBag.QuantityZero = true;
                }
                else if (chinaOrderVM.chinaOrder.Id == 0)
                {
                    ViewBag.QuantityZero = false;
                    _unitOfWork.ChinaOrder.Add(chinaOrderVM.chinaOrder);
                    //Once added, we need to add to the onthe way column on product
                    Product product = _unitOfWork.Product.GetAll().Where(a => a.Id == chinaOrderVM.chinaOrder.ProductId).FirstOrDefault();
                    product.OnTheWayInventory = product.OnTheWayInventory + chinaOrderVM.chinaOrder.Quantity;
                    _unitOfWork.Save();
                }
                ViewBag.ShowMsg = 1;

                //return RedirectToAction(nameof(Index));
            }

            return(View(chinaOrderVM2));
        }
Ejemplo n.º 4
0
        public IActionResult UpdateChinaOrder(ChinaOrderVM chinaOrderVM)
        {
            ChinaOrderVM chinaOrderVM2 = new ChinaOrderVM()
            {
                chinaOrder  = _unitOfWork.ChinaOrder.GetAll().Where(a => a.Id == chinaOrderVM.chinaOrder.Id).FirstOrDefault(),
                ProductList = _unitOfWork.Product.GetAll().OrderBy(a => a.ProductName).
                              Select(i => new SelectListItem
                {
                    Text  = i.ProductName,
                    Value = i.Id.ToString()
                })
            };

            ViewBag.QuantityZero = false;
            if (ModelState.IsValid)
            {
                if (chinaOrderVM.chinaOrder.QuantityReceived <= 0)
                {
                    ViewBag.QuantityZero = true;
                }
                else
                {
                    ChinaOrder oldChinaOrder  = _unitOfWork.ChinaOrder.GetAll().Where(a => a.Id == chinaOrderVM.chinaOrder.Id).FirstOrDefault();
                    Product    product        = _unitOfWork.Product.GetAll().Where(a => a.Id == chinaOrderVM.chinaOrder.ProductId).FirstOrDefault();
                    int        QuantityUpdate = chinaOrderVM.chinaOrder.QuantityReceived - oldChinaOrder.QuantityReceived;
                    //update Inventory
                    product.InventoryCount = product.InventoryCount + QuantityUpdate;
                    //update onTheWayInventory
                    if (QuantityUpdate == 0 && !chinaOrderVM.chinaOrder.IgnoreMissingQuantity)//ignore didnt change and quantity didnt change
                    {
                    }
                    else if (QuantityUpdate == 0 && chinaOrderVM.chinaOrder.IgnoreMissingQuantity && !oldChinaOrder.IgnoreMissingQuantity)//quantity didnt change ignore did
                    {
                        int missingQ = chinaOrderVM.chinaOrder.Quantity - chinaOrderVM.chinaOrder.QuantityReceived;
                        if (missingQ >= 0)
                        {
                            product.OnTheWayInventory = product.OnTheWayInventory - missingQ;
                        }
                    }
                    else if (QuantityUpdate != 0 && !chinaOrderVM.chinaOrder.IgnoreMissingQuantity)//quantity changed and ignore didnt
                    {
                        if (chinaOrderVM.chinaOrder.QuantityReceived > chinaOrderVM.chinaOrder.Quantity)
                        {
                            product.OnTheWayInventory = product.OnTheWayInventory - QuantityUpdate + (chinaOrderVM.chinaOrder.QuantityReceived - chinaOrderVM.chinaOrder.Quantity);
                        }
                        else
                        {
                            product.OnTheWayInventory = product.OnTheWayInventory - QuantityUpdate;
                        }
                    }
                    else if (QuantityUpdate != 0 && chinaOrderVM.chinaOrder.IgnoreMissingQuantity && !oldChinaOrder.IgnoreMissingQuantity)//quantity changed and ignore changed
                    {
                        if (chinaOrderVM.chinaOrder.QuantityReceived > chinaOrderVM.chinaOrder.Quantity)
                        {
                            product.OnTheWayInventory = product.OnTheWayInventory - QuantityUpdate + (chinaOrderVM.chinaOrder.QuantityReceived - chinaOrderVM.chinaOrder.Quantity);
                        }
                        else
                        {
                            product.OnTheWayInventory = product.OnTheWayInventory - QuantityUpdate - (chinaOrderVM.chinaOrder.Quantity - chinaOrderVM.chinaOrder.QuantityReceived);
                        }
                    }
                    _unitOfWork.ChinaOrder.update(chinaOrderVM.chinaOrder);
                    _unitOfWork.Save();
                    ViewBag.ShowMsg = 1;
                }
            }
            ViewBag.ShowMsg = 1;
            return(View(chinaOrderVM2));
        }