如何使用C#和Quickbook SDK在QuickBook中添加发票?

时间:2014-01-19 12:45:51

标签: c# .net sdk quickbooks

我对QuickBook(桌面)集成完全陌生。我想使用Quickbook SDK在QuickBook中创建一个Invoice。我正在关注C# .NET Application with QuickBooks Desktop Edition来为我的客户和发票打包。

我可以创建客户,但无法发票。

这是我的代码:

ICustomerAdd customerAddRq = requestMsgSet.AppendCustomerAddRq();
customerAddRq.Name.SetValue(Customer.Name);

IMsgSetResponse responseMsgSet = sessionManager.DoRequests(requestMsgSet);
IResponse response = responseMsgSet.ResponseList.GetAt(0);
ICustomerRet customerRet = (ICustomerRet)response.Detail;

IInvoiceAdd invoiceAddRq = requestMsgSet.AppendInvoiceAddRq();
invoiceAddRq.CustomerRef.ListID.SetValue(customerRet.ListID.GetValue());

IMsgSetResponse invoiceResponseMsgSet = sessionManager.DoRequests(requestMsgSet);
IResponse invoiceResponse = invoiceResponseMsgSet.ResponseList.GetAt(0);
IInvoiceRet invoiceRet = (IInvoiceRet)invoiceResponse.Detail;

invoiceRet总是null

另一个问题是Invoice Number中的IInvoiceAdd用户属于哪个属性?

1 个答案:

答案 0 :(得分:3)

当您收到回复时,您需要检查响应状态以查看请求是否有效。例如:

IResponse invoiceResponse = invoiceResponseMsgSet.ResponseList.GetAt(0);
if(invoiceResponse.StatusCode !=0)
{
    // There was an error with the request.
    string errorMsg = invoiceResponse.StatusMessage;
}

在这种情况下,您将收到错误消息:“事务为空。”这意味着您需要在发票中添加一些项目以在发票上创建美元金额。即使OSR没有声明这些是必需的,你仍然需要在那里,即使它们是零金额。这与您尝试在QuickBooks中手动创建发票而不指定任何项目相同。

假设您有一个名为“Sales”的项目设置,您的请求将如下所示:

ICustomerAdd customerAddRq = requestMsgSet.AppendCustomerAddRq();
customerAddRq.Name.SetValue(Customer.Name);

IMsgSetResponse responseMsgSet = sessionManager.DoRequests(requestMsgSet);
IResponse response = responseMsgSet.ResponseList.GetAt(0);
ICustomerRet customerRet = (ICustomerRet)response.Detail;

IInvoiceAdd invoiceAddRq = requestMsgSet.AppendInvoiceAddRq();
invoiceAddRq.CustomerRef.ListID.SetValue(customerRet.ListID.GetValue());

// Add these lines to your request
IORInvoiceLineAdd invoiceLineAdd = invoiceAddRq.ORInvoiceLineAddList.Append();
invoiceLineAdd.InvoiceLineAdd.ItemRef.FullName.SetValue("Sales");

IMsgSetResponse invoiceResponseMsgSet = sessionManager.DoRequests(requestMsgSet);
IResponse invoiceResponse = invoiceResponseMsgSet.ResponseList.GetAt(0);
IInvoiceRet invoiceRet = (IInvoiceRet)invoiceResponse.Detail;

发票编号的字段称为RefNumber。