2016-08-24 36 views
0

我正在製作一個應用程序,獲取所有發票一個月,然後將每個發票保存爲PDF,我從未使用QuickBooks開發過,因此我對此知之甚少。有人能夠給我任何源代碼,做這個或類似的東西來建立我的?我發現,我認爲都指向我朝着正確的方向一對夫婦的聯繫,但我不是100%地肯定:如何獲得一個月的所有發票並將它們全部保存爲使用QBFC13和C#的PDF?

How can I get the invoices that has been paid on an specific date from QuickBooks to .NET app?

https://intuitdeveloper.lc.intuit.com/questions/1382278-sample-net-code-for-quickbooks-api-oauth-call-to-create-an-invoice-and-pdf-or-any-api-call-if-no-invoice

https://intuitdeveloper.lc.intuit.com/questions/1060982-quickbooks-online-api-invoice-pdf-download

我使用C#.NET和QBFC13Lib。

編輯:

我採取這種代碼從鏈接的問題,讓所有的發票。

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", 13, 0); 
      requestMsgSet.Attributes.OnError = ENRqOnError.roeContinue; 

      //Connect to QuickBooks and begin a session 
      sessionManager.OpenConnection("", "GenerateInvoicePDFs"); 
      connectionOpen = true; 
      sessionManager.BeginSession("", 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() 
        }; 
       } 
      } 
     } 
     catch 
     { 

     } 

我收到一個錯誤,說發票不是一種類型。

+0

分享代碼和當前面臨的問題。我們將幫助您解決特定問題,而不是一般概念。抱歉。 –

+0

「發票不是類型」是一個編譯錯誤。你看到這個錯誤,因爲你還沒有定義類「發票」。如果您對軟件開發不熟悉,則此[鏈接](https://msdn.microsoft.com/en-IN/library/x9afc042.aspx)解釋如何在C#中定義類。 – Naveen

+0

@Naveen我對軟件開發並不陌生,但我認爲這種類型在QBFC13Lib中。 –

回答

1

SDK在查詢對象上提供過濾器,使您能夠查詢數據的子集。您可以根據交易日期過濾發票:

// get all invoices for the month of august 2016 
invoiceQueryRq.ORInvoiceQuery.InvoiceFilter.ORDateRangeFilter.TxnDateRangeFilter.ORTxnDateRangeFilter.TxnDateFilter.FromTxnDate.SetValue(new DateTime(2016, 8, 1)); 
invoiceQueryRq.ORInvoiceQuery.InvoiceFilter.ORDateRangeFilter.TxnDateRangeFilter.ORTxnDateRangeFilter.TxnDateFilter.ToTxnDate.SetValue(new DateTime(2016, 8, 31)); 

或者,您也可以查詢已修改的指定日期範圍內的發票:

// all invoices modified in the month of August 2016 
invoiceQueryRq.ORInvoiceQuery.InvoiceFilter.ORDateRangeFilter.ModifiedDateRangeFilter.FromModifiedDate.SetValue(new DateTime(2016, 8, 1)); 
invoiceQueryRq.ORInvoiceQuery.InvoiceFilter.ORDateRangeFilter.ModifiedDateRangeFilter.ToModifiedDate.SetValue(new DateTime(2016, 8, 31)); 

在代碼中,你都在用,你的時候調用BeginSession,第一個參數是Blank。雖然這是通過採用當前打開的公司文件來工作的,但建議您明確提供要查詢的公司文件的文件路徑。

一定要清理你完成之後查詢:

if (requestMsgSet != null) 
{ 
    Marshal.FinalReleaseComObject(requestMsgSet); 
} 
if (invoiceQueryRq != null) 
{ 
    Marshal.FinalReleaseComObject(invoiceQueryRq); 
} 
sessionMgr.EndSession(); 
sessionMgr.CloseConnection(); 

在任何情況下,我會建議你去通過SDK開發人員指南,瞭解你的代碼實際上做的事情。

更新:

你問題的第二部分是回答here

+0

比你這是非常有幫助的。你知道關於將發票保存爲pdf嗎? –

+1

SDK只允許您從公司文件提取數據。保存爲PDF將不得不在您正在開發的應用程序中實施。您是否想要將單個發票保存爲PDF或將發票清單保存到單個PDF中?如果每張發票都必須保存爲PDF,那麼您是否有可用的模板? – Naveen

+0

我想將單個發票保存爲PDF,但我沒有可用的模板,但QuickBooks已具備將發票製作爲PDF的功能,我希望PDF格式爲相同格式。您在答案中鏈接的問題是4歲,因此我不確定這些信息是否準確: https://intuitdeveloper.lc.intuit.com/questions/823768 https://intuitdeveloper.lc .intuit.com/questions/1060982 在任何情況下,我都可以使用QuickBooks製作的PDF作爲模板。 –

相關問題