/// <summary> /// Wraps a custom field result /// </summary> /// <param name="dataExtensions">The field list to wrap</param> /// <param name="requireFieldMatch">if true, name mismatch will throw an exception</param> public CustomFieldGroup(IDataExtRetList dataExtensions, bool requireFieldMatch) { _fields = new QBFCIterator <IDataExtRetList, IDataExtRet>(dataExtensions); _requireFieldMatch = requireFieldMatch; }
private ESRI.ArcLogistics.DomainObjects.Order MakeOrderFromInvoice(IInvoiceRet invoiceRet, QBSessionManager session) { ESRI.ArcLogistics.DomainObjects.Order resultOrder = null; ICustomerRet customerRet = QueryCustomer(session, invoiceRet.CustomerRef.FullName.GetValue()); CapacitiesInfo capInfo = m_application.Project.CapacitiesInfo; OrderCustomPropertiesInfo propInfo = m_application.Project.OrderCustomPropertiesInfo; resultOrder = new ESRI.ArcLogistics.DomainObjects.Order(capInfo, propInfo); resultOrder.PlannedDate = m_application.CurrentDate; if (customerRet.ParentRef != null) { resultOrder.Name = customerRet.ParentRef.FullName.GetValue(); } else { resultOrder.Name = customerRet.FullName.GetValue(); } IAddress useAddress = null; if (customerRet.ShipAddress != null) { useAddress = customerRet.ShipAddress; } else if (customerRet.BillAddress != null) { useAddress = customerRet.BillAddress; } else { m_application.Messenger.AddWarning("No address for: " + resultOrder.Name); } if (useAddress != null) { if (useAddress.Addr2 != null) { resultOrder.Address.AddressLine = useAddress.Addr2.GetValue(); } else { resultOrder.Address.AddressLine = useAddress.Addr1.GetValue(); } resultOrder.Address.Locality3 = useAddress.City.GetValue(); resultOrder.Address.StateProvince = useAddress.State.GetValue(); resultOrder.Address.PostalCode1 = useAddress.PostalCode.GetValue(); AddressCandidate candidate = m_application.Geocoder.Geocode(resultOrder.Address); resultOrder.GeoLocation = candidate.GeoLocation; } // Look in the order custom properties for matching invoice detail items (by item description). // Look in the order capacities for matching item type custom fields. OrderCustomPropertiesInfo orderPropertiesInfo = resultOrder.CustomPropertiesInfo; OrderCustomProperties orderProperties = resultOrder.CustomProperties; CapacitiesInfo orderCapacitiesInfo = resultOrder.CapacitiesInfo; Capacities orderCapacities = resultOrder.Capacities; // Retrieve invoice line list // Each line can be either InvoiceLineRet OR InvoiceLineGroupRet IORInvoiceLineRetList orInvoiceLineRetList = invoiceRet.ORInvoiceLineRetList; if (orInvoiceLineRetList != null && (orderProperties.Count > 0 || orderCapacities.Count > 0)) { int lineCount = orInvoiceLineRetList.Count; for (int i = 0; i < lineCount; i++) { IORInvoiceLineRet orInvoiceLineRet = orInvoiceLineRetList.GetAt(i); // Check what to retrieve from the orInvoiceLineRet object // based on the "ortype" property. Skip summary lines. if (orInvoiceLineRet.ortype != ENORInvoiceLineRet.orilrInvoiceLineRet) { continue; } if (orInvoiceLineRet.InvoiceLineRet.ItemRef.FullName != null) { string itemName = orInvoiceLineRet.InvoiceLineRet.ItemRef.FullName.GetValue(); double itemQuantity = 0; if (orInvoiceLineRet.InvoiceLineRet.ItemRef != null) { itemQuantity = System.Convert.ToDouble(orInvoiceLineRet.InvoiceLineRet.Quantity.GetValue()); } // look for matching custom order property OrderCustomProperty orderPropertyInfoItem = null; for (int j = 0; j < orderPropertiesInfo.Count; j++) { orderPropertyInfoItem = orderPropertiesInfo.ElementAt(j) as OrderCustomProperty; if (orderPropertyInfoItem.Name == itemName) { if (orderPropertyInfoItem.Type == OrderCustomPropertyType.Numeric) { orderProperties[j] = itemQuantity; } else { orderProperties[j] = itemQuantity.ToString(); } break; } } // look for matching capacity // need to lookup item record so we get the extra field(s) // TODO: It might be a good idea to cache these locally to avoid // excess QB queries. IORItemRet orItemRet = QueryItem(session, itemName); IDataExtRetList custItemFieldsRetList = null; switch (orItemRet.ortype) { case ENORItemRet.orirItemServiceRet: { // orir prefix comes from OR + Item + Ret IItemServiceRet ItemServiceRet = orItemRet.ItemServiceRet; custItemFieldsRetList = ItemServiceRet.DataExtRetList; } break; case ENORItemRet.orirItemInventoryRet: { IItemInventoryRet ItemInventoryRet = orItemRet.ItemInventoryRet; custItemFieldsRetList = ItemInventoryRet.DataExtRetList; } break; case ENORItemRet.orirItemNonInventoryRet: { IItemNonInventoryRet ItemNonInventoryRet = orItemRet.ItemNonInventoryRet; custItemFieldsRetList = ItemNonInventoryRet.DataExtRetList; } break; } int custItemFieldCount = 0; if (custItemFieldsRetList != null) { custItemFieldCount = custItemFieldsRetList.Count; } for (int j = 0; j < custItemFieldCount; j++) { IDataExtRet custItemField = custItemFieldsRetList.GetAt(j); string custItemFieldName = custItemField.DataExtName.GetValue(); CapacityInfo orderCapacityInfoItem = null; for (int k = 0; k < orderCapacitiesInfo.Count; k++) { orderCapacityInfoItem = orderCapacitiesInfo.ElementAt(k); if (orderCapacityInfoItem.Name == custItemFieldName) { orderCapacities[k] += System.Convert.ToDouble(custItemField.DataExtValue.GetValue()) * itemQuantity; break; } } } } } } resultOrder.CustomProperties = orderProperties; resultOrder.Capacities = orderCapacities; return(resultOrder); }
/// <summary> /// Wraps a custom field result /// </summary> /// <param name="dataExtensions">The field list to wrap</param> /// <param name="requireFieldMatch">if true, name mismatch will throw an exception</param> public CustomFieldGroup(IDataExtRetList dataExtensions, bool requireFieldMatch) { _fields = new QBFCIterator<IDataExtRetList, IDataExtRet>(dataExtensions); _requireFieldMatch = requireFieldMatch; }