我正在创建一个获取所有发票一个月的应用程序,然后将每个发票保存为PDF,我从未使用QuickBooks开发,所以我对它的了解甚少。有人能够给我任何源代码来做这个或类似我的东西建立?我发现了一些我认为指向正确方向的链接,但我并非100%确定:
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/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
{
}
我收到一条错误消息,指出Invoice不是一种类型。
答案 0 :(得分:2)
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。