public decimal GetConsumption() { if (PhysicalInventory == null) { return(GetPredictedConsumption()); } return((InStock + Purchase) - PhysicalInventory.GetValueOrDefault(0)); }
public ProductCountRepository(string inventoryRef, string bin, string user) { _inventoryRef = _dataContext.PhysicalInventories.Single(p => p.Code.Equals(inventoryRef)); this.Bin = bin; _user = user; }
public ProductCount(PhysicalInventory inventoryRef, Item item, string bin, string user) { _currentBin = bin; _currentUser = user; _item = item; _inventoryRef = inventoryRef; this.Aliases = new List <string>(); }
// Use this for initialization void Start() { inv = inventory.GetComponent <PhysicalInventory>(); _timers = new List <Image>() { RadialTimer1, RadialTimer2, RadialTimer3 }; }
public BinUpdateService(string inventoryRef) { _inventoryRef = _dataContext.PhysicalInventories.Single(p => p.Code.Equals(inventoryRef)); }
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 })); }