This commit is contained in:
2022-07-06 20:16:45 +00:00
parent 5431428589
commit c83414a68d
2 changed files with 163 additions and 83 deletions

View File

@@ -714,7 +714,7 @@ namespace AyaNovaQBI
if (!present)
BadIntegrationItemIds.Add(new NameIdItem { Name = m.IntegrationItemName, Id = m.Id });
//dtTemp.Rows.Add(new object[] { m.Id, m.AType.ToString() + ": " + m.IntegrationItemName });
//dtTemp.Rows.Add(new object[] { m.Id, m.AType.ToString() + ": " + m.IntegrationItemName });
}
@@ -758,7 +758,7 @@ namespace AyaNovaQBI
await IntegrationLog("PFC: Some integration maps do not match qb database objects");
//foreach (DataRow row in dtTemp.Rows)
foreach(var bi in BadIntegrationItemIds)
foreach (var bi in BadIntegrationItemIds)
{
DialogResult dr = MessageBox.Show("Linked object: " + bi.Name + "\r\n" +
@@ -769,7 +769,7 @@ namespace AyaNovaQBI
{
//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
//TODO: this needs to be a reverse for next loop
bool bResult = QBIntegration.Items.Remove(removeItem);
if (!bResult)
MessageBox.Show("Error attempting to remove unmapped item; it could not be found in the map list");
@@ -1677,7 +1677,7 @@ namespace AyaNovaQBI
await PopulateQBClientCacheAsync();
w.Step = "Items";
await PopulateQBItemCache();
await PopulateQBItemCacheAsync();
if (!(QVersion < 3))//qbXML 3.0 or higher (QB 2004 any country or newer)
{
@@ -1750,7 +1750,7 @@ namespace AyaNovaQBI
/// Populate the cached qb data
/// billable
/// </summary>
private async static Task PopulateQBItemCache()
internal async static Task PopulateQBItemCacheAsync()
{
if (_dtQBItems == null)
{
@@ -2531,7 +2531,7 @@ namespace AyaNovaQBI
/// Populate the cached qb data
/// of customers / clients
/// </summary>
private static async Task PopulateQBClientCacheAsync()
internal static async Task PopulateQBClientCacheAsync()
{
if (_dtQBClients == null)
{
@@ -2761,7 +2761,7 @@ namespace AyaNovaQBI
/// Populate the cached qb data
/// of Vendors
/// </summary>
private static async Task PopulateQBVendorCacheAsync()
internal static async Task PopulateQBVendorCacheAsync()
{
if (_dtQBVendors == null)
{
@@ -4058,26 +4058,29 @@ namespace AyaNovaQBI
public static async Task RefreshAyaNovaPartFromQB(List<long> objectIDList)
{
await PopulateQBItemCache();
foreach (long id in objectIDList)
{
try
{
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 async Task RefreshAyaNovaPartFromQB(List<long> objectIDList)
//{
// await PopulateQBItemCache();
// foreach (long id in objectIDList)
// {
// try
// {
// 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 async Task RefreshAyaNovaPartFromQB(Part c)
public static async Task RefreshAyaNovaPartFromQB(long PartId, bool pricesOnly = false)
{
await PopulateQBItemCache();
var r = await GetAsync($"part/{PartId}");
var c = r.ObjectResponse["data"].ToObject<Part>();
if (c == null) return;
IntegrationItem im = util.QBIntegration.Items.FirstOrDefault(z => z.ObjectId == c.Id && z.AType == AyaType.Part);
if (im == null) return;//this part is not linked
@@ -4925,7 +4928,7 @@ namespace AyaNovaQBI
//Link
var m = new IntegrationItem { AType = AyaType.Vendor, IntegrationItemName = sName, IntegrationItemId = sNewCustID, LastSync = DateTime.Now, ObjectId = c.Id };
QBIntegration.Items.Add(m);
}
catch (Exception ex)
{
@@ -4972,8 +4975,10 @@ namespace AyaNovaQBI
/// Refresh the indicated AyaNova part
/// to it's linked QuickBooks item record
/// </summary>
public static async Task RefreshQBPartFromAyaNova(Part c)
public static async Task RefreshQBPartFromAyaNova(long PartId, bool pricesOnly = false)
{
var r = await GetAsync($"part/{PartId}");
var c = r.ObjectResponse["data"].ToObject<Part>();
IntegrationItem im = QBIntegration.Items.FirstOrDefault(z => z.ObjectId == c.Id && z.AType == AyaType.Part);
if (im == null) return;//this part is not linked
@@ -5018,48 +5023,29 @@ namespace AyaNovaQBI
//Get and set edit sequence
string sEditSequence = await GetInventoryItemEditSequenceAsync(im.IntegrationItemId);
if (!pricesOnly)
{
dr["FullName"] = sName;
dr["Type"] = qbitemtype.Inventory;
dr["VendorID"] = c.WholeSalerId.ToString();
dr["SalesDesc"] = sDescription;
//create a new row to add to the client cache datatable
dr["FullName"] = sName;
dr["Type"] = qbitemtype.Inventory;
//Set the qb item values
ca.Name.SetValue(sName);
ca.SalesDesc.SetValue(sDescription);
ca.PurchaseDesc.SetValue(sDescription);
}
dr["Price"] = c.Retail;
dr["Cost"] = c.Cost;
dr["SalesDesc"] = sDescription;
//dr["ReorderPoint"] = 0;
dr["Modified"] = DateTime.Now;
dr["VendorID"] = c.WholeSalerId.ToString();
//Set the QB item identification and edit sequence
ca.ListID.SetValue(im.IntegrationItemId);
ca.EditSequence.SetValue(sEditSequence);
//------------------------
//Set the qb item values
ca.Name.SetValue(sName);
//ca.IncomeAccountRef.ListID.SetValue(QDat.QBInventoryIncomeAccountReference);
// ca.COGSAccountRef.ListID.SetValue(QDat.QBInventoryCOGSAccountRef);
// ca.AssetAccountRef.ListID.SetValue(QDat.QBInventoryAssetAccountRef);
ca.SalesDesc.SetValue(sDescription);
ca.PurchaseDesc.SetValue(sDescription);
ca.SalesPrice.SetValue((double)c.Retail);
ca.PurchaseCost.SetValue((double)c.Cost);
//Inventory values cannot be updated this way
//they require generating a PO or making an invoice so
//the refresh command won't support inventory values
//if (AyaBizUtils.GlobalSettings.UseInventory)
//{
// PartInventoryValuesFetcher pbw = PartInventoryValuesFetcher.GetItem(c.ID);
// ca.QuantityOnHand.SetValue((double)pbw.QuantityOnHand);
// ca.ReorderPoint.SetValue((double)pbw.MinStockLevel);
//}
//------------------------
//Set the QB item identification and edit sequence
ca.ListID.SetValue(im.IntegrationItemId);
ca.EditSequence.SetValue(sEditSequence);
//This is intended to be called after already sucessfully connected
//to get version info so no special safety checks here
@@ -5088,8 +5074,6 @@ namespace AyaNovaQBI
}
// IItemInventoryRet cr = response.Detail as IItemInventoryRet;
// string sNewID = cr.ListID.GetValue();
requestSet.ClearRequests();
//----------------
@@ -5098,23 +5082,8 @@ namespace AyaNovaQBI
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
//// IntegrationMap m = QBI.Maps.Add(QBI);
////m.Name = sName;
//// m.RootObjectID = c.ID;
//// m.RootObjectType = RootObjectTypes.Part;
//im.LastSync = DateTime.Now;
////m.ForeignID = sNewID;
//QBI = (Integration)QBI.Save();
//v8NOTE: name was not set here as you can see above, maybe on purpose? leaving as is, not sure why but safest option to copy what was done before
im.LastSync = DateTime.Now;
await SaveIntegrationObject();
}
catch (Exception ex)
{
@@ -5128,7 +5097,7 @@ namespace AyaNovaQBI
//and it is if it's got an inner exception of any kind
if (ex.InnerException != null) ex = ex.InnerException;
CopyableMessageBox cp = new CopyableMessageBox(
"RefreshQBPartFromAyaNova: QuickBooks won't allow import of " + sName + "\r\n" +
"RefreshQBPartFromAyaNova: QuickBooks won't allow update of " + sName + "\r\n" +
"Due to the following error:\r\n" + ex.Message);
cp.ShowDialog();
@@ -5318,7 +5287,7 @@ namespace AyaNovaQBI
//Link
var m = new IntegrationItem { AType = AyaType.Part, IntegrationItemName = sName, IntegrationItemId = sNewID, LastSync = DateTime.Now, ObjectId = c.Id };
QBIntegration.Items.Add(m);
}
catch (Exception ex)
{
@@ -5470,7 +5439,7 @@ namespace AyaNovaQBI
//Link
var m = new IntegrationItem { AType = AyaType.ServiceRate, IntegrationItemName = sName, IntegrationItemId = sNewID, LastSync = DateTime.Now, ObjectId = c.Id };
QBIntegration.Items.Add(m);
}
catch (Exception ex)
{
@@ -5620,7 +5589,7 @@ namespace AyaNovaQBI
//Link
var m = new IntegrationItem { AType = AyaType.TravelRate, IntegrationItemName = sName, IntegrationItemId = sNewID, LastSync = DateTime.Now, ObjectId = c.Id };
QBIntegration.Items.Add(m);
}
catch (Exception ex)
{