private void LoadNotes(SampleOrder sampleOrder, tblSampleDTO tblSample) { var journalEntries = new List <SampleOrderJournalEntry>(); var noteSequence = 1; foreach (var tblSampleNote in tblSample.tblSampleNotes) { LoadCount.AddRead(EntityType.SampleOrderJournalEntry); var employeeId = _newContextHelper.DefaultEmployee.EmployeeId; if (tblSampleNote.EmployeeID != null) { employeeId = tblSampleNote.EmployeeID.Value; } else { Log(new CallbackParameters(CallbackReason.tblSampleNote_EmployeeID_Null) { tblSampleNote = tblSampleNote }); } journalEntries.Add(new SampleOrderJournalEntry { SampleOrderYear = sampleOrder.Year, SampleOrderSequence = sampleOrder.Sequence, EntrySequence = noteSequence++, EmployeeId = employeeId, Date = tblSampleNote.SampleJnlDate, Text = tblSampleNote.SampleNote, SamNoteID = tblSampleNote.SamNoteID }); } sampleOrder.JournalEntries = journalEntries; }
private void LoadDetails(SampleOrder sampleOrder, tblSampleDTO tblSample) { var items = new List <SampleOrderItem>(); var itemSequence = 1; foreach (var tblSampleDetail in tblSample.tblSampleDetails) { LoadCount.AddRead(EntityType.SampleOrderItem); var product = _newContextHelper.GetProduct(tblSampleDetail.ProdID); if (product == null && tblSampleDetail.ProdID != null) { Log(new CallbackParameters(CallbackReason.tblSampleDetail_MissingProduct) { tblSampleDetail = tblSampleDetail }); continue; } LotKey lotKey = null; if (tblSampleDetail.Lot != null) { lotKey = LotNumberParser.ParseLotNumber(tblSampleDetail.Lot.Value); if (lotKey == null) { Log(new CallbackParameters(CallbackReason.tblSampleDetail_InvalidLotNumber) { tblSampleDetail = tblSampleDetail }); continue; } if (!_newContextHelper.LotLoaded(lotKey)) { Log(new CallbackParameters(CallbackReason.tblSampleDetail_MissingLot) { tblSampleDetail = tblSampleDetail }); continue; } } var sampleOrderItem = new SampleOrderItem { SampleOrderYear = sampleOrder.Year, SampleOrderSequence = sampleOrder.Sequence, ItemSequence = itemSequence++, ProductId = product == null ? (int?)null : product.ProductKey.ProductKey_ProductId, LotDateCreated = lotKey == null ? (DateTime?)null : lotKey.LotKey_DateCreated, LotDateSequence = lotKey == null ? (int?)null : lotKey.LotKey_DateSequence, LotTypeId = lotKey == null ? (int?)null : lotKey.LotKey_LotTypeId, Quantity = (int)(tblSampleDetail.Qty ?? 0), Description = tblSampleDetail.Desc, CustomerProductName = tblSampleDetail.SampleMatch, SampleDetailID = tblSampleDetail.SampleDetailID, }; LoadItemSpec(tblSampleDetail.tblSampleCustSpec, sampleOrderItem); LoadItemMatch(tblSampleDetail.tblSampleRVCMatch, sampleOrderItem); items.Add(sampleOrderItem); } sampleOrder.Items = items; }
private SampleOrder LoadSampleOrder(tblSampleDTO tblSample) { LoadCount.AddRead(EntityType.SampleOrder); var employeeId = _newContextHelper.DefaultEmployee.EmployeeId; if (tblSample.EmployeeID != null) { employeeId = tblSample.EmployeeID.Value; } else { Log(new CallbackParameters(CallbackReason.tblSample_EmployeeID_Null) { tblSample = tblSample }); } var requestCustomer = _newContextHelper.GetCompany(tblSample.Company_IA, CompanyType.Customer); if (requestCustomer == null && !string.IsNullOrWhiteSpace(tblSample.Company_IA)) { Log(new CallbackParameters(CallbackReason.tblSample_MissingCompanyIA) { tblSample = tblSample }); return(null); } var broker = _newContextHelper.GetCompany(tblSample.Broker, CompanyType.Broker); if (broker == null && !string.IsNullOrWhiteSpace(tblSample.Broker)) { Log(new CallbackParameters(CallbackReason.tblSample_MissingBroker) { tblSample = tblSample }); return(null); } var status = ParseStatus(tblSample.Status); if (status == null) { Log(new CallbackParameters(CallbackReason.tblSample_InvalidStatus) { tblSample = tblSample }); return(null); } var dateDue = tblSample.SampleDate ?? tblSample.EntryDate.GetDate().Value; var dateReceived = tblSample.DateRecd ?? tblSample.EntryDate.GetDate().Value; var dateCompleted = tblSample.DateCompleted; if (tblSample.Completed && dateCompleted == null) { dateCompleted = tblSample.SampleDate ?? tblSample.EntryDate.Value; } var sampleOrderKey = ParseSampleOrderKey(tblSample.SampleID); var sampleOrder = new SampleOrder { Year = sampleOrderKey.SampleOrderKey_Year, Sequence = sampleOrderKey.SampleOrderKey_Sequence, EmployeeId = employeeId, TimeStamp = tblSample.EntryDate.Value.ConvertLocalToUTC(), Comments = tblSample.Comments, PrintNotes = tblSample.Notes2Print, Volume = (double)(tblSample.Volume ?? 0), DateDue = dateDue, DateReceived = dateReceived, DateCompleted = dateCompleted, ShipmentMethod = tblSample.Priority, FOB = tblSample.FOB, Status = status.Value, Active = tblSample.Active, RequestCustomerId = requestCustomer == null ? (int?)null : requestCustomer.Id, BrokerId = broker == null ? (int?)null : broker.Id, Request = new ShippingLabel { Name = tblSample.Contact_IA, Address = new Address { AddressLine1 = tblSample.Address1_IA, AddressLine2 = tblSample.Address2_IA, AddressLine3 = tblSample.Address3_IA, City = tblSample.City_IA, State = tblSample.State_IA, PostalCode = tblSample.Zip_IA, Country = tblSample.Country_IA, } }, ShipToCompany = tblSample.SCompany, ShipTo = new ShippingLabel { Name = tblSample.SContact, Phone = tblSample.SPhone, Address = new Address { AddressLine1 = tblSample.SAddress1, AddressLine2 = tblSample.SAddress2, AddressLine3 = tblSample.SAddress3, City = tblSample.SCity, State = tblSample.SState, PostalCode = tblSample.SZip, Country = tblSample.SCountry } }, SampleID = tblSample.SampleID }; LoadNotes(sampleOrder, tblSample); LoadDetails(sampleOrder, tblSample); return(sampleOrder); }