This commit is contained in:
@@ -3122,6 +3122,161 @@ namespace AyaNovaQBI
|
||||
|
||||
#endregion quickbooks Terms
|
||||
|
||||
|
||||
#region Change QB Item price
|
||||
|
||||
public static async Task ChangeQBItemPrice(string QBListID, decimal NewPrice)
|
||||
{
|
||||
|
||||
//Added: 18-Nov-2006 CASE 92
|
||||
//check if inventory item as this code only handles price changing for inventory
|
||||
//items in qb
|
||||
qbitemtype qtype = (qbitemtype)QBItems.Rows.Find(QBListID)["Type"];
|
||||
if (qtype != qbitemtype.Inventory)
|
||||
{
|
||||
MessageBox.Show("Only inventory items in QuickBooks can have their price changed\r\n" +
|
||||
"The current item is of type: " + qtype.ToString());
|
||||
return;
|
||||
}
|
||||
|
||||
//----Get the edit sequence-----
|
||||
string sEditSequence = GetInventoryItemEditSequence(QBListID);
|
||||
|
||||
//Connect to QB and fill
|
||||
// IY: Create the session manager object using QBFC
|
||||
QBSessionManager sessionManager = new QBSessionManager();
|
||||
|
||||
// IY: We want to know if we begun a session so we can end it if an
|
||||
// error happens
|
||||
bool booSessionBegun = false;
|
||||
|
||||
try
|
||||
{
|
||||
// IY: Get the RequestMsgSet based on the correct QB Version
|
||||
IMsgSetRequest requestSet = getLatestMsgSetRequest(sessionManager);
|
||||
|
||||
// IY: Initialize the message set request object
|
||||
requestSet.Attributes.OnError = ENRqOnError.roeStop;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//------change the price----
|
||||
// IY: Add the request to the message set request object
|
||||
IItemInventoryMod ItemQ = requestSet.AppendItemInventoryModRq();
|
||||
|
||||
ItemQ.ListID.SetValue(QBListID);
|
||||
ItemQ.EditSequence.SetValue(sEditSequence);
|
||||
ItemQ.SalesPrice.SetValue((double)NewPrice);
|
||||
|
||||
//This is intended to be called after already sucessfully connected
|
||||
//to get version info so no special safety checks here
|
||||
sessionManager.OpenConnection2("", "AyaNova QBI", ENConnectionType.ctLocalQBDLaunchUI);
|
||||
sessionManager.BeginSession("", ENOpenMode.omDontCare);
|
||||
booSessionBegun = true;
|
||||
|
||||
// IY: Do the request and get the response message set object
|
||||
IMsgSetResponse responseSet = sessionManager.DoRequests(requestSet);
|
||||
//-------------------------
|
||||
|
||||
|
||||
|
||||
//--------------
|
||||
// IY: Close the session and connection with QuickBooks
|
||||
sessionManager.EndSession();
|
||||
booSessionBegun = false;
|
||||
sessionManager.CloseConnection();
|
||||
QBItems.Rows.Find(QBListID)["Price"] = NewPrice;
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await IntegrationLog("ChangeQBItemPrice: Failed with exception:" + ex.Message);
|
||||
if (booSessionBegun)
|
||||
{
|
||||
sessionManager.EndSession();
|
||||
sessionManager.CloseConnection();
|
||||
}
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public static async Task<string> GetInventoryItemEditSequenceAsync(string QBListID)
|
||||
{
|
||||
//Connect to QB and fill
|
||||
// IY: Create the session manager object using QBFC
|
||||
QBSessionManager sessionManager = new QBSessionManager();
|
||||
|
||||
// IY: We want to know if we begun a session so we can end it if an
|
||||
// error happens
|
||||
bool booSessionBegun = false;
|
||||
|
||||
try
|
||||
{
|
||||
// IY: Get the RequestMsgSet based on the correct QB Version
|
||||
IMsgSetRequest requestSet = getLatestMsgSetRequest(sessionManager);
|
||||
|
||||
// IY: Initialize the message set request object
|
||||
requestSet.Attributes.OnError = ENRqOnError.roeStop;
|
||||
|
||||
//----Get the edit sequence-----
|
||||
// IY: Add the request to the message set request object
|
||||
IItemInventoryQuery iq = requestSet.AppendItemInventoryQueryRq();
|
||||
|
||||
//v8NOTE apparently this was changed in the api so if it fails need to dig in docs but it's a close match so suspect they just "improved" upon it with a breaking change
|
||||
//iq.ORListQuery.ListIDList.Add(QBListID);
|
||||
iq.ORListQueryWithOwnerIDAndClass.ListIDList.Add(QBListID);
|
||||
|
||||
|
||||
|
||||
|
||||
//This is intended to be called after already sucessfully connected
|
||||
//to get version info so no special safety checks here
|
||||
sessionManager.OpenConnection2("", "AyaNova QBI", ENConnectionType.ctLocalQBDLaunchUI);
|
||||
sessionManager.BeginSession("", ENOpenMode.omDontCare);
|
||||
booSessionBegun = true;
|
||||
|
||||
// IY: Do the request and get the response message set object
|
||||
IMsgSetResponse responseSet = sessionManager.DoRequests(requestSet);
|
||||
//-------------------------
|
||||
IResponse response = responseSet.ResponseList.GetAt(0);
|
||||
|
||||
//Added: 18-Nov-2006 nonzero status codes 500 and higher are serious errors, less than 500 could just mean no matching items in list
|
||||
if (response.StatusCode > 499)
|
||||
{
|
||||
throw new ApplicationException(response.StatusMessage + " Code: " + response.StatusCode);
|
||||
|
||||
}
|
||||
|
||||
|
||||
IItemInventoryRetList il = response.Detail as IItemInventoryRetList;
|
||||
IItemInventoryRet i = il.GetAt(0);
|
||||
string EditSequence = i.EditSequence.GetValue();
|
||||
|
||||
|
||||
//--------------
|
||||
// IY: Close the session and connection with QuickBooks
|
||||
sessionManager.EndSession();
|
||||
booSessionBegun = false;
|
||||
sessionManager.CloseConnection();
|
||||
return EditSequence;
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await IntegrationLog("PopulateQBItems: Failed with exception:" + ex.Message);
|
||||
if (booSessionBegun)
|
||||
{
|
||||
sessionManager.EndSession();
|
||||
sessionManager.CloseConnection();
|
||||
}
|
||||
throw;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#endregion QB api helper methods end
|
||||
|
||||
#region AyaNova cached lists
|
||||
@@ -4748,19 +4903,19 @@ namespace AyaNovaQBI
|
||||
public static async Task RefreshQBPartFromAyaNova(Part c)
|
||||
{
|
||||
|
||||
IntegrationMap im = QBI.Maps[c.ID];
|
||||
IntegrationItem im = QBIntegration.Items.FirstOrDefault(z => z.ObjectId == c.Id && z.AType == AyaType.Part);
|
||||
if (im == null) return;//this part is not linked
|
||||
|
||||
DataRow dr = _dtQBItems.Rows.Find(im.ForeignID);
|
||||
DataRow dr = _dtQBItems.Rows.Find(im.IntegrationItemId);
|
||||
if (dr == null) return; //QBListID not found in part list?
|
||||
|
||||
string sName = c.PartNumber;
|
||||
string sName = c.Name;
|
||||
if (sName.Length > 31)
|
||||
sName = sName.Substring(0, 31);
|
||||
|
||||
|
||||
|
||||
string sDescription = PartPickList.GetOnePart(c.ID)[0].DisplayName(AyaBizUtils.GlobalSettings.DefaultPartDisplayFormat);
|
||||
string sDescription = c.Description;// PartPickList.GetOnePart(c.ID)[0].DisplayName(AyaBizUtils.GlobalSettings.DefaultPartDisplayFormat);
|
||||
if (sDescription.Length > 4095)
|
||||
sDescription = sDescription.Substring(0, 4095);
|
||||
|
||||
@@ -4789,7 +4944,7 @@ namespace AyaNovaQBI
|
||||
// IY: Add the request to the message set request object
|
||||
IItemInventoryMod ca = requestSet.AppendItemInventoryModRq();
|
||||
//Get and set edit sequence
|
||||
string sEditSequence = GetInventoryItemEditSequence(im.ForeignID);
|
||||
string sEditSequence = await GetInventoryItemEditSequenceAsync(im.IntegrationItemId);
|
||||
|
||||
|
||||
|
||||
@@ -4802,10 +4957,10 @@ namespace AyaNovaQBI
|
||||
dr["SalesDesc"] = sDescription;
|
||||
//dr["ReorderPoint"] = 0;
|
||||
dr["Modified"] = DateTime.Now;
|
||||
dr["VendorID"] = c.WholesalerID.ToString();
|
||||
dr["VendorID"] = c.WholeSalerId.ToString();
|
||||
|
||||
//Set the QB item identification and edit sequence
|
||||
ca.ListID.SetValue(im.ForeignID);
|
||||
ca.ListID.SetValue(im.IntegrationItemId);
|
||||
ca.EditSequence.SetValue(sEditSequence);
|
||||
|
||||
|
||||
@@ -4878,13 +5033,16 @@ namespace AyaNovaQBI
|
||||
// _dtQBItems.Rows.Add(dr);
|
||||
|
||||
//Link
|
||||
// IntegrationMap m = QBI.Maps.Add(QBI);
|
||||
//m.Name = sName;
|
||||
// m.RootObjectID = c.ID;
|
||||
// m.RootObjectType = RootObjectTypes.Part;
|
||||
//// 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;
|
||||
//m.ForeignID = sNewID;
|
||||
QBI = (Integration)QBI.Save();
|
||||
await SaveIntegrationObject();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -4911,15 +5069,15 @@ namespace AyaNovaQBI
|
||||
/// Import a list of ayanova parts to QuickBooks
|
||||
/// </summary>
|
||||
/// <param name="objectIDList"></param>
|
||||
public static void ImportAyaPart(List<Guid> objectIDList)
|
||||
public static async Task ImportAyaPart(List<long> objectIDList)
|
||||
{
|
||||
ArrayList alErrors = new ArrayList();
|
||||
foreach (Guid g in objectIDList)
|
||||
foreach (long ayid in objectIDList)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
ImportAyaPart(g, alErrors);
|
||||
await ImportAyaPart(ayid, alErrors);
|
||||
|
||||
}
|
||||
catch { };
|
||||
@@ -4952,34 +5110,32 @@ namespace AyaNovaQBI
|
||||
/// </summary>
|
||||
/// <param name="VendorID"></param>
|
||||
/// <param name="alErrors">An arraylist to hold strings indicating errors on fail</param>
|
||||
public static void ImportAyaPart(Guid PartID, ArrayList alErrors)
|
||||
public static async Task ImportAyaPart(long PartID, ArrayList alErrors)
|
||||
{
|
||||
|
||||
if (!Part.Exists(PartID, ""))
|
||||
if (!AyaPartList.Any(z => z.Id == PartID))
|
||||
{
|
||||
alErrors.Add("ImportAyaPart: Part not found in AyaNova (deleted recently?) (" + PartID.ToString() + ")");
|
||||
return;
|
||||
|
||||
}
|
||||
Part c = Part.GetItem(PartID);
|
||||
var r = await GetAsync($"part/{PartID}");
|
||||
var c = r.ObjectResponse["data"].ToObject<Part>();
|
||||
|
||||
|
||||
|
||||
|
||||
string sName = c.PartNumber;
|
||||
string sName = c.Name;
|
||||
if (sName.Length > 31)
|
||||
{
|
||||
sName = sName.Substring(0, 31);
|
||||
alErrors.Add("ImportAyaPart: AyaNova part number exceeds 31 character limit for QuickBooks\r\n" +
|
||||
"Number: " + c.PartNumber + "\r\n" +
|
||||
alErrors.Add("ImportAyaPart: AyaNova part name exceeds 31 character limit for QuickBooks\r\n" +
|
||||
"Name: " + c.Name + "\r\n" +
|
||||
"will be imported as: " + sName);
|
||||
|
||||
}
|
||||
string sDescription = PartPickList.GetOnePart(c.ID)[0].DisplayName(AyaBizUtils.GlobalSettings.DefaultPartDisplayFormat);
|
||||
string sDescription = c.Description;//PartPickList.GetOnePart(c.ID)[0].DisplayName(AyaBizUtils.GlobalSettings.DefaultPartDisplayFormat);
|
||||
if (sDescription.Length > 4095)
|
||||
{
|
||||
sDescription = sDescription.Substring(0, 4095);
|
||||
alErrors.Add("ImportAyaPart: AyaNova part full display name exceeds 4095 character limit for sales description in QuickBooks\r\n" +
|
||||
alErrors.Add("ImportAyaPart: AyaNova part Description exceeds 4095 character limit for sales description in QuickBooks\r\n" +
|
||||
"will be imported as: " + sDescription);
|
||||
|
||||
}
|
||||
@@ -5016,7 +5172,7 @@ namespace AyaNovaQBI
|
||||
dr["SalesDesc"] = sDescription;
|
||||
dr["ReorderPoint"] = 0;
|
||||
dr["Modified"] = DateTime.MinValue;
|
||||
dr["VendorID"] = c.WholesalerID.ToString();
|
||||
dr["VendorID"] = c.WholeSalerId.ToString();
|
||||
|
||||
//------------------------
|
||||
//Set the qb item values
|
||||
@@ -5029,6 +5185,8 @@ namespace AyaNovaQBI
|
||||
|
||||
ca.SalesPrice.SetValue((double)c.Retail);
|
||||
ca.PurchaseCost.SetValue((double)c.Cost);
|
||||
|
||||
HERE TODO NEXT
|
||||
if (AyaBizUtils.GlobalSettings.UseInventory)
|
||||
{
|
||||
PartInventoryValuesFetcher pbw = PartInventoryValuesFetcher.GetItem(c.ID);
|
||||
|
||||
Reference in New Issue
Block a user