Пример #1
0
        public ActionResult CreateForGift()
        {
            var model = new PhysicalInventoryViewModel();

            model.Type = PhysicalInventoryType.Gift;
            var warehouseList = WarehouseRepository.GetAllWarehouse().Where(x => x.BranchId == Helpers.Common.CurrentUser.BranchId && x.Categories.Contains("GIFT")).AsEnumerable()
                                .Select(item => new SelectListItem
            {
                Text  = item.Name,
                Value = item.Id.ToString()
            });

            ViewBag.warehouseList = warehouseList;
            return(View(model));
        }
Пример #2
0
        public ActionResult Create()
        {
            var model = new PhysicalInventoryViewModel();

            var warehouseList = WarehouseRepository.GetAllWarehouse().AsEnumerable()
                                .Select(item => new SelectListItem
            {
                Text  = item.Name,
                Value = item.Id.ToString()
            });

            ViewBag.warehouseList = warehouseList;
            var manufacturer = categoryRepository.GetCategoryByCode("manufacturerList").AsEnumerable()
                               .Select(item => new SelectListItem
            {
                Text  = item.Name,
                Value = item.Value
            });

            ViewBag.manufacturer = manufacturer;
            return(View(model));
        }
Пример #3
0
        public ActionResult Detail(int?Id)
        {
            var PhysicalInventory = PhysicalInventoryRepository.GetAllvwPhysicalInventory()
                                    .Where(item => item.Id == Id).FirstOrDefault();

            if (PhysicalInventory != null)
            {
                var model = new PhysicalInventoryViewModel();
                AutoMapper.Mapper.Map(PhysicalInventory, model);

                var detailList = PhysicalInventoryRepository.GetAllvwPhysicalInventoryDetail(Id.Value);
                model.DetailList = detailList.Select(item => new PhysicalInventoryDetailViewModel
                {
                    Note                = item.Note,
                    ProductId           = item.ProductId,
                    ProductCode         = item.ProductCode,
                    ProductName         = item.ProductName,
                    PhysicalInventoryId = item.PhysicalInventoryId,
                    QuantityInInventory = item.QuantityInInventory,
                    QuantityRemaining   = item.QuantityRemaining,
                    QuantityDiff        = item.QuantityDiff,
                    CategoryCode        = item.CategoryCode,
                    ExpiryDate          = item.ExpiryDate,
                    LoCode              = item.LoCode
                })
                                   .OrderBy(item => item.CategoryCode)
                                   .ThenBy(item => item.ProductCode)
                                   .ToList();

                return(View(model));
            }

            if (Request.UrlReferrer != null)
            {
                return(Redirect(Request.UrlReferrer.AbsoluteUri));
            }
            return(RedirectToAction("Index"));
        }
Пример #4
0
        public ActionResult Create()
        {
            var model = new PhysicalInventoryViewModel();

            model.Type = PhysicalInventoryType.Product;
            var warehouseList = WarehouseRepository.GetAllWarehouse().Where(x => x.BranchId == Helpers.Common.CurrentUser.BranchId).AsEnumerable()
                                .Select(item => new SelectListItem
            {
                Text  = item.Name,
                Value = item.Id.ToString()
            });

            ViewBag.warehouseList = warehouseList;
            var manufacturer = categoryRepository.GetCategoryByCode("manufacturerList").AsEnumerable()
                               .Select(item => new SelectListItem
            {
                Text  = item.Name,
                Value = item.Value
            });

            ViewBag.manufacturer = manufacturer;
            return(View(model));
        }
Пример #5
0
        public ActionResult Create(PhysicalInventoryViewModel model)
        {
            if (ModelState.IsValid)
            {
                PhysicalInventory PhysicalInventory = new Domain.Sale.Entities.PhysicalInventory();
                AutoMapper.Mapper.Map(model, PhysicalInventory);
                PhysicalInventory.CreatedUserId  = WebSecurity.CurrentUserId;
                PhysicalInventory.CreatedDate    = DateTime.Now;
                PhysicalInventory.ModifiedUserId = WebSecurity.CurrentUserId;
                PhysicalInventory.ModifiedDate   = DateTime.Now;
                PhysicalInventory.IsDeleted      = false;
                PhysicalInventory.IsExchange     = false;
                PhysicalInventory.BranchId       = Helpers.Common.CurrentUser.BranchId;
                List <PhysicalInventoryDetail> PhysicalInventoryDetailList = new List <PhysicalInventoryDetail>();
                if (model.DetailList != null)
                {
                    foreach (var item in model.DetailList)
                    {
                        Inventory inventoryProduct    = InventoryRepository.GetInventoryByWarehouseIdAndProductId(model.WarehouseId.Value, item.ProductId);
                        int       QuantityInInventory = 0;
                        if (inventoryProduct != null)
                        {
                            QuantityInInventory       = inventoryProduct.Quantity.Value;
                            inventoryProduct.Quantity = item.QuantityRemaining;
                            InventoryRepository.UpdateInventory(inventoryProduct);
                        }

                        PhysicalInventoryDetailList.Add(new PhysicalInventoryDetail
                        {
                            CreatedDate         = DateTime.Now,
                            CreatedUserId       = WebSecurity.CurrentUserId,
                            IsDeleted           = false,
                            Note                = item.Note,
                            ProductId           = item.ProductId,
                            QuantityInInventory = QuantityInInventory,
                            QuantityRemaining   = item.QuantityRemaining,
                            QuantityDiff        = item.QuantityRemaining - QuantityInInventory
                        });
                    }
                }

                PhysicalInventoryRepository.InsertPhysicalInventory(PhysicalInventory, PhysicalInventoryDetailList);

                //cập nhật lại mã kiểm kho
                PhysicalInventory.Code = Erp.BackOffice.Helpers.Common.GetOrderNo("InventoryCheck");
                PhysicalInventoryRepository.UpdatePhysicalInventory(PhysicalInventory);
                Erp.BackOffice.Helpers.Common.SetOrderNo("InventoryCheck");
                TempData[Globals.SuccessMessageKey] = App_GlobalResources.Wording.InsertSuccess;
                if (model.Type == PhysicalInventoryType.Product)
                {
                    return(RedirectToAction("Index"));
                }
                else
                {
                    return(RedirectToAction("ListForCard"));
                }
            }

            var warehouseList = WarehouseRepository.GetAllWarehouse().Where(x => x.BranchId == Helpers.Common.CurrentUser.BranchId).AsEnumerable();

            if (model.Type == PhysicalInventoryType.Card)
            {
                warehouseList = warehouseList.Where(x => x.Categories.Contains("CARD"));
            }
            else if (model.Type == PhysicalInventoryType.Gift)
            {
                warehouseList = warehouseList.Where(x => x.Categories.Contains("GIFT"));
            }
            var warehouseSelectList = warehouseList
                                      .Select(item => new SelectListItem
            {
                Text  = item.Name,
                Value = item.Id.ToString()
            });

            ViewBag.warehouseList = warehouseSelectList;
            var manufacturer = categoryRepository.GetCategoryByCode("manufacturerList").AsEnumerable()
                               .Select(item => new SelectListItem
            {
                Text  = item.Name,
                Value = item.Value
            });

            ViewBag.manufacturer = manufacturer;
            return(View(model));
        }
Пример #6
0
 private void PhysicalInventories_OnUnloaded(object sender, RoutedEventArgs e)
 {
     PhysicalInventoryViewModel.CleanUp();
 }
Пример #7
0
        public ActionResult Create(PhysicalInventoryViewModel model)
        {
            if (ModelState.IsValid)
            {
                using (var scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    try
                    {
                        PhysicalInventory PhysicalInventory = new Domain.Sale.Entities.PhysicalInventory();
                        AutoMapper.Mapper.Map(model, PhysicalInventory);
                        PhysicalInventory.CreatedUserId  = WebSecurity.CurrentUserId;
                        PhysicalInventory.CreatedDate    = DateTime.Now;
                        PhysicalInventory.ModifiedUserId = WebSecurity.CurrentUserId;
                        PhysicalInventory.ModifiedDate   = DateTime.Now;
                        PhysicalInventory.IsDeleted      = false;
                        PhysicalInventory.IsExchange     = false;
                        var warehouse = WarehouseRepository.GetWarehouseById(model.WarehouseId.Value);
                        PhysicalInventory.BranchId = warehouse.BranchId;

                        List <PhysicalInventoryDetail> PhysicalInventoryDetailList = new List <PhysicalInventoryDetail>();
                        if (model.DetailList != null)
                        {
                            var list_inventoryProduct = InventoryRepository.GetAllInventory();
                            foreach (var item in model.DetailList)
                            {
                                var inventoryProduct = list_inventoryProduct.Where(x => x.WarehouseId == PhysicalInventory.WarehouseId && x.ProductId == item.ProductId).ToList();
                                if (!string.IsNullOrEmpty(item.LoCode))
                                {
                                    inventoryProduct = inventoryProduct.Where(x => x.LoCode == item.LoCode).ToList();
                                }
                                else
                                {
                                    inventoryProduct = inventoryProduct.Where(x => x.LoCode == null).ToList();
                                }

                                if (item.ExpiryDate == null)
                                {
                                    inventoryProduct = inventoryProduct.Where(x => x.ExpiryDate == null).ToList();
                                }
                                else
                                {
                                    inventoryProduct = inventoryProduct.Where(x => x.ExpiryDate == item.ExpiryDate).ToList();
                                }

                                int QuantityInInventory = 0;
                                if (inventoryProduct.Count() > 0)
                                {
                                    var ii = inventoryProduct.FirstOrDefault();
                                    QuantityInInventory = ii.Quantity.Value;
                                    ii.Quantity         = item.QuantityRemaining;
                                    InventoryRepository.UpdateInventory(ii);
                                }

                                PhysicalInventoryDetailList.Add(new PhysicalInventoryDetail
                                {
                                    CreatedDate         = DateTime.Now,
                                    CreatedUserId       = WebSecurity.CurrentUserId,
                                    IsDeleted           = false,
                                    Note                = item.Note,
                                    ProductId           = item.ProductId,
                                    QuantityInInventory = QuantityInInventory,
                                    QuantityRemaining   = item.QuantityRemaining,
                                    QuantityDiff        = item.QuantityRemaining - QuantityInInventory,
                                    LoCode              = item.LoCode,
                                    ExpiryDate          = item.ExpiryDate
                                });
                            }
                        }

                        PhysicalInventoryRepository.InsertPhysicalInventory(PhysicalInventory, PhysicalInventoryDetailList);

                        //cập nhật lại mã kiểm kho
                        string prefix = Erp.BackOffice.Helpers.Common.GetSetting("prefixOrderNo_InventoryCheck");
                        PhysicalInventory.Code = Erp.BackOffice.Helpers.Common.GetCode(prefix, PhysicalInventory.Id);
                        PhysicalInventoryRepository.UpdatePhysicalInventory(PhysicalInventory);
                        scope.Complete();
                    }
                    catch (DbUpdateException)
                    {
                        return(Content("Fail"));
                    }
                }
                TempData[Globals.SuccessMessageKey] = App_GlobalResources.Wording.InsertSuccess;
                return(RedirectToAction("Index"));
            }

            var warehouseList = WarehouseRepository.GetAllWarehouse().AsEnumerable()
                                .Select(item => new SelectListItem
            {
                Text  = item.Name,
                Value = item.Id.ToString()
            });

            ViewBag.warehouseList = warehouseList;
            var manufacturer = categoryRepository.GetCategoryByCode("manufacturerList").AsEnumerable()
                               .Select(item => new SelectListItem
            {
                Text  = item.Name,
                Value = item.Value
            });

            ViewBag.manufacturer = manufacturer;
            return(View(model));
        }