Exemplo n.º 1
0
        public ActionResult Edit(int?Id)
        {
            var Product = productRepository.GetProductById(Id.Value);

            if (Product != null && Product.IsDeleted != true)
            {
                var model = new ProductViewModel();
                AutoMapper.Mapper.Map(Product, model);
                model.Image_Name = Erp.BackOffice.Helpers.Common.KiemTraTonTaiHinhAnh(Product.Image_Name, "product-image-folder", "product");
                string productId    = "," + model.Id + ",";
                var    supplierList = SupplierRepository.GetAllSupplier().AsEnumerable().Where(item => ("," + item.ProductIdOfSupplier + ",").Contains(productId) == true).ToList();
                ViewBag.supplierList = supplierList;

                return(View(model));
            }

            if (Request.UrlReferrer != null)
            {
                return(Redirect(Request.UrlReferrer.AbsoluteUri));
            }
            return(RedirectToAction("Index"));
        }
Exemplo n.º 2
0
        public ActionResult Create(RequestInboundViewModel model)
        {
            if (ModelState.IsValid && model.DetailList.Count != 0)
            {
                var requestInbound = new Domain.Sale.Entities.RequestInbound();
                using (var scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    try
                    {
                        AutoMapper.Mapper.Map(model, requestInbound);
                        if (model.Id > 0)
                        {
                        }
                        else
                        {
                            requestInbound.IsDeleted      = false;
                            requestInbound.CreatedUserId  = WebSecurity.CurrentUserId;
                            requestInbound.ModifiedUserId = WebSecurity.CurrentUserId;
                            requestInbound.CreatedDate    = DateTime.Now;
                            requestInbound.ModifiedDate   = DateTime.Now;
                            var branch = WarehouseRepository.GetWarehouseById(requestInbound.WarehouseDestinationId.Value);
                            requestInbound.BranchId = branch.BranchId;
                            requestInbound.Status   = "new";
                        }
                        //duyệt qua danh sách sản phẩm mới xử lý tình huống user chọn 2 sản phầm cùng id
                        List <Domain.Sale.Entities.RequestInboundDetail> listNewCheckSameId = new List <Domain.Sale.Entities.RequestInboundDetail>();
                        foreach (var group in model.DetailList.GroupBy(x => x.ProductId))
                        {
                            var product = ProductRepository.GetProductById(group.Key.Value);

                            listNewCheckSameId.Add(new Domain.Sale.Entities.RequestInboundDetail
                            {
                                ProductId      = group.Key,
                                Quantity       = group.Sum(x => x.Quantity),
                                Unit           = product.Unit,
                                Price          = product.PriceOutbound,
                                IsDeleted      = false,
                                CreatedUserId  = WebSecurity.CurrentUserId,
                                ModifiedUserId = WebSecurity.CurrentUserId,
                                CreatedDate    = DateTime.Now,
                                ModifiedDate   = DateTime.Now,
                            });
                        }

                        requestInbound.TotalAmount = listNewCheckSameId.Sum(x => x.Price * x.Quantity);

                        if (model.Id > 0)
                        {
                            requestInbound.Status = "new";
                            RequestInboundRepository.UpdateRequestInbound(requestInbound);
                            var listDetail = RequestInboundRepository.GetAllRequestInboundDetailsByInvoiceId(requestInbound.Id).ToList();
                            //xóa danh sách dữ liệu cũ dưới database
                            RequestInboundRepository.DeleteRequestInboundDetail(listDetail);
                            //thêm mới toàn bộ database
                            foreach (var item in listNewCheckSameId)
                            {
                                item.RequestInboundId = requestInbound.Id;
                                RequestInboundRepository.InsertRequestInboundDetail(item);
                            }
                            //lấy thông tin chi nhánh gửi yêu cầu hiện vào notification
                            var branchName = branchRepository.GetBranchById(model.BranchId.Value);

                            //Apply business process flow
                            Crm.Controllers.ProcessController.Run("RequestInbound", "Create", requestInbound.Id, requestInbound.ModifiedUserId, null, requestInbound);
                        }
                        else
                        {
                            RequestInboundRepository.InsertRequestInbound(requestInbound, listNewCheckSameId);

                            //cập nhật lại mã hóa đơn
                            string prefix = Erp.BackOffice.Helpers.Common.GetSetting("prefixOrderNo_RequestInbound");
                            requestInbound.Code = Erp.BackOffice.Helpers.Common.GetCode(prefix, requestInbound.Id);
                            RequestInboundRepository.UpdateRequestInbound(requestInbound);

                            var branchName = branchRepository.GetBranchById(requestInbound.BranchId.Value);

                            //run process task
                            Crm.Controllers.ProcessController.Run("RequestInbound", "Create", requestInbound.Id, requestInbound.ModifiedUserId, null, requestInbound, requestInbound.BranchId.Value.ToString());
                        }
                        scope.Complete();
                    }
                    catch (DbUpdateException)
                    {
                        TempData[Globals.FailedMessageKey] = App_GlobalResources.Wording.Error;
                        return(View(model));
                    }
                }
                return(RedirectToAction("Detail", new { Id = requestInbound.Id }));
            }
            return(View(model));
        }
Exemplo n.º 3
0
        public ActionResult Edit(ServiceViewModel model)
        {
            if (ModelState.IsValid)
            {
                if (Request["Submit"] == "Save")
                {
                    var Service = ServiceRepository.GetProductById(model.Id);
                    AutoMapper.Mapper.Map(model, Service);
                    Service.ModifiedUserId = WebSecurity.CurrentUserId;
                    Service.ModifiedDate   = DateTime.Now;
                    Service.Type           = "service";
                    var path     = Helpers.Common.GetSetting("service-image-folder");
                    var filepath = System.Web.HttpContext.Current.Server.MapPath("~" + path);
                    if (Request.Files["file-image"] != null)
                    {
                        var file = Request.Files["file-image"];
                        if (file.ContentLength > 0)
                        {
                            FileInfo fi = new FileInfo(Server.MapPath("~" + path) + Service.Image_Name);
                            if (fi.Exists)
                            {
                                fi.Delete();
                            }

                            string image_name = "service_" + Helpers.Common.ChuyenThanhKhongDau(Regex.Replace(Service.Name, @"\s+", "_")) + "." + file.FileName.Split('.').Last();
                            bool   isExists   = System.IO.Directory.Exists(filepath);
                            if (!isExists)
                            {
                                System.IO.Directory.CreateDirectory(filepath);
                            }
                            file.SaveAs(filepath + image_name);
                            Service.Image_Name = image_name;
                        }
                    }
                    if (model.IsCombo == true)
                    {
                        var q = serviceComboRepository.GetAllServiceCombo().Where(x => x.ComboId == Service.Id).ToList();
                        ServiceRepository.DeleteServiceCombo(q);
                        if (model.DetailList != null)
                        {
                            foreach (var item in model.DetailList)
                            {
                                var serviceCombo = new ServiceCombo();
                                serviceCombo.IsDeleted      = false;
                                serviceCombo.CreatedUserId  = WebSecurity.CurrentUserId;
                                serviceCombo.ModifiedUserId = WebSecurity.CurrentUserId;
                                serviceCombo.AssignedUserId = WebSecurity.CurrentUserId;
                                serviceCombo.CreatedDate    = DateTime.Now;
                                serviceCombo.ModifiedDate   = DateTime.Now;
                                serviceCombo.ComboId        = Service.Id;
                                serviceCombo.Quantity       = item.Quantity;
                                serviceCombo.ServiceId      = item.ServiceId;
                                serviceComboRepository.InsertServiceCombo(serviceCombo);
                            }
                        }
                    }
                    else
                    {
                        var q = serviceReminderGroupRepository.GetAllServiceReminderGroup().Where(x => x.ServiceId == Service.Id).ToList();
                        serviceReminderGroupRepository.DeleteServiceReminderGroupList(q);

                        if (model.ReminderList != null)
                        {
                            foreach (var item in model.ReminderList)
                            {
                                var reminder = new ServiceReminderGroup();
                                reminder.IsDeleted         = false;
                                reminder.CreatedUserId     = WebSecurity.CurrentUserId;
                                reminder.ModifiedUserId    = WebSecurity.CurrentUserId;
                                reminder.AssignedUserId    = WebSecurity.CurrentUserId;
                                reminder.CreatedDate       = DateTime.Now;
                                reminder.ModifiedDate      = DateTime.Now;
                                reminder.ServiceId         = Service.Id;
                                reminder.ServiceReminderId = item.ServiceReminderId;
                                serviceReminderGroupRepository.InsertServiceReminderGroup(reminder);
                            }
                        }
                    }
                    //tạo hoặc cập nhật đặc tính động cho sản phẩm nếu có danh sách đặc tính động truyền vào và đặc tính đó phải có giá trị
                    ObjectAttributeController.CreateOrUpdateForObject(Service.Id, model.AttributeValueList);

                    ServiceRepository.UpdateService(Service);

                    if (string.IsNullOrEmpty(Request["IsPopup"]) == false)
                    {
                        return(RedirectToAction("Edit", new { Id = model.Id, IsPopup = Request["IsPopup"] }));
                    }
                    TempData[Globals.SuccessMessageKey] = App_GlobalResources.Wording.UpdateSuccess;
                    return(RedirectToAction("Index"));
                }

                return(View(model));
            }

            return(View(model));

            //if (Request.UrlReferrer != null)
            //    return Redirect(Request.UrlReferrer.AbsoluteUri);
            //return RedirectToAction("Index");
        }
Exemplo n.º 4
0
        public ActionResult Exchange(int Id)
        {
            var PhysicalInventory = PhysicalInventoryRepository.GetvwPhysicalInventoryById(Id);
            var model             = new PhysicalInventory();

            if (PhysicalInventory == null)
            {
                TempData[Globals.FailedMessageKey] = App_GlobalResources.Wording.NotfoundObject;
                return(RedirectToAction("Index"));
            }
            using (var scope = new TransactionScope(TransactionScopeOption.Required))
            {
                try
                {
                    AutoMapper.Mapper.Map(PhysicalInventory, model);
                    List <ProductOutboundDetail> outboundDetails = new List <ProductOutboundDetail>();
                    List <ProductInboundDetail>  inboundDetails  = new List <ProductInboundDetail>();
                    var outbounds = productOutboundRepository.GetAllProductOutbound().Where(item => item.Code == PhysicalInventory.ProductOutboundCode);
                    if (outbounds.Count() > 0)
                    {
                        //Xóa chi tiết xuất cũ
                        var outboundDetails_old = productOutboundRepository.GetAllProductOutboundDetailByOutboundId(outbounds.FirstOrDefault().Id).Select(item => item.Id).ToList();
                        foreach (var item in outboundDetails_old)
                        {
                            productOutboundRepository.DeleteProductOutboundDetail(item);
                        }
                        productOutboundRepository.DeleteProductOutbound(outbounds.FirstOrDefault().Id);
                    }
                    var inbounds = productInboundRepository.GetAllProductInbound().Where(item => item.Code == PhysicalInventory.ProductInboundCode);
                    if (inbounds.Count() > 0)
                    {
                        //Xóa chi tiết nhập cũ
                        var inboundDetails_old = productInboundRepository.GetAllProductInboundDetailByInboundId(inbounds.FirstOrDefault().Id).Select(item => item.Id).ToList();
                        foreach (var item in inboundDetails_old)
                        {
                            productInboundRepository.DeleteProductInboundDetail(item);
                        }
                        productInboundRepository.DeleteProductInbound(inbounds.FirstOrDefault().Id);
                    }

                    var listDetail = PhysicalInventoryRepository.GetAllPhysicalInventoryDetail(Id).Where(x => x.QuantityInInventory != x.QuantityRemaining).ToList();
                    foreach (var item in listDetail)
                    {
                        var product = ProductRepository.GetProductById(item.ProductId);

                        if (item.QuantityDiff < 0) //Chênh lệch dương thì thuộc về xuất
                        {
                            outboundDetails.Add(
                                new ProductOutboundDetail
                            {
                                IsDeleted      = false,
                                CreatedDate    = DateTime.Now,
                                CreatedUserId  = Helpers.Common.CurrentUser.Id,
                                ModifiedDate   = DateTime.Now,
                                ModifiedUserId = Helpers.Common.CurrentUser.Id,
                                Price          = product.PriceOutbound,
                                ProductId      = product.Id,
                                Quantity       = Math.Abs(item.QuantityDiff),
                                ExpiryDate     = item.ExpiryDate,
                                LoCode         = item.LoCode
                            }
                                );
                        }
                        else if (item.QuantityDiff > 0) //Chênh lệch âm thì thuộc về nhập
                        {
                            inboundDetails.Add(
                                new ProductInboundDetail
                            {
                                IsDeleted      = false,
                                CreatedDate    = DateTime.Now,
                                CreatedUserId  = Helpers.Common.CurrentUser.Id,
                                ModifiedDate   = DateTime.Now,
                                ModifiedUserId = Helpers.Common.CurrentUser.Id,
                                Price          = product.PriceInbound,
                                ProductId      = product.Id,
                                Quantity       = Math.Abs(item.QuantityDiff),
                                LoCode         = item.LoCode,
                                ExpiryDate     = item.ExpiryDate
                            }
                                );
                        }
                    }

                    if (outboundDetails.Count != 0)
                    {
                        var outbound = new ProductOutbound
                        {
                            IsDeleted           = false,
                            CreatedDate         = DateTime.Now,
                            CreatedUserId       = Helpers.Common.CurrentUser.Id,
                            ModifiedDate        = DateTime.Now,
                            ModifiedUserId      = Helpers.Common.CurrentUser.Id,
                            BranchId            = model.BranchId,
                            IsDone              = true,
                            Type                = "PhysicalInventory",
                            TotalAmount         = outboundDetails.Sum(x => x.Quantity * x.Price),
                            WarehouseSourceId   = PhysicalInventory.WarehouseId,
                            PhysicalInventoryId = PhysicalInventory.Id,
                            Note                = "Xuất kho kiểm kê"
                        };

                        productOutboundRepository.InsertProductOutbound(outbound);

                        foreach (var item in outboundDetails)
                        {
                            item.ProductOutboundId = outbound.Id;
                            item.IsDeleted         = false;
                            item.CreatedUserId     = WebSecurity.CurrentUserId;
                            item.ModifiedUserId    = WebSecurity.CurrentUserId;
                            item.CreatedDate       = DateTime.Now;
                            item.ModifiedDate      = DateTime.Now;
                            productOutboundRepository.InsertProductOutboundDetail(item);
                        }

                        //cập nhật lại mã xuất kho
                        string prefix = Erp.BackOffice.Helpers.Common.GetSetting("prefixOrderNo_Outbound");
                        outbound.Code = Erp.BackOffice.Helpers.Common.GetCode(prefix, outbound.Id);
                        productOutboundRepository.UpdateProductOutbound(outbound);

                        foreach (var item in listDetail.Where(x => x.QuantityDiff < 0))
                        {
                            item.ModifiedDate     = DateTime.Now;
                            item.ModifiedUserId   = Helpers.Common.CurrentUser.Id;
                            item.ReferenceVoucher = outbound.Code;
                            PhysicalInventoryRepository.UpdatePhysicalInventoryDetail(item);
                        }
                    }

                    if (inboundDetails.Count != 0)
                    {
                        var inbound = new ProductInbound
                        {
                            IsDeleted              = false,
                            CreatedDate            = DateTime.Now,
                            CreatedUserId          = Helpers.Common.CurrentUser.Id,
                            ModifiedDate           = DateTime.Now,
                            ModifiedUserId         = Helpers.Common.CurrentUser.Id,
                            BranchId               = model.BranchId,
                            IsDone                 = true,
                            Type                   = "PhysicalInventory",
                            TotalAmount            = inboundDetails.Sum(x => x.Quantity * x.Price),
                            WarehouseDestinationId = PhysicalInventory.WarehouseId,
                            PhysicalInventoryId    = PhysicalInventory.Id,
                            Note                   = "Nhập kho kiểm kê"
                        };

                        productInboundRepository.InsertProductInbound(inbound);

                        //Thêm chi tiết phiếu nhập
                        foreach (var item in inboundDetails)
                        {
                            item.ProductInboundId = inbound.Id;
                            item.IsDeleted        = false;
                            item.CreatedUserId    = WebSecurity.CurrentUserId;
                            item.ModifiedUserId   = WebSecurity.CurrentUserId;
                            item.CreatedDate      = DateTime.Now;
                            item.ModifiedDate     = DateTime.Now;
                            productInboundRepository.InsertProductInboundDetail(item);
                        }

                        //cập nhật lại mã xuất kho
                        string prefix = Erp.BackOffice.Helpers.Common.GetSetting("prefixOrderNo_Inbound");
                        inbound.Code = Erp.BackOffice.Helpers.Common.GetCode(prefix, inbound.Id);
                        productInboundRepository.UpdateProductInbound(inbound);

                        foreach (var item in listDetail.Where(x => x.QuantityDiff > 0))
                        {
                            item.ModifiedDate     = DateTime.Now;
                            item.ModifiedUserId   = Helpers.Common.CurrentUser.Id;
                            item.ReferenceVoucher = inbound.Code;
                            PhysicalInventoryRepository.UpdatePhysicalInventoryDetail(item);
                        }
                    }

                    model.IsExchange     = true;
                    model.ModifiedDate   = DateTime.Now;
                    model.ModifiedUserId = Helpers.Common.CurrentUser.Id;
                    PhysicalInventoryRepository.UpdatePhysicalInventory(model);
                    scope.Complete();
                }
                catch (DbUpdateException)
                {
                    return(Content("Fail"));
                }
            }
            TempData[Globals.SuccessMessageKey] = App_GlobalResources.Wording.Success;
            return(RedirectToAction("Detail", new { Id = PhysicalInventory.Id }));
        }