2

I am making an application that gets all invoices for one month, and then saves each of those invoices as a PDF, I have never developed with QuickBooks so I have very little knowledge about it. Would someone be able to give me any source code that does this or something similar for me to build off of? I have found a couple links that I think are pointing me in the right direction but I'm not 100% sure:

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

I am using C# .NET and QBFC13Lib.

Edit:

I have taken this code for getting all invoices from the linked question.

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
        {

        }

I am given an error that says that Invoice is not a type.

Community
  • 1
  • 1
Jake Farley
  • 72
  • 1
  • 8
  • Share the code and the problem you are facing at the moment. We will help you in a specific problem, not in a general concept. Sorry. – Afzaal Ahmad Zeeshan Aug 24 '16 at 14:46
  • "Invoice is not a type" is a compilation error. You are seeing this error because you haven't defined the class "Invoice" yet. If you are new to software development, this [link](https://msdn.microsoft.com/en-IN/library/x9afc042.aspx) explains how to define classes in C#. – Nacharya Aug 25 '16 at 06:15
  • @Naveen I am not new to software development but I thought this type was in the QBFC13Lib. – Jake Farley Aug 25 '16 at 12:41

1 Answers1

2

The SDK provides filters on the query object to enable you to query a subset of data. You can filter the invoices based on transaction date:

// 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));

Or, you can query invoices that have been modified within a given date range:

// 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));

In the code that you are using, when you call BeginSession, the first argument is Blank. Although this works by taking the currently open company file, it is advised to explicitly provide the file path of company file you want to query for.

Be sure to cleanup after you are done querying:

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

In any case, I would advise you to go through the SDK developers guide to understand what your code is actually doing.

Update:

The second part of your question is answered here.

Community
  • 1
  • 1
Nacharya
  • 229
  • 2
  • 8
  • Than you this is very helpful. Do you know anything about saving the invoices as pdfs? – Jake Farley Aug 25 '16 at 12:40
  • 1
    SDK only allows you to extract data from a company file. Saving as PDF would have to be implemented in the app that you are developing. Do you want to save individual invoices as PDFs or save the list of invoices into a single PDF? If each invoice has to be saved as a PDF, do you have a template available? – Nacharya Aug 26 '16 at 06:25
  • I want to save individual invoices as PDFs, I do not have a template available however, QuickBooks already has the functionality to make invoices into a PDF, I would like the PDFs to be in the same format. The question you linked in your answer is 4 years old and I am not sure that the information is accurate due to these questions: https://intuitdeveloper.lc.intuit.com/questions/823768 https://intuitdeveloper.lc.intuit.com/questions/1060982 In any case, I can use the PDF that QuickBooks makes as a template. – Jake Farley Aug 26 '16 at 12:21
  • 1
    @JakeFarley The links that you are referring to are for QuickBooks Online - the online version of QuickBooks. I assume that you are using QuickBooks Desktop since QBFC13 is the SDK for QuickBooks Desktop. – Nacharya Aug 26 '16 at 16:56
  • Yes I am using QuickBooks Desktop, is it not possible to save individual Invoices as PDFs in the desktop version? – Jake Farley Aug 29 '16 at 12:12
  • 1
    @JakeFarley QuickBooks Desktop allows you to save PDFs, but the SDK for QuickBooks Desktop only allows you to extract data from your company file. The application that you are developing can do the task of generating PDFs from the data provided by SDK. – Nacharya Sep 01 '16 at 05:37