简体   繁体   English

无法在 Intuit quickbooks api C# 中设置 SalesItemLineDetail 税码

[英]Not able to set SalesItemLineDetail tax code in Intuit quickbooks api C#

I am trying to add Tax Code for SalesItemLineDetail inside Invoice of Quickbooks online api, but it is not setting tax code correctly when checking it in Online Quickbooks.我正在尝试在 Quickbooks 在线 api 的发票中为 SalesItemLineDetail 添加税码,但是在 Online Quickbooks 中检查时它没有正确设置税码。

Here is my C# Code, which I am using to create Line Item这是我的 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;

I have tried these reference links, but it is not working for me我已经尝试过这些参考链接,但它对我不起作用

https://gist.github.com/IntuitDeveloperRelations/6500373 https://gist.github.com/IntuitDeveloperRelations/6500373

How to export Line items with Tax Code and Value in QBO Canada 如何在 QBO Canada 中导出带有税码和价值的行项目

https://developer.intuit.com/app/developer/qbo/docs/develop/tutorials/manage-sales-tax-for-non-us-locales https://developer.intuit.com/app/developer/qbo/docs/develop/tutorials/manage-sales-tax-for-non-us-locales

Using above links, I can see we can create Tax Code ref using this line of code, for Each Invoice Line item, but it is not setting value correctly.使用上面的链接,我可以看到我们可以使用这行代码为每个发票行项目创建税码引用,但它没有正确设置值。

                           InvoiceLine.TaxCodeRef = new Intuit.Ipp.Data.ReferenceType
                            {
                                name = taxName,
                                Value = TaxId

                            };

But it is not working.但它不起作用。 Note: this is non-US company, so I have to specify tax code ref for each Invoice Line.注意:这是非美国公司,所以我必须为每个发票行指定税码参考。

Edit 1: Attaching Image of Postman API request, which I sent to Quickbooks for creating invoice.编辑 1:附加 Postman API 请求的图像,我将其发送到 Quickbooks 以创建发票。 在此处输入图片说明

try by removing the name field I think it might not be required尝试删除名称字段,我认为它可能不是必需的

InvoiceLine.TaxCodeRef = new Intuit.Ipp.Data.ReferenceType()
                        {

                            Value = TaxId

                        };

The main difference between our versions is that I let QB calculate the tax.我们版本之间的主要区别是我让 QB 计算税款。 I commented out the Tax detail line, and told QB that tax amount wasn't included.我注释掉了税收详细信息行,并告诉 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;

Here is my code for doing this, and it definitely works.这是我执行此操作的代码,它绝对有效。 I can't see a difference between the two though.This calculates VAT in Europe and puts in the Tax Code.不过,我看不出两者之间的区别。这会计算欧洲的增值税并输入税法。 Hope this helps.希望这可以帮助。

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

Finally was able to find the correct solution.终于能够找到正确的解决方案。

My Above code is right, there is no issue in it and @sheavens code is also right .我上面的代码是正确的,它没有问题,@sheavens 代码也是正确的

Actual problem was, I was assigning "default Tax code" to a selected company , which we cannot override while passing tax code reference in Invoice Line item.实际问题是,我将“默认税码”分配给选定的公司,在发票行项目中传递税码参考时我们无法覆盖它。

To Check if there is any default code for company, navigate to Companies list in quickbooks online website , Select your desired Company from the list, click "Edit", then in the "Tax Info" tab, uncheck "Assign Default tax code" to pass tax code using Invoice Line item.要检查公司是否有任何默认代码,请导航到 quickbooks 在线网站中的公司列表,从列表中选择您想要的公司,单击“编辑”,然后在“税务信息”选项卡中,取消选中“分配默认税务代码”以使用发票行项目传递税码。

Hope this helps other developers, with same problem.希望这可以帮助其他开发人员,有同样的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Intuit Quickbooks在线API-如何购买 - Intuit Quickbooks Online API - How to get purchases QuickBooks Intuit IPP问题检查 - QuickBooks Intuit IPP Issue Check 通过C#代码从QuickBooks桌面检索贷项通知单 - Retrive credit memo from quickbooks desktop through c# code 无法使用C#代码隐藏设置区域 - Not able to hide set area using C# Code IntuIt QuickBooks付款API,如何使用IppDotNetSdkForQuickBooksApiV3软件包的servicecontext执行信用卡交易? - IntuIt QuickBooks payments API, How can I perform credit card transactions using servicecontext of IppDotNetSdkForQuickBooksApiV3 package? 通过Intuit API访问quickBooks数据时,.NET中出现“ Unauthorized-401”错误 - Getting “Unauthorized-401” Error in .NET while accessing quickBooks data through Intuit API Intuit QuickBooks集成(C#.NET / SDK)-哪个PhysicalAddress属性用于ZipCode和“状态”字段? - Intuit QuickBooks Integration (C#.NET/SDK) - Which PhysicalAddress property is for ZipCode, and State field? 我必须安装什么才能制作使用QuickBooks API的C#程序? - What do I have to install to be able to make a C# program that uses the QuickBooks APIs? Quickbooks 在线集成 c# - Quickbooks Online integration c# Quickbooks Online Api SDK c# - 有没有办法使用 api 为账单创建和更新隐藏的自定义字段 - Quickbooks Online Api SDK c# - Is there a way to create and update hidden custom field for bill with use api
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM