public ActionResult Detail(int?Id) { var Product = ProductRepository.GetvwProductById(Id.Value); if (Product != null && Product.IsDeleted != true) { var model = new ProductViewModel(); AutoMapper.Mapper.Map(Product, model); var inboundDetails = ProductInboundRepository.GetAllvwProductInboundDetailByProductId(Id.Value) .Where(item => item.IsArchive).OrderBy(x => x.ProductInboundId).OrderByDescending(x => x.CreatedDate); var outboundDetails = ProductOutboundRepository.GetAllvwProductOutboundDetailByProductId(Id.Value) .Where(item => item.IsArchive) .OrderBy(x => x.ProductOutboundId) .OrderByDescending(x => x.CreatedDate); ViewBag.inboundDetails = inboundDetails; ViewBag.outboundDetails = outboundDetails; return(View(model)); } if (Request.UrlReferrer != null) { return(Redirect(Request.UrlReferrer.AbsoluteUri)); } return(RedirectToAction("Index")); }
public ActionResult Detail(int?Id, int?WarehouseId, string LoCode, int?day, int?month, int?year) { var Product = ProductRepository.GetvwProductById(Id.Value); if (Product != null && Product.IsDeleted != true) { var model = new ProductViewModel(); AutoMapper.Mapper.Map(Product, model); var inboundDetails = ProductInboundRepository.GetAllvwProductInboundDetailByProductId(Id.Value).AsEnumerable() .Where(item => item.IsArchive && item.LoCode == LoCode); var outboundDetails = ProductOutboundRepository.GetAllvwProductOutboundDetailByProductId(Id.Value).AsEnumerable() .Where(item => item.IsArchive && item.LoCode == LoCode); if (WarehouseId != null && WarehouseId > 0) { inboundDetails = inboundDetails.Where(x => x.WarehouseDestinationId == WarehouseId); outboundDetails = outboundDetails.Where(x => x.WarehouseSourceId == WarehouseId); } if (day != null && month != null && year != null) { inboundDetails = inboundDetails.Where(x => x.ExpiryDate != null && x.ExpiryDate.Value.Day == day && x.ExpiryDate.Value.Month == month && x.ExpiryDate.Value.Year == year); outboundDetails = outboundDetails.Where(x => x.ExpiryDate != null && x.ExpiryDate.Value.Day == day && x.ExpiryDate.Value.Month == month && x.ExpiryDate.Value.Year == year); } else { inboundDetails = inboundDetails.Where(x => x.ExpiryDate == null); outboundDetails = outboundDetails.Where(x => x.ExpiryDate == null); } inboundDetails = inboundDetails.OrderBy(x => x.ProductInboundId); outboundDetails = outboundDetails.OrderBy(x => x.ProductOutboundId); ViewBag.inboundDetails = inboundDetails; ViewBag.outboundDetails = outboundDetails; return(View(model)); } if (Request.UrlReferrer != null) { return(Redirect(Request.UrlReferrer.AbsoluteUri)); } return(RedirectToAction("Index")); }
public ActionResult CheckData(int Id) { var physicalInventory = PhysicalInventoryRepository.GetAllvwPhysicalInventory().Where(item => item.Id == Id).FirstOrDefault(); if (physicalInventory == null) { TempData[Globals.FailedMessageKey] = App_GlobalResources.Wording.NotfoundObject; return(RedirectToAction("Index")); } //Cập nhật lại tồn kho hệ thống đến thời điểm kiểm kê var listDetail = PhysicalInventoryRepository.GetAllPhysicalInventoryDetail(Id).ToList(); foreach (var item in listDetail) { //Số lượng nhập var soLuongNhap = productInboundRepository.GetAllvwProductInboundDetailByProductId(item.ProductId) .Where(x => x.IsArchive == true && x.WarehouseDestinationId == physicalInventory.WarehouseId).Sum(x => x.Quantity); //Số lượng xuất var soLuongXuat = productOutboundRepository.GetAllvwProductOutboundDetailByProductId(item.ProductId) .Where(x => x.IsArchive == true && x.WarehouseSourceId == physicalInventory.WarehouseId).Sum(x => x.Quantity); //Cập nhật lại item.QuantityInInventory = (soLuongNhap - soLuongXuat); item.QuantityDiff = item.QuantityRemaining - item.QuantityInInventory; PhysicalInventoryRepository.UpdatePhysicalInventoryDetail(item); } //Tách dữ liệu cần nhập/xuất kiểm kê List <ProductOutboundDetail> outboundDetails = new List <ProductOutboundDetail>(); List <ProductInboundDetail> inboundDetails = new List <ProductInboundDetail>(); 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), } ); } 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.Value, ProductId = product.Id, Quantity = Math.Abs(item.QuantityDiff), } ); } } //Cập nhật phiếu xuất if (outboundDetails.Count != 0) { var outbound = productOutboundRepository.GetAllProductOutbound().Where(item => item.Code == physicalInventory.ProductOutboundCode).FirstOrDefault(); if (outbound != null) { //Xóa chi tiết xuất cũ var outboundDetails_old = productOutboundRepository.GetAllProductOutboundDetailByOutboundId(outbound.Id).Select(item => item.Id).ToList(); foreach (var item in outboundDetails_old) { productOutboundRepository.DeleteProductOutboundDetail(item); } //Thêm chi tiết xuất mới 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 tham chiếu trong chi tiết kiểm kê 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); } } } //Cập nhật phiếu nhập if (inboundDetails.Count != 0) { var inbound = productInboundRepository.GetAllProductInbound().Where(item => item.Code == physicalInventory.ProductInboundCode).FirstOrDefault(); //Xóa chi tiết nhập cũ var inboundDetails_old = productInboundRepository.GetAllProductInboundDetailByInboundId(inbound.Id).Select(item => item.Id).ToList(); foreach (var item in inboundDetails_old) { productInboundRepository.DeleteProductInboundDetail(item); } //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 tham chiếu trong chi tiết kiểm kê 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); } } TempData[Globals.SuccessMessageKey] = App_GlobalResources.Wording.Success; return(RedirectToAction("Detail", new { Id = physicalInventory.Id })); }