internal IResult <ILotKey> Execute(DateTime timestamp, SetLotAttributeParameters parameters) { if (parameters == null) { throw new ArgumentNullException("parameters"); } var employeeResult = new GetEmployeeCommand(_lotUnitOfWork).GetEmployee(parameters.Parameters); if (!employeeResult.Success) { return(employeeResult.ConvertTo <ILotKey>()); } var dataResult = GetLotData(parameters.LotKey); if (!dataResult.Success) { return(dataResult.ConvertTo <ILotKey>()); } var data = dataResult.ResultingObject.First(); var attributeNames = _lotUnitOfWork.AttributeNameRepository.Filter(a => true, a => a.ValidTreatments).ToList(); var setAttributesResult = SetLotAttributes(data, employeeResult.ResultingObject, timestamp, attributeNames, parameters.Attributes); if (!setAttributesResult.Success) { return(setAttributesResult.ConvertTo <ILotKey>()); } data.Lot.Notes = parameters.Parameters.Notes; return(new SuccessResult <ILotKey>(parameters.LotKey)); }
internal IResult <Note> Execute(INotebookKey notebookKey, DateTime timestamp, ICreateNoteParameters parameters) { if (notebookKey == null) { throw new ArgumentNullException("notebookKey"); } if (timestamp == null) { throw new ArgumentNullException("timestamp"); } if (parameters == null) { throw new ArgumentNullException("parameters"); } var employeeResult = new GetEmployeeCommand(_notebookUnitOfWork).GetEmployee(parameters); if (!employeeResult.Success) { return(employeeResult.ConvertTo((Note)null)); } var notebookKeyFind = new NotebookKey(notebookKey); var notebook = _notebookUnitOfWork.NotebookRepository.FindByKey(notebookKeyFind); if (notebook == null) { return(new InvalidResult <Note>(null, string.Format(UserMessages.NotebookNotFound, notebookKeyFind))); } return(Execute(notebook, timestamp, employeeResult.ResultingObject, parameters.Text)); }
internal IResult <ChileLotProduction> Execute(DateTime timeStamp, UpdateMillAndWetdownParameters parameters) { if (parameters == null) { throw new ArgumentNullException("parameters"); } var employeeResult = new GetEmployeeCommand(ProductionUnitOfWork).GetEmployee(parameters.Params); if (!employeeResult.Success) { return(employeeResult.ConvertTo <ChileLotProduction>()); } var chileLotResult = ProductionUnitOfWork.ChileLotProductionRepository.FindByKey(parameters.LotKey, c => c.ResultingChileLot.ChileProduct, c => c.PickedInventory.Items.Select(i => i.CurrentLocation), c => c.Results.ResultItems); if (chileLotResult == null || chileLotResult.ProductionType != ProductionType.MillAndWetdown) { return(new InvalidResult <ChileLotProduction>(null, string.Format(UserMessages.MillAndWetdownEntryNotFound, parameters.LotKey))); } return(SetMillAndWetdown(chileLotResult, parameters, timeStamp, employeeResult.ResultingObject)); }
internal IResult <ProductionSchedule> Update(DateTime timestamp, UpdateProductionScheduleParameters parameters) { if (parameters == null) { throw new ArgumentNullException("parameters"); } var employeeResult = new GetEmployeeCommand(ProductionUnitOfWork).GetEmployee(parameters.Parameters); if (!employeeResult.Success) { return(employeeResult.ConvertTo <ProductionSchedule>()); } var productionSchedule = ProductionUnitOfWork.ProductionScheduleRepository.FindByKey(parameters.ProductionScheduleKey, p => p.ProductionLineLocation, p => p.ScheduledItems); if (productionSchedule == null) { return(new InvalidResult <ProductionSchedule>(null, string.Format(UserMessages.ProductionScheduleNotFound, parameters.ProductionScheduleKey))); } var items = parameters.ScheduledItems.Select(i => new SetProductionScheduleItemParameters { Index = i.Parameters.Index, FlushBefore = i.Parameters.FlushBefore, FlushBeforeInstructions = i.Parameters.FlushBeforeInstructions, FlushAfter = i.Parameters.FlushAfter, FlushAfterInstructions = i.Parameters.FlushAfterInstructions, PackScheduleKey = i.PackScheduleKey }).ToList(); return(Set(productionSchedule, employeeResult.ResultingObject, timestamp, items)); }
public IResult UpdateLocation(IUpdateLocationParameters parameters) { var parameterResult = parameters.ToParsedParameters(); if (!parameterResult.Success) { return(parameterResult); } var employeeResult = new GetEmployeeCommand(_facilityUnitOfWork).GetEmployee(parameters); if (!employeeResult.Success) { return(employeeResult.ConvertTo <string>()); } var result = new UpdateLocationCommand(_facilityUnitOfWork).UpdateLocation(parameterResult.ResultingObject); if (!result.Success) { return(result); } _facilityUnitOfWork.Commit(); return(SyncParameters.Using(new SuccessResult(), new SyncLocationsParameters { EmployeeKey = employeeResult.ResultingObject, Locations = new List <ILocationKey> { parameterResult.ResultingObject.LocationKey } })); }
internal IResult <ChileMaterialsReceived> Execute(CreateChileMaterialsReceivedParameters parameters, DateTime timeStamp) { if (parameters == null) { throw new ArgumentNullException("parameters"); } var employeeResult = new GetEmployeeCommand(MaterialsReceivedUnitOfWork).GetEmployee(parameters.Params); if (!employeeResult.Success) { return(employeeResult.ConvertTo <ChileMaterialsReceived>()); } var chileProduct = MaterialsReceivedUnitOfWork.ChileProductRepository.FindByKey(parameters.ChileProductKey); if (chileProduct == null) { return(new InvalidResult <ChileMaterialsReceived>(null, string.Format(UserMessages.ChileProductNotFound, parameters.ChileProductKey.KeyValue))); } if (parameters.Params.ChileMaterialsReceivedType == ChileMaterialsReceivedType.Dehydrated && chileProduct.ChileState != ChileStateEnum.Dehydrated) { return(new InvalidResult <ChileMaterialsReceived>(null, string.Format(UserMessages.ChileProductInvalidState, parameters.ChileProductKey.KeyValue, chileProduct.ChileState, ChileStateEnum.Dehydrated))); } var createChileLotResult = new CreateNewChileLotCommand(MaterialsReceivedUnitOfWork).Execute(new CreateNewChileLotCommandParameters { EmployeeKey = employeeResult.ResultingObject, TimeStamp = timeStamp, LotDate = parameters.Params.DateReceived.Date, LotType = LotTypeEnum.DeHydrated, ChileProductKey = chileProduct, SetLotProductionStatus = LotProductionStatus.Produced, SetLotQualityStatus = LotQualityStatus.Pending }); if (!createChileLotResult.Success) { return(createChileLotResult.ConvertTo <ChileMaterialsReceived>()); } var chileLot = createChileLotResult.ResultingObject; var materialsReceived = MaterialsReceivedUnitOfWork.ChileMaterialsReceivedRepository.Add(new ChileMaterialsReceived { ChileLot = chileLot, LotDateCreated = chileLot.LotDateCreated, LotDateSequence = chileLot.LotDateSequence, LotTypeId = chileLot.LotTypeId, Items = new List <ChileMaterialsReceivedItem>() }); return(Set(materialsReceived, chileProduct, parameters, employeeResult.ResultingObject, timeStamp)); }
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)); }
public IResult <PackSchedule> Execute(DateTime timestamp, CreatePackScheduleCommandParameters parameters) { if (parameters == null) { throw new ArgumentNullException("parameters"); } var dateCreated = parameters.Parameters.DateCreated?.Date ?? timestamp.Date; var sequence = parameters.Parameters.Sequence ?? new EFUnitOfWorkHelper(_productionUnitOfWork).GetNextSequence <PackSchedule>(p => p.DateCreated == dateCreated, p => p.SequentialNumber); var employeeResult = new GetEmployeeCommand(_productionUnitOfWork).GetEmployee(parameters.Parameters); if (!employeeResult.Success) { return(employeeResult.ConvertTo <PackSchedule>()); } Data.Models.Company customer = null; if (parameters.CustomerKey != null) { var companyResult = new GetCompanyCommand(_productionUnitOfWork).Execute(parameters.CustomerKey, CompanyType.Customer); if (!companyResult.Success) { return(companyResult.ConvertTo <PackSchedule>()); } customer = companyResult.ResultingObject; } var packSchedule = _productionUnitOfWork.PackScheduleRepository.Add(new PackSchedule { EmployeeId = employeeResult.ResultingObject.EmployeeId, TimeStamp = timestamp, PackSchID = DataConstants.SqlMinDate, PSNum = parameters.Parameters.PSNum ?? _productionUnitOfWork.PackScheduleRepository.SourceQuery.Select(p => p.PSNum).Where(p => p != null).DefaultIfEmpty(0).Max().Value + 1, DateCreated = dateCreated, SequentialNumber = sequence, WorkTypeId = parameters.WorkTypeKey.WorkTypeKey_WorkTypeId, ChileProductId = parameters.ChileProductKey.ChileProductKey_ProductId, PackagingProductId = parameters.PackagingProductKey.PackagingProductKey_ProductId, ScheduledProductionDate = parameters.Parameters.ScheduledProductionDate, ProductionDeadline = parameters.Parameters.ProductionDeadline, ProductionLineLocationId = parameters.ProductionLocationKey.LocationKey_Id, SummaryOfWork = parameters.Parameters.SummaryOfWork ?? "", CustomerId = customer == null ? (int?)null : customer.Id, OrderNumber = parameters.Parameters.OrderNumber.TrimTruncate(Constants.StringLengths.OrderNumber), DefaultBatchTargetParameters = new ProductionBatchTargetParameters(parameters.Parameters) }); return(new SuccessResult <PackSchedule>(packSchedule)); }
internal IResult <SampleOrderJournalEntry> Execute(SetSampleJournalEntryCommandParameters parameters) { if (parameters == null) { throw new ArgumentNullException("parameters"); } var employeeResult = new GetEmployeeCommand(_sampleOrderUnitOfWork).GetEmployee(parameters.Parameters); if (!employeeResult.Success) { return(employeeResult.ConvertTo <SampleOrderJournalEntry>()); } var sampleOrder = _sampleOrderUnitOfWork.SampleOrderRepository.FindByKey(parameters.SampleOrderKey, o => o.JournalEntries); if (sampleOrder == null) { return(new InvalidResult <SampleOrderJournalEntry>(null, string.Format(UserMessages.SampleOrderNotFound, parameters.SampleOrderKey))); } SampleOrderJournalEntry journalEntry; if (parameters.JournalEntryKey != null) { journalEntry = sampleOrder.JournalEntries.FirstOrDefault(parameters.JournalEntryKey.FindByPredicate.Compile()); if (journalEntry == null) { return(new InvalidResult <SampleOrderJournalEntry>(null, string.Format(UserMessages.SampleOrderJournalEntryNotFound, parameters.JournalEntryKey))); } } else { journalEntry = _sampleOrderUnitOfWork.SampleOrderJournalEntryRepository.Add(new SampleOrderJournalEntry { SampleOrderYear = sampleOrder.Year, SampleOrderSequence = sampleOrder.Sequence, EntrySequence = sampleOrder.JournalEntries.Select(j => j.EntrySequence).DefaultIfEmpty(0).Max() + 1 }); } journalEntry.EmployeeId = employeeResult.ResultingObject.EmployeeId; journalEntry.Date = parameters.Parameters.Date; journalEntry.Text = parameters.Parameters.Text; return(new SuccessResult <SampleOrderJournalEntry>(journalEntry)); }
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)); }
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)); }
public IResult <LotKey> Execute(DateTime timeStamp, ISetPickedInventoryParameters pickedInventory, LotKey batchKey) { var productionBatch = UnitOfWork.ProductionBatchRepository.FindByKey(batchKey, b => b.Production.ResultingChileLot.Lot.Attributes.Select(a => a.AttributeName), b => b.Production.PickedInventory.Items.Select(i => i.CurrentLocation)); if (productionBatch == null) { return(new InvalidResult <LotKey>(null, string.Format(UserMessages.ProductionBatchNotFound, batchKey.KeyValue))); } if (productionBatch.ProductionHasBeenCompleted) { return(new InvalidResult <LotKey>(null, string.Format(UserMessages.ProductionBatchAlreadyComplete, batchKey.KeyValue))); } var employeeResult = new GetEmployeeCommand(UnitOfWork).GetEmployee(pickedInventory); if (!employeeResult.Success) { return(employeeResult.ConvertTo <LotKey>()); } var parsedPicked = pickedInventory.PickedInventoryItems.ToParsedParameters(); if (!parsedPicked.Success) { return(parsedPicked.ConvertTo <LotKey>()); } var pickResult = UpdatePickedInventory(PickedInventoryValidator.ForProductionBatch, employeeResult.ResultingObject, timeStamp, productionBatch.Production.PickedInventory, parsedPicked.ResultingObject); if (!pickResult.Success) { return(pickResult.ConvertTo <LotKey>()); } var setWeightedAttributes = new SetLotWeightedAttributesConductor(UnitOfWork).Execute(productionBatch.Production.ResultingChileLot, productionBatch.Production.PickedInventory.Items.ToList(), timeStamp); if (!setWeightedAttributes.Success) { return(setWeightedAttributes.ConvertTo <LotKey>()); } return(new SuccessResult <LotKey>(batchKey)); }
internal IResult <LotDefect> Execute(CreateLotDefectParameters parameters, DateTime timestamp) { if (parameters == null) { throw new ArgumentNullException("parameters"); } var employeeResult = new GetEmployeeCommand(_lotUnitOfWork).GetEmployee(parameters.Parameters); if (!employeeResult.Success) { return(employeeResult.ConvertTo <LotDefect>()); } var lotKey = parameters.LotKey; var lot = _lotUnitOfWork.LotRepository.FindByKey(lotKey, l => l.ChileLot, l => l.Attributes); if (lot == null) { return(new InvalidResult <LotDefect>(null, string.Format(UserMessages.LotNotFound, lotKey.KeyValue))); } var historyResult = new RecordLotHistoryCommand(_lotUnitOfWork).Execute(lot, timestamp); if (!historyResult.Success) { return(historyResult.ConvertTo <LotDefect>()); } var newDefectId = new EFUnitOfWorkHelper(_lotUnitOfWork).GetNextSequence <LotDefect>(d => d.LotDateCreated == lot.LotDateCreated && d.LotDateSequence == lot.LotDateSequence && d.LotTypeId == lot.LotTypeId, d => d.DefectId); var newDefect = _lotUnitOfWork.LotDefectRepository.Add(new LotDefect { LotDateCreated = lot.LotDateCreated, LotDateSequence = lot.LotDateSequence, LotTypeId = lot.LotTypeId, DefectId = newDefectId, DefectType = DefectTypeEnum.InHouseContamination, Description = parameters.Parameters.Description }); lot.EmployeeId = employeeResult.ResultingObject.EmployeeId; lot.TimeStamp = timestamp; return(new SuccessResult <LotDefect>(newDefect)); }
private IResult <CustomerNote> SetCustomerNote(CustomerNote note, DateTime timestamp, ISetCustomerNoteParameters parameters) { var employeeResult = new GetEmployeeCommand(_companyUnitOfWork).GetEmployee(parameters); if (!employeeResult.Success) { return(employeeResult.ConvertTo <CustomerNote>()); } note.EmployeeId = employeeResult.ResultingObject.EmployeeId; note.TimeStamp = timestamp; note.Type = parameters.Type; note.Text = parameters.Text; note.Bold = parameters.Bold; return(new SuccessResult <CustomerNote>(note)); }
internal IResult <SampleOrder> Execute(DateTime timeStamp, SetSampleOrderParameters parameters) { if (parameters == null) { throw new ArgumentNullException("parameters"); } var employeeResult = new GetEmployeeCommand(_sampleOrderUnitOfWork).GetEmployee(parameters.Parameters); if (!employeeResult.Success) { return(employeeResult.ConvertTo <SampleOrder>()); } SampleOrder sampleOrder; if (parameters.SampleOrderKey != null) { sampleOrder = _sampleOrderUnitOfWork.SampleOrderRepository.FindByKey(parameters.SampleOrderKey, o => o.Items.Select(i => i.Spec), o => o.Items.Select(i => i.Match)); if (sampleOrder == null) { return(new InvalidResult <SampleOrder>(null, string.Format(UserMessages.SampleOrderNotFound, parameters.SampleOrderKey))); } } else { var year = timeStamp.Year; var sequence = new EFUnitOfWorkHelper(_sampleOrderUnitOfWork).GetNextSequence <SampleOrder>(o => o.Year == year, o => o.Sequence); sampleOrder = _sampleOrderUnitOfWork.SampleOrderRepository.Add(new SampleOrder { Year = year, Sequence = sequence, Items = new List <SampleOrderItem>() }); } return(SetSampleOrder(employeeResult.ResultingObject, timeStamp, sampleOrder, parameters)); }
internal IResult AddLotAttributes(DateTime timestamp, AddLotAttributeParameters parameters) { if (parameters == null) { throw new ArgumentNullException("parameters"); } var lotKeys = parameters.LotKeys.Where(k => k != null).Distinct().ToList(); if (!lotKeys.Any()) { return(new NoWorkRequiredResult()); } var employeeResult = new GetEmployeeCommand(_lotUnitOfWork).GetEmployee(parameters.Parameters); if (!employeeResult.Success) { return(employeeResult.ConvertTo <ILotKey>()); } var dataResult = GetLotData(lotKeys.ToArray()); if (!dataResult.Success) { return(dataResult); } var attributeNames = _lotUnitOfWork.AttributeNameRepository.Filter(a => true, a => a.ValidTreatments).ToList(); foreach (var chileLot in dataResult.ResultingObject) { var setResult = SetLotAttributes(chileLot, timestamp, parameters, employeeResult.ResultingObject, attributeNames); if (!setResult.Success) { return(setResult); } } return(new SuccessResult()); }
internal IResult <InventoryShipmentOrder> SetPickedInventory(DateTime timeStamp, Parameters parameters) { var inventoryShipmentOrder = UnitOfWork.InventoryShipmentOrderRepository.FindByKey(parameters.OrderKey, i => i.ShipmentInformation, i => i.SourceFacility, i => i.PickedInventory.Items.Select(t => t.FromLocation), i => i.PickedInventory.Items.Select(t => t.CurrentLocation)); if (inventoryShipmentOrder == null) { return(new InvalidResult <InventoryShipmentOrder>(null, string.Format(UserMessages.InventoryShipmentOrderNotFound, parameters.OrderKey))); } var employeeResult = new GetEmployeeCommand(UnitOfWork).GetEmployee(parameters.User); if (!employeeResult.Success) { return(employeeResult.ConvertTo <InventoryShipmentOrder>()); } if (inventoryShipmentOrder.ShipmentInformation.Status != ShipmentStatus.Scheduled && inventoryShipmentOrder.ShipmentInformation.Status != ShipmentStatus.Unscheduled) { return(new InvalidResult <InventoryShipmentOrder>(null, string.Format(UserMessages.CannotPickShipment, inventoryShipmentOrder.ShipmentInformation.Status))); } var validator = GetInventoryValidator(inventoryShipmentOrder); if (!validator.Success) { return(validator.ConvertTo <InventoryShipmentOrder>()); } var pickedResult = UpdatePickedInventory(validator.ResultingObject, employeeResult.ResultingObject, timeStamp, inventoryShipmentOrder.PickedInventory, parameters.PickedInventoryParameters); if (!pickedResult.Success) { return(pickedResult.ConvertTo <InventoryShipmentOrder>()); } return(new SuccessResult <InventoryShipmentOrder>(inventoryShipmentOrder)); }
protected IResult <Data.Models.Company> SetCompany <T>(Data.Models.Company company, DateTime timestamp, SetCompanyCommandParameters <T> parameters) where T : ISetCompanyParameters { var employeeResult = new GetEmployeeCommand(CompanyUnitOfWork).GetEmployee(parameters.Parameters); if (!employeeResult.Success) { return(employeeResult.ConvertTo <Data.Models.Company>()); } company.EmployeeId = employeeResult.ResultingObject.EmployeeId; company.TimeStamp = timestamp; company.Active = parameters.Parameters.Active; var setTypesResult = SetCompanyTypes(company, parameters.Parameters.CompanyTypes, parameters.BrokerKey); if (!setTypesResult.Success) { return(setTypesResult.ConvertTo <Data.Models.Company>()); } return(new SuccessResult <Data.Models.Company>(company)); }
internal IResult <ChileMaterialsReceived> Execute(UpdateChileMaterialsReceivedParameters parameters, DateTime timeStamp) { if (parameters == null) { throw new ArgumentNullException("parameters"); } var employeeResult = new GetEmployeeCommand(MaterialsReceivedUnitOfWork).GetEmployee(parameters.Params); if (!employeeResult.Success) { return(employeeResult.ConvertTo <ChileMaterialsReceived>()); } var materialsReceived = MaterialsReceivedUnitOfWork.ChileMaterialsReceivedRepository.FindByKey(parameters.LotKey, m => m.ChileLot.Lot, m => m.Items); if (materialsReceived == null) { return(new InvalidResult <ChileMaterialsReceived>(null, string.Format(UserMessages.ChileMaterialsReceivedNotFound, parameters.LotKey))); } var chileProduct = MaterialsReceivedUnitOfWork.ChileProductRepository.FindByKey(parameters.ChileProductKey); if (chileProduct == null) { return(new InvalidResult <ChileMaterialsReceived>(null, string.Format(UserMessages.ChileProductNotFound, parameters.ChileProductKey))); } if (parameters.Params.ChileMaterialsReceivedType == ChileMaterialsReceivedType.Dehydrated && chileProduct.ChileState != ChileStateEnum.Dehydrated) { return(new InvalidResult <ChileMaterialsReceived>(null, string.Format(UserMessages.ChileProductInvalidState, parameters.ChileProductKey.KeyValue, chileProduct.ChileState, ChileStateEnum.Dehydrated))); } return(Set(materialsReceived, chileProduct, parameters, employeeResult.ResultingObject, timeStamp)); }
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)); }
internal IResult <ProductionSchedule> Create(DateTime timestamp, CreateProductionScheduleParameters parameters) { if (parameters == null) { throw new ArgumentNullException("parameters"); } var employeeResult = new GetEmployeeCommand(ProductionUnitOfWork).GetEmployee(parameters.Parameters); if (!employeeResult.Success) { return(employeeResult.ConvertTo <ProductionSchedule>()); } var location = ProductionUnitOfWork.LocationRepository.FindByKey(parameters.ProductionLocationKey); if (location == null || location.LocationType != LocationType.ProductionLine) { return(new InvalidResult <ProductionSchedule>(null, string.Format(UserMessages.ProductionLocationNotFound, parameters.ProductionLocationKey))); } if (ProductionUnitOfWork.ProductionScheduleRepository.Filter(p => p.ProductionDate == parameters.Parameters.ProductionDate && p.ProductionLineLocationId == location.Id).Any()) { return(new InvalidResult <ProductionSchedule>(null, string.Format(UserMessages.ProductionScheduleAlreadyExists, parameters.Parameters.ProductionDate.ToShortDateString(), location.Description))); } var packSchedules = ProductionUnitOfWork.PackScheduleRepository .Filter(p => p.ProductionLineLocationId == location.Id && p.ProductionBatches.Any(b => !b.ProductionHasBeenCompleted)) .Select(p => new { packSchedule = p, lastScheduled = p.ScheduledItems .OrderByDescending(i => i.ProductionSchedule.TimeStamp) .FirstOrDefault() }) .ToList(); var index = 0; var scheduledItems = new List <SetProductionScheduleItemParameters>(); foreach (var packSchedule in packSchedules .OrderByDescending(p => p.lastScheduled != null) .ThenBy(p => p.lastScheduled != null ? p.lastScheduled.Index : int.MaxValue) .ThenByDescending(p => p.lastScheduled != null ? p.lastScheduled.ProductionDate : DateTime.MinValue) .ThenBy(p => p.packSchedule.ScheduledProductionDate) .ThenBy(p => p.packSchedule.DateCreated) .ThenBy(p => p.packSchedule.SequentialNumber)) { var scheduledItem = new SetProductionScheduleItemParameters { PackScheduleKey = packSchedule.packSchedule.ToPackScheduleKey(), Index = index++ }; if (packSchedule.lastScheduled != null) { scheduledItem.FlushBefore = packSchedule.lastScheduled.FlushBefore; scheduledItem.FlushBeforeInstructions = packSchedule.lastScheduled.FlushBeforeInstructions; scheduledItem.FlushAfter = packSchedule.lastScheduled.FlushAfter; scheduledItem.FlushAfterInstructions = packSchedule.lastScheduled.FlushAfterInstructions; } scheduledItems.Add(scheduledItem); } var productionSchedule = ProductionUnitOfWork.ProductionScheduleRepository.Add(new ProductionSchedule { ProductionDate = parameters.Parameters.ProductionDate, ProductionLineLocationId = location.Id, ProductionLineLocation = location, ScheduledItems = new List <ProductionScheduleItem>() }); return(Set(productionSchedule, employeeResult.ResultingObject, timestamp, scheduledItems)); }
internal IResult <ChileProduct> Execute(ChileProduct chileProduct, IUserIdentifiable user, DateTime timeStamp, IEnumerable <SetChileProductAttributeRangeParameters> ranges) { var employeeResult = new GetEmployeeCommand(_productUnitOfWork).GetEmployee(user); if (!employeeResult.Success) { return(employeeResult.ConvertTo <ChileProduct>()); } AttributeNameKey[] notFound; var attributeNames = _productUnitOfWork.AttributeNameRepository.FindByKeys(out notFound, ranges.Select(r => r.AttributeNameKey).ToArray()); if (notFound.Any()) { return(new InvalidResult <ChileProduct>(null, string.Format(UserMessages.AttributeNameNotFound, notFound.First()))); } var invalidForChile = attributeNames.FirstOrDefault(n => !n.ValidForChileInventory); if (invalidForChile != null) { return(new InvalidResult <ChileProduct>(null, string.Format(UserMessages.AttributeNameNotValidForChile, invalidForChile.ToAttributeNameKey()))); } foreach (var match in (chileProduct.ProductAttributeRanges ?? new List <ChileProductAttributeRange>()).BestMatches(ranges, (e, n) => e.AttributeShortName == n.AttributeNameKey.AttributeNameKey_ShortName, (e, n) => e.RangeMin == n.Parameters.RangeMin, (e, n) => e.RangeMax == n.Parameters.RangeMax)) { if (match.Item2 == null) { _productUnitOfWork.ChileProductAttributeRangeRepository.Remove(match.Item1); } else { bool update; var range = match.Item1; if (range == null || !match.Item2.AttributeNameKey.Equals(range)) { if (range != null) { _productUnitOfWork.ChileProductAttributeRangeRepository.Remove(range); } update = true; range = _productUnitOfWork.ChileProductAttributeRangeRepository.Add(new ChileProductAttributeRange { ChileProductId = chileProduct.Id, AttributeShortName = match.Item2.AttributeNameKey.AttributeNameKey_ShortName }); } else { update = range.RangeMin != match.Item2.Parameters.RangeMin || range.RangeMax != match.Item2.Parameters.RangeMax; } if (update) { range.EmployeeId = employeeResult.ResultingObject.EmployeeId; range.TimeStamp = timeStamp; range.RangeMin = match.Item2.Parameters.RangeMin; range.RangeMax = match.Item2.Parameters.RangeMax; } } } return(new SuccessResult <ChileProduct>(chileProduct)); }
internal IResult <ChileProduct> Execute(ChileProduct chileProduct, IUserIdentifiable user, DateTime timeStamp, IEnumerable <SetChileProductIngredientCommandParameters> ingredients, out List <AdditiveTypeKey> deletedIngredients) { deletedIngredients = new List <AdditiveTypeKey>(); var employeeResult = new GetEmployeeCommand(_productUnitOfWork).GetEmployee(user); if (!employeeResult.Success) { return(employeeResult.ConvertTo <ChileProduct>()); } AdditiveTypeKey[] missingAdditiveTypes; _productUnitOfWork.AdditiveTypeRepository.FindByKeys(out missingAdditiveTypes, ingredients.Select(i => i.AdditiveTypeKey).ToArray()); if (missingAdditiveTypes.Any()) { return(new InvalidResult <ChileProduct>(null, string.Format(UserMessages.AdditiveTypeNotFound, missingAdditiveTypes.First()))); } foreach (var match in (chileProduct.Ingredients ?? new List <ChileProductIngredient>()).BestMatches(ingredients, (e, n) => e.AdditiveTypeId == n.AdditiveTypeKey.AdditiveTypeKey_AdditiveTypeId, (e, n) => e.Percentage == n.Parameters.Percentage)) { if (match.Item2 == null) { deletedIngredients.Add(match.Item1.ToAdditiveTypeKey()); _productUnitOfWork.ChileProductIngredientRepository.Remove(match.Item1); } else { bool update; var ingredient = match.Item1; if (ingredient == null || ingredient.AdditiveTypeId != match.Item2.AdditiveTypeKey.AdditiveTypeKey_AdditiveTypeId) { if (ingredient != null) { deletedIngredients.Add(ingredient.ToAdditiveTypeKey()); _productUnitOfWork.ChileProductIngredientRepository.Remove(ingredient); } update = true; ingredient = _productUnitOfWork.ChileProductIngredientRepository.Add(new ChileProductIngredient { ChileProductId = chileProduct.Id, AdditiveTypeId = match.Item2.AdditiveTypeKey.AdditiveTypeKey_AdditiveTypeId }); } else { update = ingredient.Percentage != match.Item2.Parameters.Percentage; } if (update) { ingredient.EmployeeId = employeeResult.ResultingObject.EmployeeId; ingredient.TimeStamp = timeStamp; ingredient.Percentage = match.Item2.Parameters.Percentage; } } } return(new SuccessResult().ConvertTo(chileProduct)); }
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)); }
protected IResult <InventoryShipmentOrder> SetOrder <TParams>(InventoryShipmentOrder inventoryShipmentOrder, DateTime timeStamp, SetInventoryShipmentOrderConductorParameters <TParams> parameters) where TParams : ISetOrderParameters { if (inventoryShipmentOrder == null) { throw new ArgumentNullException("inventoryShipmentOrder"); } if (parameters == null) { throw new ArgumentNullException("parameters"); } var employeeResult = new GetEmployeeCommand(UnitOfWork).GetEmployee(parameters.Params); if (!employeeResult.Success) { return(employeeResult.ConvertTo <InventoryShipmentOrder>()); } inventoryShipmentOrder.EmployeeId = employeeResult.ResultingObject.EmployeeId; inventoryShipmentOrder.TimeStamp = timeStamp; if (parameters.Params.HeaderParameters != null) { inventoryShipmentOrder.SetHeaderParameters(parameters.Params.HeaderParameters); } if (parameters.DestinationFacilityKey != null) { var destinationFacility = UnitOfWork.FacilityRepository.FindByKey(parameters.DestinationFacilityKey, f => f.Locations); if (destinationFacility == null) { return(new InvalidResult <InventoryShipmentOrder>(null, string.Format(UserMessages.FacilityNotFound, parameters.DestinationFacilityKey))); } var validateFacility = ValidateDestinationFacility(destinationFacility); if (!validateFacility.Success) { return(validateFacility.ConvertTo <InventoryShipmentOrder>()); } inventoryShipmentOrder.DestinationFacility = destinationFacility; inventoryShipmentOrder.DestinationFacilityId = destinationFacility.Id; } if (parameters.SourceFacilityKey != null) { var sourceFacility = UnitOfWork.FacilityRepository.FindByKey(parameters.SourceFacilityKey, f => f.Locations); if (sourceFacility == null) { return(new InvalidResult <InventoryShipmentOrder>(null, string.Format(UserMessages.FacilityNotFound, parameters.SourceFacilityKey))); } var currentKeys = inventoryShipmentOrder.PickedInventory.Items.Select(i => new LocationKey(i.FromLocation)).ToList(); if (currentKeys.Any(l => sourceFacility.Locations.All(c => !l.Equals(c)))) { return(new InvalidResult <InventoryShipmentOrder>(null, string.Format(UserMessages.SourceLocationMustBelongToFacility, parameters.SourceFacilityKey))); } inventoryShipmentOrder.SourceFacility = sourceFacility; inventoryShipmentOrder.SourceFacilityId = sourceFacility.Id; } if (parameters.Params.SetShipmentInformation != null) { inventoryShipmentOrder.ShipmentInformation.SetShipmentInformation(parameters.Params.SetShipmentInformation); } if (parameters.Params.InventoryPickOrderItems != null) { var pickOrderResult = new InventoryPickOrderCommand(UnitOfWork).Execute(inventoryShipmentOrder.InventoryPickOrder, parameters.PickOrderItems); if (!pickOrderResult.Success) { return(pickOrderResult.ConvertTo <InventoryShipmentOrder>()); } } return(new SuccessResult <InventoryShipmentOrder>(inventoryShipmentOrder)); }
public IResult <ProductionBatch> Execute(DateTime timestamp, CreateProductionBatchCommandParameters parameters) { if (parameters == null) { throw new ArgumentNullException("parameters"); } var packSchedule = _productionUnitOfWork.PackScheduleRepository.FindByKey(parameters.PackScheduleKey, p => p.ChileProduct); if (packSchedule == null) { return(new InvalidResult <ProductionBatch>(null, string.Format(UserMessages.PackScheduleNotFound, parameters.PackScheduleKey.KeyValue))); } var employeeResult = new GetEmployeeCommand(_productionUnitOfWork).GetEmployee(parameters.Parameters); if (!employeeResult.Success) { return(employeeResult.ConvertTo <ProductionBatch>()); } var createChileLotCommand = new CreateNewChileLotCommand(_productionUnitOfWork); var createChileLotResult = createChileLotCommand.Execute(new CreateNewChileLotCommandParameters { EmployeeKey = employeeResult.ResultingObject, TimeStamp = timestamp, PackagingReceivedKey = packSchedule, ChileProductKey = new ChileProductKey(packSchedule), LotType = parameters.Parameters.LotType ?? packSchedule.ChileProduct.ChileState.ToLotType(), LotDate = parameters.Parameters.LotDateCreated?.Date ?? timestamp, LotSequence = parameters.Parameters.LotSequence, SetLotProductionStatus = LotProductionStatus.Batched, SetLotQualityStatus = LotQualityStatus.Pending }); if (!createChileLotResult.Success) { return(createChileLotResult.ConvertTo <ProductionBatch>()); } var chileLot = createChileLotResult.ResultingObject; chileLot.Lot.Notes = parameters.Parameters.Notes.TrimTruncate(Constants.StringLengths.LotNotes); var productionResult = new CreateChileLotProductionCommand(_productionUnitOfWork).Execute(new CreateChileLotProduction { TimeStamp = timestamp, EmployeeKey = employeeResult.ResultingObject, LotKey = chileLot, ProductionType = ProductionType.ProductionBatch }); if (!productionResult.Success) { return(productionResult.ConvertTo <ProductionBatch>()); } var production = productionResult.ResultingObject; var notebookResult = new CreateNotebookCommand(_productionUnitOfWork).Execute(timestamp, employeeResult.ResultingObject, parameters.Parameters.Instructions); if (!notebookResult.Success) { return(notebookResult.ConvertTo <ProductionBatch>()); } var notebook = notebookResult.ResultingObject; var productionBatch = new ProductionBatch { EmployeeId = employeeResult.ResultingObject.EmployeeId, TimeStamp = timestamp, LotDateCreated = chileLot.LotDateCreated, LotDateSequence = chileLot.LotDateSequence, LotTypeId = chileLot.LotTypeId, PackScheduleDateCreated = parameters.PackScheduleKey.PackScheduleKey_DateCreated, PackScheduleSequence = parameters.PackScheduleKey.PackScheduleKey_DateSequence, InstructionNotebook = notebook, InstructionNotebookDateCreated = notebook.Date, InstructionNotebookSequence = notebook.Sequence, ProductionHasBeenCompleted = false, TargetParameters = new ProductionBatchTargetParameters(parameters.Parameters), Production = production }; _productionUnitOfWork.ProductionBatchRepository.Add(productionBatch); return(new SuccessResult <ProductionBatch>(productionBatch)); }
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)); }
protected IResult <SalesOrder> SetSalesOrder(SalesOrder salesOrder, DateTime timeStamp, SetSalesOrderParametersBase parameters) { if (salesOrder == null) { throw new ArgumentNullException("salesOrder"); } 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>()); } if (parameters.BrokerKey != null) { if (salesOrder.BrokerId != parameters.BrokerKey.CompanyKey_Id) { var broker = SalesUnitOfWork.CompanyRepository.FindByKey(parameters.BrokerKey, c => c.CompanyTypes); if (broker == null) { return(new InvalidResult <SalesOrder>(null, string.Format(UserMessages.CompanyNotFound, parameters.BrokerKey))); } if (broker.CompanyTypes.All(t => t.CompanyTypeEnum != CompanyType.Broker)) { return(new InvalidResult <SalesOrder>(null, string.Format(UserMessages.CompanyNotOfType, parameters.BrokerKey, CompanyType.Broker))); } salesOrder.Broker = null; salesOrder.BrokerId = broker.Id; } } else { salesOrder.Broker = null; salesOrder.BrokerId = null; } salesOrder.InventoryShipmentOrder.EmployeeId = employeeResult.ResultingObject.EmployeeId; salesOrder.InventoryShipmentOrder.TimeStamp = timeStamp; salesOrder.InventoryShipmentOrder.SourceFacility = null; salesOrder.InventoryShipmentOrder.SourceFacilityId = parameters.ShipFromFacilityKey.FacilityKey_Id; salesOrder.InventoryShipmentOrder.DestinationFacilityId = null; salesOrder.InventoryShipmentOrder.PurchaseOrderNumber = parameters.Parameters.HeaderParameters.CustomerPurchaseOrderNumber; salesOrder.InventoryShipmentOrder.DateReceived = parameters.Parameters.HeaderParameters.DateOrderReceived; salesOrder.InventoryShipmentOrder.RequestedBy = parameters.Parameters.HeaderParameters.OrderRequestedBy; salesOrder.InventoryShipmentOrder.TakenBy = parameters.Parameters.HeaderParameters.OrderTakenBy; salesOrder.PaymentTerms = parameters.Parameters.HeaderParameters.PaymentTerms; salesOrder.PreShipmentSampleRequired = parameters.Parameters.PreShipmentSampleRequired; salesOrder.InvoiceDate = parameters.Parameters.InvoiceDate; salesOrder.InvoiceNotes = parameters.Parameters.InvoiceNotes; salesOrder.FreightCharge = parameters.Parameters.FreightCharge; if (parameters.Parameters.SetShipmentInformation != null && parameters.Parameters.SetShipmentInformation.ShippingInstructions != null) { salesOrder.SetSoldTo(parameters.Parameters.SetShipmentInformation.ShippingInstructions.ShipFromOrSoldTo); } else { salesOrder.SetSoldTo(null); } salesOrder.InventoryShipmentOrder.ShipmentInformation.SetShipmentInformation(parameters.Parameters.SetShipmentInformation, false); if (parameters.OrderItems != null) { var setItemsResult = new SetSalesOrderItemsConductor(SalesUnitOfWork).SetOrderItems(salesOrder, parameters.OrderItems); if (!setItemsResult.Success) { return(setItemsResult.ConvertTo <SalesOrder>()); } } return(new SuccessResult <SalesOrder>(salesOrder)); }
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)); }