This commit is contained in:
2022-07-06 21:04:50 +00:00
parent c83414a68d
commit fb7291c9b0
2 changed files with 149 additions and 157 deletions

View File

@@ -3542,39 +3542,20 @@ namespace AyaNovaQBI
#region Import / refresh to AyaNova
//public static async Task RefreshAyaNovaClientFromQB(List<long> objectIDList)
//{
// await PopulateQBClientCacheAsync();
// foreach (long id in objectIDList)
// {
// try
// {
// var r = await GetAsync($"customer/{id}");
// var c = r.ObjectResponse["data"].ToObject<Customer>();
// RefreshAyaNovaClientFromQB(c);
// r = await PutAsync($"customer", Newtonsoft.Json.JsonConvert.SerializeObject(c));
// }
// catch { };
// }
//}
public static async void RefreshAyaNovaClientFromQB(Customer c)
public static async Task RefreshAyaNovaCustomerFromQBAsync(IntegrationItem im)
{
await PopulateQBClientCacheAsync();
IntegrationItem im = util.QBIntegration.Items.FirstOrDefault(z => z.ObjectId == c.Id && z.AType == AyaType.Customer);
if (im == null) return;//this client is not linked
if (im == null) return;//this object is not linked
var r = await GetAsync($"customer/{im.ObjectId}");
var c = r.ObjectResponse["data"].ToObject<Customer>();
if (c == null) return;
DataRow dr = _dtQBClients.Rows.Find(im.IntegrationItemId);
if (dr == null) return; //QBListID not found in client list?
CopyQBCustomerInfoToAyaNovaClient(dr, c);
string sName = dr["FullName"].ToString();
c.Name = sName;
await PutAsync($"customer", Newtonsoft.Json.JsonConvert.SerializeObject(c));
im.LastSync = DateTime.Now;
}
@@ -3718,6 +3699,52 @@ namespace AyaNovaQBI
}
public static async Task RefreshAyaNovaVendorFromQBAsync(IntegrationItem im)
{
if (im == null) return;//this object is not linked
var r = await GetAsync($"vendor/{im.ObjectId}");
var c = r.ObjectResponse["data"].ToObject<Vendor>();
if (c == null) return;
DataRow dr = _dtQBClients.Rows.Find(im.IntegrationItemId);
if (dr == null) return; //QBListID not found in client list?
//CopyQBVendorInfoToAyaNovaVendor(dr, c);
Address a = (Address)dr["MailAddress"];
c.PostAddress = a.DeliveryAddress;
c.PostCity = a.City;
c.PostRegion = a.StateProv;
c.PostCountry = a.Country;
c.PostCode = a.Postal;
a = (Address)dr["StreetAddress"];
c.Address = a.DeliveryAddress;
c.City = a.City;
c.Region = a.StateProv;
c.Country = a.Country;
c.Contact = dr["Contact"].ToString();
if (dr["Phone"].ToString() != "")
c.Phone1 = dr["Phone"].ToString();
if (dr["Fax"].ToString() != "")
c.Phone2 = dr["Fax"].ToString();
if (dr["AltPhone"].ToString() != "")
c.Phone3 = dr["AltPhone"].ToString();
if (dr["Email"].ToString() != "")
c.EmailAddress = dr["Email"].ToString();
if (dr["Account"].ToString() != "")
c.AccountNumber = dr["Account"].ToString();
string sName = dr["FullName"].ToString();
c.Name = sName;
await PutAsync($"vendor", Newtonsoft.Json.JsonConvert.SerializeObject(c));
im.LastSync = DateTime.Now;
}
/// <summary>
/// Import the indicated Vendor
/// to an AyaNova vendor record
@@ -3773,73 +3800,23 @@ namespace AyaNovaQBI
c.Region = a.StateProv;
c.Country = a.Country;
//Contact cn=c.Contacts.Add(RootObjectTypes.Vendor,c.ID);
c.Contact = dr["Contact"].ToString();
////if it's completely empty we'll substitute the word Contact instead
//if(qbcontact=="")
// cn.FirstName="Contact";
//else
//{
// //default it first
// cn.FirstName=qbcontact;
// string [] contactnames=null;
// if(qbcontact.IndexOf(" ")!=-1)
// contactnames=qbcontact.Replace(",","").Split(' ');//replace any commas if present
// else
// if(qbcontact.IndexOf(",")!=-1)
// contactnames=qbcontact.Split(',');
// //Quickbooks just has one field for contact so
// //we'll assume the english speaking tradition of firstname space lastname
// //if there is a space otherwise we'll assume it's just a first name if there are no spaces in it
// if(contactnames!=null && contactnames.GetLength(0)>1)
// {
// cn.FirstName=contactnames[0];
// cn.LastName=contactnames[1];
// }
//}
//Phone field
if (dr["Phone"].ToString() != "")
{
//ContactPhone cp=cn.Phones.Add(cn);
//cp.ContactPhoneType=ContactPhoneTypes.Business;
c.Phone1 = dr["Phone"].ToString();
//case 124
//cp.PhoneDefault=true;
}
//Fax field
if (dr["Fax"].ToString() != "")
{
//ContactPhone cp=cn.Phones.Add(cn);
//cp.ContactPhoneType=ContactPhoneTypes.Fax;
c.Phone2 = dr["Fax"].ToString();
}
//AltPhone field
if (dr["AltPhone"].ToString() != "")
{
//ContactPhone cp=cn.Phones.Add(cn);
//cp.ContactPhoneType=ContactPhoneTypes.Business;
c.Phone3 = dr["AltPhone"].ToString();
}
//Email field
if (dr["Email"].ToString() != "")
{
c.Phone3 = dr["AltPhone"].ToString();
if (dr["Email"].ToString() != "")
c.EmailAddress = dr["Email"].ToString();
}
//Account number
if (dr["Account"].ToString() != "")
{
if (dr["Account"].ToString() != "")
c.AccountNumber = dr["Account"].ToString();
}
//Try to save and return errors if not in alerrors
var r = await PostAsync($"vendor", Newtonsoft.Json.JsonConvert.SerializeObject(c));
@@ -4058,44 +4035,29 @@ namespace AyaNovaQBI
//public static async Task RefreshAyaNovaPartFromQB(List<long> objectIDList)
//{
// await PopulateQBItemCache();
// foreach (long id in objectIDList)
// {
// try
// {
// var r = await GetAsync($"part/{id}");
// var c = r.ObjectResponse["data"].ToObject<Part>();
// await RefreshAyaNovaPartFromQB(c);
// r = await PutAsync($"part", Newtonsoft.Json.JsonConvert.SerializeObject(c));
// }
// catch { };
// }
//}
public static async Task RefreshAyaNovaPartFromQB(long PartId, bool pricesOnly = false)
public static async Task RefreshAyaNovaPartFromQBAsync(IntegrationItem im, bool pricesOnly = false)
{
var r = await GetAsync($"part/{PartId}");
if (im == null) return;//this part is not linked
var r = await GetAsync($"part/{im.ObjectId}");
var c = r.ObjectResponse["data"].ToObject<Part>();
if (c == null) return;
IntegrationItem im = util.QBIntegration.Items.FirstOrDefault(z => z.ObjectId == c.Id && z.AType == AyaType.Part);
if (im == null) return;//this part is not linked
DataRow dr = _dtQBItems.Rows.Find(im.IntegrationItemId);
if (dr == null) return; //QBListID not found in part list?
string sName = dr["FullName"].ToString();
c.Name = sName;
c.Description = T(255, dr["SalesDesc"].ToString());
c.WholeSalerId = AyaVendorForQBItem(im.IntegrationItemId);
if (!pricesOnly)
{
string sName = dr["FullName"].ToString();
c.Name = sName;
c.Description = T(255, dr["SalesDesc"].ToString());
c.WholeSalerId = AyaVendorForQBItem(im.IntegrationItemId);
}
c.Retail = (decimal)dr["Price"];
c.Cost = (decimal)dr["Cost"];
await PutAsync($"part", Newtonsoft.Json.JsonConvert.SerializeObject(c));
im.LastSync = DateTime.Now;
}
@@ -4975,17 +4937,18 @@ namespace AyaNovaQBI
/// Refresh the indicated AyaNova part
/// to it's linked QuickBooks item record
/// </summary>
public static async Task RefreshQBPartFromAyaNova(long PartId, bool pricesOnly = false)
public static async Task RefreshQBPartFromAyaNova(IntegrationItem im, bool pricesOnly = false)
{
var r = await GetAsync($"part/{PartId}");
if (im == null) return;//this object is not linked
var r = await GetAsync($"part/{im.ObjectId}");
var c = r.ObjectResponse["data"].ToObject<Part>();
if (c == null) return;
IntegrationItem im = QBIntegration.Items.FirstOrDefault(z => z.ObjectId == c.Id && z.AType == AyaType.Part);
if (im == null) return;//this part is not linked
DataRow dr = _dtQBItems.Rows.Find(im.IntegrationItemId);
if (dr == null) return; //QBListID not found in part list?
string sName = c.Name;
if (sName.Length > 31)
sName = sName.Substring(0, 31);
@@ -5083,6 +5046,8 @@ namespace AyaNovaQBI
booSessionBegun = false;
sessionManager.CloseConnection();
im.LastSync = DateTime.Now;
if (!pricesOnly)
im.IntegrationItemName = sName;
}
catch (Exception ex)