diff --git a/AyaNovaQBI/Customer.cs b/AyaNovaQBI/Customer.cs index 9f22d6b..94333b9 100644 --- a/AyaNovaQBI/Customer.cs +++ b/AyaNovaQBI/Customer.cs @@ -68,5 +68,7 @@ namespace AyaNovaQBI } + + }//eoc } diff --git a/AyaNovaQBI/util.cs b/AyaNovaQBI/util.cs index c42af42..afbe6bf 100644 --- a/AyaNovaQBI/util.cs +++ b/AyaNovaQBI/util.cs @@ -11,6 +11,7 @@ using Interop.QBFC15; using System.Text.RegularExpressions; using System.Windows.Forms; using System.Data; +using System.Collections; namespace AyaNovaQBI { @@ -3341,14 +3342,8 @@ namespace AyaNovaQBI #endregion exception helper - #region Import / refresh to AyaNova - #region Import / refresh customer - - #region Refresh Customer - - public static void RefreshAyaNovaClientFromQB(List objectIDList) { PopulateQBClientCache(); @@ -3386,16 +3381,15 @@ namespace AyaNovaQBI } - #endregion refresh customer - #region Import customer + /// /// Import the indicated customer /// to an AyaNova client record /// /// /// An arraylist to hold strings indicating errors on fail - public static void ImportQBCustomer(string QuickBooksID, ArrayList alErrors) + public static async Task ImportQBCustomer(string QuickBooksID, ArrayList alErrors) { DataRow dr = _dtQBClients.Rows.Find(QuickBooksID); @@ -3416,8 +3410,8 @@ namespace AyaNovaQBI } try { - //already a client by that name - if (Client.Exists(Guid.Empty, dr["FullName"].ToString())) + //already a client by that name cached here? (qbi7 would check directly if existing but we'll let save handle that if there is a conflict for v8 and just check the obvious first) + if (util.QBIntegration.Items.Any(z => z.AType == AyaType.Customer && z.IntegrationItemName == dr["FullName"].ToString())) { alErrors.Add("ImportQBCustomer: " + dr["FullName"].ToString() + " already exists in AyaNova"); return; @@ -3425,7 +3419,7 @@ namespace AyaNovaQBI //Import seems safe... - Client c = Client.NewItem(); + Customer c = new Customer(); c.Name = sName;//1 CopyQBCustomerInfoToAyaNovaClient(dr, c); @@ -3458,31 +3452,36 @@ namespace AyaNovaQBI } } - #endregion Import customer - #region Copy QB Customer info to AyaNova client - public static void CopyQBCustomerInfoToAyaNovaClient(DataRow dr, Client c) + + public static void CopyQBCustomerInfoToAyaNovaClient(DataRow dr, Customer c) { Address a = (Address)dr["MailAddress"]; - c.MailToAddress.DeliveryAddress = a.DeliveryAddress;//2 - c.MailToAddress.City = a.City;//3 - c.MailToAddress.StateProv = a.StateProv;//4 - c.MailToAddress.Country = a.Country;//5 - c.MailToAddress.Postal = a.Postal;//6 + c.PostAddress = a.DeliveryAddress;//2 + c.PostCity = a.City;//3 + c.PostRegion = a.StateProv;//4 + c.PostCountry = a.Country;//5 + c.PostCode = a.Postal;//6 a = (Address)dr["StreetAddress"]; - c.GoToAddress.DeliveryAddress = a.DeliveryAddress;//7 - c.GoToAddress.City = a.City;//8 - c.GoToAddress.StateProv = a.StateProv;//9 - c.GoToAddress.Country = a.Country;//10 - c.GoToAddress.Postal = a.Postal;//11 + c.Address = a.DeliveryAddress;//7 + c.City = a.City;//8 + c.Region = a.StateProv;//9 + c.Country = a.Country;//10 + //Case 518 - c.PopulateBothAddresses(); + if (string.IsNullOrWhiteSpace(c.Address)) c.Address = c.PostAddress; + if (string.IsNullOrWhiteSpace(c.PostAddress)) c.PostAddress = c.Address; + CopyToEmptyString(c.Address, c.PostAddress); + CopyToEmptyString(c.City, c.PostCity); + CopyToEmptyString(c.Region, c.PostRegion); + CopyToEmptyString(c.Country, c.PostCountry); + //Contact cn=c.Contacts.Add(RootObjectTypes.Client,c.ID); - c.Contact = dr["Contact"].ToString(); + c.Notes = $"QB Contact - {dr["Contact"].ToString()}"; //Phone field @@ -3506,7 +3505,7 @@ namespace AyaNovaQBI //Email field if (dr["Email"].ToString() != "") { - c.Email = dr["Email"].ToString();//17 + c.EmailAddress = dr["Email"].ToString();//17 } //Account number field @@ -3514,16 +3513,8 @@ namespace AyaNovaQBI { c.AccountNumber = dr["Account"].ToString();//18 } - - - } - #endregion copy qb customer info to aya client - - #endregion import refresh customer - - #region Vendor /// /// Import the indicated Vendor @@ -3531,7 +3522,7 @@ namespace AyaNovaQBI /// /// /// An arraylist to hold strings indicating errors on fail - public static void ImportQBVendor(string QuickBooksID, VendorTypes AsVendorType, ArrayList alErrors) + public static async Task ImportQBVendor(string QuickBooksID, ArrayList alErrors) { DataRow dr = _dtQBVendors.Rows.Find(QuickBooksID); @@ -3676,9 +3667,7 @@ namespace AyaNovaQBI } } - #endregion - #region Rate /// /// Import the indicated QB Item @@ -3686,7 +3675,7 @@ namespace AyaNovaQBI /// /// /// An arraylist to hold strings indicating errors on fail - public static void ImportQBRate(string QuickBooksID, RateTypes AsRateType, Guid MostLikelyRateUnitChargeDescriptionID, ArrayList alErrors) + public static async Task ImportQBServiceRate(string QuickBooksID, ArrayList alErrors) { DataRow dr = _dtQBItems.Rows.Find(QuickBooksID); @@ -3723,7 +3712,7 @@ namespace AyaNovaQBI c.ContractRate = false; c.Cost = (decimal)dr["Cost"]; c.Description = T(255, dr["SalesDesc"].ToString()); - c.RateUnitChargeDescriptionID = MostLikelyRateUnitChargeDescriptionID; + // c.RateUnitChargeDescriptionID = MostLikelyRateUnitChargeDescriptionID; @@ -3755,9 +3744,86 @@ namespace AyaNovaQBI } } - #endregion - #region Part + + /// + /// Import the indicated QB Item + /// to an AyaNova TravelRate record + /// + /// + /// An arraylist to hold strings indicating errors on fail + public static async Task ImportQBTravelRate(string QuickBooksID, ArrayList alErrors) + { + + DataRow dr = _dtQBItems.Rows.Find(QuickBooksID); + //QBListID not found in Rate list? + if (dr == null) + { + alErrors.Add("ImportQBRate: ID not found " + QuickBooksID); + return; + } + + string sName = dr["FullName"].ToString(); + if (sName.Length > 255) + { + alErrors.Add("ImportQBRate: QuickBooks Rate name exceeds 255 character limit for AyaNova\r\n" + + "Name: " + dr["FullName"].ToString() + "\r\n" + + "was imported as: " + sName); + sName = sName.Substring(0, 255); + } + try + { + //already a Rate by that name + if (Rate.Exists(Guid.Empty, dr["FullName"].ToString())) + { + alErrors.Add("ImportQBRate: " + dr["FullName"].ToString() + " already exists in AyaNova"); + return; + } + + //Import seems safe... + Rates rates = Rates.GetItems(false); + Rate c = rates.Add(); + c.RateType = AsRateType; + c.Name = sName; + c.Charge = (decimal)dr["Price"]; + c.ContractRate = false; + c.Cost = (decimal)dr["Cost"]; + c.Description = T(255, dr["SalesDesc"].ToString()); + // c.RateUnitChargeDescriptionID = MostLikelyRateUnitChargeDescriptionID; + + + + if (!c.IsSavable) + { + alErrors.Add("ImportQBRate: AyaNova won't allow import of " + c.Name + "\r\n" + + "Due to the following broken rules:\r\n" + c.GetBrokenRulesString()); + return; + } + + + rates = (Rates)rates.Save(); + //Link + IntegrationMap m = QBI.Maps.Add(QBI); + m.Name = sName; + m.RootObjectID = c.ID; + m.RootObjectType = RootObjectTypes.Rate; + m.LastSync = DateTime.Now; + m.ForeignID = QuickBooksID; + QBI = (Integration)QBI.Save(); + } + catch (Exception ex) + { + //crack the exception in case it's a generic dataportal one + //and it is if it's got an inner exception of any kind + if (ex.InnerException != null) ex = ex.InnerException; + alErrors.Add("ImportQBRate: AyaNova won't allow import / link of " + sName + "\r\n" + + "Due to the following error:\r\n" + ex.Message); + + } + } + + + public static void RefreshAyaNovaPartFromQB(List objectIDList) { @@ -3807,7 +3873,7 @@ namespace AyaNovaQBI /// /// /// An arraylist to hold strings indicating errors on fail - public static void ImportQBPart(string QuickBooksID, ArrayList alErrors) + public static async Task ImportQBPart(string QuickBooksID, ArrayList alErrors) { DataRow dr = _dtQBItems.Rows.Find(QuickBooksID); @@ -3876,16 +3942,13 @@ namespace AyaNovaQBI } } - #endregion + #endregion Import to AyaNova #region Export / refresh to QuickBooks - #region Customer - - - #region Refresh to QB + public static void RefreshQBClientFromAyaNova(List objectIDList) @@ -3907,16 +3970,16 @@ namespace AyaNovaQBI /// Refresh the indicated AyaNova client /// to it's linked QuickBooks customer record /// - public static void RefreshQBClientFromAyaNova(Client c) + public static async void RefreshQBClientFromAyaNova(Customer c) { + IntegrationItem im = util.QBIntegration.Items.FirstOrDefault(z => z.ObjectId == c.Id && z.AType == AyaType.Customer); - IntegrationMap im = QBI.Maps[c.ID]; if (im == null) return;//this client is not linked - DataRow dr = _dtQBClients.Rows.Find(im.ForeignID); + DataRow dr = _dtQBClients.Rows.Find(im.IntegrationItemId); if (dr == null) return; //QBListID not found in client list? - string strEditSequence = GetQBCustomerEditSequence(im.ForeignID); + string strEditSequence = await GetQBCustomerEditSequenceAsync(im.IntegrationItemId); if (string.IsNullOrEmpty(strEditSequence)) { MessageBox.Show("RefreshQBClientFromAyaNova -> Error: unable to fetch edit sequence from QuickBooks. No changes made."); @@ -3953,7 +4016,7 @@ namespace AyaNovaQBI ICustomerMod ca = requestSet.AppendCustomerModRq(); //Set field value for ListID - ca.ListID.SetValue(im.ForeignID); + ca.ListID.SetValue(im.IntegrationItemId); // ca.ParentRef.ListID.SetValue(im.ForeignID); ca.EditSequence.SetValue(strEditSequence); @@ -3972,7 +4035,7 @@ namespace AyaNovaQBI ca.Name.SetValue(sName); //ca.FirstName.SetValue(T(25,Primary.FirstName)); //Case 686 - ca.Contact.SetValue(T(41, c.Contact)); + //V8NOTSUPPORTED ca.Contact.SetValue(T(41, c.Contact)); //ca.LastName.SetValue(T(25, c.Contact)); if (c.Phone1 != null) @@ -3981,10 +4044,10 @@ namespace AyaNovaQBI ca.Phone.SetValue(""); ca.Fax.SetValue(T(21, c.Phone2)); ca.AltPhone.SetValue(T(21, c.Phone3)); - ca.Email.SetValue(T(99, c.Email)); + ca.Email.SetValue(T(99, c.EmailAddress)); - #region Addresses + bool bHasBillAddress = false; //Mailing address @@ -3994,10 +4057,10 @@ namespace AyaNovaQBI //as that is what is documented, not sure why they were set to 21 here before ca.BillAddress.Addr1.SetValue(T(41, c.Name)); - if (c.MailToAddress.DeliveryAddress != "") + if (c.PostAddress != "") { bHasBillAddress = true; - string[] sad = c.MailToAddress.DeliveryAddress.Replace("\r\n", "\n").Split('\n'); + string[] sad = c.PostAddress.Replace("\r\n", "\n").Split('\n'); if (sad.GetLength(0) > 0) ca.BillAddress.Addr2.SetValue(T(41, sad[0].TrimEnd())); if (sad.GetLength(0) > 1) @@ -4010,12 +4073,12 @@ namespace AyaNovaQBI ca.BillAddress.Addr4.SetValue(T(41, sad[2].TrimEnd())); } - ca.BillAddress.City.SetValue(T(31, c.MailToAddress.City)); - ca.BillAddress.Country.SetValue(T(31, c.MailToAddress.Country)); - ca.BillAddress.PostalCode.SetValue(T(13, c.MailToAddress.Postal)); + ca.BillAddress.City.SetValue(T(31, c.PostCity)); + ca.BillAddress.Country.SetValue(T(31, c.PostCountry)); + ca.BillAddress.PostalCode.SetValue(T(13, c.PostCode)); //QBFC7 - unifies county and province to "State" - ca.BillAddress.State.SetValue(T(21, c.MailToAddress.StateProv)); + ca.BillAddress.State.SetValue(T(21, c.PostRegion)); //switch(QCountry) //{ // case "CA": @@ -4041,10 +4104,10 @@ namespace AyaNovaQBI //as that is what is documented, not sure why they were set to 21 here before ca.ShipAddress.Addr1.SetValue(T(41, c.Name)); - if (c.GoToAddress.DeliveryAddress != "") + if (c.Address != "") { bHasShipAddress = true; - string[] sad = c.GoToAddress.DeliveryAddress.Replace("\r\n", "\n").Split('\n'); + string[] sad = c.Address.Replace("\r\n", "\n").Split('\n'); if (sad.GetLength(0) > 0) ca.ShipAddress.Addr2.SetValue(T(41, sad[0].TrimEnd())); if (sad.GetLength(0) > 1) @@ -4059,12 +4122,12 @@ namespace AyaNovaQBI } - ca.ShipAddress.City.SetValue(T(31, c.GoToAddress.City)); - ca.ShipAddress.Country.SetValue(T(31, c.GoToAddress.Country)); - ca.ShipAddress.PostalCode.SetValue(T(13, c.GoToAddress.Postal)); + ca.ShipAddress.City.SetValue(T(31, c.City)); + ca.ShipAddress.Country.SetValue(T(31, c.Country)); + ca.ShipAddress.PostalCode.SetValue(T(13, c.PostCode)); //QBFC7 - unifies county and province to "State" - ca.ShipAddress.State.SetValue(T(21, c.GoToAddress.StateProv)); + ca.ShipAddress.State.SetValue(T(21, c.Region)); //switch(QCountry) //{ // case "CA": @@ -4080,7 +4143,6 @@ namespace AyaNovaQBI //} - #endregion //Added: 18-Nov-2006 CASE 95 //ensure that if only one address in ayanova that both types in QB get it @@ -4142,19 +4204,13 @@ namespace AyaNovaQBI booSessionBegun = false; sessionManager.CloseConnection(); - //catch the new ID for the QB Item - // dr["ID"] = sNewCustID; - //add the new row for the newly imported object - // _dtQBClients.Rows.Add(dr); + //Link - //IntegrationMap m = QBI.Maps.Add(QBI); - im.Name = sName; - //m.RootObjectID = c.ID; - //m.RootObjectType = RootObjectTypes.Client; + im.IntegrationItemName = sName; im.LastSync = DateTime.Now; - //m.ForeignID = sNewCustID; - QBI = (Integration)QBI.Save(); + await SaveIntegrationObject(); + //BI = (Integration)QBI.Save(); } catch (Exception ex) { @@ -4175,20 +4231,17 @@ namespace AyaNovaQBI } - #endregion Refresh to qb - #region Export to QB - - public static void ImportAyaClient(List objectIDList) + public static void ImportAyaClient(List objectIDList) { ArrayList alErrors = new ArrayList(); - foreach (Guid g in objectIDList) + foreach (long ayid in objectIDList) { try { - ImportAyaClient(g, alErrors); + ImportAyaClient(ayid, alErrors); } catch { }; @@ -4219,18 +4272,18 @@ namespace AyaNovaQBI /// Import the indicated client /// to QuickBooks customer record /// - /// + /// /// An arraylist to hold strings indicating errors on fail - public static void ImportAyaClient(Guid ClientID, ArrayList alErrors) + public static void ImportAyaClient(long CustomerId, ArrayList alErrors) { - if (!Client.Exists(ClientID, "")) + if (!Client.Exists(CustomerId, "")) { - alErrors.Add("ImportAyaClient: Client not found in AyaNova (deleted recently?) (" + ClientID.ToString() + ")"); + alErrors.Add("ImportAyaClient: Client not found in AyaNova (deleted recently?) (" + CustomerId.ToString() + ")"); return; } - Client c = Client.GetItem(ClientID); + Client c = Client.GetItem(CustomerId); @@ -4301,7 +4354,7 @@ namespace AyaNovaQBI ca.Email.SetValue(T(99, c.Email)); - #region Addresses + bool bHasBillAddress = false; //Mailing address @@ -4397,7 +4450,7 @@ namespace AyaNovaQBI //} - #endregion + //Added: 18-Nov-2006 CASE 95 //ensure that if only one address in ayanova that both types in QB get it @@ -4492,7 +4545,6 @@ namespace AyaNovaQBI } - #endregion export to qb /// /// Copy the contents of one address to the other @@ -4529,27 +4581,10 @@ namespace AyaNovaQBI if (from.State.IsSet()) to.State.SetValue(from.State.GetValue()); - //switch (QCountry) - //{ - // case "CA": - // if (from.Province.IsSet()) - // to.Province.SetValue(from.Province.GetValue()); - // break; - // case "UK": - // if (from.County.IsSet()) - // to.County.SetValue(from.County.GetValue()); - // break; - // default: - // if (from.State.IsSet()) - // to.State.SetValue(from.State.GetValue()); - // break; - - //} - } - #endregion customer + - #region Vendor + /// /// Import the indicated Vendor /// to QuickBooks Vendor record @@ -4739,9 +4774,8 @@ namespace AyaNovaQBI } } - #endregion vendor - #region Part case 632 + /// @@ -4928,7 +4962,6 @@ namespace AyaNovaQBI } - #region AyaNova Part to Quickbooks /// /// Import a list of ayanova parts to QuickBooks @@ -5134,11 +5167,7 @@ namespace AyaNovaQBI - #endregion AyaNova part to Quickbooks - #endregion part - - #region Rate case 632 /// /// Import the indicated service rate /// to QuickBooks item record @@ -5290,7 +5319,6 @@ namespace AyaNovaQBI } } - #endregion rate private static string T(int nLength, string s) @@ -5303,9 +5331,6 @@ namespace AyaNovaQBI #endregion export to quickbooks - - #endregion qb specific non-api stuff - - - } -} + #endregion qbi stuff (anything not api) + }//EOC +}//EONS