Exemplo n.º 1
0
        public ActionResult Edit(RePayPointsViewModel model)
        {
            if (ModelState.IsValid)
            {
                if (Request["Submit"] == "Save")
                {
                    var RePayPoints = RePayPointsService.Get(model.Id);
                    AutoMapper.Mapper.Map(model, RePayPoints);
                    SetModifier(RePayPoints, true);
                    RePayPointsService.Update(RePayPoints);

                    TempData[Globals.SuccessMessageKey] = App_GlobalResources.Wording.UpdateSuccess;
                    if (Request["IsPopup"] != null && Request["IsPopup"].ToString().ToLower().Equals("true"))
                    {
                        return(RedirectToAction("_ClosePopup", "Home", new { area = "", FunctionCallback = "ClosePopupAndReloadPage" }));
                    }
                    return(RedirectToAction("Index"));
                }

                return(View(model));
            }

            return(View(model));

            //if (Request.UrlReferrer != null)
            //    return Redirect(Request.UrlReferrer.AbsoluteUri);
            //return RedirectToAction("Index");
        }
Exemplo n.º 2
0
        public ActionResult Archive(RePayPointsViewModel model)
        {
            if (Request["Submit"] == "Save")
            {
                var rePayPoints = RePayPointsService.Get(model.Id);

                //Kiểm tra cho phép sửa chứng từ này hay không
                if (!Helpers.Common.KiemTraNgaySuaChungTu(rePayPoints.CreatedDate.Value))
                {
                    return(RedirectToAction("Detail", new { Id = rePayPoints.Id }));
                }

                //Coi thử đã xuất kho chưa mới cho ghi sổ
                var hasProductOutbound = ProductOutboundRepository.GetAllProductOutbound().Any(item => item.Type == ProductOutboundType.Gift && item.PayPointId == rePayPoints.Id);

                if (!hasProductOutbound)
                {
                    TempData[Globals.FailedMessageKey] = "Chưa lập phiếu xuất kho!";
                    return(RedirectToAction("Detail", new { Id = rePayPoints.Id }));
                }

                if (rePayPoints.IsArchive == false)
                {
                    //Cập nhật đơn hàng
                    rePayPoints.ModifiedUserId = WebSecurity.CurrentUserId;
                    rePayPoints.ModifiedDate   = DateTime.Now;
                    rePayPoints.IsArchive      = true;
                    rePayPoints.Status         = RePayPointsStatus.Complete;
                    RePayPointsService.Update(rePayPoints);
                    RecordPoint(rePayPoints);
                }

                TempData[Globals.SuccessMessageKey] = App_GlobalResources.Wording.ArchiveSuccess;

                //Cảnh báo cập nhật phiếu xuất kho
                if (hasProductOutbound)
                {
                    TempData[Globals.SuccessMessageKey] += "<br/>Đơn quà này đã được xuất kho! Vui lòng kiểm tra lại chứng từ xuất kho để tránh sai xót dữ liệu!";
                }
            }

            return(RedirectToAction("Detail", new { Id = model.Id }));
        }
Exemplo n.º 3
0
        public ActionResult Detail(int?Id)
        {
            var RePayPoints = vwRePayPointsService.Get(Id.Value);

            if (RePayPoints != null && RePayPoints.IsDeleted != true)
            {
                var model = new RePayPointsViewModel();
                AutoMapper.Mapper.Map(RePayPoints, model);
                model.DetailList = new List <RePayPointsDetailViewModel>();
                var listDetail = vwRePayPointsDetailService.GetAllvwRePayPointsDetailByRePayPointId(RePayPoints.Id);
                AutoMapper.Mapper.Map(listDetail, model.DetailList);

                //Lấy danh sách chứng từ liên quan
                model.ListTransactionRelationship = new List <TransactionRelationshipViewModel>();
                var listTransactionRelationship = transactionRepository.GetAllvwTransactionRelationship()
                                                  .Where(item => item.TransactionA == RePayPoints.Code ||
                                                         item.TransactionB == RePayPoints.Code).OrderByDescending(item => item.CreatedDate)
                                                  .ToList();
                AutoMapper.Mapper.Map(listTransactionRelationship, model.ListTransactionRelationship);

                var productOutbound = ProductOutboundRepository.GetAllvwProductOutbound().Where(x => x.Type == ProductOutboundType.Gift && x.PayPointId == RePayPoints.Id).FirstOrDefault();
                if (productOutbound != null)
                {
                    model.ProductOutboundViewModel = new ProductOutboundViewModel();
                    AutoMapper.Mapper.Map(productOutbound, model.ProductOutboundViewModel);
                }
                //Lấy thông tin kiểm tra cho phép sửa chứng từ này hay không
                model.AllowEdit        = Helpers.Common.KiemTraNgaySuaChungTu(model.CreatedDate.Value);
                ViewBag.SuccessMessage = TempData["SuccessMessage"];
                ViewBag.FailedMessage  = TempData["FailedMessage"];
                ViewBag.AlertMessage   = TempData["AlertMessage"];
                return(View(model));
            }
            if (Request.UrlReferrer != null)
            {
                return(Redirect(Request.UrlReferrer.AbsoluteUri));
            }
            return(RedirectToAction("Index"));
        }
Exemplo n.º 4
0
        public ActionResult Edit(int?Id)
        {
            var RePayPoints = RePayPointsService.Get(Id.Value);

            if (RePayPoints != null && RePayPoints.IsDeleted != true)
            {
                var model = new RePayPointsViewModel();
                AutoMapper.Mapper.Map(RePayPoints, model);

                if (model.CreatedUserId != Helpers.Common.CurrentUser.Id && Helpers.Common.CurrentUser.UserTypeId != 1)
                {
                    TempData["FailedMessage"] = "NotOwner";
                    return(RedirectToAction("Index"));
                }

                return(View(model));
            }
            if (Request.UrlReferrer != null)
            {
                return(Redirect(Request.UrlReferrer.AbsoluteUri));
            }
            return(RedirectToAction("Index"));
        }
Exemplo n.º 5
0
        public ActionResult Create(RePayPointsViewModel model)
        {
            if (ModelState.IsValid && model.DetailList.Count != 0)
            {
                RePayPoints rePayPoints = null;
                if (model.Id > 0)
                {
                    rePayPoints = RePayPointsService.Get(model.Id);
                }

                if (rePayPoints != null)
                {
                    #region Cập nhật
                    //Nếu đã ghi sổ rồi thì không được sửa
                    if (rePayPoints.IsArchive == true)
                    {
                        TempData[Globals.FailedMessageKey] = "Đã ghi sổ. không được chỉnh sửa";
                        return(RedirectToAction("Detail", new { Id = rePayPoints.Id }));
                    }

                    //Kiểm tra xem nếu có xuất kho rồi thì return
                    var checkProductOutbound = ProductOutboundRepository.GetAllProductOutbound()
                                               .Where(item => item.Type == ProductOutboundType.Gift && item.PayPointId == rePayPoints.Id).FirstOrDefault();
                    if (checkProductOutbound != null)
                    {
                        TempData[Globals.FailedMessageKey] = "Phiếu xuất kho đã có!";
                        return(RedirectToAction("Detail", new { Id = rePayPoints.Id }));
                    }

                    AutoMapper.Mapper.Map(model, rePayPoints);
                    rePayPoints.ModifiedUserId = WebSecurity.CurrentUserId;
                    rePayPoints.ModifiedDate   = DateTime.Now;
                    rePayPoints.Status         = RePayPointsStatus.Pending;
                    rePayPoints.BranchId       = Helpers.Common.CurrentUser.BranchId;
                    rePayPoints.IsArchive      = false;
                    RePayPointsService.Update(rePayPoints);

                    //Xóa chi tiết cũ và thêm chi tiết mới
                    var listDetail_old = RePayPointsDetailService.GetRePayPointsDetailByPayPointId(rePayPoints.Id).ToList();
                    foreach (var item in listDetail_old)
                    {
                        RePayPointsDetailService.Delete(item);
                    }

                    foreach (var item in model.DetailList)
                    {
                        RePayPointsDetail rePayPointsDetail = new RePayPointsDetail();
                        AutoMapper.Mapper.Map(item, rePayPointsDetail);
                        rePayPointsDetail.RePayPointId   = rePayPoints.Id;
                        rePayPointsDetail.IsDeleted      = false;
                        rePayPointsDetail.CreatedUserId  = WebSecurity.CurrentUserId;
                        rePayPointsDetail.ModifiedUserId = WebSecurity.CurrentUserId;
                        rePayPointsDetail.CreatedDate    = DateTime.Now;
                        rePayPointsDetail.ModifiedDate   = DateTime.Now;
                        RePayPointsDetailService.Create(rePayPointsDetail);
                    }

                    #endregion
                }
                else// Thêm mới
                {
                    #region MyRegion
                    rePayPoints = new RePayPoints();
                    AutoMapper.Mapper.Map(model, rePayPoints);
                    rePayPoints.IsDeleted      = false;
                    rePayPoints.CreatedUserId  = WebSecurity.CurrentUserId;
                    rePayPoints.ModifiedUserId = WebSecurity.CurrentUserId;
                    rePayPoints.CreatedDate    = DateTime.Now;
                    rePayPoints.ModifiedDate   = DateTime.Now;
                    rePayPoints.Status         = RePayPointsStatus.Pending;
                    rePayPoints.BranchId       = Helpers.Common.CurrentUser.BranchId;
                    rePayPoints.IsArchive      = false;
                    RePayPointsService.Create(rePayPoints);
                    //Cập nhật lại mã xuất kho
                    rePayPoints.Code = Erp.BackOffice.Helpers.Common.GetOrderNo("RepayPoints", model.Code);
                    RePayPointsService.Update(rePayPoints);
                    Erp.BackOffice.Helpers.Common.SetOrderNo("RepayPoints");

                    foreach (var item in model.DetailList)
                    {
                        RePayPointsDetail rePayPointsDetail = new RePayPointsDetail();
                        AutoMapper.Mapper.Map(item, rePayPointsDetail);
                        rePayPointsDetail.IsDeleted      = false;
                        rePayPointsDetail.CreatedUserId  = WebSecurity.CurrentUserId;
                        rePayPointsDetail.ModifiedUserId = WebSecurity.CurrentUserId;
                        rePayPointsDetail.CreatedDate    = DateTime.Now;
                        rePayPointsDetail.ModifiedDate   = DateTime.Now;
                        rePayPointsDetail.RePayPointId   = rePayPoints.Id;
                        RePayPointsDetailService.Create(rePayPointsDetail);
                    }

                    //Thêm vào quản lý chứng từ
                    TransactionController.Create(new TransactionViewModel
                    {
                        TransactionModule = "RePayPoints",
                        TransactionCode   = rePayPoints.Code,
                        TransactionName   = "Trả điểm"
                    });
                    #endregion
                }
                //Tạo phiếu nhập, nếu là tự động
                string sale_tu_dong_tao_chung_tu = Erp.BackOffice.Helpers.Common.GetSetting("sale_auto_outbound");
                if (sale_tu_dong_tao_chung_tu == "true")
                {
                    ProductOutboundViewModel productOutboundViewModel = new ProductOutboundViewModel();
                    // var warehouseDefault = WarehouseRepository.GetAllWarehouse().Where(x => x.BranchId == Helpers.Common.CurrentUser.BranchId && x.IsSale == true).FirstOrDefault();

                    //Nếu trong đơn hàng có sản phẩm thì xuất kho
                    if (model.WarehouseSourceId != null)
                    {
                        productOutboundViewModel.PayPointId        = rePayPoints.Id;
                        productOutboundViewModel.PayPointCode      = rePayPoints.Code;
                        productOutboundViewModel.WarehouseSourceId = model.WarehouseSourceId;
                        productOutboundViewModel.Note = "Xuất kho cho đơn trả điểm " + rePayPoints.Code;
                        // lấy các danh sách không Xuất kho
                        var productNoInbound = ProductRepository.GetAllProduct().Where(x => x.Type == ProductType.Gift && x.NoInbound == true).ToList();
                        //Lấy dữ liệu cho chi tiết
                        productOutboundViewModel.DetailList = model.DetailList.Where(x => !productNoInbound.Any(y => y.Id == x.GiftId)).Select(x => new ProductOutboundDetailViewModel
                        {
                            ProductId = x.GiftId,
                            Quantity  = x.Quantity,
                            Price     = 0,
                            Unit      = x.Unit,
                        }).ToList();

                        var productOutbound = ProductOutboundController.CreateFromPayPoint(ProductOutboundRepository, productOutboundViewModel, rePayPoints.Code, TempData);
                        PostController.SavePost(rePayPoints.Id, "RePayPoints", "Xuất kho trả điểm (" + productOutbound.Code + ")");
                    }
                    //Ghi sổ chứng từ bán hàng
                    model.Id = rePayPoints.Id;
                    Archive(model);
                }
                return(RedirectToAction("Detail", new { Id = rePayPoints.Id }));
            }
            return(View(model));
        }
Exemplo n.º 6
0
        public ActionResult Create(int?Id)
        {
            var model = new RePayPointsViewModel();

            model.DetailList = new List <RePayPointsDetailViewModel>();
            if (Id.HasValue && Id > 0)
            {
                #region Cập nhật
                var rePayPoint = RePayPointsService.Get(Id.Value);
                //Nếu đã ghi sổ rồi thì không được sửa
                if (rePayPoint.IsArchive == true)
                {
                    TempData[Globals.FailedMessageKey] = "Đã ghi sổ. không được chỉnh sửa";
                    return(RedirectToAction("Detail", new { Id = rePayPoint.Id }));
                }

                AutoMapper.Mapper.Map(rePayPoint, model);

                var detailList = vwRePayPointsDetailService.GetAllvwRePayPointsDetailByRePayPointId(rePayPoint.Id);
                AutoMapper.Mapper.Map(detailList, model.DetailList);
                #endregion
            }
            else
            {
                //Nhân viên
                string id_default_user = Helpers.Common.GetSetting("id_default_user");
                int    deaultUserId    = string.IsNullOrEmpty(id_default_user) ? 0 : Convert.ToInt32(id_default_user);
                var    deaultUser      = userRepository.GetUserById(deaultUserId);

                if (deaultUser != null)
                {
                    model.SaleId = deaultUser.Id;
                }
                model.TotalPoint        = 0;
                model.WarehouseSourceId = WarehouseRepository.GetAllWarehouse()
                                          .Where(x => x.BranchId == Helpers.Common.CurrentUser.BranchId && x.Categories.Contains("GIFT")).FirstOrDefault()?.Id;
            }
            var productList = ProductRepository.GetAllvwProduct().Where(x => x.Type == "gift" || x.QuantityTotalInventory > 0 || x.NoInbound == true);
            if (model.DetailList != null && model.DetailList.Count > 0)
            {
                foreach (var item in model.DetailList)
                {
                    var product = productList.Where(i => i.Id == item.GiftId).FirstOrDefault();
                    if (product != null)
                    {
                        item.GiftCode = product.Code;
                    }
                    else
                    {
                        item.Id = 0;
                    }
                }
                model.DetailList.RemoveAll(x => x.Id == 0);
                int n = 0;
                foreach (var item in model.DetailList)
                {
                    item.OrderNo = n;
                    n++;
                }
            }
            return(View(model));
        }