Beispiel #1
0
        protected IResult UpdatePickedInventory(IInventoryValidator inventoryValidator, Employee employee, DateTime timeStamp, PickedInventory existingPickedInventory, List <PickedInventoryParameters> setPickedInventoryItems, ref List <ModifyInventoryParameters> pendingInventoryModifications, bool moveToDestination = false)
        {
            if (employee != null)
            {
                existingPickedInventory.EmployeeId = employee.EmployeeId;
            }
            existingPickedInventory.TimeStamp = timeStamp;

            var pickedInventoryModifications = PickedInventoryHelper.CreateModifyPickedInventoryItemParameters(existingPickedInventory, setPickedInventoryItems);

            if (inventoryValidator != null)
            {
                var validatorResult = inventoryValidator.ValidateItems(UnitOfWork.InventoryRepository, pickedInventoryModifications.Where(i => i.DeltaQuantity > 0).Select(i => i.InventoryKey));
                if (!validatorResult.Success)
                {
                    return(validatorResult.ConvertTo <List <PickedInventoryItem> >());
                }
            }

            var modifyPickedResult = new ModifyPickedInventoryItemsCommand(UnitOfWork).Execute(existingPickedInventory, pickedInventoryModifications);

            if (!modifyPickedResult.Success)
            {
                return(modifyPickedResult);
            }

            pendingInventoryModifications = pendingInventoryModifications ?? new List <ModifyInventoryParameters>();
            pendingInventoryModifications.AddRange(pickedInventoryModifications.Select(p => p.ToModifySourceInventoryParameters()));
            if (moveToDestination)
            {
                pendingInventoryModifications.AddRange(pickedInventoryModifications.Select(p => p.ToModifyDestinationInventoryParameters()));
            }

            return(modifyPickedResult);
        }
        internal IResult Execute(LotKey lotKey)
        {
            var includePaths = DeleteLotConductor.ConstructIncludePaths <ChileLotProduction>(p => p.ResultingChileLot.Lot,
                                                                                             p => p.PickedInventory.Items.Select(i => i.CurrentLocation),
                                                                                             p => p.Results.ResultItems).ToArray();
            var lotProduction = _productionUnitOfWork.ChileLotProductionRepository.FindByKey(lotKey, includePaths);

            if (lotProduction == null)
            {
                return(new NoWorkRequiredResult());
            }

            if (lotProduction.ProductionType != ProductionType.MillAndWetdown)
            {
                return(new InvalidResult(string.Format(UserMessages.MillAndWetdownEntryNotFound, lotKey)));
            }

            var pickedInventoryItemModifications = PickedInventoryHelper.CreateModifyPickedInventoryItemParameters(lotProduction.PickedInventory, new List <PickedInventoryParameters>());
            var modifyPickedResult = new ModifyPickedInventoryItemsCommand(_productionUnitOfWork).Execute(lotProduction, pickedInventoryItemModifications);

            if (!modifyPickedResult.Success)
            {
                return(modifyPickedResult.ConvertTo <ChileLotProduction>());
            }

            var inventoryModifications = pickedInventoryItemModifications.Select(i => i.ToModifySourceInventoryParameters()).ToList();
            var setResults             = new SetLotProductionResultItemsCommand(_productionUnitOfWork).Execute(lotProduction.Results, new List <IProductionResultItemParameters>(), ref inventoryModifications);

            if (!setResults.Success)
            {
                return(setResults.ConvertTo <ChileLotProduction>());
            }

            var modifyInventoryResult = new ModifyInventoryCommand(_productionUnitOfWork).Execute(inventoryModifications, null);

            if (!modifyInventoryResult.Success)
            {
                return(modifyInventoryResult.ConvertTo <ChileLotProduction>());
            }

            _productionUnitOfWork.LotProductionResultsRepository.Remove(lotProduction.Results);
            _productionUnitOfWork.PickedInventoryRepository.Remove(lotProduction.PickedInventory);

            var deleteLotResult = new DeleteLotConductor(_productionUnitOfWork).Delete(lotProduction.ResultingChileLot.Lot);

            if (!deleteLotResult.Success)
            {
                return(deleteLotResult);
            }

            return(new SuccessResult());
        }
        internal IResult UpdatePickedInventory(InventoryShipmentOrderKey orderKey, IUserIdentifiable user, DateTime timestamp, List <PickedInventoryParameters> setPickedInventoryItems)
        {
            var employeeResult = new GetEmployeeCommand(_inventoryShipmentUnitOfWork).GetEmployee(user);

            if (!employeeResult.Success)
            {
                return(employeeResult.ConvertTo <InventoryShipmentOrder>());
            }

            var orderResult = GetOrder(orderKey);

            if (!orderResult.Success)
            {
                return(orderResult);
            }

            orderResult.ResultingObject.PickedInventory.EmployeeId = employeeResult.ResultingObject.EmployeeId;
            orderResult.ResultingObject.PickedInventory.TimeStamp  = timestamp;

            var pickedInventoryModifications = PickedInventoryHelper.CreateModifyPickedInventoryItemParameters(orderResult.ResultingObject.PickedInventory, setPickedInventoryItems);
            var validatorResult = ValidateModifyPickedInventoryItems(orderResult.ResultingObject, pickedInventoryModifications);

            if (!validatorResult.Success)
            {
                return(validatorResult.ConvertTo <SalesOrder>());
            }

            var modifyPickedResult = new ModifyPickedInventoryItemsCommand(_inventoryShipmentUnitOfWork).Execute(orderResult.ResultingObject.PickedInventory, pickedInventoryModifications);

            if (!modifyPickedResult.Success)
            {
                return(modifyPickedResult);
            }

            return(new ModifyInventoryCommand(_inventoryShipmentUnitOfWork).Execute(pickedInventoryModifications.Select(p => p.ToModifySourceInventoryParameters()).ToList(), null));
        }
        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));
        }