This commit is contained in:
@@ -643,46 +643,100 @@ namespace AyaNovaQBI
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static async Task<bool> ValidateMap(StringBuilder initErrors)
|
public static async Task<bool> ValidateMap(StringBuilder initErrors)
|
||||||
{
|
{
|
||||||
ApiResponse r = null;
|
//Missing links table:
|
||||||
try
|
DataTable dtTemp = new DataTable();
|
||||||
{
|
dtTemp.Columns.Add("MAPID", typeof(Guid));
|
||||||
r = await GetAsync($"integration/exists/{QBI_INTEGRATION_ID}");
|
dtTemp.Columns.Add("Name", typeof(string));
|
||||||
|
|
||||||
if (r.ObjectResponse["data"].Value<bool>() == false)
|
bool present = true;
|
||||||
|
foreach (IntegrationItem m in QBIntegration.Items)
|
||||||
{
|
{
|
||||||
//doesn't exist, need to create it now
|
present = true;
|
||||||
QBIntegration = new Integration();
|
|
||||||
QBIntegration.IntegrationAppId = QBI_INTEGRATION_ID;
|
switch (m.AType)
|
||||||
QBIntegration.Active = true;
|
{
|
||||||
QBIntegration.Name = "QBI - QuickBooks Desktop integration";
|
case AyaType.Customer:
|
||||||
r = await PostAsync("integration", Newtonsoft.Json.JsonConvert.SerializeObject(QBIntegration));
|
present = QBClients.Rows.Contains(m.IntegrationItemId);
|
||||||
QBIntegration.Id = IdFromResponse(r);
|
break;
|
||||||
await IntegrationLog("AyaNova QBI Integration installed to AyaNova");
|
case AyaType.Vendor:
|
||||||
|
present = QBVendors.Rows.Contains(m.IntegrationItemId);
|
||||||
|
break;
|
||||||
|
case AyaType.ServiceRate:
|
||||||
|
case AyaType.TravelRate:
|
||||||
|
case AyaType.Part:
|
||||||
|
present = QBItems.Rows.Contains(m.IntegrationItemId);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!present)
|
||||||
|
dtTemp.Rows.Add(new object[] { m.Id, m.AType.ToString() + ": " + m.IntegrationItemName });
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dtTemp.Rows.Count > 0)
|
||||||
|
{
|
||||||
|
if (dtTemp.Rows.Count == QBIntegration.Items.Count)
|
||||||
|
{
|
||||||
|
//None of the items mapped match offer to remove them all
|
||||||
|
#region Nothing matches
|
||||||
|
await IntegrationLog("PFC: No integration maps match qb database objects!");
|
||||||
|
|
||||||
|
DialogResult dr = MessageBox.Show("None of the mapped items in AyaNova were found in the \r\n" +
|
||||||
|
"Currently open QuickBooks database.\r\n" +
|
||||||
|
"It's possible you have the wrong database open.\r\n\r\n" +
|
||||||
|
"Do you want to remove all mappings from AyaNova?", "", MessageBoxButtons.YesNoCancel,
|
||||||
|
MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button3);
|
||||||
|
|
||||||
|
if (dr == DialogResult.Yes)
|
||||||
|
{
|
||||||
|
dr = MessageBox.Show("If you select YES all mappings will be removed from AyaNova.", "", MessageBoxButtons.YesNoCancel,
|
||||||
|
MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button3);
|
||||||
|
if (dr == DialogResult.Yes)
|
||||||
|
{
|
||||||
|
await IntegrationLog("PFC: User opted to remove all mappings after double warning.");
|
||||||
|
QBIntegration.Items.Clear();
|
||||||
|
//foreach (DataRow row in dtTemp.Rows)
|
||||||
|
//{
|
||||||
|
// QBIntegration.Items.Remove(row["MAPID"].ToString());
|
||||||
|
//}
|
||||||
|
//TODO: POST BACK TO SERVER
|
||||||
|
//Exists, fetch it check if active then we're done here
|
||||||
|
ApiResponse r = await PostAsync($"integration/{QBI_INTEGRATION_ID}", Newtonsoft.Json.JsonConvert.SerializeObject(QBIntegration));
|
||||||
|
QBIntegration = r.ObjectResponse["data"].ToObject<Integration>();
|
||||||
|
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//Exists, fetch it check if active then we're done here
|
//some items match so iterate them and offer to delete one by one
|
||||||
r = await GetAsync($"integration/{QBI_INTEGRATION_ID}");
|
|
||||||
|
await IntegrationLog("PFC: Some integration maps do not match qb database objects");
|
||||||
|
foreach (DataRow row in dtTemp.Rows)
|
||||||
|
{
|
||||||
|
|
||||||
|
DialogResult dr = MessageBox.Show("Linked object: " + row["Name"].ToString() + "\r\n" +
|
||||||
|
"Is missing or set Inactive in QuickBooks.\r\n\r\nRemove it's link from AyaNova?", "", MessageBoxButtons.YesNoCancel,
|
||||||
|
MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button3);
|
||||||
|
if (dr == DialogResult.Cancel) return false;
|
||||||
|
if (dr == DialogResult.Yes)
|
||||||
|
QBIntegration.Items.Remove(QBIntegration.Items.Where(z => z.IntegrationItemId == row["MAPID"].ToString()).First());
|
||||||
|
}
|
||||||
|
|
||||||
|
ApiResponse r = await PostAsync($"integration/{QBI_INTEGRATION_ID}", Newtonsoft.Json.JsonConvert.SerializeObject(QBIntegration));
|
||||||
QBIntegration = r.ObjectResponse["data"].ToObject<Integration>();
|
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;
|
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 }));
|
public static async Task IntegrationLog(string logLine) => await PostAsync("integration/log", Newtonsoft.Json.JsonConvert.SerializeObject(new NameIdItem { Id = QBIntegration.Id, Name = logLine }));
|
||||||
@@ -2170,7 +2224,7 @@ namespace AyaNovaQBI
|
|||||||
|
|
||||||
DataRow dr = _dtQBVendors.Rows.Add(
|
DataRow dr = _dtQBVendors.Rows.Add(
|
||||||
new object[]
|
new object[]
|
||||||
{
|
{
|
||||||
clitem.ListID.GetValue(),
|
clitem.ListID.GetValue(),
|
||||||
clitem.Name.GetValue(),
|
clitem.Name.GetValue(),
|
||||||
ProcessAddress(clitem.VendorAddress),
|
ProcessAddress(clitem.VendorAddress),
|
||||||
@@ -2183,7 +2237,7 @@ namespace AyaNovaQBI
|
|||||||
clitem.TimeCreated.GetValue(),
|
clitem.TimeCreated.GetValue(),
|
||||||
clitem.TimeModified.GetValue(),
|
clitem.TimeModified.GetValue(),
|
||||||
ProcessQBString(clitem.AccountNumber)
|
ProcessQBString(clitem.AccountNumber)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} // for loop
|
} // for loop
|
||||||
} // if
|
} // if
|
||||||
|
|||||||
Reference in New Issue
Block a user