private IORItemRet QueryItem(QBSessionManager session, string itemFullName) { // query for the customer information IMsgSetRequest requestMsgSet = getLatestMsgSetRequest(session); requestMsgSet.Attributes.OnError = ENRqOnError.roeContinue; IItemQuery pItemQuery = requestMsgSet.AppendItemQueryRq(); pItemQuery.ORListQuery.ListFilter.ORNameFilter.NameFilter.Name.SetValue(itemFullName); pItemQuery.ORListQuery.ListFilter.ORNameFilter.NameFilter.MatchCriterion.SetValue(ENMatchCriterion.mcContains); pItemQuery.OwnerIDList.Add("0"); IMsgSetResponse responseMsgSet = session.DoRequests(requestMsgSet); // Uncomment the following to see the request and response XML for debugging //string rq = requestMsgSet.ToXMLString(); //string rs = responseMsgSet.ToXMLString(); //m_application.Messenger.AddInfo("Item Resquest: " + rq); //m_application.Messenger.AddInfo("Item Response: " + rs); // Interpret the response IResponseList rsList = responseMsgSet.ResponseList; // Retrieve the one response corresponding to our single request IResponse response = rsList.GetAt(0); if (response.StatusCode != 0) { string msg = ""; if (response.StatusCode == 1) //No record found { msg = "Item not found: " + itemFullName; } else { msg = "Error getting item. Status: " + response.StatusCode.ToString() + ", Message: " + response.StatusMessage; } throw new Exception(msg); } // We have one or more customers (expect one) IORItemRetList orItemRetList = response.Detail as IORItemRetList; int itemCount = orItemRetList.Count; if (itemCount > 1) { m_application.Messenger.AddWarning("Multiple items found: " + itemFullName); } return(orItemRetList.GetAt(0)); }
private void initializeObjects() { readItem = new QBReadItem(); itemQuery = apiQBSession.getRequestMsgSet().AppendItemQueryRq(); itemQuery.IncludeRetElementList.Add("ListID"); itemQuery.IncludeRetElementList.Add("Name"); itemQuery.IncludeRetElementList.Add("FullName"); }
/// <inheritdoc/> public async Task <QBItemCollection <T> > GetInventory <T>() { await OpenConnection(); IMsgSetRequest request = CreateRequest(); IItemQuery itemRequest = request.AppendItemQueryRq(); IMsgSetResponse queryResponse = await MakeRequestAsync(request).ConfigureAwait(false); CloseConnection(); return(ProcessQueryAsXML <QBItemCollection <T> >(queryResponse, "ItemQueryRs")); }
/// <summary> /// Creates the request to count the number of items in the response list. /// </summary> /// <param name="requestType"></param> /// <returns></returns> private async Task <int> GetCount(string requestType) { IMsgSetRequest request = CreateRequest(); switch (requestType) { case "ItemQueryRq": IItemQuery itemQuery = request.AppendItemQueryRq(); itemQuery.metaData.SetValue(ENmetaData.mdMetaDataOnly); break; } IMsgSetResponse queryResponse = await MakeRequestAsync(request).ConfigureAwait(false); return(ParseRsForCount(queryResponse)); }
private IMsgSetRequest buildItemQueryRq(string fullName) { IMsgSetRequest requestMsgSet = sessionManager.getMsgSetRequest(); requestMsgSet.Attributes.OnError = ENRqOnError.roeContinue; if (fullName != null) { IItemQuery itemQuery = requestMsgSet.AppendItemQueryRq(); try { itemQuery.ORListQuery.ListFilter.ORNameFilter.NameFilter.MatchCriterion.SetValue(ENMatchCriterion.mcEndsWith); itemQuery.ORListQuery.ListFilter.ORNameFilter.NameFilter.Name.SetValue(fullName); } catch (Exception ex) { consoleOutput.AppendText("\r\n" + ex); } } //Only need FullName return(requestMsgSet); }
/* private void loadItems() * { * string request = "ItemQueryRq"; * connectToQB(); * int count = getCount(request); * IMsgSetResponse responseMsgSet = processRequestFromQB(buildItemQueryRq(new string[] { "FullName" }, null)); * string[,] retVal = parseItemQueryRs(responseMsgSet, count, 1); * disconnectFromQB(); * string[] itemList = getItemFullNames(retVal); * fillComboBox(comboBox_Item1, itemList); * fillComboBox(comboBox_Item2, itemList); * fillComboBox(comboBox_Item3, itemList); * fillComboBox(comboBox_Item4, itemList); * fillComboBox(comboBox_Item5, itemList); * } * * private string[] getItemFullNames(string[,] retVal) * { * //retVal[countOfRows, arraySize] * //arraySize is 3 for FullName, Desc, Price but in this case 1 for FullName only * int countOfRows = retVal.GetUpperBound(0); * string[] itemList = new string[countOfRows]; * for (int i = 0; i < countOfRows; i++) * { * itemList[i] = retVal[i, 0]; * } * return itemList; * } * * private void loadTerms() * { * string request = "TermsQueryRq"; * connectToQB(); * int count = getCount(request); * IMsgSetResponse responseMsgSet = processRequestFromQB(buildTermsQueryRq()); * string[] termsList = parseTermsQueryRs(responseMsgSet, count); * disconnectFromQB(); * fillComboBox(this.comboBox_Terms, termsList); * } * * private void loadSalesTaxCodes() * { * string request = "SalesTaxCodeQueryRq"; * connectToQB(); * int count = getCount(request); * IMsgSetResponse responseMsgSet = processRequestFromQB(buildSalesTaxCodeQueryRq()); * string[] salesTaxCodeList = parseSalesTaxCodeQueryRs(responseMsgSet, count); * disconnectFromQB(); * fillComboBox(this.comboBox_Tax1, salesTaxCodeList); * fillComboBox(this.comboBox_Tax2, salesTaxCodeList); * fillComboBox(this.comboBox_Tax3, salesTaxCodeList); * fillComboBox(this.comboBox_Tax4, salesTaxCodeList); * fillComboBox(this.comboBox_Tax5, salesTaxCodeList); * } * * private void loadCustomerMsg() * { * string request = "CustomerMsgQueryRq"; * connectToQB(); * int count = getCount(request); * IMsgSetResponse responseMsgSet = processRequestFromQB(buildCustomerMsgQueryRq(new string[] { "Name" }, null)); * string[] customerMsgList = parseCustomerMsgQueryRs(responseMsgSet, count); * disconnectFromQB(); * fillComboBox(comboBox_CustomerMessage, customerMsgList); * } * * private string getBillShipTo(string customerName, string billOrShip) * { * connectToQB(); * IMsgSetResponse responseMsgSet = processRequestFromQB(buildCustomerQueryRq(new string[] { billOrShip }, customerName)); * string[] billShipTo = parseCustomerQueryRs(responseMsgSet, 1); * if (billShipTo[0] == null) billShipTo[0] = ""; * disconnectFromQB(); * return billShipTo[0]; * } * * private string getCurrencyCode(string customerName) * { * connectToQB(); * IMsgSetResponse responseMsgSet = processRequestFromQB(buildCustomerQueryRq(new string[] { "CurrencyRef" }, customerName)); * string[] currencyCode = parseCustomerQueryRs(responseMsgSet, 1); * disconnectFromQB(); * return currencyCode[0]; * } * * private string getExchangeRate(string currencyName) * { * connectToQB(); * IMsgSetResponse responseMsgSet = processRequestFromQB(buildCurrencyQueryRq(currencyName)); * string[] exrate = parseCurrencyQueryRs(responseMsgSet, 1); * disconnectFromQB(); * if (exrate[0] == null || exrate[0] == "") exrate[0] = "1.0"; * return exrate[0]; * } * * // REQUEST BUILDING * private IMsgSetRequest buildPreferencesQueryRq(string[] includeRetElement, string fullName) * { * IMsgSetRequest requestMsgSet = sessionManager.getMsgSetRequest(); * requestMsgSet.Attributes.OnError = ENRqOnError.roeContinue; * IPreferencesQuery prefQuery = requestMsgSet.AppendPreferencesQueryRq(); * for (int x = 0; x < includeRetElement.Length; x++) * { * prefQuery.IncludeRetElementList.Add(includeRetElement[x]); * } * return requestMsgSet; * } */ private IMsgSetRequest buildDataCountQuery(string request) { IMsgSetRequest requestMsgSet = sessionManager.getMsgSetRequest(); requestMsgSet.Attributes.OnError = ENRqOnError.roeContinue; switch (request) { case "CustomerQueryRq": ICustomerQuery custQuery = requestMsgSet.AppendCustomerQueryRq(); custQuery.metaData.SetValue(ENmetaData.mdMetaDataOnly); break; case "ItemQueryRq": IItemQuery itemQuery = requestMsgSet.AppendItemQueryRq(); itemQuery.metaData.SetValue(ENmetaData.mdMetaDataOnly); break; case "TermsQueryRq": ITermsQuery termsQuery = requestMsgSet.AppendTermsQueryRq(); termsQuery.metaData.SetValue(ENmetaData.mdMetaDataOnly); break; case "SalesTaxCodeQueryRq": ISalesTaxCodeQuery salesTaxQuery = requestMsgSet.AppendSalesTaxCodeQueryRq(); salesTaxQuery.metaData.SetValue(ENmetaData.mdMetaDataOnly); break; case "CustomerMsgQueryRq": ICustomerMsgQuery custMsgQuery = requestMsgSet.AppendCustomerMsgQueryRq(); custMsgQuery.metaData.SetValue(ENmetaData.mdMetaDataOnly); break; default: break; } return(requestMsgSet); }
public static void DoQbXml() { bool sessionBegun = false; bool connectionOpen = false; QBSessionManager sessionManager = null; sessionManager = new QBSessionManager(); //Connect to QuickBooks and begin a session sessionManager.OpenConnection("", "GenerateInvoicePDFs"); connectionOpen = true; sessionManager.BeginSession("", ENOpenMode.omDontCare); sessionBegun = true; //Create the message set request object to hold our request IMsgSetRequest requestMsgSet = sessionManager.CreateMsgSetRequest("US", 13, 0); requestMsgSet.Attributes.OnError = ENRqOnError.roeContinue; IInvoiceQuery invoiceQueryRq = requestMsgSet.AppendInvoiceQueryRq(); invoiceQueryRq.IncludeLineItems.SetValue(true); //Send the request and get the response from QuickBooks IMsgSetResponse responseMsgSet = sessionManager.DoRequests(requestMsgSet); IResponse response = responseMsgSet.ResponseList.GetAt(0); IInvoiceRetList invoiceRetList = (IInvoiceRetList)response.Detail; var invoices = new List <Invoice>(); if (invoiceRetList != null) { for (int i = 0; i < invoiceRetList.Count; i++) { IInvoiceRet invoiceRet = invoiceRetList.GetAt(i); var invoice = new Invoice { QuickBooksID = invoiceRet.TxnID.GetValue(), EditSequence = invoiceRet.EditSequence.GetValue(), InvoiceNumber = invoiceRet.RefNumber?.GetValue(), Memo = invoiceRet.Memo?.GetValue(), JobNumber = invoiceRet.Other?.GetValue() }; Console.WriteLine($"INv:{invoice.InvoiceNumber}, EditSequence: {invoice.JobNumber}"); requestMsgSet.ClearRequests(); ICustomerQuery customerQueryRq = requestMsgSet.AppendCustomerQueryRq(); customerQueryRq.ORCustomerListQuery.ListIDList.Add(invoiceRet.CustomerRef.ListID.GetValue()); //Send the request and get the response from QuickBooks responseMsgSet = sessionManager.DoRequests(requestMsgSet); response = responseMsgSet.ResponseList.GetAt(0); ICustomerRetList customerRetList = (ICustomerRetList)response.Detail; ICustomerRet customerRet = customerRetList.GetAt(0); if (i > 200) { return; } invoice.Customer = new Customer { Name = customerRet.Name.GetValue(), QuickBooksID = customerRet.ListID.GetValue(), EditSequence = customerRet.EditSequence.GetValue() }; if (invoiceRet.ORInvoiceLineRetList != null) { for (int j = 0; j < invoiceRet.ORInvoiceLineRetList.Count; j++) { IORInvoiceLineRet ORInvoiceLineRet = invoiceRet.ORInvoiceLineRetList.GetAt(j); try { var invoiceItem = new InvoiceItem { Amount = ORInvoiceLineRet.InvoiceLineRet.Amount.GetValue(), QuickBooksID = ORInvoiceLineRet.InvoiceLineRet.TxnLineID.GetValue() }; requestMsgSet.ClearRequests(); IItemQuery itemQueryRq = requestMsgSet.AppendItemQueryRq(); itemQueryRq.ORListQuery.ListIDList.Add(ORInvoiceLineRet.InvoiceLineRet.ItemRef.ListID.GetValue()); //Send the request and get the response from QuickBooks responseMsgSet = sessionManager.DoRequests(requestMsgSet); response = responseMsgSet.ResponseList.GetAt(0); IORItemRetList itemRetList = (IORItemRetList)response.Detail; IORItemRet itemRet = itemRetList.GetAt(0); if (itemRet.ItemInventoryRet != null) { IItemInventoryRet itemInventoryRet = itemRet.ItemInventoryRet; var item = new Item { Name = itemInventoryRet.Name.GetValue(), Description = itemInventoryRet.SalesDesc.GetValue(), Rate = itemInventoryRet.SalesPrice.GetValue(), //ItemType = ItemType.Inventory, QuickBooksID = itemInventoryRet.ListID.GetValue(), EditSequence = itemInventoryRet.EditSequence.GetValue() }; invoiceItem.Item = item; } else if (itemRet.ItemServiceRet != null) { IItemServiceRet itemServiceRet = itemRet.ItemServiceRet; var item = new Item { Name = itemServiceRet.Name.GetValue(), Description = itemServiceRet.ORSalesPurchase.SalesOrPurchase.Desc.GetValue(), Rate = itemServiceRet.ORSalesPurchase.SalesOrPurchase.ORPrice.Price.GetValue(), //ItemType = ItemType.Service, QuickBooksID = itemServiceRet.ListID.GetValue(), EditSequence = itemServiceRet.EditSequence.GetValue() }; invoiceItem.Item = item; } invoice.InvoiceItems.Add(invoiceItem); } catch (Exception ex) { Console.WriteLine(invoice.Customer.Name); throw; } } } invoices.Add(invoice); } } }
public ItemService(IItemCommand command, IItemQuery query, IBus bus) { cmd = command; qry = query; this.bus = bus; }
public ItemAppService(IItemQuery itemQuery, IItemRepository itemRepository) { _itemQuery = itemQuery; _itemRepository = itemRepository; }
public ItemsController(IItemQuery itemQuery, IItemsCommand itemsCommand) { _itemQuery = itemQuery; _itemsCommand = itemsCommand; }
public ItemService(IItemQuery itemQuery, IItemCommands itemCommands) { _iq = itemQuery; _ic = itemCommands; }
public List <InventoryItem> getAllItems() { try { //Item Request IMsgSetRequest itemRequestset = _MySessionManager.CreateMsgSetRequest("US", 13, 0); IItemQuery itemQuery = itemRequestset.AppendItemQueryRq(); itemQuery.OwnerIDList.Add("0"); ////Get item codes from sales order and add to item request //for (int i = 0; i < SalesOrderItems.Count; ++i) //{ // IORSalesOrderLineRet SalesOrderItem = SalesOrderItems.GetAt(i); // itemQuery.ORListQuery.FullNameList.Add(SalesOrderItem.SalesOrderLineRet.ItemRef.FullName.GetValue()); //} //itemQuery.ORListQuery.FullNameList.Add("17531"); //itemQuery.ORListQuery.FullNameList.Add("17534"); //itemQuery.ORListQuery.FullNameList.Add("17535"); //itemQuery.ORListQuery.FullNameList.Add("17536"); //itemQuery.ORListQuery.FullNameList.Add("17537"); //itemQuery.ORListQuery.FullNameList.Add("17538"); //itemQuery.ORListQuery.FullNameList.Add("62231"); //itemQuery.ORListQuery.FullNameList.Add("12061"); IMsgSetResponse responseItemRq = _MySessionManager.DoRequests(itemRequestset); IResponseList itemResponseList = responseItemRq.ResponseList; IResponse itemResponse = itemResponseList.GetAt(0); ENResponseType responseType = (ENResponseType)itemResponse.Type.GetValue(); IORItemRetList QBItemList = (IORItemRetList)itemResponse.Detail; for (int i = 0; i <= QBItemList.Count - 1; i++) { InventoryItem item = new InventoryItem(); IDataExtRetList customFieldsList; if (QBItemList.GetAt(i).ItemNonInventoryRet != null) { IItemNonInventoryRet inventoryItem = QBItemList.GetAt(i).ItemNonInventoryRet; customFieldsList = QBItemList.GetAt(i).ItemNonInventoryRet.DataExtRetList; item.ListID = inventoryItem.ListID != null?inventoryItem.ListID.GetValue() : ""; item.ItemCode = inventoryItem.Name != null?inventoryItem.Name.GetValue() : ""; item.Description = inventoryItem.FullName.GetValue() != null?inventoryItem.FullName.GetValue() : ""; item.MPN = inventoryItem.ManufacturerPartNumber != null?inventoryItem.ManufacturerPartNumber.GetValue() : ""; } else if (QBItemList.GetAt(i).ItemInventoryRet != null) { IItemInventoryRet inventoryItem = QBItemList.GetAt(i).ItemInventoryRet; customFieldsList = QBItemList.GetAt(i).ItemInventoryRet.DataExtRetList; item.ListID = inventoryItem.ListID != null?inventoryItem.ListID.GetValue() : ""; item.ItemCode = inventoryItem.Name != null?inventoryItem.Name.GetValue() : ""; item.Description = inventoryItem.SalesDesc != null?inventoryItem.SalesDesc.GetValue() : ""; item.MPN = inventoryItem.ManufacturerPartNumber != null?inventoryItem.ManufacturerPartNumber.GetValue() : ""; item.Price = inventoryItem.SalesPrice.GetValue(); } else if (QBItemList.GetAt(i).ItemInventoryAssemblyRet != null) { IItemInventoryAssemblyRet inventoryItem = QBItemList.GetAt(i).ItemInventoryAssemblyRet; customFieldsList = QBItemList.GetAt(i).ItemInventoryAssemblyRet.DataExtRetList; item.ListID = inventoryItem.ListID != null?inventoryItem.ListID.GetValue() : ""; item.ItemCode = inventoryItem.Name != null?inventoryItem.Name.GetValue() : ""; item.Description = inventoryItem.SalesDesc.GetValue() != null?inventoryItem.SalesDesc.GetValue() : ""; item.MPN = inventoryItem.ManufacturerPartNumber != null?inventoryItem.ManufacturerPartNumber.GetValue() : ""; } else { customFieldsList = null; } //get item external data (custom fields) if (customFieldsList != null) { for (int iCustomField = 0; iCustomField <= customFieldsList.Count - 1; iCustomField++) { string fieldName = customFieldsList.GetAt(iCustomField).DataExtName.GetValue(); string fieldValue = customFieldsList.GetAt(iCustomField).DataExtValue.GetValue(); if (fieldName == "Inner") { item.Inner = fieldValue; } if (fieldName == "Case") { item.Case = fieldValue; } if (fieldName == "Price2") { item.Price2 = Convert.ToDouble(fieldValue); } if (fieldName == "Volume") { item.Volume = fieldValue; } if (fieldName == "Price3") { item.Price3 = Convert.ToDouble(fieldValue); } } } if (item.ItemCode != null) { _inventoryItems.Add(item); } } return(_inventoryItems); } catch (Exception) { throw new Exception("Failed to read Items from QuickBooks."); } }
public ProductByIdQuerySpec([NotNull] IItemQuery <Guid, TResponse> queryInput) { ApplyIncludeList(queryInput.Includes); _id = queryInput.Id; }
public IList <Invoice> GetInvoiceDetail() { bool sessionBegun = false; QBSessionManager sessionManager = null; var invoices = new List <Invoice>(); sessionManager = new QBSessionManager(); IMsgSetRequest requestMsgSet = null; var fromDate = new DateTime(2018, 1, 5); var toDate = new DateTime(2018, 1, 5); try { //Connect to QuickBooks and begin a session sessionManager.OpenConnection("", "GenerateInvoicePDFs"); //connectionOpen = true; sessionManager.BeginSession("", ENOpenMode.omDontCare); sessionBegun = true; //Create the message set request object to hold our request requestMsgSet = sessionManager.CreateMsgSetRequest("US", 13, 0); requestMsgSet.Attributes.OnError = ENRqOnError.roeContinue; IInvoiceQuery invoiceQueryRq = requestMsgSet.AppendInvoiceQueryRq(); // all invoices modified in the month of August 2016 // get all invoices for the month of august 2016 invoiceQueryRq.ORInvoiceQuery.InvoiceFilter.ORDateRangeFilter.TxnDateRangeFilter.ORTxnDateRangeFilter.TxnDateFilter.FromTxnDate.SetValue(fromDate); invoiceQueryRq.ORInvoiceQuery.InvoiceFilter.ORDateRangeFilter.TxnDateRangeFilter.ORTxnDateRangeFilter.TxnDateFilter.ToTxnDate.SetValue(toDate); // invoiceQueryRq.ORInvoiceQuery.InvoiceFilter.ORDateRangeFilter.ModifiedDateRangeFilter.FromModifiedDate.SetValue(new DateTime(2017, 12, 1), true); // invoiceQueryRq.ORInvoiceQuery.InvoiceFilter.ORDateRangeFilter.ModifiedDateRangeFilter.ToModifiedDate.SetValue(new DateTime(2017, 12, 31), true); invoiceQueryRq.IncludeLineItems.SetValue(true); //Send the request and get the response from QuickBooks IMsgSetResponse responseMsgSet = sessionManager.DoRequests(requestMsgSet); IResponse response = responseMsgSet.ResponseList.GetAt(0); IInvoiceRetList invoiceRetList = (IInvoiceRetList)response.Detail; Console.WriteLine($"Invoices found: {invoiceRetList.Count}"); if (invoiceRetList != null) { for (int i = 0; i < invoiceRetList.Count; i++) { IInvoiceRet invoiceRet = invoiceRetList.GetAt(i); var invoice = new Invoice { QuickBooksID = invoiceRet.TxnID.GetValue(), EditSequence = invoiceRet.EditSequence.GetValue(), InvoiceNumber = invoiceRet.RefNumber?.GetValue(), Memo = invoiceRet.Memo?.GetValue(), JobNumber = invoiceRet.Other?.GetValue(), CustomerName = invoiceRet.CustomerRef.FullName?.GetValue() }; var customerListId = invoiceRet.CustomerRef?.ListID?.GetValue(); if (customerListId != null) { // Console.WriteLine($"{i}\tInv:{invoice.InvoiceNumber}, Job: {invoice.JobNumber}, Name:{invoice.CustomerName}"); requestMsgSet.ClearRequests(); ICustomerQuery customerQueryRq = requestMsgSet.AppendCustomerQueryRq(); customerQueryRq.ORCustomerListQuery.ListIDList.Add(customerListId); //Send the request and get the response from QuickBooks responseMsgSet = sessionManager.DoRequests(requestMsgSet); response = responseMsgSet.ResponseList.GetAt(0); ICustomerRetList customerRetList = (ICustomerRetList)response.Detail; ICustomerRet customerRet = customerRetList.GetAt(0); invoice.Customer = new Customer { Name = customerRet.Name?.GetValue(), QuickBooksID = customerRet.ListID?.GetValue(), EditSequence = customerRet.EditSequence?.GetValue(), FullName = customerRet.FullName?.GetValue(), CompanyName = customerRet.CompanyName?.GetValue() }; // Console.WriteLine($"{i}\t{invoice.Customer.Name}\t{invoice.Customer.FullName}\t{invoice.Customer.CompanyName}"); // Console.WriteLine($"{i}\t\tInvoice detail starts"); if (invoiceRet.ORInvoiceLineRetList != null) { Console.WriteLine($"InvoiceList Count: {invoiceRet.ORInvoiceLineRetList.Count}"); for (int j = 0; j < invoiceRet.ORInvoiceLineRetList.Count; j++) { IORInvoiceLineRet orInvoiceLineRet = invoiceRet.ORInvoiceLineRetList.GetAt(j); if (orInvoiceLineRet != null && orInvoiceLineRet.InvoiceLineRet != null) { var invoiceItem = new InvoiceItem { Amount = orInvoiceLineRet.InvoiceLineRet.Amount?.GetValue(), QuickBooksID = orInvoiceLineRet.InvoiceLineRet.TxnLineID?.GetValue(), Description = orInvoiceLineRet.InvoiceLineRet.Desc?.GetValue() }; Console.WriteLine($"j: {j}\tDescription: {invoiceItem.Description}"); requestMsgSet.ClearRequests(); IItemQuery itemQueryRq = requestMsgSet.AppendItemQueryRq(); itemQueryRq.ORListQuery.ListIDList.Add(orInvoiceLineRet.InvoiceLineRet.ItemRef?.ListID?.GetValue()); //Send the request and get the response from QuickBooks responseMsgSet = sessionManager.DoRequests(requestMsgSet); response = responseMsgSet.ResponseList.GetAt(0); IORItemRetList itemRetList = (IORItemRetList)response.Detail; // Console.WriteLine($"ItemRetList.Count: {itemRetList.Count}"); IORItemRet itemRet = itemRetList.GetAt(0); WalkItemServiceRet(itemRet.ItemServiceRet); var ortype = itemRet.ortype; if (itemRet.ItemInventoryRet != null) { IItemInventoryRet itemInventoryRet = itemRet.ItemInventoryRet; var item = new Item { Name = itemInventoryRet.Name?.GetValue(), Description = itemInventoryRet.SalesDesc?.GetValue(), Rate = itemInventoryRet.SalesPrice?.GetValue(), ItemType = ortype.ToString(), QuickBooksID = itemInventoryRet.ListID?.GetValue(), EditSequence = itemInventoryRet.EditSequence?.GetValue() }; if (string.IsNullOrEmpty(item.Name)) { item.Name = itemInventoryRet.FullName?.GetValue(); } invoiceItem.Item = item; } else if (itemRet.ItemServiceRet != null) { IItemServiceRet itemServiceRet = itemRet.ItemServiceRet; var item = new Item { Name = itemServiceRet.Name.GetValue(), Description = itemServiceRet.ORSalesPurchase.SalesOrPurchase.Desc?.GetValue(), Rate = itemServiceRet.ORSalesPurchase.SalesOrPurchase.ORPrice.Price?.GetValue(), //ItemType = ItemType.Service, ItemType = ortype.ToString(), QuickBooksID = itemServiceRet.ListID?.GetValue(), EditSequence = itemServiceRet.EditSequence?.GetValue(), // FullName = itemServiceRet.ToString() }; if (string.IsNullOrEmpty(item.Name)) { item.Name = itemServiceRet.FullName?.GetValue(); } invoiceItem.Item = item; } else if (itemRet.ItemOtherChargeRet != null) { IItemOtherChargeRet itemOtherChargeRet = itemRet.ItemOtherChargeRet; var item = new Item { Name = itemOtherChargeRet.Name?.GetValue(), Description = itemOtherChargeRet.ORSalesPurchase.SalesOrPurchase.Desc?.GetValue(), Rate = itemOtherChargeRet.ORSalesPurchase.SalesOrPurchase.ORPrice.Price?.GetValue(), ItemType = ortype.ToString() }; if (string.IsNullOrEmpty(item.Name)) { item.Name = itemOtherChargeRet.FullName?.GetValue(); } invoiceItem.Item = item; } else if (itemRet.ItemNonInventoryRet != null) { IItemNonInventoryRet itemNonInventoryRet = itemRet.ItemNonInventoryRet; var item = new Item { Name = itemNonInventoryRet.Name?.GetValue(), Description = itemNonInventoryRet.ORSalesPurchase.SalesOrPurchase.Desc?.GetValue(), ItemType = ortype.ToString() }; if (string.IsNullOrEmpty(item.Name)) { item.Name = itemNonInventoryRet.FullName?.GetValue(); } invoiceItem.Item = item; } Console.WriteLine($"{invoiceItem.Item.FullName}\t{invoice.InvoiceNumber}\t{invoiceItem.Amount}\t{invoiceItem.Item.Description}"); invoice.InvoiceItems.Add(invoiceItem); } } } } invoices.Add(invoice); } } if (requestMsgSet != null) { Marshal.FinalReleaseComObject(requestMsgSet); } sessionManager.EndSession(); sessionBegun = false; sessionManager.CloseConnection(); } catch (Exception ex) { Console.WriteLine(ex.Message.ToString() + "\nStack Trace: \n" + ex.StackTrace + "\nExiting the application"); if (requestMsgSet != null) { Marshal.FinalReleaseComObject(requestMsgSet); } if (sessionBegun) { sessionManager.EndSession(); sessionManager.CloseConnection(); } } return(invoices); }
public ItemCrud(IItemQuery itemQuery, IItemCommand itemCommand, IMapper mapper) { this.itemQuery = itemQuery; this.itemCommand = itemCommand; this.mapper = mapper; }
private void InputItem_Load(object sender, System.EventArgs e) { // 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; // IY: Add the request to the message set request object IItemQuery ItemQ = requestSet.AppendItemQueryRq(); // IY: Optionally, you can put filter on it. // ItemQ.ORListQuery.ListFilter.MaxReturned.SetValue(30); // IY: Open the connection and begin a session to QuickBooks sessionManager.OpenConnection("", "IDN InvoiceAdd C# sample"); sessionManager.BeginSession("", ENOpenMode.omDontCare); booSessionBegun = true; // IY: Do the request and get the response message set object IMsgSetResponse responseSet = sessionManager.DoRequests(requestSet); // Uncomment the following to view and save the request and response XML //string requestXML = requestSet.ToXMLString(); //MessageBox.Show(requestXML); // SaveXML(requestXML); //string responseXML = responseSet.ToXMLString(); //MessageBox.Show(responseXML); // SaveXML(responseXML); IResponse response = responseSet.ResponseList.GetAt(0); //int statusCode = response.StatusCode; //string statusMessage = response.StatusMessage; //string statusSeverity = response.StatusSeverity; //MessageBox.Show("Status:\nCode = " + statusCode + "\nMessage = " + statusMessage + "\nSeverity = " + statusSeverity); IORItemRetList orItemRetList = response.Detail as IORItemRetList; if (!(orItemRetList.Count == 0)) { for (int ndx = 0; ndx <= (orItemRetList.Count - 1); ndx++) { IORItemRet orItemRet = orItemRetList.GetAt(ndx); // IY: The ortype property returns an enum // of the elements that can be contained in the OR object switch (orItemRet.ortype) { case ENORItemRet.orirItemServiceRet: { // orir prefix comes from OR + Item + Ret IItemServiceRet ItemServiceRet = orItemRet.ItemServiceRet; isTaxable = ItemServiceRet?.SalesTaxCodeRef?.FullName?.GetValue(); SetTaxableDefaultIfEmpty(ref isTaxable); cmboBx2_Item.Items.Add(ItemServiceRet?.FullName?.GetValue() + ":" + isTaxable); } break; case ENORItemRet.orirItemInventoryRet: { IItemInventoryRet ItemInventoryRet = orItemRet.ItemInventoryRet; isTaxable = ItemInventoryRet?.SalesTaxCodeRef?.FullName?.GetValue(); SetTaxableDefaultIfEmpty(ref isTaxable); cmboBx2_Item.Items.Add(ItemInventoryRet?.FullName?.GetValue() + ":" + isTaxable); } break; case ENORItemRet.orirItemNonInventoryRet: { IItemNonInventoryRet ItemNonInventoryRet = orItemRet.ItemNonInventoryRet; isTaxable = ItemNonInventoryRet?.SalesTaxCodeRef?.FullName?.GetValue(); SetTaxableDefaultIfEmpty(ref isTaxable); cmboBx2_Item.Items.Add(ItemNonInventoryRet?.FullName?.GetValue() + ":" + isTaxable); } break; } } // for loop } // if // IY: Close the session and connection with QuickBooks sessionManager.EndSession(); booSessionBegun = false; sessionManager.CloseConnection(); } catch (Exception ex) { MessageBox.Show(ex.Message.ToString() + "\nStack Trace: \n" + ex.StackTrace + "\nExiting the application"); if (booSessionBegun) { sessionManager.EndSession(); sessionManager.CloseConnection(); } } }
public List <InventoryItem> UpdateItemUPCAndListID(List <InventoryItem> inventoryItems) { //Item Request IMsgSetRequest itemRequestset = _MySessionManager.CreateMsgSetRequest("US", 13, 0); IItemQuery itemQuery = itemRequestset.AppendItemQueryRq(); itemQuery.OwnerIDList.Add("0"); //Get item codes from sales order and add to item request foreach (InventoryItem item in inventoryItems) { itemQuery.ORListQuery.FullNameList.Add(item.ItemCode); } IMsgSetResponse responseItemRq = _MySessionManager.DoRequests(itemRequestset); IResponseList itemResponseList = responseItemRq.ResponseList; IResponse itemResponse = itemResponseList.GetAt(0); ENResponseType responseType = (ENResponseType)itemResponse.Type.GetValue(); IORItemRetList QBItemList = (IORItemRetList)itemResponse.Detail; for (int i = 0; i <= QBItemList.Count - 1; i++) { if (QBItemList.GetAt(i).ItemNonInventoryRet != null) { if (QBItemList.GetAt(i).ItemNonInventoryRet.Name != null) { string itemCode = QBItemList.GetAt(i).ItemNonInventoryRet.Name.GetValue(); if (QBItemList.GetAt(i).ItemNonInventoryRet.ManufacturerPartNumber != null) { inventoryItems.First(a => a.ItemCode == itemCode).MPN = QBItemList.GetAt(i).ItemNonInventoryRet.ManufacturerPartNumber.GetValue(); } if (QBItemList.GetAt(i).ItemNonInventoryRet.ListID != null) { inventoryItems.First(a => a.ItemCode == itemCode).ListID = QBItemList.GetAt(i).ItemNonInventoryRet.ListID.GetValue(); } } } if (QBItemList.GetAt(i).ItemInventoryRet != null) { IItemInventoryRet iInventory = QBItemList.GetAt(i).ItemInventoryRet; //get item external data (custom fields) //IDataExtRetList dataExtRetList = OR.GetAt(i).ItemInventoryRet.DataExtRetList; //if (dataExtRetList != null) //{ // Console.WriteLine(dataExtRetList.Count); // IDataExtRet dataExtRet = dataExtRetList.GetAt(0); // Console.WriteLine(dataExtRet.DataExtName.GetValue() + " === " + dataExtRet.DataExtValue.GetValue()); //} if (QBItemList.GetAt(i).ItemInventoryRet.Name != null) { string itemCode = QBItemList.GetAt(i).ItemInventoryRet.Name.GetValue(); if (QBItemList.GetAt(i).ItemInventoryRet.ManufacturerPartNumber != null) { inventoryItems.First(a => a.ItemCode == itemCode).MPN = QBItemList.GetAt(i).ItemInventoryRet.ManufacturerPartNumber.GetValue(); } if (QBItemList.GetAt(i).ItemInventoryRet.ListID != null) { inventoryItems.First(a => a.ItemCode == itemCode).ListID = QBItemList.GetAt(i).ItemInventoryRet.ListID.GetValue(); } } } if (QBItemList.GetAt(i).ItemInventoryAssemblyRet != null) { if (QBItemList.GetAt(i).ItemInventoryAssemblyRet.Name != null) { string itemCode = QBItemList.GetAt(i).ItemInventoryAssemblyRet.Name.GetValue(); if (QBItemList.GetAt(i).ItemInventoryAssemblyRet.ManufacturerPartNumber != null) { inventoryItems.First(a => a.ItemCode == itemCode).MPN = QBItemList.GetAt(i).ItemInventoryAssemblyRet.ManufacturerPartNumber.GetValue(); } if (QBItemList.GetAt(i).ItemInventoryAssemblyRet.ListID != null) { inventoryItems.First(a => a.ItemCode == itemCode).ListID = QBItemList.GetAt(i).ItemInventoryAssemblyRet.ListID.GetValue(); } } } //if (item.ItemCode != null) // _inventoryItems.Add(item); } return(inventoryItems); }