This commit is contained in:
@@ -5318,7 +5318,7 @@ namespace AyaNovaQBI
|
|||||||
|
|
||||||
if (!AyaServiceRateList.Any(z => z.Id == RateID))
|
if (!AyaServiceRateList.Any(z => z.Id == RateID))
|
||||||
{
|
{
|
||||||
alErrors.Add("ImportAyaRate: Rate not found in AyaNova (deleted recently?) (" + RateID.ToString() + ")");
|
alErrors.Add("ImportAyaServiceRate: ServiceRate not found in AyaNova (deleted recently?) (" + RateID.ToString() + ")");
|
||||||
return;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -5326,23 +5326,22 @@ namespace AyaNovaQBI
|
|||||||
var r = await GetAsync($"service-rate/{RateID}");
|
var r = await GetAsync($"service-rate/{RateID}");
|
||||||
var c = r.ObjectResponse["data"].ToObject<ServiceRate>();
|
var c = r.ObjectResponse["data"].ToObject<ServiceRate>();
|
||||||
|
|
||||||
HERE
|
|
||||||
|
|
||||||
string sName = c.Name;
|
string sName = c.Name;
|
||||||
if (sName.Length > 31)
|
if (sName.Length > 31)
|
||||||
{
|
{
|
||||||
sName = sName.Substring(0, 31);
|
sName = sName.Substring(0, 31);
|
||||||
alErrors.Add("ImportAyaRate: AyaNova Rate name exceeds 31 character limit for QuickBooks\r\n" +
|
alErrors.Add("ImportAyaServiceRate: AyaNova ServiceRate name exceeds 31 character limit for QuickBooks\r\n" +
|
||||||
"Name: " + c.Name + "\r\n" +
|
"Name: " + c.Name + "\r\n" +
|
||||||
"will be imported as: " + sName);
|
"will be imported as: " + sName);
|
||||||
|
|
||||||
}
|
}
|
||||||
string sDescription = c.Description;
|
string sDescription = c.Name;
|
||||||
if (string.IsNullOrEmpty(sDescription)) sDescription = c.Name;
|
if (string.IsNullOrEmpty(sDescription)) sDescription = c.Name;
|
||||||
if (sDescription.Length > 4095)
|
if (sDescription.Length > 4095)
|
||||||
{
|
{
|
||||||
sDescription = sDescription.Substring(0, 4095);
|
sDescription = sDescription.Substring(0, 4095);
|
||||||
alErrors.Add("ImportAyaRate: AyaNova Rate description exceeds 4095 character limit for sales description in QuickBooks\r\n" +
|
alErrors.Add("ImportAyaServiceRate: AyaNova ServiceRate description exceeds 4095 character limit for sales description in QuickBooks\r\n" +
|
||||||
"will be imported as: " + sDescription);
|
"will be imported as: " + sDescription);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -5434,13 +5433,16 @@ namespace AyaNovaQBI
|
|||||||
_dtQBItems.Rows.Add(dr);
|
_dtQBItems.Rows.Add(dr);
|
||||||
|
|
||||||
//Link
|
//Link
|
||||||
IntegrationMap m = QBI.Maps.Add(QBI);
|
var m = new IntegrationItem { AType = AyaType.ServiceRate, IntegrationItemName = sName, IntegrationItemId = sNewID, LastSync = DateTime.Now, ObjectId = c.Id };
|
||||||
m.Name = sName;
|
QBIntegration.Items.Add(m);
|
||||||
m.RootObjectID = c.ID;
|
await util.SaveIntegrationObject();
|
||||||
m.RootObjectType = RootObjectTypes.Rate;
|
//IntegrationMap m = QBI.Maps.Add(QBI);
|
||||||
m.LastSync = DateTime.Now;
|
//m.Name = sName;
|
||||||
m.ForeignID = sNewID;
|
//m.RootObjectID = c.ID;
|
||||||
QBI = (Integration)QBI.Save();
|
//m.RootObjectType = RootObjectTypes.Rate;
|
||||||
|
//m.LastSync = DateTime.Now;
|
||||||
|
//m.ForeignID = sNewID;
|
||||||
|
//QBI = (Integration)QBI.Save();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@@ -5454,7 +5456,164 @@ namespace AyaNovaQBI
|
|||||||
//crack the exception in case it's a generic dataportal one
|
//crack the exception in case it's a generic dataportal one
|
||||||
//and it is if it's got an inner exception of any kind
|
//and it is if it's got an inner exception of any kind
|
||||||
if (ex.InnerException != null) ex = ex.InnerException;
|
if (ex.InnerException != null) ex = ex.InnerException;
|
||||||
alErrors.Add("ImportAyaRate: QuickBooks won't allow import of " + sName + "\r\n" +
|
alErrors.Add("ImportAyaServiceRate: QuickBooks won't allow import of " + sName + "\r\n" +
|
||||||
|
"Due to the following error:\r\n" + ex.Message);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//TRAVEL RATE
|
||||||
|
/// <summary>
|
||||||
|
/// Import the indicated Travel rate
|
||||||
|
/// to QuickBooks item record
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="VendorID"></param>
|
||||||
|
/// <param name="alErrors">An arraylist to hold strings indicating errors on fail</param>
|
||||||
|
public static async Task ImportAyaTravelRate(long RateID, ArrayList alErrors)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (!AyaTravelRateList.Any(z => z.Id == RateID))
|
||||||
|
{
|
||||||
|
alErrors.Add("ImportAyaTravelRate: TravelRate not found in AyaNova (deleted recently?) (" + RateID.ToString() + ")");
|
||||||
|
return;
|
||||||
|
|
||||||
|
}
|
||||||
|
// RatePickList.RatePickListInfo c = ratelist[RateID];
|
||||||
|
var r = await GetAsync($"travel-rate/{RateID}");
|
||||||
|
var c = r.ObjectResponse["data"].ToObject<TravelRate>();
|
||||||
|
|
||||||
|
|
||||||
|
string sName = c.Name;
|
||||||
|
if (sName.Length > 31)
|
||||||
|
{
|
||||||
|
sName = sName.Substring(0, 31);
|
||||||
|
alErrors.Add("ImportAyaTravelRate: AyaNova TravelRate name exceeds 31 character limit for QuickBooks\r\n" +
|
||||||
|
"Name: " + c.Name + "\r\n" +
|
||||||
|
"will be imported as: " + sName);
|
||||||
|
|
||||||
|
}
|
||||||
|
string sDescription = c.Name;
|
||||||
|
if (string.IsNullOrEmpty(sDescription)) sDescription = c.Name;
|
||||||
|
if (sDescription.Length > 4095)
|
||||||
|
{
|
||||||
|
sDescription = sDescription.Substring(0, 4095);
|
||||||
|
alErrors.Add("ImportAyaTravelRate: AyaNova TravelRate description exceeds 4095 character limit for sales description in QuickBooks\r\n" +
|
||||||
|
"will be imported as: " + sDescription);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//Connect to QB and fill
|
||||||
|
// IY: Create the session manager object using QBFC
|
||||||
|
QBSessionManager sessionManager = new QBSessionManager();
|
||||||
|
|
||||||
|
// IY: We want to know if we begun a session so we can end it if an
|
||||||
|
// error happens
|
||||||
|
bool booSessionBegun = false;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
//Import seems safe...
|
||||||
|
|
||||||
|
// IY: Get the RequestMsgSet based on the correct QB Version
|
||||||
|
IMsgSetRequest requestSet = getLatestMsgSetRequest(sessionManager);
|
||||||
|
|
||||||
|
// IY: Initialize the message set request object
|
||||||
|
requestSet.Attributes.OnError = ENRqOnError.roeStop;
|
||||||
|
|
||||||
|
// IY: Add the request to the message set request object
|
||||||
|
IItemServiceAdd ca = requestSet.AppendItemServiceAddRq();
|
||||||
|
//create a new row to add to the client cache datatable
|
||||||
|
DataRow dr = _dtQBItems.NewRow();
|
||||||
|
dr["FullName"] = sName;
|
||||||
|
dr["Type"] = qbitemtype.Service;
|
||||||
|
dr["Price"] = c.Charge;
|
||||||
|
dr["Cost"] = c.Cost;
|
||||||
|
dr["SalesDesc"] = sDescription;
|
||||||
|
dr["ReorderPoint"] = 0;
|
||||||
|
dr["Modified"] = DateTime.MinValue;
|
||||||
|
dr["VendorID"] = "";
|
||||||
|
|
||||||
|
//------------------------
|
||||||
|
//Set the qb item values
|
||||||
|
ca.Name.SetValue(sName);
|
||||||
|
ca.ORSalesPurchase.SalesOrPurchase.Desc.SetValue(sDescription);
|
||||||
|
ca.ORSalesPurchase.SalesOrPurchase.ORPrice.Price.SetValue((double)c.Charge);
|
||||||
|
ca.ORSalesPurchase.SalesOrPurchase.AccountRef.ListID.SetValue(QDat.QBServiceIncomeAccountRef);
|
||||||
|
//------------------------
|
||||||
|
|
||||||
|
|
||||||
|
//This is intended to be called after already sucessfully connected
|
||||||
|
//to get version info so no special safety checks here
|
||||||
|
sessionManager.OpenConnection2("", "AyaNova QBI", ENConnectionType.ctLocalQBDLaunchUI);
|
||||||
|
sessionManager.BeginSession("", ENOpenMode.omDontCare);
|
||||||
|
booSessionBegun = true;
|
||||||
|
|
||||||
|
|
||||||
|
IMsgSetResponse responseSet = sessionManager.DoRequests(requestSet);
|
||||||
|
|
||||||
|
// Uncomment the following to view and save the request and response XML
|
||||||
|
//string requestXML = requestSet.ToXMLString();
|
||||||
|
//MessageBox.Show(requestXML);
|
||||||
|
// SaveXML(requestXML);
|
||||||
|
//string responseXML = responseSet.ToXMLString();
|
||||||
|
//MessageBox.Show(responseXML);
|
||||||
|
// SaveXML(responseXML);
|
||||||
|
|
||||||
|
IResponse response = responseSet.ResponseList.GetAt(0);
|
||||||
|
//nonzero indicates an error this is unrecoverable
|
||||||
|
//so throw an exception
|
||||||
|
|
||||||
|
if (response.StatusCode != 0)
|
||||||
|
{
|
||||||
|
throw new ApplicationException(response.StatusMessage + " Code: " + response.StatusCode);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
IItemServiceRet cr = response.Detail as IItemServiceRet;
|
||||||
|
string sNewID = cr.ListID.GetValue();
|
||||||
|
requestSet.ClearRequests();
|
||||||
|
//----------------
|
||||||
|
|
||||||
|
|
||||||
|
// Close the session and connection with QuickBooks
|
||||||
|
sessionManager.EndSession();
|
||||||
|
booSessionBegun = false;
|
||||||
|
sessionManager.CloseConnection();
|
||||||
|
|
||||||
|
//catch the new ID for the QB Item
|
||||||
|
dr["ID"] = sNewID;
|
||||||
|
//add the new row for the newly imported object
|
||||||
|
_dtQBItems.Rows.Add(dr);
|
||||||
|
|
||||||
|
//Link
|
||||||
|
var m = new IntegrationItem { AType = AyaType.TravelRate, IntegrationItemName = sName, IntegrationItemId = sNewID, LastSync = DateTime.Now, ObjectId = c.Id };
|
||||||
|
QBIntegration.Items.Add(m);
|
||||||
|
await util.SaveIntegrationObject();
|
||||||
|
//IntegrationMap m = QBI.Maps.Add(QBI);
|
||||||
|
//m.Name = sName;
|
||||||
|
//m.RootObjectID = c.ID;
|
||||||
|
//m.RootObjectType = RootObjectTypes.Rate;
|
||||||
|
//m.LastSync = DateTime.Now;
|
||||||
|
//m.ForeignID = sNewID;
|
||||||
|
//QBI = (Integration)QBI.Save();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
if (booSessionBegun)
|
||||||
|
{
|
||||||
|
sessionManager.EndSession();
|
||||||
|
sessionManager.CloseConnection();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//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("ImportAyaTravelRate: QuickBooks won't allow import of " + sName + "\r\n" +
|
||||||
"Due to the following error:\r\n" + ex.Message);
|
"Due to the following error:\r\n" + ex.Message);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user