public IResult <IQueryable <IInventoryTransactionReturn> > GetInventoryTransactions(string lotKey) { var lotKeyResult = KeyParserHelper.ParseResult <ILotKey>(lotKey); if (!lotKeyResult.Success) { return(lotKeyResult.ConvertTo <IQueryable <IInventoryTransactionReturn> >()); } var parsedLotKey = lotKeyResult.ResultingObject.ToLotKey(); var predicate = InventoryTransactionPredicates.BySourceLot(parsedLotKey); var select = InventoryTransactionProjectors.Select(_inventoryUnitOfWork); var query = _inventoryUnitOfWork.InventoryTransactionsRepository.Filter(predicate).Select(select); var pickedPredicate = PickedInventoryItemPredicates.FilterByLotKey(parsedLotKey); var pickedSelect = PickedInventoryItemProjectors.SelectTransaction(_inventoryUnitOfWork); var pickedResults = _inventoryUnitOfWork.ProductionBatchRepository .Filter(b => new[] { b.Production.Results }.All(r => r == null)) .AsExpandable() .SelectMany(b => b.Production.PickedInventory.Items .Where(i => pickedPredicate.Invoke(i)) .Select(i => pickedSelect.Invoke(i, b))); var results = query.ToList <IInventoryTransactionReturn>().Concat(pickedResults).AsQueryable(); return(new SuccessResult <IQueryable <IInventoryTransactionReturn> >(results)); }
protected IResult <ChileMaterialsReceived> Set(ChileMaterialsReceived received, ChileProduct chileProduct, ISetChileMaterialsReceivedParameters parameters, Employee employee, DateTime timeStamp) { if (received.ChileProductId != chileProduct.Id) { if (MaterialsReceivedUnitOfWork.PickedInventoryItemRepository.Filter(PickedInventoryItemPredicates.FilterByLotKey(received)).Any()) { return(new InvalidResult <ChileMaterialsReceived>(null, string.Format(UserMessages.LotHasExistingPickedInventory, received.ToLotKey()))); } } var previousTreatment = received.ToInventoryTreatmentKey(); var treatment = MaterialsReceivedUnitOfWork.InventoryTreatmentRepository.FindByKey(parameters.TreatmentKey); if (treatment == null) { return(new InvalidResult <ChileMaterialsReceived>(null, string.Format(UserMessages.InventoryTreatmentNotFound, parameters.TreatmentKey))); } var supplier = MaterialsReceivedUnitOfWork.CompanyRepository.FindByKey(parameters.SupplierKey, c => c.CompanyTypes); if (supplier == null) { return(new InvalidResult <ChileMaterialsReceived>(null, string.Format(UserMessages.SupplierCompanyNotFound, parameters.SupplierKey))); } if (parameters.ChileMaterialsReceivedType == ChileMaterialsReceivedType.Dehydrated && supplier.CompanyTypes.All(c => c.CompanyTypeEnum != CompanyType.Dehydrator)) { return(new InvalidResult <ChileMaterialsReceived>(null, string.Format(UserMessages.CompanyNotOfType, parameters.SupplierKey, CompanyType.Dehydrator))); } received.EmployeeId = employee.EmployeeId; received.TimeStamp = timeStamp; received.ChileMaterialsReceivedType = parameters.ChileMaterialsReceivedType; received.DateReceived = parameters.DateReceived; received.LoadNumber = parameters.LoadNumber; received.ChileLot.Lot.PurchaseOrderNumber = parameters.PurchaseOrder; received.ChileLot.Lot.ShipperNumber = parameters.ShipperNumber; received.TreatmentId = treatment.Id; received.ChileProductId = chileProduct.Id; received.ChileLot.ChileProductId = chileProduct.Id; received.Supplier = supplier; received.SupplierId = supplier.Id; var setItemsResult = SetItems(received, parameters.Items, previousTreatment, employee, timeStamp); if (!setItemsResult.Success) { return(setItemsResult.ConvertTo <ChileMaterialsReceived>()); } return(new SuccessResult <ChileMaterialsReceived>(received)); }
protected IResult <ChileLotProduction> SetMillAndWetdown <TParams>(ChileLotProduction millAndWetdown, SetMillAndWetdownParameters <TParams> parameters, DateTime timestamp, IEmployeeKey employee) where TParams : ISetMillAndWetdownParameters { millAndWetdown.ProductionType = ProductionType.MillAndWetdown; millAndWetdown.EmployeeId = employee.EmployeeKey_Id; millAndWetdown.TimeStamp = timestamp; millAndWetdown.Results.EmployeeId = employee.EmployeeKey_Id; millAndWetdown.Results.TimeStamp = timestamp; millAndWetdown.Results.ProductionLineLocationId = parameters.ProductionLineKey.LocationKey_Id; millAndWetdown.Results.ShiftKey = parameters.Params.ShiftKey; millAndWetdown.Results.ProductionBegin = parameters.Params.ProductionBegin; millAndWetdown.Results.ProductionEnd = parameters.Params.ProductionEnd; var lotKey = new LotKey(millAndWetdown); if (!parameters.ChileProductKey.Equals(millAndWetdown.ResultingChileLot)) { var chileProduct = ProductionUnitOfWork.ChileProductRepository.FindByKey(parameters.ChileProductKey); if (chileProduct == null) { return(new InvalidResult <ChileLotProduction>(null, string.Format(UserMessages.ChileProductNotFound, parameters.ChileProductKey))); } if (chileProduct.ChileState.ToLotType() != millAndWetdown.ResultingChileLot.ChileProduct.ChileState.ToLotType()) { return(new InvalidResult <ChileLotProduction>(null, UserMessages.ChileProductDifferentLotType)); } if (ProductionUnitOfWork.PickedInventoryItemRepository.Filter(PickedInventoryItemPredicates.FilterByLotKey(lotKey)).Any()) { return(new InvalidResult <ChileLotProduction>(null, string.Format(UserMessages.LotHasExistingPickedInventory, lotKey))); } millAndWetdown.ResultingChileLot.ChileProductId = parameters.ChileProductKey.ChileProductKey_ProductId; } var pickedInventoryItemModifications = PickedInventoryHelper.CreateModifyPickedInventoryItemParameters(millAndWetdown.PickedInventory, parameters.PickedItems); var validationResults = PickedInventoryValidator.ForMillAndWetdown.ValidateItems(ProductionUnitOfWork.InventoryRepository, pickedInventoryItemModifications.Where(i => i.DeltaQuantity > 0).Select(i => i.InventoryKey)); if (!validationResults.Success) { return(validationResults.ConvertTo <ChileLotProduction>()); } var modifyPickedResult = new ModifyPickedInventoryItemsCommand(ProductionUnitOfWork).Execute(millAndWetdown, pickedInventoryItemModifications); if (!modifyPickedResult.Success) { return(modifyPickedResult.ConvertTo <ChileLotProduction>()); } millAndWetdown.PickedInventory.Archived = true; var inventoryModifications = pickedInventoryItemModifications.Select(i => i.ToModifySourceInventoryParameters()).ToList(); var setResults = new SetLotProductionResultItemsCommand(ProductionUnitOfWork).Execute(millAndWetdown.Results, parameters.ResultItems, ref inventoryModifications); if (!setResults.Success) { return(setResults.ConvertTo <ChileLotProduction>()); } var transaction = new InventoryTransactionParameters(employee, timestamp, InventoryTransactionType.CreatedMillAndWetdown, lotKey, millAndWetdown); var modifyInventoryResult = new ModifyInventoryCommand(ProductionUnitOfWork).Execute(inventoryModifications, transaction); if (!modifyInventoryResult.Success) { return(modifyInventoryResult.ConvertTo <ChileLotProduction>()); } return(new SuccessResult <ChileLotProduction>(millAndWetdown)); }
private IResult <List <LotData> > GetLotData(params LotKey[] lotKeys) { var lotPredicate = lotKeys.Aggregate(PredicateBuilder.False <Lot>(), (c, n) => c.Or(n.FindByPredicate)).ExpandAll(); var lots = _lotUnitOfWork.LotRepository .Filter(lotPredicate, l => l.ChileLot.ChileProduct.ProductAttributeRanges.Select(r => r.AttributeName), l => l.Inventory.Select(i => i.Treatment), l => l.Attributes.Select(a => a.AttributeName), l => l.LotDefects.Select(d => d.Resolution), l => l.AttributeDefects.Select(d => d.LotDefect.Resolution)) .ToList(); var lotsReference = lots.ToList(); var missingKeys = lotKeys.Where(k => lotsReference.RemoveAll(k.Equals) < 1).ToList(); if (missingKeys.Any()) { return(new InvalidResult <List <LotData> >(null, string.Format(UserMessages.LotNotFound, missingKeys.First()))); } var pickedPredicate = lotKeys .Aggregate(PredicateBuilder.False <PickedInventoryItem>(), (c, n) => c.Or(PickedInventoryItemPredicates.FilterByLotKey(n))) .And(i => !i.PickedInventory.Archived).ExpandAll(); var pickedInventoryItems = _lotUnitOfWork.PickedInventoryItemRepository.Filter(pickedPredicate, i => i.PickedInventory, i => i.Treatment) .ToList() .GroupBy(i => i.ToLotKey()) .ToDictionary(g => g.Key, g => g.ToList()); var results = lots.Select(l => { var lotKey = l.ToLotKey(); List <PickedInventoryItem> picked; if (!pickedInventoryItems.TryGetValue(lotKey, out picked)) { picked = new List <PickedInventoryItem>(); } return(new LotData { Lot = l, Picked = picked, }); }).ToList(); return(new SuccessResult <List <LotData> >(results)); }
internal IResult <List <PickedInventoryItem> > Execute(IPickedInventoryKey pickedInventoryKey, IEnumerable <ModifyPickedInventoryItemParameters> items) { if (pickedInventoryKey == null) { throw new ArgumentNullException("pickedInventoryKey"); } if (items == null) { throw new ArgumentNullException("items"); } var newItems = new List <PickedInventoryItem>(); foreach (var item in items) { if (item.PickedInventoryItemKey != null) { var notPendingResult = _unitOfWorkHelper.EntityHasNoPendingChanges(item.PickedInventoryItemKey, item.PickedInventoryItemKey); if (!notPendingResult.Success) { return(notPendingResult.ConvertTo <List <PickedInventoryItem> >()); } var pickedItem = _pickedInventoryUnitOfWork.PickedInventoryItemRepository.FindByKey(item.PickedInventoryItemKey); if (pickedItem == null) { return(new InvalidResult <List <PickedInventoryItem> >(null, string.Format(UserMessages.PickedInventoryItemNotFound, item.PickedInventoryItemKey.KeyValue))); } if (pickedItem.CurrentLocationId != pickedItem.FromLocationId) { return(new InvalidResult <List <PickedInventoryItem> >(null, string.Format(UserMessages.PickedInventoryItemNotInOriginalLocation, new PickedInventoryItemKey(pickedItem).KeyValue))); } pickedItem.Quantity = item.NewQuantity; pickedItem.CurrentLocationId = item.CurrentLocationKey.LocationKey_Id; pickedItem.CustomerLotCode = item.CustomerLotCode; pickedItem.CustomerProductCode = item.CustomerProductCode; if (pickedItem.Quantity < 0) { return(new InvalidResult <List <PickedInventoryItem> >(null, string.Format(UserMessages.QuantityForPickedCannotBeNegative, item.PickedInventoryItemKey.KeyValue))); } if (pickedItem.Quantity == 0) { _pickedInventoryUnitOfWork.PickedInventoryItemRepository.Remove(pickedItem); } else { newItems.Add(pickedItem); } } else { if (item.NewQuantity <= 0) { return(new InvalidResult <List <PickedInventoryItem> >(null, string.Format(UserMessages.QuantityForPickingFromInventoryMustBeGreaterThanZero, item.InventoryKey.KeyValue))); } var newSequence = _unitOfWorkHelper.GetNextSequence(PickedInventoryItemPredicates.FilterByPickedInventoryKey(pickedInventoryKey), i => i.ItemSequence); var newPickedInventoryItem = new PickedInventoryItem { DateCreated = pickedInventoryKey.PickedInventoryKey_DateCreated, Sequence = pickedInventoryKey.PickedInventoryKey_Sequence, ItemSequence = newSequence, LotDateCreated = item.InventoryKey.LotKey_DateCreated, LotDateSequence = item.InventoryKey.LotKey_DateSequence, LotTypeId = item.InventoryKey.LotKey_LotTypeId, PackagingProductId = item.InventoryKey.PackagingProductKey_ProductId, TreatmentId = item.InventoryKey.InventoryTreatmentKey_Id, ToteKey = item.InventoryKey.InventoryKey_ToteKey, FromLocationId = item.InventoryKey.LocationKey_Id, CurrentLocationId = item.CurrentLocationKey.LocationKey_Id, CustomerLotCode = item.CustomerLotCode, CustomerProductCode = item.CustomerProductCode, Quantity = item.NewQuantity }; newItems.Add(_pickedInventoryUnitOfWork.PickedInventoryItemRepository.Add(newPickedInventoryItem)); } } return(new SuccessResult <List <PickedInventoryItem> >(newItems)); }
internal IResult Execute(PickedInventoryKey pickedInventoryKey, List <ModifySalesOrderPickedInventoryItemParameters> items) { if (items == null) { throw new ArgumentNullException("items"); } foreach (var item in items) { if (item.SalesOrderPickedItemKey != null) { var notPendingResult = new EFUnitOfWorkHelper(_salesUnitOfWork).EntityHasNoPendingChanges(item.SalesOrderPickedItemKey, item.SalesOrderPickedItemKey); if (!notPendingResult.Success) { return(notPendingResult); } var pickedItem = _salesUnitOfWork.SalesOrderPickedItemRepository.FindByKey(item.SalesOrderPickedItemKey); if (pickedItem == null) { return(new InvalidResult(string.Format(UserMessages.SalesOrderPickedItemNotFound, item.SalesOrderPickedItemKey.KeyValue))); } if (pickedItem.PickedInventoryItem.CurrentLocationId != pickedItem.PickedInventoryItem.FromLocationId) { return(new InvalidResult(string.Format(UserMessages.PickedInventoryItemNotInOriginalLocation, new PickedInventoryItemKey(pickedItem).KeyValue))); } pickedItem.PickedInventoryItem.Quantity = item.NewQuantity; pickedItem.OrderItemSequence = item.SalesOrderItemKey.SalesOrderItemKey_ItemSequence; if (pickedItem.PickedInventoryItem.Quantity < 0) { return(new InvalidResult(string.Format(UserMessages.QuantityForPickedCannotBeNegative, item.PickedInventoryItemKey.KeyValue))); } if (pickedItem.PickedInventoryItem.Quantity == 0) { _salesUnitOfWork.PickedInventoryItemRepository.Remove(pickedItem.PickedInventoryItem); _salesUnitOfWork.SalesOrderPickedItemRepository.Remove(pickedItem); } else { pickedItem.PickedInventoryItem.CustomerLotCode = item.CustomerLotCode; pickedItem.PickedInventoryItem.CustomerProductCode = item.CustomerProductCode; } } else { if (item.NewQuantity <= 0) { return(new InvalidResult(string.Format(UserMessages.QuantityForPickingFromInventoryMustBeGreaterThanZero, item.InventoryKey.KeyValue))); } var newSequence = new EFUnitOfWorkHelper(_salesUnitOfWork).GetNextSequence(PickedInventoryItemPredicates.FilterByPickedInventoryKey(pickedInventoryKey), i => i.ItemSequence); var newPickedInventoryItem = new PickedInventoryItem { DateCreated = pickedInventoryKey.PickedInventoryKey_DateCreated, Sequence = pickedInventoryKey.PickedInventoryKey_Sequence, ItemSequence = newSequence, LotDateCreated = item.InventoryKey.LotKey_DateCreated, LotDateSequence = item.InventoryKey.LotKey_DateSequence, LotTypeId = item.InventoryKey.LotKey_LotTypeId, PackagingProductId = item.InventoryKey.PackagingProductKey_ProductId, FromLocationId = item.InventoryKey.LocationKey_Id, TreatmentId = item.InventoryKey.InventoryTreatmentKey_Id, CurrentLocationId = item.InventoryKey.LocationKey_Id, ToteKey = item.InventoryKey.InventoryKey_ToteKey, Quantity = item.NewQuantity, CustomerLotCode = item.CustomerLotCode, CustomerProductCode = item.CustomerProductCode }; _salesUnitOfWork.PickedInventoryItemRepository.Add(newPickedInventoryItem); var customerOrderPickedItem = new SalesOrderPickedItem { DateCreated = pickedInventoryKey.PickedInventoryKey_DateCreated, Sequence = pickedInventoryKey.PickedInventoryKey_Sequence, ItemSequence = newSequence, OrderItemSequence = item.SalesOrderItemKey.SalesOrderItemKey_ItemSequence }; _salesUnitOfWork.SalesOrderPickedItemRepository.Add(customerOrderPickedItem); } } return(new SuccessResult()); }