コード例 #1
0
        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());
        }
コード例 #2
0
        public IResult Execute(DateTime timestamp, ReceiveTreatmentOrderParameters parameters)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }

            var employeeResult = new GetEmployeeCommand(_treatmentOrderUnitOfWork).GetEmployee(parameters.Parameters);

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

            var order = _treatmentOrderUnitOfWork.TreatmentOrderRepository.FindByKey(parameters.TreatmentOrderKey, o => o.InventoryShipmentOrder.PickedInventory.Items.Select(i => i.CurrentLocation));

            if (order == null)
            {
                return(new FailureResult(string.Format(UserMessages.TreatmentOrderNotFound, parameters.TreatmentOrderKey.KeyValue)));
            }

            if (order.InventoryShipmentOrder.OrderStatus == OrderStatus.Fulfilled)
            {
                return(new FailureResult <PickedInventory>(null, string.Format(UserMessages.TreatmentOrderAlreadyFulfilled, new TreatmentOrderKey(order).KeyValue)));
            }

            var inventoryModifications = new List <ModifyInventoryParameters>();

            foreach (var item in order.InventoryShipmentOrder.PickedInventory.Items)
            {
                inventoryModifications.Add(new ModifyInventoryParameters(item, item, item.CurrentLocation, item, item.ToteKey, -item.Quantity));
                inventoryModifications.Add(item.ToModifyInventoryDestinationParameters(parameters.DestinationLocationKey, order));
                item.CurrentLocationId = parameters.DestinationLocationKey.LocationKey_Id;
            }

            var modificationsResult = new ModifyInventoryCommand(_treatmentOrderUnitOfWork).Execute(inventoryModifications,
                                                                                                    new InventoryTransactionParameters(employeeResult.ResultingObject, timestamp, InventoryTransactionType.ReceiveTreatmentOrder, parameters.TreatmentOrderKey));

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

            order.InventoryShipmentOrder.OrderStatus = OrderStatus.Fulfilled;
            order.InventoryShipmentOrder.PickedInventory.Archived = true;
            order.Returned = DateTime.UtcNow;

            return(new SuccessResult <PickedInventory>(order.InventoryShipmentOrder.PickedInventory));
        }
コード例 #3
0
        internal IResult <InventoryAdjustment> Execute(DateTime timeStamp, CreateInventoryAdjustmentConductorParameters parameters)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }

            var employeeResult = new GetEmployeeCommand(_inventoryUnitOfWork).GetEmployee(parameters.CreateInventoryAdjustmentParameters);

            if (!employeeResult.Success)
            {
                return(employeeResult.ConvertTo((InventoryAdjustment)null));
            }
            var employee = employeeResult.ResultingObject;

            var createAdjustmentResult = CreateInventoryAdjustment(timeStamp, employee, parameters.CreateInventoryAdjustmentParameters.Comment);

            if (!createAdjustmentResult.Success)
            {
                return(createAdjustmentResult.ConvertTo((InventoryAdjustment)null));
            }
            var inventoryAdjustment = createAdjustmentResult.ResultingObject;

            var createInventoryAdjustmentItemCommand = new CreateInventoryAdjustmentItemCommand(_inventoryUnitOfWork);
            var inventoryModifications = new List <ModifyInventoryParameters>();

            foreach (var adjustment in parameters.Items)
            {
                var createAdjustmentItemResult = createInventoryAdjustmentItemCommand.Execute(inventoryAdjustment, adjustment);
                if (!createAdjustmentItemResult.Success)
                {
                    return(createAdjustmentItemResult.ConvertTo((InventoryAdjustment)null));
                }

                inventoryModifications.Add(new ModifyInventoryParameters(new InventoryKey(createAdjustmentItemResult.ResultingObject), adjustment.InventoryAdjustmentParameters.Adjustment));
            }

            var modifyInventoryResult = new ModifyInventoryCommand(_inventoryUnitOfWork).Execute(inventoryModifications,
                                                                                                 new InventoryTransactionParameters(employee, timeStamp, InventoryTransactionType.InventoryAdjustment, new InventoryAdjustmentKey(inventoryAdjustment)));

            if (!modifyInventoryResult.Success)
            {
                return(modifyInventoryResult.ConvertTo((InventoryAdjustment)null));
            }

            return(new SuccessResult <InventoryAdjustment>(inventoryAdjustment));
        }
コード例 #4
0
        internal IResult <Lot> ReceiveInventory(DateTime timeStamp, ReceiveInventoryParameters parameters)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }
            if (timeStamp == null)
            {
                throw new ArgumentNullException("timeStamp");
            }

            var employeeResult = new GetEmployeeCommand(_inventoryUnitOfWork).GetEmployee(parameters.Parameters);

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

            IResult <Lot> lotResult;
            var           productType = parameters.Parameters.LotType.ToProductType();

            switch (productType)
            {
            case ProductTypeEnum.Additive:  lotResult = CreateAdditiveLot(timeStamp, employeeResult.ResultingObject, parameters); break;

            case ProductTypeEnum.Chile:     lotResult = CreateChileLot(timeStamp, employeeResult.ResultingObject, parameters); break;

            case ProductTypeEnum.Packaging: lotResult = CreatePackagingLot(timeStamp, employeeResult.ResultingObject, parameters); break;

            default: throw new ArgumentOutOfRangeException(productType.ToString());
            }

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

            var inventoryResult = new ModifyInventoryCommand(_inventoryUnitOfWork).Execute(parameters.Items.Select(i => i.ToModifyInventory(lotResult.ResultingObject)),
                                                                                           new InventoryTransactionParameters(employeeResult.ResultingObject, timeStamp, InventoryTransactionType.ReceiveInventory, null));

            if (!inventoryResult.Success)
            {
                return(inventoryResult.ConvertTo <Lot>());
            }

            return(new SuccessResult <Lot>(lotResult.ResultingObject));
        }
コード例 #5
0
        protected IResult UpdatePickedInventory(IInventoryValidator inventoryValidator, Employee employee, DateTime timeStamp, PickedInventory existingPickedInventory, List <PickedInventoryParameters> setPickedInventoryItems, bool moveToDestination = false)
        {
            List <ModifyInventoryParameters> inventoryModifications = null;
            var updateResult = UpdatePickedInventory(inventoryValidator, employee, timeStamp, existingPickedInventory, setPickedInventoryItems, ref inventoryModifications, moveToDestination);

            if (!updateResult.Success)
            {
                return(updateResult.ConvertTo <List <PickedInventoryItem> >());
            }

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

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

            return(updateResult);
        }
コード例 #6
0
        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));
        }
コード例 #7
0
        internal IResult <SalesOrder> Execute(DateTime timestamp, ISalesOrderKey salesOrderKey, ISetPickedInventoryParameters setPickedInventory)
        {
            if (salesOrderKey == null)
            {
                throw new ArgumentNullException("salesOrderKey");
            }
            if (setPickedInventory == null)
            {
                throw new ArgumentNullException("setPickedInventory");
            }

            var employeeResult = new GetEmployeeCommand(_salesUnitOfWork).GetEmployee(setPickedInventory);

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

            var customerOrderResult = GetSalesOrder(salesOrderKey);

            if (!customerOrderResult.Success)
            {
                return(customerOrderResult);
            }
            var salesOrder = customerOrderResult.ResultingObject;

            salesOrder.InventoryShipmentOrder.PickedInventory.EmployeeId = employeeResult.ResultingObject.EmployeeId;
            salesOrder.InventoryShipmentOrder.PickedInventory.TimeStamp  = timestamp;

            var parsedPickedInventory = new List <PickedInventoryParameters>();

            foreach (var item in setPickedInventory.PickedInventoryItems)
            {
                var itemParseResult = item.ToParsedParameters(true);
                if (!itemParseResult.Success)
                {
                    return(itemParseResult.ConvertTo <SalesOrder>());
                }
                parsedPickedInventory.Add(itemParseResult.ResultingObject);
            }

            var pickedInventoryModifications = PickedInventoryHelper.CreateModifyCustomerOrderPickedInventoryItemParameters(salesOrder, parsedPickedInventory);
            var validatorResult = ValidateModifyPickedInventoryItems(salesOrder, pickedInventoryModifications);

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

            var modifyPickedResult = new ModifySalesOrderPickedItemsCommand(_salesUnitOfWork).Execute(new PickedInventoryKey(salesOrder.InventoryShipmentOrder), pickedInventoryModifications);

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

            var inventoryModifications = pickedInventoryModifications.Select(p => p.ToModifySourceInventoryParameters());
            var modifyInventoryResult  = new ModifyInventoryCommand(_salesUnitOfWork).Execute(inventoryModifications, null);

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

            return(new SuccessResult <SalesOrder>(salesOrder));
        }
コード例 #8
0
        private IResult <LotProductionResults> SetProductionResults(ProductionBatch productionBatch, DateTime timestamp, ProductionResultParameters parameters, bool logOriginalPicked)
        {
            if (productionBatch == null)
            {
                throw new ArgumentNullException("productionBatch");
            }
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }

            var employee = new GetEmployeeCommand(_productionUnitOfWork).GetEmployee(parameters.Parameters);

            if (!employee.Success)
            {
                return(employee.ConvertTo <LotProductionResults>());
            }

            var productionLine = _productionUnitOfWork.LocationRepository.FindByKey(parameters.ProductionLineLocationKey);

            if (productionLine == null)
            {
                return(new InvalidResult <LotProductionResults>(null, string.Format(UserMessages.ProductionLocationNotFound, parameters.ProductionLineLocationKey)));
            }

            productionBatch.ProductionHasBeenCompleted          = true;
            productionBatch.Production.PickedInventory.Archived = true;
            productionBatch.Production.ResultingChileLot.Lot.ProductionStatus = LotProductionStatus.Produced;

            var productionResults = productionBatch.Production.Results;

            productionResults.EmployeeId               = employee.ResultingObject.EmployeeId;
            productionResults.TimeStamp                = timestamp;
            productionResults.ProductionLineLocation   = productionLine;
            productionResults.ProductionLineLocationId = productionLine.Id;
            productionResults.ProductionBegin          = parameters.Parameters.ProductionStartTimestamp;
            productionResults.ProductionEnd            = parameters.Parameters.ProductionEndTimestamp;
            productionResults.ShiftKey = parameters.Parameters.ProductionShiftKey;

            List <ModifyInventoryParameters> inventoryModifications = null;
            var updateResultItems = new SetLotProductionResultItemsCommand(_productionUnitOfWork).Execute(productionResults, parameters.InventoryItems, ref inventoryModifications);

            if (!updateResultItems.Success)
            {
                return(updateResultItems.ConvertTo <LotProductionResults>());
            }

            var transactionParameters = new InventoryTransactionParameters(employee.ResultingObject, timestamp, InventoryTransactionType.ProductionResults, parameters.TransactionSourceReference, productionResults);

            if (logOriginalPicked)
            {
                var logPicked = new CreateInventoryTransactionCommand(_productionUnitOfWork).LogPickedInventory(transactionParameters, productionResults.Production.PickedInventory.Items);
                if (!logPicked.Success)
                {
                    return(logPicked.ConvertTo <LotProductionResults>());
                }
            }

            var updatePickedItems = UpdatePickedItems(employee.ResultingObject, timestamp, productionBatch, parameters.PickedInventoryItemChanges, ref inventoryModifications);

            if (!updatePickedItems.Success)
            {
                return(updatePickedItems.ConvertTo <LotProductionResults>());
            }

            var modifyInventory = new ModifyInventoryCommand(_productionUnitOfWork).Execute(inventoryModifications, transactionParameters);

            if (!modifyInventory.Success)
            {
                return(modifyInventory.ConvertTo <LotProductionResults>());
            }

            return(new SuccessResult <LotProductionResults>(productionResults));
        }
コード例 #9
0
        internal IResult Post(Parameters parameters, DateTime timestamp)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }

            var employeeResult = new GetEmployeeCommand(_inventoryShipmentOrderUnitOfWork).GetEmployee(parameters.Params);

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

            var order = _inventoryShipmentOrderUnitOfWork.InventoryShipmentOrderRepository.FindByKey(parameters.InventoryShipmentOrderKey,
                                                                                                     o => o.ShipmentInformation,
                                                                                                     o => o.PickedInventory.Items,
                                                                                                     o => o.DestinationFacility.Locations);

            if (order == null)
            {
                return(new InvalidResult(string.Format(UserMessages.InventoryShipmentOrderNotFound, parameters.InventoryShipmentOrderKey)));
            }

            var moveResult = PostOrder(parameters, order, employeeResult.ResultingObject);

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

            var sourceReference = parameters.InventoryShipmentOrderKey.KeyValue;
            InventoryTransactionType transactionType;

            switch (order.OrderType)
            {
            case InventoryShipmentOrderTypeEnum.InterWarehouseOrder:
                order.OrderStatus = OrderStatus.Fulfilled;
                order.PickedInventory.Archived = true;
                transactionType = InventoryTransactionType.PostedInterWarehouseOrder;
                break;

            case InventoryShipmentOrderTypeEnum.TreatmentOrder:
                transactionType = InventoryTransactionType.PostedTreatmentOrder;
                break;

            case InventoryShipmentOrderTypeEnum.SalesOrder:
                order.OrderStatus = OrderStatus.Fulfilled;
                order.PickedInventory.Archived = true;
                transactionType = InventoryTransactionType.PostedCustomerOrder;
                if (order.MoveNum != null)
                {
                    sourceReference = order.MoveNum.ToString();
                }
                break;

            case InventoryShipmentOrderTypeEnum.MiscellaneousOrder:
                order.OrderStatus = OrderStatus.Fulfilled;
                order.PickedInventory.Archived = true;
                transactionType = InventoryTransactionType.PostedMiscellaneousOrder;
                if (order.MoveNum != null)
                {
                    sourceReference = order.MoveNum.ToString();
                }
                break;

            default: throw new ArgumentOutOfRangeException("order.OrderType");
            }

            var transactionParameters = new InventoryTransactionParameters(employeeResult.ResultingObject, timestamp, transactionType, sourceReference);
            var modifyResult          = new ModifyInventoryCommand(_inventoryShipmentOrderUnitOfWork).Execute(moveResult.ResultingObject, transactionParameters);

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

            return(new CreateInventoryTransactionCommand(_inventoryShipmentOrderUnitOfWork).LogPickedInventory(transactionParameters, order.PickedInventory.Items));
        }