This commit is contained in:
@@ -566,20 +566,12 @@ namespace AyaNovaQBI
|
|||||||
await PopulateAyaListCache();
|
await PopulateAyaListCache();
|
||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(QBIntegration.IntegrationData) || QBIntegration.Items.Count == 0)
|
if (string.IsNullOrWhiteSpace(QBIntegration.IntegrationData) || QBIntegration.Items.Count == 0)
|
||||||
return true;//all ok, no maps
|
return true;//nothing mapped or set to validate return to mainform for initial setup to be triggered
|
||||||
|
|
||||||
//PFC - Validate settings, create if necessary (Util.ValidateSettings()) and save
|
|
||||||
//TODO: if QBIntegration.IntegrationData==null then nothing is set yet and it's fresh so trigger the setup stuff
|
|
||||||
// but perhaps this should be done / called by mainform as this block and function is strictly related to initialization and caching only
|
|
||||||
// and mapping and setup is not really part of that
|
|
||||||
// So, if there are no mappings and integrationData=null just return but if there are then they need to be validated here
|
|
||||||
|
|
||||||
// next: if QBIntegration.IntegrationData==null then we're done for now let mainform handle initial setup
|
|
||||||
//also if there are no mappings then same thing, let mainform handle setup
|
|
||||||
//However, if there *are* integration data or mappings then they need to be validated here
|
|
||||||
|
|
||||||
|
|
||||||
//PFC - verify integration mapped objects still exist at each end (Util.PreFlightCheck() line 199)
|
//PFC - verify integration mapped objects still exist at each end (Util.PreFlightCheck() line 199)
|
||||||
|
if (!await ValidateMap(initErrors))
|
||||||
|
return false;
|
||||||
|
|
||||||
//DONE
|
//DONE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -643,17 +635,59 @@ namespace AyaNovaQBI
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
public static async Task IntegrationLog(string logLine)
|
/// Ensure existance of QBI Integration object
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="initErrors"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static async Task<bool> ValidateMap(StringBuilder initErrors)
|
||||||
{
|
{
|
||||||
|
ApiResponse r = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
r = await GetAsync($"integration/exists/{QBI_INTEGRATION_ID}");
|
||||||
|
|
||||||
await PostAsync("integration/log", Newtonsoft.Json.JsonConvert.SerializeObject(new NameIdItem { Id = QBIntegration.Id, Name = logLine }));
|
if (r.ObjectResponse["data"].Value<bool>() == false)
|
||||||
|
{
|
||||||
|
//doesn't exist, need to create it now
|
||||||
|
QBIntegration = new Integration();
|
||||||
|
QBIntegration.IntegrationAppId = QBI_INTEGRATION_ID;
|
||||||
|
QBIntegration.Active = true;
|
||||||
|
QBIntegration.Name = "QBI - QuickBooks Desktop integration";
|
||||||
|
r = await PostAsync("integration", Newtonsoft.Json.JsonConvert.SerializeObject(QBIntegration));
|
||||||
|
QBIntegration.Id = IdFromResponse(r);
|
||||||
|
await IntegrationLog("AyaNova QBI Integration installed to AyaNova");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//Exists, fetch it check if active then we're done here
|
||||||
|
r = await GetAsync($"integration/{QBI_INTEGRATION_ID}");
|
||||||
|
QBIntegration = r.ObjectResponse["data"].ToObject<Integration>();
|
||||||
|
|
||||||
|
if (!QBIntegration.Active)
|
||||||
|
{
|
||||||
|
initErrors.AppendLine("QBI Integration is currently deactivated and can not be used\r\nThis setting can be changed in AyaNova in the Administration section -> Integrations -> QuickBooks Desktop integration record\r\nSet to active and save to enable QBI");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
initErrors.AppendLine("Error fetching QBI Integration object");
|
||||||
|
initErrors.AppendLine(ex.Message);
|
||||||
|
initErrors.AppendLine(r.CompactResponse);
|
||||||
|
return false;
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static async Task IntegrationLog(string logLine) => await PostAsync("integration/log", Newtonsoft.Json.JsonConvert.SerializeObject(new NameIdItem { Id = QBIntegration.Id, Name = logLine }));
|
||||||
|
|
||||||
|
|
||||||
#region PFC QB side
|
#region PFC QB side
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Open QB connection
|
/// Open QB connection
|
||||||
@@ -812,10 +846,6 @@ namespace AyaNovaQBI
|
|||||||
}
|
}
|
||||||
#endregion pfc qb side
|
#endregion pfc qb side
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#region QB Specific utils
|
#region QB Specific utils
|
||||||
|
|
||||||
|
|
||||||
@@ -935,13 +965,6 @@ namespace AyaNovaQBI
|
|||||||
|
|
||||||
#endregion qb specific utils
|
#endregion qb specific utils
|
||||||
|
|
||||||
#region QB API helper methods/ attributes/cached lists
|
|
||||||
/// <summary>
|
|
||||||
/// Populate or repopulate the list of
|
|
||||||
/// </summary>
|
|
||||||
|
|
||||||
#endregion qb specific utils
|
|
||||||
|
|
||||||
#region QB API helper methods/ attributes/cached lists
|
#region QB API helper methods/ attributes/cached lists
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Populate or repopulate the list of
|
/// Populate or repopulate the list of
|
||||||
@@ -2457,7 +2480,6 @@ namespace AyaNovaQBI
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
#region AyaNova cached lists
|
#region AyaNova cached lists
|
||||||
public async static Task PopulateAyaListCache()
|
public async static Task PopulateAyaListCache()
|
||||||
{
|
{
|
||||||
@@ -2590,8 +2612,7 @@ namespace AyaNovaQBI
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#endregion qb specific non-api stuff
|
||||||
#endregion qb stuff
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user