Exemple #1
0
        public new PartialViewResult View(string id)
        {
            StockTransferModels model = GetDetail(id);
            var issueStore            = lstStoreReceiving.Where(z => z.Id.Equals(model.IssueStoreId)).FirstOrDefault();

            if (issueStore != null)
            {
                model.IssueStoreName = issueStore.Name;
            }
            var receiveStore = lstStoreReceiving.Where(z => z.Id.Equals(model.ReceiveStoreId)).FirstOrDefault();

            if (receiveStore != null)
            {
                model.ReceiveStoreName = receiveStore.Name;
            }
            //==========
            List <EmployeeModels> listEmp = _EmployeeFactory.GetListEmployee(model.IssueStoreId, null, CurrentUser.ListOrganizationId);
            var Emp = listEmp.Where(x => x.ID.Equals(model.IssueBy)).FirstOrDefault();

            model.IssueBy = Emp == null ? "" : Emp.Name;

            listEmp = _EmployeeFactory.GetListEmployee(model.ReceiveStoreId, null, CurrentUser.ListOrganizationId);
            var EmpRequestBy = listEmp.Where(x => x.ID.Equals(model.RequestBy)).FirstOrDefault();

            model.RequestBy = EmpRequestBy == null ? "" : EmpRequestBy.Name;

            var EmpReceiveBy = listEmp.Where(x => x.ID.Equals(model.ReceiveBy)).FirstOrDefault();

            model.ReceiveBy = EmpReceiveBy == null ? "" : EmpReceiveBy.Name;

            return(PartialView("_View", model));
        }
Exemple #2
0
        //public PartialViewResult Edit(string id)
        //{
        //    StockTransferModels model = GetDetail(id);
        //    return PartialView("_Edit", model);
        //}

        //[HttpGet]
        //public PartialViewResult Delete(string id)
        //{
        //    StockTransferModels model = GetDetail(id);
        //    return PartialView("_Delete", model);
        //}


        //Issuing Warehouse
        public ActionResult LoadEmployee(string StoreID, string empId = null)
        {
            List <EmployeeModels> lstData = new List <EmployeeModels>();

            if (!string.IsNullOrEmpty(StoreID))
            {
                lstData = _EmployeeFactory.GetListEmployee(StoreID, null, CurrentUser.ListOrganizationId);
            }

            StockTransferModels model = new StockTransferModels();

            if (!string.IsNullOrEmpty(empId))
            {
                model.IssueBy = empId;
            }
            if (lstData != null && lstData.Any())
            {
                lstData = lstData.OrderBy(oo => oo.Name).ToList();
                foreach (EmployeeModels emp in lstData)
                {
                    model.ListEmployee.Add(new SelectListItem
                    {
                        Value    = emp.ID,
                        Text     = emp.Name,
                        Selected = false
                    });
                }
            }

            return(PartialView("_DDLEmployee", model));
        }
Exemple #3
0
 public StockTransferModels GetDetail(string id)
 {
     try
     {
         StockTransferModels model = _factory.GetDetail(id);
         return(model);
     }
     catch (Exception ex)
     {
         _logger.Error("StockTransfer_Detail: " + ex);
         return(null);
     }
 }
Exemple #4
0
        public ActionResult AddIngredient(STIngredientViewModels data)
        {
            StockTransferModels model = new StockTransferModels();

            model.ListItem = new List <StockTransferDetailModels>();
            foreach (var item in data.ListItemView)
            {
                var itemDetail = new StockTransferDetailModels
                {
                    Id = "", // Add New

                    IngredientId   = item.IngredientId,
                    IngredientName = item.IngredientName,
                    IngredientCode = item.IngredientCode,

                    IsSelect   = item.IsSelect,
                    RequestQty = item.RequestQty,
                    IssueQty   = item.IssueQty,
                    ReceiveQty = item.ReceiveQty,

                    UOMId   = item.UOMId,
                    BaseUOM = item.BaseUOM,
                };
                var lstItem = _UOMFactory.GetDataUOMRecipe(item.IngredientId).ToList();
                if (lstItem != null)
                {
                    foreach (UnitOfMeasureModel uom in lstItem)
                    {
                        itemDetail.ListUOM.Add(new SelectListItem
                        {
                            Text  = uom.Name,
                            Value = uom.Id
                        });
                    }
                }
                model.ListItem.Add(itemDetail);
            }
            return(PartialView("_ListIngredients", model));
        }
Exemple #5
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));
            }
        }
Exemple #6
0
        public ActionResult Create()
        {
            StockTransferModels model = new StockTransferModels();

            return(View(model));
        }
Exemple #7
0
        public bool Insert(StockTransferModels model, ref string msg)
        {
            bool result = true;

            using (NuWebContext cxt = new NuWebContext())
            {
                using (var transaction = cxt.Database.BeginTransaction())
                {
                    try
                    {
                        ResultModels resultModels = new ResultModels();

                        I_Stock_Transfer item            = new I_Stock_Transfer();
                        string           StockTransferId = Guid.NewGuid().ToString();

                        item.Id = StockTransferId;
                        item.StockTransferNo = CommonHelper.GetGenNo(Commons.ETableZipCode.StockTransfer, model.IssueStoreId);

                        item.IssueStoreId   = model.IssueStoreId;
                        item.ReceiveStoreId = model.ReceiveStoreId;

                        item.RequestBy   = model.RequestBy;
                        item.RequestDate = model.RequestDate;

                        item.IssueBy   = model.IssueBy;
                        item.IssueDate = model.IssueDate;

                        item.ReceiveBy   = model.ReceiveBy;
                        item.ReceiveDate = model.ReceiveDate;

                        item.IsActive = model.IsActive;

                        List <I_Stock_Transfer_Detail> listInsert = new List <I_Stock_Transfer_Detail>();
                        I_Stock_Transfer_Detail        itemDetail = null;
                        //for stock
                        List <InventoryTransferModels> lstInventory = new List <InventoryTransferModels>();
                        InventoryTransferModels        inventory    = null;
                        foreach (var STDetailItem in model.ListItem)
                        {
                            itemDetail = new I_Stock_Transfer_Detail();

                            itemDetail.Id = Guid.NewGuid().ToString();
                            itemDetail.StockTransferId = StockTransferId;
                            itemDetail.IngredientId    = STDetailItem.IngredientId;
                            itemDetail.RequestQty      = STDetailItem.RequestQty;
                            itemDetail.ReceiveQty      = STDetailItem.ReceiveQty;
                            itemDetail.IssueQty        = STDetailItem.IssueQty;
                            itemDetail.UOMId           = STDetailItem.UOMId;
                            itemDetail.ReceiveBaseQty  = (STDetailItem.ReceiveQty * STDetailItem.Rate);
                            itemDetail.IssueBaseQty    = (STDetailItem.IssueQty * STDetailItem.Rate);

                            listInsert.Add(itemDetail);

                            inventory = new InventoryTransferModels();
                            inventory.IssueStoreId   = model.IssueStoreId;
                            inventory.ReceiveStoreId = model.ReceiveStoreId;
                            inventory.IngredientId   = STDetailItem.IngredientId;
                            inventory.IssueQty       = (STDetailItem.IssueQty * STDetailItem.Rate);
                            inventory.ReceiveQty     = (STDetailItem.ReceiveQty * STDetailItem.Rate);

                            inventory.Price = 0;

                            lstInventory.Add(inventory);
                        }

                        cxt.I_Stock_Transfer.Add(item);
                        cxt.I_Stock_Transfer_Detail.AddRange(listInsert);
                        cxt.SaveChanges();
                        transaction.Commit();

                        //Update inventory
                        _inventoryFactory.UpdateInventoryForTransfer(lstInventory, StockTransferId, ref resultModels);
                        _logger.Info(string.Format("UpdateInventoryForTransfer: [{0}] - [{1}] - [{2}] ", resultModels.IsOk, StockTransferId, resultModels.Message));
                    }
                    catch (Exception ex)
                    {
                        _logger.Error(ex);
                        result = false;
                        transaction.Rollback();
                    }
                    finally
                    {
                        if (cxt != null)
                        {
                            cxt.Dispose();
                        }
                    }
                }
            }
            return(result);
        }