internal IResult <Note> Execute(Data.Models.Notebook notebook, DateTime timestamp, Employee employee, string text) { if (notebook == null) { throw new ArgumentNullException("notebook"); } if (timestamp == null) { throw new ArgumentNullException("timestamp"); } if (employee == null) { throw new ArgumentNullException("employee"); } if (text == null) { throw new ArgumentNullException("text"); } var newSequence = new EFUnitOfWorkHelper(_notebookUnitOfWork).GetNextSequence <Note>(n => n.NotebookDate == notebook.NotebookKey_Date && n.NotebookSequence == notebook.NotebookKey_Sequence, n => n.Sequence); var newNote = _notebookUnitOfWork.NoteRepository.Add(new Note { NotebookDate = notebook.Date, NotebookSequence = notebook.Sequence, Sequence = newSequence, EmployeeId = employee.EmployeeId, TimeStamp = timestamp, Text = text }); return(new SuccessResult <Note>(newNote)); }
public IResult <PickedInventory> Execute(ICreatePickedInventory parameters) { if (parameters == null) { throw new ArgumentNullException("parameters"); } var dateCreated = parameters.TimeStamp.Date; var sequence = new EFUnitOfWorkHelper(_pickedInventoryUnitOfWork).GetNextSequence <PickedInventory>(i => i.DateCreated == dateCreated, i => i.Sequence); var pickedInventory = new PickedInventory { EmployeeId = parameters.EmployeeKey.EmployeeKey_Id, TimeStamp = parameters.TimeStamp, DateCreated = dateCreated, Sequence = sequence, PickedReason = parameters.PickedReason, Archived = false, Items = new List <PickedInventoryItem>() }; _pickedInventoryUnitOfWork.PickedInventoryRepository.Add(pickedInventory); return(new SuccessResult <PickedInventory>(pickedInventory)); }
internal IResult <InventoryTransaction> Create(InventoryTransactionParameters parameters, IInventoryKey inventoryKey, int quantity) { var date = parameters.TimeStamp.Date; var sequence = new EFUnitOfWorkHelper(_coreUnitOfWork).GetNextSequence <InventoryTransaction>(t => t.DateCreated == date, t => t.Sequence); var setDestinationLot = quantity < 0 && parameters.DestinationLotKey != null; var transaction = _coreUnitOfWork.InventoryTransactionsRepository.Add(new InventoryTransaction { DateCreated = date, Sequence = sequence, EmployeeId = parameters.EmployeeKey.EmployeeKey_Id, TimeStamp = parameters.TimeStamp, TransactionType = parameters.TransactionType, Description = parameters.Description, SourceReference = parameters.SourceReference, SourceLotDateCreated = inventoryKey.LotKey_DateCreated, SourceLotDateSequence = inventoryKey.LotKey_DateSequence, SourceLotTypeId = inventoryKey.LotKey_LotTypeId, PackagingProductId = inventoryKey.PackagingProductKey_ProductId, LocationId = inventoryKey.LocationKey_Id, TreatmentId = inventoryKey.InventoryTreatmentKey_Id, ToteKey = inventoryKey.InventoryKey_ToteKey, DestinationLotDateCreated = setDestinationLot ? parameters.DestinationLotKey.LotKey_DateCreated : (DateTime?)null, DestinationLotDateSequence = setDestinationLot ? parameters.DestinationLotKey.LotKey_DateSequence : (int?)null, DestinationLotTypeId = setDestinationLot ? parameters.DestinationLotKey.LotKey_LotTypeId : (int?)null, Quantity = quantity }); return(new SuccessResult <InventoryTransaction>(transaction)); }
internal ModifyPickedInventoryItemsCommand(IPickedInventoryUnitOfWork pickedInventoryUnitOfWork) { if (pickedInventoryUnitOfWork == null) { throw new ArgumentNullException("pickedInventoryUnitOfWork"); } _pickedInventoryUnitOfWork = pickedInventoryUnitOfWork; _unitOfWorkHelper = new EFUnitOfWorkHelper(_pickedInventoryUnitOfWork); }
private IResult <Data.Models.Inventory> ModifyInventory(ModifyInventoryParameters input) { if (input == null) { throw new ArgumentNullException("input"); } Data.Models.Inventory inventory; EntityState? state; var notPendingResult = new EFUnitOfWorkHelper(_inventoryUnitOfWork).EntityHasNoPendingChanges(input.InventoryKey, input.InventoryKey, out inventory, out state); if (!notPendingResult.Success) { if (state != EntityState.Added && state != EntityState.Modified) { return(notPendingResult.ConvertTo <Data.Models.Inventory>()); } } var addedOrModified = !notPendingResult.Success; if (inventory == null) { inventory = _inventoryUnitOfWork.InventoryRepository.FindByKey(input.InventoryKey); if (inventory == null) { inventory = _inventoryUnitOfWork.InventoryRepository.Add(new Data.Models.Inventory { LotDateCreated = input.InventoryKey.LotKey_DateCreated, LotDateSequence = input.InventoryKey.LotKey_DateSequence, LotTypeId = input.InventoryKey.LotKey_LotTypeId, PackagingProductId = input.InventoryKey.PackagingProductKey_ProductId, LocationId = input.InventoryKey.LocationKey_Id, TreatmentId = input.InventoryKey.InventoryTreatmentKey_Id, ToteKey = input.InventoryKey.InventoryKey_ToteKey, Quantity = 0 }); addedOrModified = true; } } inventory.Quantity += input.ModifyQuantity; if (inventory.Quantity == 0) { if (addedOrModified) { return(new InvalidResult <Data.Models.Inventory>(null, string.Format(UserMessages.QuantityForInventoryMustBeGreaterThanZero, input.InventoryKey))); } _inventoryUnitOfWork.InventoryRepository.Remove(inventory); inventory = null; } return(new SuccessResult <Data.Models.Inventory>(inventory)); }
internal IResult <CustomerNote> Create(ICustomerKey customerKey, DateTime timestamp, ISetCustomerNoteParameters parameters) { var noteId = new EFUnitOfWorkHelper(_companyUnitOfWork).GetNextSequence <CustomerNote>(c => c.CustomerId == customerKey.CustomerKey_Id, c => c.NoteId); var note = _companyUnitOfWork.CustomerNoteRepository.Add(new CustomerNote { CustomerId = customerKey.CustomerKey_Id, NoteId = noteId }); return(SetCustomerNote(note, timestamp, parameters)); }
internal IResult <Data.Models.Notebook> Execute(DateTime date) { var currentDate = date.Date; var nextSequence = new EFUnitOfWorkHelper(_notebookUnitOfWork).GetNextSequence <Data.Models.Notebook>(n => n.Date == currentDate, n => n.Sequence); var newNotebook = _notebookUnitOfWork.NotebookRepository.Add(new Data.Models.Notebook { Date = currentDate, Sequence = nextSequence }); return(new SuccessResult <Data.Models.Notebook>(newNotebook)); }
private IResult UpdateOrCreateLotDefects(LotAttribute lotAttribute, IAttributeValueParameters attributeValue, ChileProductAttributeRange range) { var unresolvedDefects = _parameters.LotAttributeDefects.Where(d => d.AttributeShortName == lotAttribute.AttributeShortName && d.LotDefect.Resolution == null).ToList(); if (unresolvedDefects.Any()) { unresolvedDefects.ForEach(d => { d.OriginalAttributeValue = attributeValue.NewValue.Value; d.OriginalAttributeMinLimit = range.RangeMin; d.OriginalAttributeMaxLimit = range.RangeMax; }); } else { int defectId; lock (LotDefectLock) { defectId = new EFUnitOfWorkHelper(_lotUnitOfWork).GetNextSequence <LotDefect>(d => d.LotDateCreated == _parameters.Lot.LotDateCreated && d.LotDateSequence == _parameters.Lot.LotDateSequence && d.LotTypeId == _parameters.Lot.LotTypeId, d => d.DefectId); } var lotDefect = _lotUnitOfWork.LotDefectRepository.Add(new LotDefect { LotDateCreated = _parameters.Lot.LotDateCreated, LotDateSequence = _parameters.Lot.LotDateSequence, LotTypeId = _parameters.Lot.LotTypeId, DefectId = defectId, DefectType = lotAttribute.AttributeName.DefectType, Description = lotAttribute.AttributeName.Name, }); _lotUnitOfWork.LotAttributeDefectRepository.Add(new LotAttributeDefect { LotDateCreated = lotDefect.LotDateCreated, LotDateSequence = lotDefect.LotDateSequence, LotTypeId = lotDefect.LotTypeId, DefectId = lotDefect.DefectId, AttributeShortName = lotAttribute.AttributeShortName, OriginalAttributeValue = attributeValue.NewValue.Value, OriginalAttributeMinLimit = range.RangeMin, OriginalAttributeMaxLimit = range.RangeMax, AttributeName = lotAttribute.AttributeName, }); } return(new SuccessResult()); }
internal IResult <ShipmentInformation> Execute(DateTime dateCreated) { if (dateCreated == null) { throw new ArgumentNullException("dateCreated"); } dateCreated = dateCreated.Date; var sequence = new EFUnitOfWorkHelper(_shipmentUnitOfWork).GetNextSequence <ShipmentInformation>(s => s.DateCreated == dateCreated, s => s.Sequence); var shipmentInfo = _shipmentUnitOfWork.ShipmentInformationRepository.Add(new ShipmentInformation { DateCreated = dateCreated, Sequence = sequence }); return(new SuccessResult <ShipmentInformation>(shipmentInfo)); }
/// <param name="contract">A Contract able to navigate to Contract.Customer.ProductCodes.</param> internal IResult Execute(Contract contract, List <SetContractItemParameters> newItems) { if (contract == null) { throw new ArgumentNullException("contract"); } if (newItems == null) { throw new ArgumentNullException("newItems"); } var unitOfWorkHelper = new EFUnitOfWorkHelper(_salesUnitOfWork); var productCodes = (contract.Customer.ProductCodes ?? new CustomerProductCode[0]).ToList(); var matches = (contract.ContractItems ?? new ContractItem[0]).BestMatches(newItems, (c, n) => n.ChileProductKey.Equals(c), (c, n) => n.PackagingProductKey.Equals(c), (c, n) => n.TreatmentKey.Equals(c), (c, n) => n.ContractItemParameters.UseCustomerSpec == c.UseCustomerSpec, (c, n) => n.ContractItemParameters.CustomerCodeOverride == c.CustomerProductCode, (c, n) => n.ContractItemParameters.Quantity == c.Quantity); foreach (var match in matches) { if (match.Item1 != null && match.Item2 != null) { SetContractItem(match.Item1, match.Item2, productCodes); } else if (match.Item1 != null) { _salesUnitOfWork.ContractItemRepository.Remove(match.Item1); } else if (match.Item2 != null) { var nextItemSequence = unitOfWorkHelper.GetNextSequence <ContractItem>(i => i.ContractYear == contract.ContractYear && i.ContractSequence == contract.ContractSequence, i => i.ContractItemSequence); SetContractItem(_salesUnitOfWork.ContractItemRepository.Add(new ContractItem { ContractYear = contract.ContractYear, ContractSequence = contract.ContractSequence, ContractItemSequence = nextItemSequence }), match.Item2, productCodes); } } return(new SuccessResult()); }
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)); }
internal IResult <Data.Models.Company> Execute(DateTime timeStamp, CreateCompanyCommandParameters parameters) { if (parameters == null) { throw new ArgumentNullException("parameters"); } var nextId = new EFUnitOfWorkHelper(CompanyUnitOfWork).GetNextSequence <Data.Models.Company>(c => true, c => c.Id); var company = CompanyUnitOfWork.CompanyRepository.Add(new Data.Models.Company { TimeStamp = timeStamp, Id = nextId, Name = parameters.Parameters.CompanyName, Active = parameters.Parameters.Active }); return(SetCompany(company, timeStamp, parameters)); }
internal IResult <Product> CreateProduct(ICreateProductParameters parameters, ProductTypeEnum productType) { if (parameters == null) { throw new ArgumentNullException("parameters"); } var nextId = new EFUnitOfWorkHelper(_productUnitOfWork).GetNextSequence <Product>(p => true, p => p.Id); var product = _productUnitOfWork.ProductRepository.Add(new Product { Id = nextId, Name = parameters.ProductName, ProductCode = parameters.ProductCode, IsActive = true, ProductType = productType }); return(new SuccessResult <Product>(product)); }
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 <InventoryAdjustmentItem> Execute(InventoryAdjustment inventoryAdjustment, CreateInventoryAdjustmentItemCommandParameters parameters) { if (inventoryAdjustment == null) { throw new ArgumentNullException("inventoryAdjustment"); } if (parameters == null) { throw new ArgumentNullException("parameters"); } if (parameters.InventoryAdjustmentParameters.Adjustment == 0) { return(new InvalidResult <InventoryAdjustmentItem>(null, UserMessages.AdjustmentQuantityCannotBeZero)); } var nextSequence = new EFUnitOfWorkHelper(_inventoryUnitOfWork).GetNextSequence <InventoryAdjustmentItem>(i => i.AdjustmentDate == inventoryAdjustment.InventoryAdjustmentKey_AdjustmentDate && i.Sequence == inventoryAdjustment.InventoryAdjustmentKey_Sequence, i => i.ItemSequence); var adjustment = _inventoryUnitOfWork.InventoryAdjustmentItemRepository.Add(new InventoryAdjustmentItem { AdjustmentDate = inventoryAdjustment.AdjustmentDate, Sequence = inventoryAdjustment.Sequence, ItemSequence = nextSequence, EmployeeId = inventoryAdjustment.EmployeeId, TimeStamp = inventoryAdjustment.TimeStamp, QuantityAdjustment = parameters.InventoryAdjustmentParameters.Adjustment, LotDateCreated = parameters.LotKey.LotKey_DateCreated, LotDateSequence = parameters.LotKey.LotKey_DateSequence, LotTypeId = parameters.LotKey.LotKey_LotTypeId, PackagingProductId = parameters.PackagingProductKey.PackagingProductKey_ProductId, LocationId = parameters.LocationKey.LocationKey_Id, TreatmentId = parameters.InventoryTreatmentKey.InventoryTreatmentKey_Id, ToteKey = parameters.ToteKey }); return(new SuccessResult <InventoryAdjustmentItem>(adjustment)); }
public IResult Execute(ISchedulePickOrderItemParameter item) { var newSequence = new EFUnitOfWorkHelper(_inventoryPickOrderUnitOfWork).GetNextSequence(InventoryPickOrderItemPredicates.FilterByInventoryPickOrderKey(item.PickOrderKey), i => i.ItemSequence); var newItem = new InventoryPickOrderItem { DateCreated = item.PickOrderKey.InventoryPickOrderKey_DateCreated, OrderSequence = item.PickOrderKey.InventoryPickOrderKey_Sequence, ItemSequence = newSequence, ProductId = item.ProductId, PackagingProductId = item.PackagingProductId, TreatmentId = item.TreatmentId ?? StaticInventoryTreatments.NoTreatment.Id, Quantity = item.Quantity, CustomerLotCode = item.CustomerLotCode, CustomerProductCode = item.CustomerProductCode, CustomerId = item.CustomerKey != null ? item.CustomerKey.CustomerKey_Id : (int?)null }; _inventoryPickOrderUnitOfWork.InventoryPickOrderItemRepository.Add(newItem); return(new SuccessResult()); }
internal IResult <Contact> Execute(CreateContactCommandParameters parameters) { if (parameters == null) { throw new ArgumentNullException("parameters"); } var company = CompanyUnitOfWork.CompanyRepository.FindByKey(parameters.CompanyKey); if (company == null) { return(new InvalidResult <Contact>(null, string.Format(UserMessages.CompanyNotFound, parameters.CompanyKey.KeyValue))); } var nextSequence = new EFUnitOfWorkHelper(CompanyUnitOfWork).GetNextSequence <Contact>(c => c.CompanyId == company.Id, c => c.ContactId); var contact = new Contact { CompanyId = company.Id, ContactId = nextSequence, Addresses = new List <ContactAddress>() }; return(SetContact(CompanyUnitOfWork.ContactRepository.Add(contact), parameters)); }
private IResult <InventoryAdjustment> CreateInventoryAdjustment(DateTime timestamp, Employee employee, string comment) { var notebookResult = CreateNotebook(timestamp, employee, comment); if (!notebookResult.Success) { return(notebookResult.ConvertTo((InventoryAdjustment)null)); } var notebook = notebookResult.ResultingObject; var newSequence = new EFUnitOfWorkHelper(_inventoryUnitOfWork).GetNextSequence(InventoryAdjustmentPredicates.ByAdjustmentDate(timestamp), a => a.Sequence); var newInventoryAdjustment = _inventoryUnitOfWork.InventoryAdjustmentRepository.Add(new InventoryAdjustment { AdjustmentDate = timestamp.Date, Sequence = newSequence, EmployeeId = employee.EmployeeId, TimeStamp = timestamp, NotebookDate = notebook.Date, NotebookSequence = notebook.Sequence }); return(new SuccessResult <InventoryAdjustment>(newInventoryAdjustment)); }
internal IResult Execute(PickedInventoryKey pickedInventoryKey, List <ModifySalesOrderPickedInventoryItemParameters> items) { if (items == null) { throw new ArgumentNullException("items"); } foreach (var item in items) { if (item.SalesOrderPickedItemKey != null) { var notPendingResult = new EFUnitOfWorkHelper(_salesUnitOfWork).EntityHasNoPendingChanges(item.SalesOrderPickedItemKey, item.SalesOrderPickedItemKey); if (!notPendingResult.Success) { return(notPendingResult); } var pickedItem = _salesUnitOfWork.SalesOrderPickedItemRepository.FindByKey(item.SalesOrderPickedItemKey); if (pickedItem == null) { return(new InvalidResult(string.Format(UserMessages.SalesOrderPickedItemNotFound, item.SalesOrderPickedItemKey.KeyValue))); } if (pickedItem.PickedInventoryItem.CurrentLocationId != pickedItem.PickedInventoryItem.FromLocationId) { return(new InvalidResult(string.Format(UserMessages.PickedInventoryItemNotInOriginalLocation, new PickedInventoryItemKey(pickedItem).KeyValue))); } pickedItem.PickedInventoryItem.Quantity = item.NewQuantity; pickedItem.OrderItemSequence = item.SalesOrderItemKey.SalesOrderItemKey_ItemSequence; if (pickedItem.PickedInventoryItem.Quantity < 0) { return(new InvalidResult(string.Format(UserMessages.QuantityForPickedCannotBeNegative, item.PickedInventoryItemKey.KeyValue))); } if (pickedItem.PickedInventoryItem.Quantity == 0) { _salesUnitOfWork.PickedInventoryItemRepository.Remove(pickedItem.PickedInventoryItem); _salesUnitOfWork.SalesOrderPickedItemRepository.Remove(pickedItem); } else { pickedItem.PickedInventoryItem.CustomerLotCode = item.CustomerLotCode; pickedItem.PickedInventoryItem.CustomerProductCode = item.CustomerProductCode; } } else { if (item.NewQuantity <= 0) { return(new InvalidResult(string.Format(UserMessages.QuantityForPickingFromInventoryMustBeGreaterThanZero, item.InventoryKey.KeyValue))); } var newSequence = new EFUnitOfWorkHelper(_salesUnitOfWork).GetNextSequence(PickedInventoryItemPredicates.FilterByPickedInventoryKey(pickedInventoryKey), i => i.ItemSequence); var newPickedInventoryItem = new PickedInventoryItem { DateCreated = pickedInventoryKey.PickedInventoryKey_DateCreated, Sequence = pickedInventoryKey.PickedInventoryKey_Sequence, ItemSequence = newSequence, LotDateCreated = item.InventoryKey.LotKey_DateCreated, LotDateSequence = item.InventoryKey.LotKey_DateSequence, LotTypeId = item.InventoryKey.LotKey_LotTypeId, PackagingProductId = item.InventoryKey.PackagingProductKey_ProductId, FromLocationId = item.InventoryKey.LocationKey_Id, TreatmentId = item.InventoryKey.InventoryTreatmentKey_Id, CurrentLocationId = item.InventoryKey.LocationKey_Id, ToteKey = item.InventoryKey.InventoryKey_ToteKey, Quantity = item.NewQuantity, CustomerLotCode = item.CustomerLotCode, CustomerProductCode = item.CustomerProductCode }; _salesUnitOfWork.PickedInventoryItemRepository.Add(newPickedInventoryItem); var customerOrderPickedItem = new SalesOrderPickedItem { DateCreated = pickedInventoryKey.PickedInventoryKey_DateCreated, Sequence = pickedInventoryKey.PickedInventoryKey_Sequence, ItemSequence = newSequence, OrderItemSequence = item.SalesOrderItemKey.SalesOrderItemKey_ItemSequence }; _salesUnitOfWork.SalesOrderPickedItemRepository.Add(customerOrderPickedItem); } } return(new SuccessResult()); }
protected IResult <Lot> CreateLot(CreateNewLotCommandParameters parameters) { if (parameters == null) { throw new ArgumentNullException("parameters"); } parameters.LotDate = parameters.LotDate.ToLocalTime().Date; // ensure LotDate is always created in local time int newLotSequence; if (parameters.LotSequence != null) { var lot = LotUnitOfWork.LotRepository.Filter(l => l.LotDateCreated == parameters.LotDate && l.LotDateSequence == parameters.LotSequence && l.LotTypeId == (int)parameters.LotType).FirstOrDefault(); if (lot != null) { return(new InvalidResult <Lot>(null, string.Format(UserMessages.LotExistsWithKey, lot.ToLotKey()))); } newLotSequence = (int)parameters.LotSequence; } else { newLotSequence = new EFUnitOfWorkHelper(LotUnitOfWork).GetNextSequence(LotPredicates.FilterByLotDateAndTypeId(parameters.LotDate, parameters.LotType), l => l.LotDateSequence); } if (newLotSequence < 1) { return(new InvalidResult <Lot>(null, string.Format(UserMessages.LotDateSequenceLessThanOne))); } var packagingKey = parameters.PackagingReceivedKey; if (packagingKey == null) { packagingKey = LotUnitOfWork.PackagingProductRepository.Filter(p => p.Weight <= 0.0, p => p.Product).ToList().FirstOrDefault(p => p.Product.Name.Replace(" ", "").ToUpper() == "NOPACKAGING"); if (packagingKey == null) { return(new InvalidResult <Lot>(null, UserMessages.NoPackagingNotFound)); } } var newLot = LotUnitOfWork.LotRepository.Add(new Lot { EmployeeId = parameters.EmployeeKey.EmployeeKey_Id, TimeStamp = parameters.TimeStamp, LotDateCreated = parameters.LotDate.Date, LotDateSequence = newLotSequence, LotTypeEnum = parameters.LotType, ReceivedPackagingProductId = packagingKey.PackagingProductKey_ProductId, QualityStatus = parameters.LotQualityStatus, ProductionStatus = parameters.LotProductionStatus, ProductSpecComplete = parameters.ProductSpecComplete, ProductSpecOutOfRange = parameters.ProductSpecOutOfRange, VendorId = parameters.VendorKey == null ? (int?)null : parameters.VendorKey.CompanyKey_Id, PurchaseOrderNumber = parameters.PurchaseOrderNumber, ShipperNumber = parameters.ShipperNumber }); return(new SuccessResult <Lot>(newLot)); }
internal IResult <SalesQuote> Execute(DateTime timestamp, SalesQuoteParameters parameters) { var employeeResult = new GetEmployeeCommand(_inventoryShipmentOrderUnitOfWork).GetEmployee(parameters.Parameters); if (!employeeResult.Success) { return(employeeResult.ConvertTo <SalesQuote>()); } SalesQuote salesQuote; if (parameters.SalesQuoteNumber == null) { var date = timestamp.Date; var shipmentInfoResult = new CreateShipmentInformationCommand(_inventoryShipmentOrderUnitOfWork).Execute(date); if (!shipmentInfoResult.Success) { return(shipmentInfoResult.ConvertTo <SalesQuote>()); } var sequence = new EFUnitOfWorkHelper(_inventoryShipmentOrderUnitOfWork).GetNextSequence <SalesQuote>(q => q.DateCreated == date, q => q.Sequence); var shipmentInformation = shipmentInfoResult.ResultingObject; var quoteNum = (date.Year * 100) - 1; salesQuote = _inventoryShipmentOrderUnitOfWork.SalesQuoteRepository.Add(new SalesQuote { DateCreated = date, Sequence = sequence, ShipmentInfoDateCreated = shipmentInformation.DateCreated, ShipmentInfoSequence = shipmentInformation.Sequence, ShipmentInformation = shipmentInformation, Items = new List <SalesQuoteItem>(), QuoteNum = _inventoryShipmentOrderUnitOfWork.SalesQuoteRepository.SourceQuery .Select(q => q.QuoteNum) .Where(q => q != null && q > quoteNum) .DefaultIfEmpty(quoteNum) .Max() + 1 }); } else { salesQuote = _inventoryShipmentOrderUnitOfWork.SalesQuoteRepository .Filter(q => q.QuoteNum == parameters.SalesQuoteNumber, q => q.ShipmentInformation, q => q.Items) .FirstOrDefault(); if (salesQuote == null) { return(new InvalidResult <SalesQuote>(null, string.Format(UserMessages.SalesQuoteNotFound_Num, parameters.SalesQuoteNumber))); } } Facility sourceFacility = null; if (parameters.SourceFacilityKey != null) { sourceFacility = _inventoryShipmentOrderUnitOfWork.FacilityRepository.FindByKey(parameters.SourceFacilityKey); if (sourceFacility == null) { return(new InvalidResult <SalesQuote>(null, string.Format(UserMessages.FacilityNotFound, parameters.SourceFacilityKey))); } } Company customer = null; var getCompanyCommand = new GetCompanyCommand(_inventoryShipmentOrderUnitOfWork); if (parameters.CustomerKey != null) { var customerResult = getCompanyCommand.Execute(parameters.CustomerKey.ToCompanyKey(), CompanyType.Customer); if (!customerResult.Success) { return(customerResult.ConvertTo <SalesQuote>()); } customer = customerResult.ResultingObject; } Company broker = null; if (parameters.BrokerKey != null) { var brokerResult = getCompanyCommand.Execute(parameters.BrokerKey, CompanyType.Broker); if (!brokerResult.Success) { return(brokerResult.ConvertTo <SalesQuote>()); } broker = brokerResult.ResultingObject; } salesQuote.EmployeeId = employeeResult.ResultingObject.EmployeeId; salesQuote.TimeStamp = timestamp; salesQuote.SourceFacilityId = sourceFacility == null ? (int?)null : sourceFacility.Id; salesQuote.CustomerId = customer == null ? (int?)null : customer.CompanyKey_Id; salesQuote.BrokerId = broker == null ? (int?)null : broker.CompanyKey_Id; salesQuote.QuoteDate = parameters.Parameters.QuoteDate; salesQuote.DateReceived = parameters.Parameters.DateReceived; salesQuote.CalledBy = parameters.Parameters.CalledBy; salesQuote.TakenBy = parameters.Parameters.TakenBy; salesQuote.PaymentTerms = parameters.Parameters.PaymentTerms; ShippingLabel shipFromOrSoldTo = null; if (parameters.Parameters.ShipmentInformation != null && parameters.Parameters.ShipmentInformation.ShippingInstructions != null) { shipFromOrSoldTo = parameters.Parameters.ShipmentInformation.ShippingInstructions.ShipFromOrSoldTo; } salesQuote.SoldTo.SetShippingLabel(shipFromOrSoldTo); salesQuote.ShipmentInformation.SetShipmentInformation(parameters.Parameters.ShipmentInformation, false); var itemSequence = 0; var itemsToRemove = salesQuote.Items.ToDictionary(i => i.ToSalesQuoteItemKey(), i => { itemSequence = Math.Max(itemSequence, i.ItemSequence); return(i); }); foreach (var item in parameters.Items) { SalesQuoteItem salesQuoteItem = null; if (item.SalesQuoteItemKey != null) { if (itemsToRemove.TryGetValue(item.SalesQuoteItemKey, out salesQuoteItem)) { itemsToRemove.Remove(item.SalesQuoteItemKey); } else { return(new InvalidResult <SalesQuote>(null, string.Format(UserMessages.SalesQuoteItemNotFound, item.SalesQuoteItemKey))); } } else { salesQuote.Items.Add(salesQuoteItem = new SalesQuoteItem { DateCreated = salesQuote.DateCreated, Sequence = salesQuote.Sequence, ItemSequence = ++itemSequence }); } salesQuoteItem.ProductId = item.ProductKey.ProductKey_ProductId; salesQuoteItem.PackagingProductId = item.PackagingProductKey.PackagingProductKey_ProductId; salesQuoteItem.TreatmentId = item.InventoryTreatmentKey.InventoryTreatmentKey_Id; salesQuoteItem.Quantity = item.Parameters.Quantity; salesQuoteItem.PriceBase = item.Parameters.PriceBase; salesQuoteItem.PriceFreight = item.Parameters.PriceFreight; salesQuoteItem.PriceTreatment = item.Parameters.PriceTreatment; salesQuoteItem.PriceWarehouse = item.Parameters.PriceWarehouse; salesQuoteItem.PriceRebate = item.Parameters.PriceRebate; salesQuoteItem.CustomerProductCode = item.Parameters.CustomerProductCode; } foreach (var item in itemsToRemove.Values) { _inventoryShipmentOrderUnitOfWork.SalesQuoteItemRepository.Remove(item); } return(new SuccessResult <SalesQuote>(salesQuote)); }
internal IResult Execute(SalesOrder order, List <SetSalesOrderItemParameters> newItems) { if (order == null) { throw new ArgumentNullException("order"); } if (newItems == null) { throw new ArgumentNullException("newItems"); } var unitOfWorkHelper = new EFUnitOfWorkHelper(_salesUnitOfWork); var matches = (order.SalesOrderItems ?? new SalesOrderItem[0]).BestMatches(newItems, (c, n) => n.ContractItemKey == null ? c.ContractItem == null : n.ContractItemKey.Equals(c.ContractItem), (c, n) => n.ProductKey.Equals(c.InventoryPickOrderItem), (c, n) => n.PackagingProductKey.Equals(c.InventoryPickOrderItem), (c, n) => n.InventoryTreatmentKey.Equals(c.InventoryPickOrderItem), (c, n) => n.SalesOrderItem.Quantity == c.InventoryPickOrderItem.Quantity, (c, n) => n.SalesOrderItem.CustomerLotCode == c.InventoryPickOrderItem.CustomerLotCode, (c, n) => n.SalesOrderItem.CustomerProductCode == c.InventoryPickOrderItem.CustomerProductCode, (c, n) => n.SalesOrderItem.PriceBase == c.PriceBase, (c, n) => n.SalesOrderItem.PriceFreight == c.PriceFreight, (c, n) => n.SalesOrderItem.PriceTreatment == c.PriceTreatment, (c, n) => n.SalesOrderItem.PriceWarehouse == c.PriceWarehouse, (c, n) => n.SalesOrderItem.PriceRebate == c.PriceRebate); foreach (var match in matches) { if (match.Item1 != null && match.Item2 != null) { SetOrderItem(match.Item1, match.Item2); } else if (match.Item1 != null) { if (match.Item1.PickedItems.Any()) { return(new InvalidResult(UserMessages.CannotRemovePickedCustomerOrderItem)); } _salesUnitOfWork.InventoryPickOrderItemRepository.Remove(match.Item1.InventoryPickOrderItem); _salesUnitOfWork.SalesOrderItemRepository.Remove(match.Item1); } else if (match.Item2 != null) { var nextItemSequence = unitOfWorkHelper.GetNextSequence <SalesOrderItem>(i => i.DateCreated == order.DateCreated && i.Sequence == order.Sequence, i => i.ItemSequence); SetOrderItem(_salesUnitOfWork.SalesOrderItemRepository.Add(new SalesOrderItem { DateCreated = order.DateCreated, Sequence = order.Sequence, ItemSequence = nextItemSequence, InventoryPickOrderItem = new InventoryPickOrderItem { DateCreated = order.DateCreated, OrderSequence = order.Sequence, ItemSequence = nextItemSequence } }), match.Item2); } } return(new SuccessResult()); }
internal IResult <Contract> Execute(CreateCustomerContractCommandParameters parameters, DateTime timeStamp) { if (parameters == null) { throw new ArgumentNullException("parameters"); } if (timeStamp == null) { throw new ArgumentNullException("timeStamp"); } var customer = _salesUnitOfWork.CustomerRepository.FindByKey(parameters.CustomerKey, c => c.Company.Contacts.Select(n => n.Addresses), c => c.ProductCodes); if (customer == null) { return(new InvalidResult <Contract>(null, string.Format(UserMessages.CustomerNotFound, parameters.CustomerKey.KeyValue))); } var facilityKey = parameters.DefaultPickFromFacilityKey ?? new FacilityKey(GlobalKeyHelpers.RinconFacilityKey); var facility = _salesUnitOfWork.FacilityRepository.FindByKey(facilityKey); if (facility == null) { return(new InvalidResult <Contract>(null, string.Format(UserMessages.FacilityNotFound, facilityKey.KeyValue))); } var employeeResult = new GetEmployeeCommand(_salesUnitOfWork).GetEmployee(parameters.CreateCustomerContractParameters); if (!employeeResult.Success) { return(employeeResult.ConvertTo <Contract>()); } var commentsNotebookResult = new CreateNotebookCommand(_salesUnitOfWork).Execute(timeStamp, employeeResult.ResultingObject, parameters.CreateCustomerContractParameters.Comments); if (!commentsNotebookResult.Success) { return(commentsNotebookResult.ConvertTo <Contract>()); } var contractYear = timeStamp.Year; var contractSequence = new EFUnitOfWorkHelper(_salesUnitOfWork).GetNextSequence <Contract>(c => c.ContractYear == contractYear, c => c.ContractSequence); var contract = _salesUnitOfWork.ContractRepository.Add(new Contract { EmployeeId = employeeResult.ResultingObject.EmployeeId, TimeStamp = timeStamp, TimeCreated = timeStamp, ContractYear = contractYear, ContractSequence = contractSequence, CustomerId = customer.Id, BrokerId = customer.BrokerId, DefaultPickFromWarehouseId = facility.Id, CommentsDate = commentsNotebookResult.ResultingObject.Date, CommentsSequence = commentsNotebookResult.ResultingObject.Sequence, Customer = customer, ContractId = _salesUnitOfWork.ContractRepository.SourceQuery.Select(c => c.ContractId).DefaultIfEmpty(0).Max() + 1 }); return(new UpdateCustomerContractConductor(_salesUnitOfWork).SetCustomerContract(contract, employeeResult.ResultingObject, timeStamp, parameters)); }