Не удается установить налоговый код SalesItemLineDetail в быстрых книгах Intuit api C# - PullRequest
0 голосов
/ 18 февраля 2020

Я пытаюсь добавить Налоговый код для SalesItemLineDetail в api Invoice of 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

Как экспортировать позиции с Налоговым кодом и значением в QBO Canada

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

Используя приведенные выше ссылки, я вижу, что мы можем создать Налоговый кодекс использует эту строку кода для каждой позиции строки счета-фактуры, но неправильно устанавливает значение.

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

                            };

Но это не работает. Примечание: это неамериканская компания, поэтому я должен указать налоговый код для каждой строки счета.

Редактировать 1: Прикрепить изображение запроса API Почтальона, которое я отправил в Quickbooks для создания счета. enter image description here

Ответы [ 3 ]

0 голосов
/ 20 февраля 2020

Основное различие между нашими версиями заключается в том, что я позволю 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();
0 голосов
/ 25 февраля 2020

Наконец-то удалось найти правильное решение.

Мой код «Выше» правильный, в нем нет проблем, и код @sheavens тоже правильный .

Фактическая проблема была, Я назначал «Налоговый код по умолчанию» для выбранной компании , который нельзя переопределить при передаче ссылки на налоговый код в строке строки счета-фактуры.

Кому Проверьте, есть ли какой-либо код по умолчанию для компании, перейдите к списку компаний на веб-сайте быстрых книг, выберите нужную компанию из списка, нажмите «Изменить», затем на вкладке «Налоговая информация» снимите флажок «Назначить код по умолчанию», чтобы пройти налоговый код с использованием строки счета-фактуры.

Надеюсь, это поможет другим разработчикам с такой же проблемой.

0 голосов
/ 18 февраля 2020

попробуйте, удалив имя поля, я думаю, что это может не потребоваться

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

                            Value = TaxId

                        };
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...