This commit is contained in:
2022-07-04 21:00:20 +00:00
parent 5a8da8902c
commit 5600ca1871
3 changed files with 45 additions and 86 deletions

View File

@@ -199,7 +199,7 @@ namespace AyaNovaQBI
switch (_Type) switch (_Type)
{ {
case AyaType.Customer: case AyaType.Customer:
await util.ImportAyaCustomer(AyaId, alErrors); util.ImportAyaCustomer(AyaId, alErrors);
break; break;
case AyaType.Vendor: case AyaType.Vendor:
await util.ImportAyaVendor(AyaId, alErrors); await util.ImportAyaVendor(AyaId, alErrors);

View File

@@ -5,3 +5,5 @@ Test persisted form settings for server url (ONCE POSTED NEW BUILD OF AYANOVA TO
Docs should not refer to autoclose anymore, it's status driven now Docs should not refer to autoclose anymore, it's status driven now
DOCS UI use "Link" and do not use "map" anywhere DOCS UI use "Link" and do not use "map" anywhere
TEST auto-linking not tested due to import not coded yet so would be fuckery to do TEST auto-linking not tested due to import not coded yet so would be fuckery to do
Integration object is saved too often as copied the code from v7, oncce working change that to save when ops are done only as it's a much more potentially expensive operation now
e.g.Util.ImportAyaCustomer at bottom

View File

@@ -3948,18 +3948,15 @@ namespace AyaNovaQBI
#region Export / refresh to QuickBooks #region Export / refresh to QuickBooks
public static async Task RefreshQBClientFromAyaNova(List<long> objectIDList)
public static void RefreshQBClientFromAyaNova(List<Guid> objectIDList)
{ {
foreach (Guid g in objectIDList) foreach (long id in objectIDList)
{ {
try try
{ {
Client c = Client.GetItemNoMRU(g); var r = await GetAsync($"customer/{id}");
var c = r.ObjectResponse["data"].ToObject<Customer>();
RefreshQBClientFromAyaNova(c); RefreshQBClientFromAyaNova(c);
} }
catch { }; catch { };
} }
@@ -4047,7 +4044,7 @@ namespace AyaNovaQBI
ca.Email.SetValue(T(99, c.EmailAddress)); ca.Email.SetValue(T(99, c.EmailAddress));
bool bHasBillAddress = false; bool bHasBillAddress = false;
//Mailing address //Mailing address
@@ -4233,7 +4230,7 @@ namespace AyaNovaQBI
public static void ImportAyaClient(List<long> objectIDList) public static async Task ImportAyaCustomer(List<long> objectIDList)
{ {
ArrayList alErrors = new ArrayList(); ArrayList alErrors = new ArrayList();
foreach (long ayid in objectIDList) foreach (long ayid in objectIDList)
@@ -4241,7 +4238,7 @@ namespace AyaNovaQBI
try try
{ {
ImportAyaClient(ayid, alErrors); await ImportAyaCustomer(ayid, alErrors);
} }
catch { }; catch { };
@@ -4274,19 +4271,17 @@ namespace AyaNovaQBI
/// </summary> /// </summary>
/// <param name="CustomerId"></param> /// <param name="CustomerId"></param>
/// <param name="alErrors">An arraylist to hold strings indicating errors on fail</param> /// <param name="alErrors">An arraylist to hold strings indicating errors on fail</param>
public static void ImportAyaClient(long CustomerId, ArrayList alErrors) public static async Task ImportAyaCustomer(long CustomerId, ArrayList alErrors)
{ {
if (!Client.Exists(CustomerId, "")) if (AyaClientList.Any(z => z.Id == CustomerId))
{ {
alErrors.Add("ImportAyaClient: Client not found in AyaNova (deleted recently?) (" + CustomerId.ToString() + ")"); alErrors.Add("ImportAyaClient: Client not found in AyaNova (deleted recently?) (" + CustomerId.ToString() + ")");
return; return;
} }
Client c = Client.GetItem(CustomerId); var r = await GetAsync($"customer/{CustomerId}");
var c = r.ObjectResponse["data"].ToObject<Customer>();
string sName = c.Name; string sName = c.Name;
if (sName.Length > 41) if (sName.Length > 41)
@@ -4298,8 +4293,6 @@ namespace AyaNovaQBI
} }
//Connect to QB and fill //Connect to QB and fill
// IY: Create the session manager object using QBFC // IY: Create the session manager object using QBFC
QBSessionManager sessionManager = new QBSessionManager(); QBSessionManager sessionManager = new QBSessionManager();
@@ -4340,10 +4333,10 @@ namespace AyaNovaQBI
dr["Account"] = ""; dr["Account"] = "";
ca.Name.SetValue(sName); ca.Name.SetValue(sName);
//ca.FirstName.SetValue(T(25,Primary.FirstName));
//Case 686 //AyaNova 8 doesn't have a single "contact" field so it can't be imported
ca.Contact.SetValue(T(41, c.Contact)); // ca.Contact.SetValue(T(41, c.Contact));
//ca.LastName.SetValue(T(25, c.Contact));
if (c.Phone1 != null) if (c.Phone1 != null)
ca.Phone.SetValue(T(21, c.Phone1)); ca.Phone.SetValue(T(21, c.Phone1));
@@ -4351,10 +4344,10 @@ namespace AyaNovaQBI
ca.Phone.SetValue(""); ca.Phone.SetValue("");
ca.Fax.SetValue(T(21, c.Phone2)); ca.Fax.SetValue(T(21, c.Phone2));
ca.AltPhone.SetValue(T(21, c.Phone3)); ca.AltPhone.SetValue(T(21, c.Phone3));
ca.Email.SetValue(T(99, c.Email)); ca.Email.SetValue(T(99, c.EmailAddress));
bool bHasBillAddress = false; bool bHasBillAddress = false;
//Mailing address //Mailing address
@@ -4364,44 +4357,23 @@ namespace AyaNovaQBI
//as that is what is documented, not sure why they were set to 21 here before //as that is what is documented, not sure why they were set to 21 here before
ca.BillAddress.Addr1.SetValue(T(41, c.Name)); ca.BillAddress.Addr1.SetValue(T(41, c.Name));
if (c.MailToAddress.DeliveryAddress != "") if (!string.IsNullOrWhiteSpace(c.PostAddress))
{ {
bHasBillAddress = true; 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) if (sad.GetLength(0) > 0)
ca.BillAddress.Addr2.SetValue(T(41, sad[0].TrimEnd())); ca.BillAddress.Addr2.SetValue(T(41, sad[0].TrimEnd()));
if (sad.GetLength(0) > 1) if (sad.GetLength(0) > 1)
ca.BillAddress.Addr3.SetValue(T(41, sad[1].TrimEnd())); ca.BillAddress.Addr3.SetValue(T(41, sad[1].TrimEnd()));
//if(sad.GetLength(0)>2)
// ca.BillAddress.Addr3.SetValue(T(21,sad[2].TrimEnd()));
if (QVersion > 1.1 && sad.GetLength(0) > 3)//4th address line is 2 or newer if (QVersion > 1.1 && sad.GetLength(0) > 3)//4th address line is 2 or newer
ca.BillAddress.Addr4.SetValue(T(41, sad[2].TrimEnd())); ca.BillAddress.Addr4.SetValue(T(41, sad[2].TrimEnd()));
} }
ca.BillAddress.City.SetValue(T(31, c.MailToAddress.City)); ca.BillAddress.City.SetValue(T(31, c.PostCity));
ca.BillAddress.Country.SetValue(T(31, c.MailToAddress.Country)); ca.BillAddress.Country.SetValue(T(31, c.PostCountry));
ca.BillAddress.PostalCode.SetValue(T(13, c.MailToAddress.Postal)); ca.BillAddress.PostalCode.SetValue(T(13, c.PostCode));
ca.BillAddress.State.SetValue(T(21, c.PostRegion));
//QBFC7 - unifies county and province to "State"
ca.BillAddress.State.SetValue(T(21, c.MailToAddress.StateProv));
//switch(QCountry)
//{
// case "CA":
// ca.BillAddress.Province.SetValue(T(21,c.MailToAddress.StateProv));
// break;
// case "UK":
// ca.BillAddress.County.SetValue(T(21,c.MailToAddress.StateProv));
// break;
// default:
// ca.BillAddress.State.SetValue(T(21,c.MailToAddress.StateProv));
// break;
//}
bool bHasShipAddress = false; bool bHasShipAddress = false;
//Delivery address //Delivery address
@@ -4411,10 +4383,10 @@ namespace AyaNovaQBI
//as that is what is documented, not sure why they were set to 21 here before //as that is what is documented, not sure why they were set to 21 here before
ca.ShipAddress.Addr1.SetValue(T(41, c.Name)); ca.ShipAddress.Addr1.SetValue(T(41, c.Name));
if (c.GoToAddress.DeliveryAddress != "") if (!string.IsNullOrWhiteSpace(c.Address))
{ {
bHasShipAddress = true; 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) if (sad.GetLength(0) > 0)
ca.ShipAddress.Addr2.SetValue(T(41, sad[0].TrimEnd())); ca.ShipAddress.Addr2.SetValue(T(41, sad[0].TrimEnd()));
if (sad.GetLength(0) > 1) if (sad.GetLength(0) > 1)
@@ -4429,28 +4401,10 @@ namespace AyaNovaQBI
} }
ca.ShipAddress.City.SetValue(T(31, c.GoToAddress.City)); ca.ShipAddress.City.SetValue(T(31, c.City));
ca.ShipAddress.Country.SetValue(T(31, c.GoToAddress.Country)); ca.ShipAddress.Country.SetValue(T(31, c.Country));
ca.ShipAddress.PostalCode.SetValue(T(13, c.GoToAddress.Postal)); ca.ShipAddress.PostalCode.SetValue(T(13, c.PostCode));
ca.ShipAddress.State.SetValue(T(21, c.Region));
//QBFC7 - unifies county and province to "State"
ca.ShipAddress.State.SetValue(T(21, c.GoToAddress.StateProv));
//switch(QCountry)
//{
// case "CA":
// ca.ShipAddress.Province.SetValue(T(21,c.GoToAddress.StateProv));
// break;
// case "UK":
// ca.ShipAddress.County.SetValue(T(21,c.GoToAddress.StateProv));
// break;
// default:
// ca.ShipAddress.State.SetValue(T(21,c.GoToAddress.StateProv));
// break;
//}
//Added: 18-Nov-2006 CASE 95 //Added: 18-Nov-2006 CASE 95
//ensure that if only one address in ayanova that both types in QB get it //ensure that if only one address in ayanova that both types in QB get it
@@ -4518,13 +4472,16 @@ namespace AyaNovaQBI
_dtQBClients.Rows.Add(dr); _dtQBClients.Rows.Add(dr);
//Link //Link
IntegrationMap m = QBI.Maps.Add(QBI); var m = new IntegrationItem { AType = AyaType.Customer, IntegrationItemName = sName, IntegrationItemId = sNewCustID, LastSync = DateTime.Now, ObjectId = c.Id };
m.Name = sName; QBIntegration.Items.Add(m);
m.RootObjectID = c.ID; await util.SaveIntegrationObject();
m.RootObjectType = RootObjectTypes.Client; //IntegrationMap m = QBI.Maps.Add(QBI);
m.LastSync = DateTime.Now; //m.Name = sName;
m.ForeignID = sNewCustID; //m.RootObjectID = c.ID;
QBI = (Integration)QBI.Save(); //m.RootObjectType = RootObjectTypes.Client;
//m.LastSync = DateTime.Now;
//m.ForeignID = sNewCustID;
//QBI = (Integration)QBI.Save();
} }
catch (Exception ex) catch (Exception ex)
{ {
@@ -4582,9 +4539,9 @@ namespace AyaNovaQBI
to.State.SetValue(from.State.GetValue()); to.State.SetValue(from.State.GetValue());
} }
/// <summary> /// <summary>
/// Import the indicated Vendor /// Import the indicated Vendor
/// to QuickBooks Vendor record /// to QuickBooks Vendor record
@@ -4775,7 +4732,7 @@ namespace AyaNovaQBI
} }
} }
/// <summary> /// <summary>