无法在 Intuit quickbooks api C# 中设置 SalesItemLineDetail 税码 [英] Not able to set SalesItemLineDetail tax code in Intuit quickbooks api C#

查看:61
本文介绍了无法在 Intuit quickbooks api C# 中设置 SalesItemLineDetail 税码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 Quickbooks online api 的 Invoice 中为 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,//这是库存商品 IDname = GetItem.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;//这行没有正确设置税码InvoiceLine.TaxCodeRef = 新 Intuit.Ipp.Data.ReferenceType{姓名 = 税名,价值 = 税号};//行销售项目行明细 - ServiceDateInvoiceLine.ServiceDate = DateTime.Now.Date;InvoiceLine.ServiceDateSpecified = true;//将销售项目行详细信息分配给行项目Line.AnyIntuitObject = InvoiceLine;行.添加(行);Intuit.Ipp.Data.Invoice invoice = new Intuit.Ipp.Data.Invoice();//SalesOrder 是一个数据库表对象,OrderNumber 是自动生成的数字发票.DocNumber = SalesOrder.OrderNumber.ToString();//发送日期发票.TxnDate = DateTime.Now.Date;发票.TxnDateSpecified = true;invoice.CustomerRef = new Intuit.Ipp.Data.ReferenceType{值 = 公司 ID};//将列表转换为 Intuit Line 的数组invoice.Line = lines.ToArray();//TxnTaxDetailIntuit.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(){价值 = 税号,名称 = SalesOrder.TaxCode.TaxCodeName};foreach(TaxObject.TaxRateDetail 中的变量 TAXName){if(TAXName.TaxRateRef.name.Contains(SalesOrder.TaxCode.TaxCodeName)){MainTaxValue = TAXName.TaxRateRef.value;}}taxLineDetail.TaxRateRef = 新的 Intuit.Ipp.Data.ReferenceType{价值 = MainTaxValue};taxLine.AnyIntuitObject = taxLineDetail;txnTaxDetail.TaxLine = new Intuit.Ipp.Data.Line[] { taxLine };//到期日invoice.DueDate = SalesOrder.InvoiceDueDate != null ?SalesOrder.InvoiceDueDate.Value : DateTime.Now.AddDays(30).Date;invoice.DueDateSpecified = true;发票.TxnTaxDetail = txnTaxDetail;

我已经尝试过这些参考链接,但对我不起作用

解决方案

终于找到了正确的解决方案.

我上面的代码是对的,没有问题,@sheavens 的代码也是对的.

实际问题是,我将默认税码"分配给选定的公司,我们无法在发票行项目中传递税码参考时覆盖它.>

要检查公司是否有任何默认代码,请导航到 quickbooks 在线网站中的公司列表,从列表中选择您想要的公司,单击编辑",然后在税务信息"选项卡中,取消选中分配默认税务"代码"以使用发票行项目传递税码.

希望这能帮助其他开发者,遇到同样的问题.

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.

Here is my C# Code, which I am using to create Line Item

                            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

How to export Line items with Tax Code and Value in QBO Canada

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.

解决方案

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.

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.

Hope this helps other developers, with same problem.

这篇关于无法在 Intuit quickbooks api C# 中设置 SalesItemLineDetail 税码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆