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

@@ -953,7 +953,7 @@ namespace AyaNovaQBI
private void updateSelectedItemsToolStripMenuItem_Click(object sender, EventArgs e)
private async void updateSelectedItemsToolStripMenuItem_Click(object sender, EventArgs e)
{
//Parts in v7 default update would do price / cost both ways in addition to the part description and other fields
// however the user could go to map and select to *only* update the prices in AyaNova from QB but not the other fields
@@ -997,7 +997,118 @@ namespace AyaNovaQBI
if (s.ShowDialog() == DialogResult.Cancel)
return;
MessageBox.Show("STUB: UPDATE SELECTED ITEMS");
bool PricesOnly = s.PriceOnly;
s.Dispose();
bool SaveIntegration = false;
if (IsAyaGrid)
{
#region AyaGrid so UPDATE AYANOVA FROM QB
switch (_Type)
{
case AyaType.Customer:
await util.PopulateQBClientCacheAsync();
break;
case AyaType.Vendor:
await util.PopulateQBVendorCacheAsync();
break;
case AyaType.Part:
await util.PopulateQBItemCacheAsync();
break;
}
foreach (DataGridViewRow r in gridAya.SelectedRows)
{
string AyaName = r.Cells[0].Value.ToString();
long AyaId = (long)r.Cells[1].Value;
//only linked items can be updated
IntegrationItem m = util.QBIntegration.Items.FirstOrDefault(z => z.ObjectId == AyaId && z.AType == _Type);
if (m != null)
{
switch (_Type)
{
case AyaType.Customer:
sType = "Customers";
break;
case AyaType.Vendor:
sType = "Vendors";
break;
case AyaType.Part:
await util.RefreshAyaNovaPartFromQB(AyaId, PricesOnly);
break;
}
SaveIntegration = true;
}
}
#endregion AyaGrid
}
else
{
#region QB GRID
//################
//QB GRID
//
if (gridQB.SelectedRows.Count > 1)
{
MessageBox.Show("You can not link more than one QuickBooks\r\n" +
"object to a single AyaNova object", "Not supported", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
var QBItemName = gridQB.SelectedRows[0].Cells[0].Value.ToString();
var QBItemId = gridQB.SelectedRows[0].Cells[1].Value.ToString();
MapSelectAyaNovaItem s = new MapSelectAyaNovaItem();
s.Items = _aya;
if (s.ShowDialog() == DialogResult.Cancel)
return;
var AyaId = s.SelectedItemId;
s.Dispose();
//This way is a one to one mapping so only one iteration and two potential things to do, add or change link
//Is it already present?
IntegrationItem m = util.QBIntegration.Items.FirstOrDefault(z => z.ObjectId == AyaId && z.AType == _Type);
if (m != null)
{
m.IntegrationItemId = QBItemId;
m.IntegrationItemName = QBItemName;
m.LastSync = System.DateTime.Now;
SaveIntegration = true;
}
else
{
//not already present, so add it
m = new IntegrationItem { AType = _Type, IntegrationItemName = QBItemName, IntegrationItemId = QBItemId, LastSync = System.DateTime.Now, ObjectId = AyaId };
util.QBIntegration.Items.Add(m);
SaveIntegration = true;
}
#endregion qb grid
}
if (SaveIntegration)
{
await util.SaveIntegrationObject();
Initialize();
}
}//eof
}//eoc

View File

@@ -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)
//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(long PartId, bool pricesOnly = false)
{
await PopulateQBItemCache();
foreach (long id in objectIDList)
{
try
{
var r = await GetAsync($"part/{id}");
var r = await GetAsync($"part/{PartId}");
var c = r.ObjectResponse["data"].ToObject<Part>();
await RefreshAyaNovaPartFromQB(c);
r = await PutAsync($"part", Newtonsoft.Json.JsonConvert.SerializeObject(c));
}
catch { };
}
if (c == null) return;
}
public static async Task RefreshAyaNovaPartFromQB(Part c)
{
await PopulateQBItemCache();
IntegrationItem im = util.QBIntegration.Items.FirstOrDefault(z => z.ObjectId == c.Id && z.AType == AyaType.Part);
if (im == null) return;//this part is not linked
@@ -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);
//create a new row to add to the client cache datatable
if (!pricesOnly)
{
dr["FullName"] = sName;
dr["Type"] = qbitemtype.Inventory;
dr["Price"] = c.Retail;
dr["Cost"] = c.Cost;
dr["SalesDesc"] = sDescription;
//dr["ReorderPoint"] = 0;
dr["Modified"] = DateTime.Now;
dr["VendorID"] = c.WholeSalerId.ToString();
dr["SalesDesc"] = sDescription;
//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);
}
dr["Price"] = c.Retail;
dr["Cost"] = c.Cost;
dr["Modified"] = DateTime.Now;
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();