2014-01-19 30 views
0

我試圖從QuickBooks的特定日期已經支付的所有發票列表中。如何獲取從QuickBooks到.NET應用程序的特定日期已支付的發票?

我在博客中找到了從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<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() 
         }; 
        } 
       } 
      } 

然後我可以檢查「IsPaid」參數。

但我在想,當我有一個非常大量的發票時,這將不再是一個有效的解決方案。

那麼,如何過濾我的查詢以獲取已在特定日期支付的發票?

注意: 我正在使用C#與QBFC13Lib庫。

回答

0

嗯,我發現了答案,我自己看看那裏的物體的領域。如果其他人有興趣。

任何您想要的過濾器只需使用「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();

+0

雖然這應該讓你大部分的交易,有一些情況下,這可能會得到你不正確的信息。例如:1月1日輸入的發票,1月2日支付,然後發票在1月3日進行編輯。這將顯示在您的第三名單中,但它應該是第二個,因爲它是在付款時。 – Hpjchobbes

2

我可能會在您正在查找的日期對所有收到的付款進行查詢,包括鏈接的交易,然後查詢這些特定的發票交易ID。這樣可以確保您獲得最少量的數據,並且可以確保您在當天只需要付款。這裏是我如何做到這一點的一個片段:

 
// Holds a list of our invoices to query for 
List InvoiceTxnIDList = new List();

// Create payment query IReceivePaymentQuery pmtQuery = MsgRequest.AppendReceivePaymentQueryRq(); pmtQuery.ORTxnQuery.TxnFilter.ORDateRangeFilter.TxnDateRangeFilter.ORTxnDateRangeFilter.TxnDateFilter.FromTxnDate.SetValue(FromDate); pmtQuery.ORTxnQuery.TxnFilter.ORDateRangeFilter.TxnDateRangeFilter.ORTxnDateRangeFilter.TxnDateFilter.ToTxnDate.SetValue(ToDate);

// Process query and get results 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 
// ***** 
// ***** 

相關問題