This commit is contained in:
@@ -3558,8 +3558,7 @@ namespace AyaNovaQBI
|
||||
CopyQBCustomerInfoToAyaNovaClient(dr, c);
|
||||
|
||||
string sName = dr["FullName"].ToString();
|
||||
if (sName.Length > 255)
|
||||
sName = sName.Substring(0, 255);
|
||||
|
||||
|
||||
c.Name = sName;
|
||||
|
||||
@@ -3616,7 +3615,7 @@ namespace AyaNovaQBI
|
||||
//Link
|
||||
var m = new IntegrationItem { AType = AyaType.Customer, IntegrationItemName = sName, IntegrationItemId = QuickBooksID, LastSync = DateTime.Now, ObjectId = newCustomerId };
|
||||
QBIntegration.Items.Add(m);
|
||||
await util.SaveIntegrationObject();
|
||||
await SaveIntegrationObject();
|
||||
//IntegrationMap m = QBI.Maps.Add(QBI);
|
||||
//m.Name = sName;
|
||||
//m.RootObjectID = c.ID;
|
||||
@@ -3754,11 +3753,10 @@ namespace AyaNovaQBI
|
||||
c.PostCode = a.Postal;
|
||||
|
||||
a = (Address)dr["StreetAddress"];
|
||||
c.GoToAddress.DeliveryAddress = a.DeliveryAddress;
|
||||
c.GoToAddress.City = a.City;
|
||||
c.GoToAddress.StateProv = a.StateProv;
|
||||
c.GoToAddress.Country = a.Country;
|
||||
c.GoToAddress.Postal = a.Postal;
|
||||
c.Address = a.DeliveryAddress;
|
||||
c.City = a.City;
|
||||
c.Region = a.StateProv;
|
||||
c.Country = a.Country;
|
||||
|
||||
|
||||
//Contact cn=c.Contacts.Add(RootObjectTypes.Vendor,c.ID);
|
||||
@@ -3819,7 +3817,7 @@ namespace AyaNovaQBI
|
||||
//Email field
|
||||
if (dr["Email"].ToString() != "")
|
||||
{
|
||||
c.Email = dr["Email"].ToString();
|
||||
c.EmailAddress = dr["Email"].ToString();
|
||||
}
|
||||
|
||||
//Account number
|
||||
@@ -3828,23 +3826,32 @@ namespace AyaNovaQBI
|
||||
c.AccountNumber = dr["Account"].ToString();
|
||||
}
|
||||
|
||||
if (!c.IsSavable)
|
||||
{
|
||||
alErrors.Add("ImportQBVendor: AyaNova won't allow import of " + c.Name + "\r\n" +
|
||||
"Due to the following broken rules:\r\n" + c.GetBrokenRulesString());
|
||||
return;
|
||||
}
|
||||
//Try to save and return errors if not in alerrors
|
||||
var r = await PostAsync($"vendor", Newtonsoft.Json.JsonConvert.SerializeObject(c));
|
||||
long newId = IdFromResponse(r);
|
||||
|
||||
|
||||
c = (Vendor)c.Save();
|
||||
//Link
|
||||
IntegrationMap m = QBI.Maps.Add(QBI);
|
||||
m.Name = sName;
|
||||
m.RootObjectID = c.ID;
|
||||
m.RootObjectType = RootObjectTypes.Vendor;
|
||||
m.LastSync = DateTime.Now;
|
||||
m.ForeignID = QuickBooksID;
|
||||
QBI = (Integration)QBI.Save();
|
||||
var m = new IntegrationItem { AType = AyaType.Vendor, IntegrationItemName = sName, IntegrationItemId = QuickBooksID, LastSync = DateTime.Now, ObjectId = newId };
|
||||
QBIntegration.Items.Add(m);
|
||||
await util.SaveIntegrationObject();
|
||||
|
||||
//if (!c.IsSavable)
|
||||
//{
|
||||
// alErrors.Add("ImportQBVendor: AyaNova won't allow import of " + c.Name + "\r\n" +
|
||||
// "Due to the following broken rules:\r\n" + c.GetBrokenRulesString());
|
||||
// return;
|
||||
//}
|
||||
|
||||
|
||||
//c = (Vendor)c.Save();
|
||||
////Link
|
||||
//IntegrationMap m = QBI.Maps.Add(QBI);
|
||||
//m.Name = sName;
|
||||
//m.RootObjectID = c.ID;
|
||||
//m.RootObjectType = RootObjectTypes.Vendor;
|
||||
//m.LastSync = DateTime.Now;
|
||||
//m.ForeignID = QuickBooksID;
|
||||
//QBI = (Integration)QBI.Save();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -3876,59 +3883,69 @@ namespace AyaNovaQBI
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
//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()))
|
||||
//if (Rate.Exists(Guid.Empty, dr["FullName"].ToString()))
|
||||
if (QBIntegration.Items.Any(z => z.AType == AyaType.ServiceRate && z.IntegrationItemName == dr["FullName"].ToString()))
|
||||
{
|
||||
alErrors.Add("ImportQBRate: " + dr["FullName"].ToString() + " already exists in AyaNova");
|
||||
alErrors.Add("ImportQBServiceRate: " + dr["FullName"].ToString() + " already exists in AyaNova");
|
||||
return;
|
||||
}
|
||||
|
||||
//Import seems safe...
|
||||
Rates rates = Rates.GetItems(false);
|
||||
Rate c = rates.Add();
|
||||
c.RateType = AsRateType;
|
||||
//Rates rates = Rates.GetItems(false);
|
||||
//Rate c = rates.Add();
|
||||
//c.RateType = AsRateType;
|
||||
ServiceRate c = new ServiceRate();
|
||||
|
||||
c.Name = sName;
|
||||
c.Charge = (decimal)dr["Price"];
|
||||
c.ContractRate = false;
|
||||
//c.ContractRate = false;
|
||||
c.Cost = (decimal)dr["Cost"];
|
||||
c.Description = T(255, dr["SalesDesc"].ToString());
|
||||
c.Notes = 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;
|
||||
}
|
||||
//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();
|
||||
//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();
|
||||
var r = await PostAsync($"service-rate", Newtonsoft.Json.JsonConvert.SerializeObject(c));
|
||||
long newId = IdFromResponse(r);
|
||||
|
||||
//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();
|
||||
var m = new IntegrationItem { AType = AyaType.ServiceRate, IntegrationItemName = sName, IntegrationItemId = QuickBooksID, LastSync = DateTime.Now, ObjectId = newId };
|
||||
QBIntegration.Items.Add(m);
|
||||
await util.SaveIntegrationObject();
|
||||
}
|
||||
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" +
|
||||
alErrors.Add("ImportQBServiceRate: AyaNova won't allow import / link of " + sName + "\r\n" +
|
||||
"Due to the following error:\r\n" + ex.Message);
|
||||
|
||||
}
|
||||
@@ -3953,59 +3970,69 @@ namespace AyaNovaQBI
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
//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()))
|
||||
//if (Rate.Exists(Guid.Empty, dr["FullName"].ToString()))
|
||||
if (QBIntegration.Items.Any(z => z.AType == AyaType.TravelRate && z.IntegrationItemName == dr["FullName"].ToString()))
|
||||
{
|
||||
alErrors.Add("ImportQBRate: " + dr["FullName"].ToString() + " already exists in AyaNova");
|
||||
alErrors.Add("ImportQBTravelRate: " + dr["FullName"].ToString() + " already exists in AyaNova");
|
||||
return;
|
||||
}
|
||||
|
||||
//Import seems safe...
|
||||
Rates rates = Rates.GetItems(false);
|
||||
Rate c = rates.Add();
|
||||
c.RateType = AsRateType;
|
||||
//Rates rates = Rates.GetItems(false);
|
||||
//Rate c = rates.Add();
|
||||
//c.RateType = AsRateType;
|
||||
TravelRate c = new TravelRate();
|
||||
c.Name = sName;
|
||||
c.Charge = (decimal)dr["Price"];
|
||||
c.ContractRate = false;
|
||||
//c.ContractRate = false;
|
||||
c.Cost = (decimal)dr["Cost"];
|
||||
c.Description = T(255, dr["SalesDesc"].ToString());
|
||||
c.Notes = 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;
|
||||
}
|
||||
//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();
|
||||
//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();
|
||||
|
||||
var r = await PostAsync($"travel-rate", Newtonsoft.Json.JsonConvert.SerializeObject(c));
|
||||
long newId = IdFromResponse(r);
|
||||
|
||||
//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();
|
||||
var m = new IntegrationItem { AType = AyaType.TravelRate, IntegrationItemName = sName, IntegrationItemId = QuickBooksID, LastSync = DateTime.Now, ObjectId = newId };
|
||||
QBIntegration.Items.Add(m);
|
||||
await util.SaveIntegrationObject();
|
||||
}
|
||||
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" +
|
||||
alErrors.Add("ImportQBTravelRate: AyaNova won't allow import / link of " + sName + "\r\n" +
|
||||
"Due to the following error:\r\n" + ex.Message);
|
||||
|
||||
}
|
||||
@@ -4014,39 +4041,38 @@ namespace AyaNovaQBI
|
||||
|
||||
|
||||
|
||||
public static void RefreshAyaNovaPartFromQB(List<Guid> objectIDList)
|
||||
public static async Task RefreshAyaNovaPartFromQB(List<long> objectIDList)
|
||||
{
|
||||
PopulateQBItemCache();
|
||||
foreach (Guid g in objectIDList)
|
||||
await PopulateQBItemCache();
|
||||
foreach (long id in objectIDList)
|
||||
{
|
||||
try
|
||||
{
|
||||
Part c = Part.GetItem(g);
|
||||
RefreshAyaNovaPartFromQB(c);
|
||||
if (c.IsSavable)
|
||||
c.Save();
|
||||
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 void RefreshAyaNovaPartFromQB(Part c)
|
||||
public static async Task RefreshAyaNovaPartFromQB(Part c)
|
||||
{
|
||||
PopulateQBItemCache();
|
||||
IntegrationMap im = QBI.Maps[c.ID];
|
||||
await PopulateQBItemCache();
|
||||
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.ForeignID);
|
||||
DataRow dr = _dtQBItems.Rows.Find(im.IntegrationItemId);
|
||||
if (dr == null) return; //QBListID not found in part list?
|
||||
|
||||
string sName = dr["FullName"].ToString();
|
||||
if (sName.Length > 255)
|
||||
sName = sName.Substring(0, 255);
|
||||
c.PartNumber = sName;
|
||||
|
||||
c.Name = T(255, dr["SalesDesc"].ToString());
|
||||
c.WholesalerID = AyaVendorForQBItem(im.ForeignID);
|
||||
c.Name = sName;
|
||||
|
||||
c.Description = T(255, dr["SalesDesc"].ToString());
|
||||
c.WholeSalerId = AyaVendorForQBItem(im.ForeignID);
|
||||
c.Retail = (decimal)dr["Price"];
|
||||
c.Cost = (decimal)dr["Cost"];
|
||||
|
||||
@@ -4074,52 +4100,61 @@ namespace AyaNovaQBI
|
||||
}
|
||||
|
||||
string sName = dr["FullName"].ToString();
|
||||
if (sName.Length > 255)
|
||||
{
|
||||
alErrors.Add("ImportQBPart: QuickBooks Part name exceeds 255 character limit for AyaNova part number\r\n" +
|
||||
"Name: " + dr["FullName"].ToString() + "\r\n" +
|
||||
"was imported as: " + sName);
|
||||
sName = sName.Substring(0, 255);
|
||||
}
|
||||
//if (sName.Length > 255)
|
||||
//{
|
||||
// alErrors.Add("ImportQBPart: QuickBooks Part name exceeds 255 character limit for AyaNova part number\r\n" +
|
||||
// "Name: " + dr["FullName"].ToString() + "\r\n" +
|
||||
// "was imported as: " + sName);
|
||||
// sName = sName.Substring(0, 255);
|
||||
//}
|
||||
try
|
||||
{
|
||||
//already a Part by that number?
|
||||
if (Part.Exists(Guid.Empty, dr["FullName"].ToString()))
|
||||
if (QBIntegration.Items.Any(z => z.AType == AyaType.Part && z.IntegrationItemName == dr["FullName"].ToString()))
|
||||
{
|
||||
alErrors.Add("ImportQBPart: Part number " + dr["FullName"].ToString() + " already exists in AyaNova");
|
||||
alErrors.Add("ImportQBPart: Part name " + dr["FullName"].ToString() + " already exists in AyaNova");
|
||||
return;
|
||||
}
|
||||
|
||||
//Import seems safe...
|
||||
Part c = Part.NewItem();
|
||||
Part c = new Part();
|
||||
|
||||
|
||||
c.PartNumber = sName;
|
||||
c.Name = T(255, dr["SalesDesc"].ToString());
|
||||
c.WholesalerID = AyaVendorForQBItem(QuickBooksID);
|
||||
c.Name = sName;
|
||||
c.Description = T(255, dr["SalesDesc"].ToString());
|
||||
c.WholeSalerId = AyaVendorForQBItem(QuickBooksID);
|
||||
c.Retail = (decimal)dr["Price"];
|
||||
c.Cost = (decimal)dr["Cost"];
|
||||
|
||||
|
||||
|
||||
if (!c.IsSavable)
|
||||
{
|
||||
alErrors.Add("ImportQBPart: AyaNova won't allow import of " + c.Name + "\r\n" +
|
||||
"Due to the following broken rules:\r\n" + c.GetBrokenRulesString());
|
||||
return;
|
||||
}
|
||||
//if (!c.IsSavable)
|
||||
//{
|
||||
// alErrors.Add("ImportQBPart: AyaNova won't allow import of " + c.Name + "\r\n" +
|
||||
// "Due to the following broken rules:\r\n" + c.GetBrokenRulesString());
|
||||
// return;
|
||||
//}
|
||||
|
||||
//Save and get ready to provide the ID
|
||||
c = (Part)c.Save();
|
||||
////Save and get ready to provide the ID
|
||||
//c = (Part)c.Save();
|
||||
|
||||
////Link
|
||||
//IntegrationMap m = QBI.Maps.Add(QBI);
|
||||
//m.Name = sName;
|
||||
//m.RootObjectID = c.ID;
|
||||
//m.RootObjectType = RootObjectTypes.Part;
|
||||
//m.LastSync = DateTime.Now;
|
||||
//m.ForeignID = QuickBooksID;
|
||||
//QBI = (Integration)QBI.Save();
|
||||
|
||||
//Try to save and return errors if not in alerrors
|
||||
var r = await PostAsync($"part", Newtonsoft.Json.JsonConvert.SerializeObject(c));
|
||||
long newId = IdFromResponse(r);
|
||||
|
||||
//Link
|
||||
IntegrationMap m = QBI.Maps.Add(QBI);
|
||||
m.Name = sName;
|
||||
m.RootObjectID = c.ID;
|
||||
m.RootObjectType = RootObjectTypes.Part;
|
||||
m.LastSync = DateTime.Now;
|
||||
m.ForeignID = QuickBooksID;
|
||||
QBI = (Integration)QBI.Save();
|
||||
var m = new IntegrationItem { AType = AyaType.Customer, IntegrationItemName = sName, IntegrationItemId = QuickBooksID, LastSync = DateTime.Now, ObjectId = newId };
|
||||
QBIntegration.Items.Add(m);
|
||||
await SaveIntegrationObject();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user