Exemple #1
0
        public IResult <LotProductionResults> Update(DateTime timestamp, ProductionResultParameters parameters)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }

            var batchResult = GetBatch(parameters.LotKey);

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

            if (batchResult.ResultingObject == null)
            {
                return(new InvalidResult <LotProductionResults>(null, string.Format(UserMessages.ProductionBatchNotFound, parameters.LotKey)));
            }

            if (batchResult.ResultingObject.Production.Results == null)
            {
                return(new InvalidResult <LotProductionResults>(null, string.Format(UserMessages.ProductionResultNotFound, parameters.LotKey)));
            }

            parameters.PackScheduleKey = new PackScheduleKey(batchResult.ResultingObject);

            return(SetProductionResults(batchResult.ResultingObject, timestamp, parameters, false));
        }
Exemple #2
0
        public IResult <LotProductionResults> Create(DateTime timestamp, ProductionResultParameters parameters)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }

            var batchResult = GetBatch(parameters.LotKey);

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

            if (batchResult.ResultingObject.ProductionHasBeenCompleted)
            {
                return(new InvalidResult <LotProductionResults>(null, string.Format(UserMessages.ProductionBatchAlreadyComplete, parameters.LotKey.KeyValue)));
            }

            if (batchResult.ResultingObject.Production.Results != null)
            {
                return(new InvalidResult <LotProductionResults>(null, string.Format(UserMessages.ProductionBatchHasResult, parameters.LotKey.KeyValue)));
            }

            parameters.PackScheduleKey = new PackScheduleKey(batchResult.ResultingObject);

            batchResult.ResultingObject.Production.Results = _productionUnitOfWork.LotProductionResultsRepository.Add(new LotProductionResults
            {
                LotDateCreated  = batchResult.ResultingObject.LotDateCreated,
                LotDateSequence = batchResult.ResultingObject.LotDateSequence,
                LotTypeId       = batchResult.ResultingObject.LotTypeId,
                DateTimeEntered = timestamp,
                ResultItems     = new List <LotProductionResultItem>(),
                Production      = batchResult.ResultingObject.Production
            });

            return(SetProductionResults(batchResult.ResultingObject, timestamp, parameters, true));
        }
Exemple #3
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));
        }