/* public Stock GetStockAsset(Guid id, string companyNamed) * { * var stock = _inRequestManager.GetStockAsset(id, companyNamed); * return stock; * }*/ public void ChangeProcessedStatus(Guid inRequestId, Guid userId, string company, IList <StockMap> stockList) { var @entity = _inRequestRepository.Get(inRequestId); var @entityDetails = _inRequestManager.GetEditDetails(inRequestId).ToList(); if (@entity == null) { throw new UserFriendlyException("No se pudo encontrar la solicitud, fue borrada o no existe."); } @entity.Status = InRequestStatus.Processed; @entity.LastModifierUserId = userId; @entity.LastModificationTime = _dateTime.Now; @entity.ProcessedDate = _dateTime.Now; //var stocksList = _inRequestManager.GetStocksList(company); //var stockListCellar = stocksList.Where(a => a.CellarId == @entity.CellarId).ToList(); IList <Movement> @movement = new List <Movement>(); IList <Stock> @updatestocks = new List <Stock>(); IList <Stock> @newstocks = new List <Stock>(); IList <PriceChange> @priceChanges = new List <PriceChange>(); @movement = Movements(@entityDetails, stockList, @entity.CellarId, userId, @entity.Id, company); //var listAsset = _inRequestManager.SearchAsset("", @entity.TypeInRequest,company).ToList(); foreach (var item in @entityDetails) { var stockListCellar = _inRequestManager.GetStocksList(company, entity.CellarId, item.AssetId); var @stockUpdate = stockListCellar.FirstOrDefault(a => a.AssetId == item.AssetId); double priceList = _inRequestManager.GetAssetId(item.AssetId).Price; if (item.Price != priceList) { var @changePrice = PriceChange.Create(item.AssetId, priceList, item.Price, userId, _dateTime.Now, company); @priceChanges.Add(@changePrice); } //var @stockUpdate = stockListCellar.FirstOrDefault(a => a.AssetId == item.AssetId); if (@stockUpdate != null) { @stockUpdate.AssetId = item.AssetId; @stockUpdate.CellarId = @entity.CellarId; @stockUpdate.AddToStock(item.StockAsset, item.Price); @updatestocks.Add(@stockUpdate); } else { var @stock = Stock.Create(@entity.CellarId, item.AssetId, item.StockAsset, item.Price, userId, _dateTime.Now, company); @newstocks.Add(@stock); } } _inRequestManager.ChangeStatus(@entity, @entityDetails, @newstocks, @updatestocks, @movement, @priceChanges); }
public void ChangeProcessedStatus(Guid adjustmentId, Guid userId, string company, IList <StockMap> stockList) { var @entity = _adjustmentRepository.Get(adjustmentId); var @entityDetails = _adjustmentManager.GetEditDetails(adjustmentId).ToList(); if (@entity == null) { throw new UserFriendlyException("No se pudo encontrar la solicitud, fue borrada o no existe."); } @entity.Status = AdjustmentStatus.Processed; @entity.LastModifierUserId = userId; @entity.LastModificationTime = _dateTime.Now; //var stocksList = _adjustmentManager.GetStocksList(company); //var stockListCellar = stocksList.Where(a => a.CellarId == @entity.CellarId).ToList(); IList <Movement> @movement = new List <Movement>(); IList <Stock> @updatestocks = new List <Stock>(); IList <PriceChange> @priceChanges = new List <PriceChange>(); //var listAsset = _adjustmentManager.SearchAsset("", company).ToList(); double stockMovement = 0; @movement = Movements(@entityDetails, stockList, @entity.CellarId.Value, userId, adjustmentId, company); foreach (var item in @entityDetails) { var stockListCellar = _adjustmentManager.GetStocksList(company, entity.CellarId.Value, item.AssetId); double priceList = _adjustmentManager.GetAssetId(item.AssetId).Price; if (item.Price != priceList) { var @changePrice = PriceChange.Create(item.AssetId, priceList, item.Price, userId, _dateTime.Now, company); @priceChanges.Add(@changePrice); } var @stockUpdate = stockListCellar.FirstOrDefault(a => a.AssetId == item.AssetId); if (@stockUpdate.GetStockItemsQty() > item.StockAsset) { stockMovement = @stockUpdate.GetStockItemsQty() - item.StockAsset; @stockUpdate.RemoveFromStock(stockMovement, item.Price); } else { stockMovement = item.StockAsset - @stockUpdate.GetStockItemsQty(); @stockUpdate.AddToStock(stockMovement, item.Price); } @stockUpdate.AssetId = item.AssetId; @stockUpdate.CellarId = @entity.CellarId.Value; @updatestocks.Add(@stockUpdate); } _adjustmentManager.ChangeStatus(@entity, @entityDetails, @updatestocks, @movement, @priceChanges); }