Exemple #1
0
        public ActionResult Create(StockTransferModels model)
        {
            try
            {
                if (string.IsNullOrEmpty(model.RequestBy))
                {
                    ModelState.AddModelError("RequestBy", CurrentUser.GetLanguageTextFromKey("Request By field is required"));
                }
                if (string.IsNullOrEmpty(model.IssueBy))
                {
                    ModelState.AddModelError("IssueBy", CurrentUser.GetLanguageTextFromKey("Issue By field is required"));
                }
                if (string.IsNullOrEmpty(model.ReceiveBy))
                {
                    ModelState.AddModelError("ReceiveBy", CurrentUser.GetLanguageTextFromKey("Receive By field is required"));
                }
                if (!ModelState.IsValid)
                {
                    return(View(model));
                }

                double qtyCurrentStock = 0, rate = 1;
                bool   isCheck        = true;
                string ingredientName = string.Empty;
                model.ListItem = model.ListItem.Where(ww => ww.Delete != (int)Commons.EStatus.Deleted).ToList();
                //Check Stock before send
                foreach (var item in model.ListItem)
                {
                    ingredientName  = string.Empty;
                    qtyCurrentStock = 0;
                    rate            = 1;

                    isCheck = _InventoryFactory.CheckStockBeforeTransfer(model.IssueStoreId, item.IngredientId
                                                                         , item.UOMId, item.IssueQty, ref qtyCurrentStock, ref ingredientName, ref rate);

                    item.Rate = rate;
                    if (!isCheck)
                    {
                        ModelState.AddModelError("error_msg", string.Format("[{0}]" + CurrentUser.GetLanguageTextFromKey("not enough stock transfer") + "!", ingredientName));
                        break;
                    }
                }

                if (!ModelState.IsValid)
                {
                    return(View(model));
                }

                model.IsActive = true;
                string msg    = "";
                bool   result = _factory.Insert(model, ref msg);
                if (result)
                {
                    return(RedirectToAction("Index"));
                }
                else
                {
                    ModelState.AddModelError("StoreId", msg);
                    return(View("Create"));
                }
            }
            catch (Exception ex)
            {
                _logger.Error("StockTransfer_Create: " + ex);
                return(new HttpStatusCodeResult(400, ex.Message));
            }
        }