我使用.NET SDK和QBO API的v3。我可以很好地创建发票,但是当我尝试包含税务信息时,它每次都会失败。正如您在下面的代码中所看到的,我首先在QBO中查询税率,并且只在发票中指定它(如果它已存在于QBO中)。 (顺便说一句,有人知道我们什么时候可以通过API创建新的税率?)
由于API文档缺乏明确性,我查询了QBO的发票,然后查看了它的属性,试图确定需要设置哪些属性。
//assume I already have an Intuit Invoice object named qbInvoice
string taxName = ValueLists.GetTaxCode(objSR.TaxCodeId);
var qbTaxRate = (new QueryService<Intuit.Ipp.Data.TaxRate>(qbContext)).ExecuteIdsQuery(String.Format("SELECT * FROM TaxRate WHERE Name = '{0}'", taxName), QueryOperationType.query);
if (qbTaxRate.Count > 0)
{
QBAPI.Line taxLine = new QBAPI.Line()
{
Amount = sr.TaxAmount,
AmountSpecified = true,
DetailType = QBAPI.LineDetailTypeEnum.TaxLineDetail,
DetailTypeSpecified = true,
AnyIntuitObject = new QBAPI.TaxLineDetail()
{
NetAmountTaxable = objSR.TaxableAmount,
NetAmountTaxableSpecified = true,
PercentBased = true,
PercentBasedSpecified = true,
TaxPercent = sr.TaxRate,
TaxPercentSpecified = true,
TaxRateRef = new QBAPI.ReferenceType()
{
Value = qbTaxRate.First().Id
}
}
};
qbInvoice.GlobalTaxCalculation = QBAPI.GlobalTaxCalculationEnum.TaxInclusive;
qbInvoice.GlobalTaxCalculationSpecified = true;
qbInvoice.TxnTaxDetail = new QBAPI.TxnTaxDetail()
{
TaxLine = new QBAPI.Line[] { taxLine },
TotalTax = sr.TaxAmount,
TotalTaxSpecified = true,
TxnTaxCodeRef = new QBAPI.ReferenceType()
{
Value = qbTaxRate.First().Id
}
};
}
使用上面的代码指定税务信息时,我收到以下错误:
Error Code: 6000,
A business validation error has occurred while processing your request - Business Validation Error: We're sorry, QuickBooks encountered an error while calculating tax. Try reselecting the tax rate or reentering the product/service item and saving the form again. <a href='https://support.qbo.intuit.com/support/answers.cfm?faq_id=5558&locale=en_US' target="_blank" title="Help">Please click here for more information</a>
答案 0 :(得分:1)
美国与全球的税收模式不同。 https://developer.intuit.com/docs/0025_quickbooksapi/0050_data_services/020_key_concepts/global_tax_model
查看您的代码,我不确定您是否要为全局设置发票。请澄清一下。
如果您想为美国创建发票,请参阅以下代码示例: https://gist.github.com/IntuitDeveloperRelations/6500373
如果是全球性的,请阅读上面的文档链接并相应地设置所需的属性。 全球税收参考与美国不同。 如您所述,您可以从UI创建发票,然后阅读它并添加发票的属性。 另请注意,有些属性以“指定”结尾。您还需要设置它们,以便将相应的元素添加到您的有效负载中。
我建议您从SDK启用请求/响应日志记录,这样您就可以更轻松地调试请求中未发送的属性。 https://developer.intuit.com/docs/0025_quickbooksapi/0055_devkits/0150_ipp_.net_devkit_3.0/logging