This commit is contained in:
2022-07-06 00:21:20 +00:00
parent 7b22f03f44
commit e87f623017
2 changed files with 26 additions and 12 deletions

View File

@@ -101,6 +101,7 @@ namespace AyaNovaQBI
break; break;
} }
} }
Initialize();
} }
#region Import to AyaNova #region Import to AyaNova

View File

@@ -692,6 +692,7 @@ namespace AyaNovaQBI
dtTemp.Columns.Add("Name", typeof(string)); dtTemp.Columns.Add("Name", typeof(string));
bool present = true; bool present = true;
List<NameIdItem> BadIntegrationItemIds = new List<NameIdItem>();
foreach (IntegrationItem m in QBIntegration.Items) foreach (IntegrationItem m in QBIntegration.Items)
{ {
present = true; present = true;
@@ -712,13 +713,14 @@ namespace AyaNovaQBI
} }
if (!present) if (!present)
dtTemp.Rows.Add(new object[] { m.Id, m.AType.ToString() + ": " + m.IntegrationItemName }); BadIntegrationItemIds.Add(new NameIdItem { Name = m.IntegrationItemName, Id = m.Id });
//dtTemp.Rows.Add(new object[] { m.Id, m.AType.ToString() + ": " + m.IntegrationItemName });
} }
if (dtTemp.Rows.Count > 0) if (BadIntegrationItemIds.Count > 0)
{ {
if (dtTemp.Rows.Count == QBIntegration.Items.Count) if (BadIntegrationItemIds.Count == QBIntegration.Items.Count)
{ {
//None of the items mapped match offer to remove them all //None of the items mapped match offer to remove them all
#region Nothing matches #region Nothing matches
@@ -738,9 +740,10 @@ namespace AyaNovaQBI
{ {
await IntegrationLog("PFC: User opted to remove all mappings after double warning."); await IntegrationLog("PFC: User opted to remove all mappings after double warning.");
QBIntegration.Items.Clear(); QBIntegration.Items.Clear();
//Exists, fetch it check if active then we're done here await SaveIntegrationObject();
ApiResponse r = await PostAsync($"integration/{QBI_INTEGRATION_ID}", Newtonsoft.Json.JsonConvert.SerializeObject(QBIntegration)); ////Exists, fetch it check if active then we're done here
QBIntegration = r.ObjectResponse["data"].ToObject<Integration>(); //ApiResponse r = await PostAsync($"integration/{QBI_INTEGRATION_ID}", Newtonsoft.Json.JsonConvert.SerializeObject(QBIntegration));
//QBIntegration = r.ObjectResponse["data"].ToObject<Integration>();
return false; return false;
} }
@@ -754,19 +757,29 @@ namespace AyaNovaQBI
//some items match so iterate them and offer to delete one by one //some items match so iterate them and offer to delete one by one
await IntegrationLog("PFC: Some integration maps do not match qb database objects"); await IntegrationLog("PFC: Some integration maps do not match qb database objects");
foreach (DataRow row in dtTemp.Rows) //foreach (DataRow row in dtTemp.Rows)
foreach(var bi in BadIntegrationItemIds)
{ {
DialogResult dr = MessageBox.Show("Linked object: " + row["Name"].ToString() + "\r\n" + DialogResult dr = MessageBox.Show("Linked object: " + bi.Name + "\r\n" +
"Is missing or set Inactive in QuickBooks.\r\n\r\nRemove it's link from AyaNova?", "", MessageBoxButtons.YesNoCancel, "Is missing or set Inactive in QuickBooks.\r\n\r\nRemove it's link from AyaNova?", "", MessageBoxButtons.YesNoCancel,
MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button3); MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button3);
if (dr == DialogResult.Cancel) return false; if (dr == DialogResult.Cancel) return false;
if (dr == DialogResult.Yes) if (dr == DialogResult.Yes)
QBIntegration.Items.Remove(QBIntegration.Items.Where(z => z.IntegrationItemId == row["MAPID"].ToString()).First()); {
} //var mapId = (long)row["MAPID"];
var removeItem = QBIntegration.Items.Where(z => z.Id == bi.Id).First();
//TODO: this needs to be a reverse for next loop
bool bResult = QBIntegration.Items.Remove(bi);
if (!bResult)
MessageBox.Show("Error attempting to remove unmapped item; it could not be found in the map list");
ApiResponse r = await PostAsync($"integration/{QBI_INTEGRATION_ID}", Newtonsoft.Json.JsonConvert.SerializeObject(QBIntegration)); }
QBIntegration = r.ObjectResponse["data"].ToObject<Integration>(); }
await SaveIntegrationObject();
//ApiResponse r = await PostAsync($"integration/{QBI_INTEGRATION_ID}", Newtonsoft.Json.JsonConvert.SerializeObject(QBIntegration));
//QBIntegration = r.ObjectResponse["data"].ToObject<Integration>();
} }
} }