private IResult <IntraWarehouseOrder> GetUpdatedOrder(DateTime timestamp, IIntraWarehouseOrderKey orderKey, IIntraWarehouseOrderParameters parameters)
        {
            var employeeResult = new GetEmployeeCommand(UnitOfWork).GetEmployee(parameters);

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

            IntraWarehouseOrder order;

            if (orderKey != null)
            {
                var key = new IntraWarehouseOrderKey(orderKey);
                order = UnitOfWork.IntraWarehouseOrderRepository.FindByKey(key, o => o.PickedInventory.Items);
                if (order == null)
                {
                    return(new InvalidResult <IntraWarehouseOrder>(null, string.Format(UserMessages.IntraWarehouseOrderNotFound, key)));
                }
            }
            else
            {
                var pickedInventoryResult = new CreatePickedInventoryCommand(UnitOfWork).Execute(new CreatePickedInventoryCommandParameters
                {
                    EmployeeKey  = employeeResult.ResultingObject,
                    PickedReason = PickedReason.IntraWarehouseMovement,
                    TimeStamp    = timestamp
                });

                if (!pickedInventoryResult.Success)
                {
                    return(pickedInventoryResult.ConvertTo <IntraWarehouseOrder>());
                }

                var pickedInventory = pickedInventoryResult.ResultingObject;
                pickedInventory.Archived = true;

                order = UnitOfWork.IntraWarehouseOrderRepository.Add(new IntraWarehouseOrder
                {
                    DateCreated     = pickedInventory.DateCreated,
                    Sequence        = pickedInventory.Sequence,
                    PickedInventory = pickedInventoryResult.ResultingObject
                });
            }

            order.TimeStamp  = timestamp;
            order.EmployeeId = employeeResult.ResultingObject.EmployeeId;
            order.Employee   = employeeResult.ResultingObject;

            order.OperatorName = parameters.OperatorName;
            order.MovementDate = parameters.MovementDate;

            return(new SuccessResult <IntraWarehouseOrder>(order));
        }
Exemple #2
0
        internal IResult <SalesOrder> Execute(DateTime timestamp, CreateSalesOrderConductorParameters parameters)
        {
            if (timestamp == null)
            {
                throw new ArgumentNullException("timestamp");
            }
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }

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

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

            Customer customer = null;

            if (parameters.CustomerKey != null)
            {
                customer = SalesUnitOfWork.CustomerRepository.FindByKey(parameters.CustomerKey,
                                                                        c => c.Company.Contacts,
                                                                        c => c.Contracts.Select(r => r.ContractItems));
            }

            if (customer == null && !parameters.CreateParameters.IsMiscellaneous)
            {
                return(new InvalidResult <SalesOrder>(null, string.Format(UserMessages.CustomerNotFound, parameters.CustomerKey)));
            }

            var pickedInventoryResult = new CreatePickedInventoryCommand(SalesUnitOfWork).Execute(new CreatePickedInventoryCommandParameters
            {
                EmployeeKey  = employeeResult.ResultingObject.ToEmployeeKey(),
                PickedReason = PickedReason.SalesOrder,
                TimeStamp    = timestamp
            });

            if (!pickedInventoryResult.Success)
            {
                pickedInventoryResult.ConvertTo <SalesOrder>();
            }
            var pickedInventory = pickedInventoryResult.ResultingObject;

            pickedInventory.Items = null;

            var pickOrderResult = new CreateInventoryPickOrderCommand(SalesUnitOfWork).Execute(pickedInventory);

            if (!pickOrderResult.Success)
            {
                return(pickOrderResult.ConvertTo <SalesOrder>());
            }
            var pickOrder = pickOrderResult.ResultingObject;

            pickOrder.Items = null;

            var shipmentInformationResult = new CreateShipmentInformationCommand(SalesUnitOfWork).Execute(timestamp.Date);

            if (!shipmentInformationResult.Success)
            {
                return(shipmentInformationResult.ConvertTo <SalesOrder>());
            }
            var shipmentInfo = shipmentInformationResult.ResultingObject;

            var salesOrder = new SalesOrder
            {
                DateCreated = pickedInventory.DateCreated,
                Sequence    = pickedInventory.Sequence,

                CustomerId = customer == null ? (int?)null : customer.Id,
                BrokerId   = customer == null ? (int?)null : customer.BrokerId,

                InventoryShipmentOrder = new InventoryShipmentOrder
                {
                    DateCreated = pickedInventory.DateCreated,
                    Sequence    = pickedInventory.Sequence,
                    EmployeeId  = employeeResult.ResultingObject.EmployeeId,
                    TimeStamp   = timestamp,

                    OrderType = parameters.CreateParameters.IsMiscellaneous ? InventoryShipmentOrderTypeEnum.MiscellaneousOrder : InventoryShipmentOrderTypeEnum.SalesOrder,
                    ShipmentInfoDateCreated = shipmentInfo.DateCreated,
                    ShipmentInfoSequence    = shipmentInfo.Sequence,
                    ShipmentInformation     = shipmentInfo,

                    MoveNum = SalesUnitOfWork.SalesOrderRepository.SourceQuery.Select(s => s.InventoryShipmentOrder.MoveNum).Where(n => n != null).DefaultIfEmpty(0).Max() + 1
                },

                Customer    = customer,
                OrderStatus = SalesOrderStatus.Ordered
            };

            var setResult = SetSalesOrder(salesOrder, timestamp, parameters);

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

            salesOrder = SalesUnitOfWork.SalesOrderRepository.Add(salesOrder);

            return(new SuccessResult <SalesOrder>(salesOrder));
        }
Exemple #3
0
        public IResult <TreatmentOrder> CreateTreatmentOrder <TParams>(DateTime timestamp, CreateTreatmentOrderConductorParameters <TParams> parameters)
            where TParams : ICreateTreatmentOrderParameters
        {
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }

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

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

            var dateCreated           = timestamp.Date;
            var pickedInventoryResult = new CreatePickedInventoryCommand(_treatmentOrderUnitOfWork).Execute(new CreatePickedInventoryCommandParameters
            {
                EmployeeKey  = new EmployeeKey(employeeResult.ResultingObject),
                TimeStamp    = dateCreated,
                PickedReason = PickedReason.TreatmentOrder
            });

            if (!pickedInventoryResult.Success)
            {
                return(pickedInventoryResult.ConvertTo <TreatmentOrder>());
            }

            var pickedOrderResult = new CreateInventoryPickOrderCommand(_treatmentOrderUnitOfWork).Execute(pickedInventoryResult.ResultingObject);

            if (!pickedOrderResult.Success)
            {
                return(pickedOrderResult.ConvertTo <TreatmentOrder>());
            }

            var shipmentInfoResult = new CreateShipmentInformationCommand(_treatmentOrderUnitOfWork).Execute(dateCreated);

            if (!shipmentInfoResult.Success)
            {
                return(shipmentInfoResult.ConvertTo <TreatmentOrder>());
            }

            var treatmentOrder = _treatmentOrderUnitOfWork.TreatmentOrderRepository.Add(new TreatmentOrder
            {
                DateCreated          = pickedInventoryResult.ResultingObject.DateCreated,
                Sequence             = pickedInventoryResult.ResultingObject.Sequence,
                InventoryTreatmentId = parameters.TreatmentKey.InventoryTreatmentKey_Id,

                InventoryShipmentOrder = new InventoryShipmentOrder
                {
                    DateCreated = pickedInventoryResult.ResultingObject.DateCreated,
                    Sequence    = pickedInventoryResult.ResultingObject.Sequence,

                    OrderType   = InventoryShipmentOrderTypeEnum.TreatmentOrder,
                    OrderStatus = OrderStatus.Scheduled,

                    ShipmentInfoDateCreated = shipmentInfoResult.ResultingObject.DateCreated,
                    ShipmentInfoSequence    = shipmentInfoResult.ResultingObject.Sequence,
                    ShipmentInformation     = shipmentInfoResult.ResultingObject,

                    InventoryPickOrder = pickedOrderResult.ResultingObject,
                    PickedInventory    = pickedInventoryResult.ResultingObject,
                    MoveNum            = new GetMoveNum(_treatmentOrderUnitOfWork.InventoryShipmentOrderRepository).Get(pickedInventoryResult.ResultingObject.DateCreated.Year)
                }
            });

            return(new UpdateTreatmentOrderConductor(_treatmentOrderUnitOfWork).Update(treatmentOrder, timestamp, parameters));
        }
        internal IResult <ChileLotProduction> Execute(DateTime timeStamp, CreateMillAndWetdownParameters parameters)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }

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

            if (!employeeResult.Success)
            {
                return(employeeResult.ConvertTo <ChileLotProduction>());
            }
            var employee = employeeResult.ResultingObject;

            var chileLotResult = new CreateNewChileLotCommand(ProductionUnitOfWork).Execute(new CreateNewChileLotCommandParameters
            {
                EmployeeKey            = employeeResult.ResultingObject,
                TimeStamp              = timeStamp,
                LotDate                = parameters.Params.ProductionDate,
                LotSequence            = parameters.Params.LotSequence,
                LotType                = LotTypeEnum.WIP,
                ChileProductKey        = parameters.ChileProductKey,
                SetLotProductionStatus = LotProductionStatus.Produced,
                SetLotQualityStatus    = LotQualityStatus.Pending
            });

            if (!chileLotResult.Success)
            {
                return(chileLotResult.ConvertTo <ChileLotProduction>());
            }
            var chileLot = chileLotResult.ResultingObject;

            var pickedInventoryResult = new CreatePickedInventoryCommand(ProductionUnitOfWork).Execute(new CreatePickedInventoryCommandParameters
            {
                PickedReason = PickedReason.Production,
                EmployeeKey  = employee,
                TimeStamp    = timeStamp
            });

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

            var millAndWetdown = ProductionUnitOfWork.ChileLotProductionRepository.Add(new ChileLotProduction
            {
                LotDateCreated    = chileLot.LotDateCreated,
                LotDateSequence   = chileLot.LotDateSequence,
                LotTypeId         = chileLot.LotTypeId,
                ResultingChileLot = chileLot,

                PickedInventoryDateCreated = pickedInventoryResult.ResultingObject.DateCreated,
                PickedInventorySequence    = pickedInventoryResult.ResultingObject.Sequence,
                PickedInventory            = pickedInventoryResult.ResultingObject,

                Results = new LotProductionResults
                {
                    LotDateCreated  = chileLot.LotDateCreated,
                    LotDateSequence = chileLot.LotDateSequence,
                    LotTypeId       = chileLot.LotTypeId,

                    DateTimeEntered = timeStamp,
                    ResultItems     = new List <LotProductionResultItem>()
                }
            });

            return(SetMillAndWetdown(millAndWetdown, parameters, timeStamp, employee));
        }
        internal IResult <InventoryShipmentOrder> Create <TParams>(DateTime timestamp, SetInventoryShipmentOrderConductorParameters <TParams> parameters)
            where TParams : ISetOrderParameters
        {
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }

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

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

            var pickedInventoryResult = new CreatePickedInventoryCommand(_interWarehouseOrderUnitOfWork).Execute(new CreatePickedInventoryCommandParameters
            {
                EmployeeKey  = new EmployeeKey(employeeResult.ResultingObject),
                TimeStamp    = timestamp,
                PickedReason = PickedReason.InterWarehouseMovement
            });

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

            var pickedOrderResult = new CreateInventoryPickOrderCommand(_interWarehouseOrderUnitOfWork).Execute(pickedInventoryResult.ResultingObject);

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

            var shipmentInfoResult = new CreateShipmentInformationCommand(_interWarehouseOrderUnitOfWork).Execute(timestamp, parameters.Params.SetShipmentInformation);

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

            var order = new InventoryShipmentOrder
            {
                OrderType               = InventoryShipmentOrderTypeEnum.InterWarehouseOrder,
                OrderStatus             = OrderStatus.Scheduled,
                DateCreated             = pickedInventoryResult.ResultingObject.DateCreated,
                Sequence                = pickedInventoryResult.ResultingObject.Sequence,
                PickedInventory         = pickedInventoryResult.ResultingObject,
                InventoryPickOrder      = pickedOrderResult.ResultingObject,
                ShipmentInformation     = shipmentInfoResult.ResultingObject,
                ShipmentInfoDateCreated = shipmentInfoResult.ResultingObject.DateCreated,
                ShipmentInfoSequence    = shipmentInfoResult.ResultingObject.Sequence,
                MoveNum = new GetMoveNum(_interWarehouseOrderUnitOfWork.InventoryShipmentOrderRepository).Get(pickedInventoryResult.ResultingObject.DateCreated.Year)
            };

            if (parameters.Params.HeaderParameters != null)
            {
                order.SetHeaderParameters(parameters.Params.HeaderParameters);
            }

            order = _interWarehouseOrderUnitOfWork.InventoryShipmentOrderRepository.Add(order);

            return(new UpdateInterWarehouseOrderConductor(_interWarehouseOrderUnitOfWork).Update(order, timestamp, parameters));
        }