如何获取从QuickBooks到.NET应用程序在特定日期支付的发票?

我正在尝试获取一份列表,其中包含已在特定日期支付的QuickBooks的所有发票。

我在博客中找到了从QuickBooks获取所有发票的方法。

bool sessionBegun = false; bool connectionOpen = false; QBSessionManager sessionManager = null; try { //Create the session Manager object sessionManager = new QBSessionManager(); //Create the message set request object to hold our request IMsgSetRequest requestMsgSet = sessionManager.CreateMsgSetRequest("US", 8, 0); requestMsgSet.Attributes.OnError = ENRqOnError.roeContinue; //Connect to QuickBooks and begin a session sessionManager.OpenConnection("", "IDN InvoiceAdd C# sample"); connectionOpen = true; sessionManager.BeginSession(@"C:\Users\Public\Documents\Intuit\QuickBooks\Company Files\MyCia.qbw", ENOpenMode.omDontCare); sessionBegun = true; 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(); 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() }; } } } 

然后我可以检查“IsPaid”参数。

但我在想,当我有大量的发票时,这将不再是一个有效的解决方案。

那么如何过滤我的查询以获取在该特定日期支付的发票?

注意:我正在使用C#和QBFC13Lib库。

我可能会查询您要查找的所有收到的付款,包括链接的交易,然后查询这些特定的发票交易ID。 这将确保您获得最少量的数据,并确保您在所需的当天只有这些付款。 这是我如何做到这一点的片段:

 //保存我们要查询的发票清单
 List InvoiceTxnIDList = new List(); 

//创建付款查询
IReceivePaymentQuery pmtQuery = MsgRequest.AppendReceivePaymentQueryRq();
pmtQuery.ORTxnQuery.TxnFilter.ORDateRangeFilter.TxnDateRangeFilter.ORTxnDateRangeFilter.TxnDateFilter.FromTxnDate.SetValue(FROM日期);
pmtQuery.ORTxnQuery.TxnFilter.ORDateRangeFilter.TxnDateRangeFilter.ORTxnDateRangeFilter.TxnDateFilter.ToTxnDate.SetValue(TODATE);

//处理查询并获得结果
IMsgSetResponse MsgResponse = SessionManager.DoRequests(MsgRequest);
IResponse response = MsgResponse.ResponseList.GetAt(0);
if(response.StatusCode == 0)
{
IReceivePaymentRetList pmtRetList =(IReceivePaymentRetList)response.Detail;

  // Loop through our payment list for (int index = 0; index < pmtRetList.Count; index++) { IReceivePaymentRet pmt = pmtRetList.GetAt(index); // Check to see if we have any linked transactions if(pmt.AppliedToTxnRetList != null) { // Loop through all the linked transactions and see if it is // already on our query list for (int indey = 0; indey < pmt.AppliedToTxnRetList.Count; indey++) { IAppliedToTxnRet appTxn = pmt.AppliedToTxnRetList.GetAt(indey); if(!InvoiceTxnIDList.Contains(appTxn.TxnID.GetValue())) InvoiceTxnIDList.Add(appTxn.TxnID.GetValue()); } } } // Create a query for all the txnIDs that we found MsgRequest.ClearRequests(); MsgRequest.Attributes.OnError = ENRqOnError.roeStop; for (int index = 0; index < InvoiceTxnIDList.Count; index++) { IInvoiceQuery invQuery = MsgRequest.AppendInvoiceQueryRq(); invQuery.ORInvoiceQuery.TxnIDList.Add(InvoiceTxnIDList[index]); } // Process the request and get the invoice ret list // ***** // ***** 

好吧,我自己找到答案,通过你拥有它的物体的领域。 如果有其他人有兴趣。

您想要的任何filter都必须使用“invoiceQueryRq”对象的“ORInvoiceQuery.InvoiceFilter”属性。 并且最后使用“SetValue”非常重要我很难尝试使用等于运算符来设置值。

 invoiceQueryRq.ORInvoiceQuery.InvoiceFilter.ORDateRangeFilter.ModifiedDateRangeFilter.FromModifiedDate.SetValue(DateTime.Now.AddDays(-1),true); invoiceQueryRq.ORInvoiceQuery.InvoiceFilter.ORDateRangeFilter.ModifiedDateRangeFilter.ToModifiedDate.SetValue(DateTime.Now.AddDays(1),true); invoiceQueryRq.ORInvoiceQuery.InvoiceFilter.PaidStatus.SetValue(ENPaidStatus.psPaidOnly); 

最后将此代码放在以下句子之后:

IInvoiceQuery invoiceQueryRq = requestMsgSet.AppendInvoiceQueryRq();