我正在尝试在Quickbooks在线api的发票内添加SalesItemLineDetail的税码,但是在Online Quickbooks中检查时,它没有正确设置税码。
这是我用来创建订单项的C#代码
Line = new Intuit.Ipp.Data.Line();
InvoiceLine = new Intuit.Ipp.Data.SalesItemLineDetail();
InvoiceLine.ItemRef = new Intuit.Ipp.Data.ReferenceType
{
Value = GetItem.Id, // this is inventory Item Id
name = GetItem.Name // inventory item name
};
Line.DetailTypeSpecified = true;
Line.DetailType = Intuit.Ipp.Data.LineDetailTypeEnum.SalesItemLineDetail;
Line.Description = inv.Description;
Line.Amount = (inv.Price == null || inv.Price == 0.0) ? (decimal)0.00 : (decimal)inv.Price;
Line.AmountSpecified = true;
InvoiceLine.Qty = decimal.Parse(inv.Quantity.Value.ToString());
InvoiceLine.QtySpecified = true;
InvoiceLine.AnyIntuitObject = (inv.Price == null || inv.Price == 0.0) ? (decimal)0.00 : (decimal)(Math.Round(inv.Price.Value, 2) / inv.Quantity.Value);
InvoiceLine.ItemElementName = Intuit.Ipp.Data.ItemChoiceType.UnitPrice;
// this line is not settings tax code properly
InvoiceLine.TaxCodeRef = new Intuit.Ipp.Data.ReferenceType
{
name = taxName,
Value = TaxId
};
//Line Sales Item Line Detail - ServiceDate
InvoiceLine.ServiceDate = DateTime.Now.Date;
InvoiceLine.ServiceDateSpecified = true;
//Assign Sales Item Line Detail to Line Item
Line.AnyIntuitObject = InvoiceLine;
lines.Add(Line);
Intuit.Ipp.Data.Invoice invoice = new Intuit.Ipp.Data.Invoice();
// SalesOrder is a database table object, and OrderNumber is auto generated number
invoice.DocNumber = SalesOrder.OrderNumber.ToString();
//TxnDate
invoice.TxnDate = DateTime.Now.Date;
invoice.TxnDateSpecified = true;
invoice.CustomerRef = new Intuit.Ipp.Data.ReferenceType
{
Value = CompanyId
};
//convert list to array for Intuit Line
invoice.Line = lines.ToArray();
//TxnTaxDetail
Intuit.Ipp.Data.Line taxLine = new Intuit.Ipp.Data.Line();
Intuit.Ipp.Data.TxnTaxDetail txnTaxDetail = new Intuit.Ipp.Data.TxnTaxDetail();
Intuit.Ipp.Data.TaxLineDetail taxLineDetail = new Intuit.Ipp.Data.TaxLineDetail(); ;
//txnTaxDetail.TotalTaxSpecified = true;
//txnTaxDetail.TotalTax = decimal.Parse("2");
var MainTaxValue = "";
txnTaxDetail.TxnTaxCodeRef = new Intuit.Ipp.Data.ReferenceType()
{
Value = TaxId,
name = SalesOrder.TaxCode.TaxCodeName
};
foreach (var TAXName in TaxObject.TaxRateDetail)
{
if(TAXName.TaxRateRef.name.Contains(SalesOrder.TaxCode.TaxCodeName))
{
MainTaxValue = TAXName.TaxRateRef.value;
}
}
taxLineDetail.TaxRateRef = new Intuit.Ipp.Data.ReferenceType
{
Value = MainTaxValue
};
taxLine.AnyIntuitObject = taxLineDetail;
txnTaxDetail.TaxLine = new Intuit.Ipp.Data.Line[] { taxLine };
//DueDate
invoice.DueDate = SalesOrder.InvoiceDueDate != null ? SalesOrder.InvoiceDueDate.Value : DateTime.Now.AddDays(30).Date;
invoice.DueDateSpecified = true;
invoice.TxnTaxDetail = txnTaxDetail;
我已经尝试过这些参考链接,但是对我来说不起作用
https://gist.github.com/IntuitDeveloperRelations/6500373
How to export Line items with Tax Code and Value in QBO Canada
使用上面的链接,我可以看到我们可以使用此代码行为每个发票行项目创建税码参考,但未正确设置值。
InvoiceLine.TaxCodeRef = new Intuit.Ipp.Data.ReferenceType
{
name = taxName,
Value = TaxId
};
但是它不起作用。注意:这是非美国公司,因此我必须为每个发票行指定税码ref。
尝试删除名称字段,我认为可能不是必需的
InvoiceLine.TaxCodeRef = new Intuit.Ipp.Data.ReferenceType()
{
Value = TaxId
};
我们两个版本之间的主要区别在于,我让QB计算税额。我注释了“税额详细信息”行,并告诉QB不包括税额。
// //TxnTaxDetail
// TxnTaxDetail txnTaxDetail = new TxnTaxDetail();
// Line taxLine = new Line();
// taxLine.DetailType = LineDetailTypeEnum.TaxLineDetail;
// TaxLineDetail taxLineDetail = new TaxLineDetail();
// taxLineDetail.TaxRateRef = stateTaxCode.SalesTaxRateList.TaxRateDetail[0].TaxRateRef;
// txnTaxDetail.TxnTaxCodeRef = new ReferenceType
// {
// name = stateTaxCode.Name,
// Value = stateTaxCode.Id
// };
// if (customer.DefaultTaxCodeRef != null)
// {
// txnTaxDetail.TxnTaxCodeRef = customer.DefaultTaxCodeRef;
// taxLineDetail.TaxRateRef = customer.DefaultTaxCodeRef;
// }
// //Assigning the first Tax Rate in this Tax Code
// taxLine.AnyIntuitObject = taxLineDetail;
// txnTaxDetail.TaxLine = new[] { taxLine };
// invoice.TxnTaxDetail = txnTaxDetail;
invoice.GlobalTaxCalculationSpecified = true;
invoice.GlobalTaxCalculation = GlobalTaxCalculationEnum.TaxExcluded;
这是我执行此操作的代码,它肯定有效。我看不到两者之间的区别,这将计算欧洲的增值税并放入税法中。希望这会有所帮助。
var invlines = new List<Line>();
foreach (var lineitem in inv.Lines)
{
//Line
Line invoiceLine = new Line();
//Line Description
invoiceLine.Description = (((lineitem.PublicationName == "N/A" || lineitem.PublicationName == "-") ? "" : lineitem.PublicationName) + " " + lineitem.Description).Trim();
//Line Detail Type
invoiceLine.DetailType = LineDetailTypeEnum.SalesItemLineDetail;
invoiceLine.DetailTypeSpecified = true;
//Line Sales Item Line Detail
SalesItemLineDetail lineSalesItemLineDetail = new SalesItemLineDetail();
//Line Sales Item Line Detail - ItemRef
if (!string.IsNullOrEmpty(lineitem.ItemCode))
{
lineSalesItemLineDetail.ItemRef = new ReferenceType()
{
Value = lineitem.ItemCode
};
}
else if (item != null)
{
lineSalesItemLineDetail.ItemRef = new ReferenceType
{
name = item.Name,
Value = item.Id
};
}
//Line Sales Item Line Detail - UnitPrice
//Line Sales Item Line Detail - Qty
lineSalesItemLineDetail.Qty = 1;
lineSalesItemLineDetail.QtySpecified = true;
if (inv.DiscountPercent > 0)
{
invoiceLine.Amount = (decimal)lineitem.PriceBeforeDiscount;
invoiceLine.AmountSpecified = true;
lineSalesItemLineDetail.ItemElementName = ItemChoiceType.UnitPrice;
}
else
{
invoiceLine.Amount = (decimal)lineitem.Price;
invoiceLine.AmountSpecified = true;
lineSalesItemLineDetail.AnyIntuitObject = lineitem.Price;
lineSalesItemLineDetail.ItemElementName = ItemChoiceType.UnitPrice;
}
//Line Sales Item Line Detail - TaxCodeRef
//For US companies, this can be 'TAX' or 'NON'
var taxref = lineitem.TaxAmount == null || lineitem.TaxAmount == 0 ? nonvatid.ToString() : vatid.ToString();
if (country == "US")
{
taxref = lineitem.TaxAmount == null || lineitem.TaxAmount == 0 ? "NON" : "TAX";
}
lineSalesItemLineDetail.TaxCodeRef = new ReferenceType
{
Value = taxref
};
//Line Sales Item Line Detail - ServiceDate
lineSalesItemLineDetail.ServiceDate = DateTimeService.Now.Date;
lineSalesItemLineDetail.ServiceDateSpecified = true;
//Assign Sales Item Line Detail to Line Item
invoiceLine.AnyIntuitObject = lineSalesItemLineDetail;
//Assign Line Item to Invoice
invlines.Add(invoiceLine);
}
if (inv.DiscountPercent > 0)
{
Line invoiceLine = new Line();
DiscountLineDetail discLine = new DiscountLineDetail();
discLine.PercentBased = true;
discLine.DiscountPercent = (decimal)inv.DiscountPercent;
discLine.DiscountPercentSpecified = true;
discLine.PercentBased = true;
discLine.PercentBasedSpecified = true;
invoiceLine.DetailType = LineDetailTypeEnum.DiscountLineDetail;
invoiceLine.DetailTypeSpecified = true;
invoiceLine.AnyIntuitObject = discLine;
invlines.Add(invoiceLine);
invoice.DiscountRate = (decimal) (inv.DiscountPercent);
invoice.DiscountRateSpecified = true;
}
invoice.Line = invlines.ToArray();
最终终于找到了正确的解决方案。
我上面的代码是正确的,没有问题,@ sheavens代码也是正确的。
实际问题是,我正在为选定的公司分配“默认税码”] >>,我们在传递发票行项目中的税码参考时无法覆盖此错误。
要检查公司是否有默认代码,请导航至快速手册在线网站上的公司列表,从列表中选择所需的公司,单击“编辑”,然后在“税收信息”选项卡中取消选中“分配默认税代码” ”以使用“发票行”项传递税码。
希望这对其他开发人员有同样的问题。