0

我正在使用 IPP.Net 尝试将单个 CreditMemo 插入 Quickbooks Online。我已成功插入具有类似代码的发票。我插入 CreditMemo 的代码如下:

Try
                        Dim qboCreditMemo As New Intuit.Ipp.Data.Qbo.CreditMemo
                        Dim qboCreditMemoHdr As New Intuit.Ipp.Data.Qbo.CreditMemoHeader
                        Dim qboCreditMemoLine As Intuit.Ipp.Data.Qbo.CreditMemoLine
                        Dim CreditMemoLines As New List(Of Intuit.Ipp.Data.Qbo.CreditMemoLine)
                        Dim CreditMemoItemAttributes As Qbo.ItemChoiceType2()
                        Dim CreditMemoItemValues As Object()

                        For Each row In tblTrans.Rows
                            If bFirstRow Then
                                'Set CreditMemo header
                                qboCreditMemoHdr.DocNumber = "SMA" & CStr(row("batch_id"))
                                qboCreditMemoHdr.TxnDate = Format(row("acct_date"), "yyyy-MM-dd")
                                qboCreditMemoHdr.Msg = row("batch_descr")
                                qboCreditMemoHdr.CustomerId = New Intuit.Ipp.Data.Qbo.IdType
                                qboCreditMemoHdr.CustomerId.Value = row("iface_owner_id")
                                qboCreditMemo.Header = qboCreditMemoHdr

                                bFirstRow = False 'only do this once
                            End If

                            'Lines
                            qboCreditMemoLine = New Qbo.CreditMemoLine
                            qboCreditMemoLine.Desc = row("descr")
                            qboCreditMemoLine.Amount = row("amount_owner")
                            qboCreditMemoLine.AmountSpecified = True
                            CreditMemoItemAttributes = {Qbo.ItemsChoiceType2.ItemId, Qbo.ItemsChoiceType2.UnitPrice, Qbo.ItemsChoiceType2.Qty}
                            CreditMemoItemValues = {New Qbo.IdType With {.idDomain = Qbo.idDomainEnum.QBO, .Value = row("iface_item_id")}, row("unitPrice"), row("quantity")}
                            qboCreditMemoLine.ItemsElementName = CreditMemoItemAttributes
                            qboCreditMemoLine.Items = CreditMemoItemValues
                            qboCreditMemoLine.ClassId = New Intuit.Ipp.Data.Qbo.IdType
                            qboCreditMemoLine.ClassId.Value = row("iface_class_id")
                            CreditMemoLines.Add(qboCreditMemoLine) 'Add line to list of lines
                        Next row

                        qboCreditMemo.Line = CreditMemoLines.ToArray  'Add CreditMemo lines to CreditMemo lines property
                        resultCreditMemo = commonService.Add(qboCreditMemo)           'Add CreditMemo to request
                        Return "OK"

                        'Catch exID As Intuit.Ipp.Exception.IdsException
                        'Return exID.Message
                    Catch ex As Exception
                        Return ex.Message

                    End Try

我收到一条错误消息“内部服务器错误”。这似乎是一个 IdsException。正如我在另一篇文章中所指出的,我能够通过 Fault 和 Error 对象获取 BatchRequest 的详细信息。但是,我不明白如何使用 Dataservices 获取有关此错误的详细信息。

我认为我可能需要更好的错误处理,假设有更多信息可用于此错误。而且,我需要帮助弄清楚为什么我为发票设置的相同属性不适用于 CreditMemo。不幸的是,Intuit 网站中列出所需属性的文档不包括 CreditMemo(尽管它包括发票)。

4

3 回答 3

0

我几乎有同样的问题,问题是数量和金额不应该是负数。我在我的 creditmemoLine 上更改了它并且它有效

于 2015-10-08T11:01:50.140 回答
-1

如果您使用的是 qbo v3,您可以执行以下代码示例,

CreditMemo objInvoice = new CreditMemo();
            if (qbLog.OperationID != (int)MyEnums.QBOperations.Create)
            {
                var qboId = _iQBLogRepository.GetFromNewContext(x => (x.ReferenceID == qbLog.ReferenceID && x.ActionID == qbLog.ActionID && x.QboId != null)).QboId;
                QueryService<CreditMemo> invoiceQueryService = new QueryService<CreditMemo>(context); 
                objInvoice = invoiceQueryService.ExecuteIdsQuery("Select * From CreditMemo Where Id='" + qboId + "'", QueryOperationType.query).FirstOrDefault();
                if (qbLog.OperationID == (int)MyEnums.QBOperations.Deleted)
                {
                    commonService.Delete<CreditMemo>(objInvoice);
                    return objInvoice.Id;
                }
            }

            objInvoice.CustomerRef = new ReferenceType()
            {
                name = objCustomer.DisplayName,
                Value = objCustomer.Id
            };

            #region Account in transaction


            objInvoice.ARAccountRef = new ReferenceType()
            {
                type = Enum.GetName(typeof(objectNameEnumType), objectNameEnumType.Account),
                name = objAccount.Name,
                Value = objAccount.Id
            };
            #endregion

            #region Items in transaction
            QueryService<Item> itemQueryService = new QueryService<Item>(context);
            Item objItem = itemQueryService.ExecuteIdsQuery("Select * From Item  Where Name = '" + myname + "'", QueryOperationType.query).FirstOrDefault();

            if (objItem == null)
            {
                objItem = new Item();
                objItem.IncomeAccountRef = new ReferenceType()
                {
                    type = Enum.GetName(typeof(objectNameEnumType), objectNameEnumType.Account),
                    name = objAccount.Name,
                    Value = objAccount.Id
                };
                objItem.Name = "name";
                objItem.Description = "description";
                objItem = commonService.Add<Item>(objItem);
            }
            #endregion

            Class objClass = new Class();
            QueryService<Class> classQueryService = new QueryService<Class>(context);
            objClass = classQueryService.ExecuteIdsQuery("Select * From Class  Where Id='" + properties.QboId + "'", QueryOperationType.query).FirstOrDefault();




            #region Sales Line items
            List<Line> lineList = new List<Line>();
            Line line = new Line();
            line.Description = "description";
            line.Amount = "amount";
            line.AmountSpecified = true;
            line.DetailType = LineDetailTypeEnum.SalesItemLineDetail;
            line.AnyIntuitObject = new SalesItemLineDetail
            {
                AnyIntuitObject = _objReceivables.Amount,
                ClassRef = (objClass != null && objClass.Id != null) ? new ReferenceType
                {
                    type = Enum.GetName(typeof(objectNameEnumType), objectNameEnumType.Class),
                    name = objClass.Name,
                    Value = objClass.Id
                } : null,
                InventorySiteRef = null,
                ItemAccountRef = null,
                ItemElementName = ItemChoiceType.UnitPrice,
                ItemRef = new ReferenceType
                {
                    type = Enum.GetName(typeof(objectNameEnumType), objectNameEnumType.Item),
                    name = objItem.Name,
                    Value = objItem.Id
                },
                MarkupInfo = null,
                Qty = 1,
                QtySpecified = true,
            };
            line.Id = "1";
            line.LineEx = null;
            line.LineNum = "1";
            line.LinkedTxn = null;
            line.DetailTypeSpecified = true;
            lineList.Add(line);
            objInvoice.Line = lineList.ToArray();
            #endregion

            #region Cash Account in transaction
            QueryService<Account> accountsQueryService = new QueryService<Account>(context);
            objCashQbAccount = accountsQueryService.ExecuteIdsQuery("Select * From Account   Where Id='" + MyAccountQboId + "'", QueryOperationType.query).FirstOrDefault();
            objInvoice.DepositToAccountRef = new ReferenceType()
            {
                type = Enum.GetName(typeof(objectNameEnumType), objectNameEnumType.Account),
                name = objCashQbAccount.Name,
                Value = objCashQbAccount.Id
            };
            #endregion

            objInvoice.DueDate = DateTime.Now;
            objInvoice.DueDateSpecified = true;

            objInvoice.TxnDate =DateTime.Now;
            objInvoice.TxnDateSpecified = true;

            objInvoice.PrivateNote ="Description";

            objInvoice.GlobalTaxCalculation = GlobalTaxCalculationEnum.TaxExcluded;
            objInvoice.GlobalTaxCalculationSpecified = true;

            objInvoice.TotalAmt = _objReceivables.Amount;
            objInvoice.TotalAmtSpecified = true;

            objInvoice.ApplyTaxAfterDiscount = false;
            objInvoice.ApplyTaxAfterDiscountSpecified = true;

            objInvoice.PrintStatus = PrintStatusEnum.NotSet;
            objInvoice.PrintStatusSpecified = true;
            objInvoice.EmailStatus = EmailStatusEnum.NotSet;
            objInvoice.EmailStatusSpecified = true;

            objInvoice.Balance = "Balance amount if any"
            objInvoice.BalanceSpecified = true;

            objInvoice.Line = lineList.ToArray();

            if (qbLog.OperationID ==  (int)MyEnums.QBOperations.Create)
                objInvoice = commonService.Add<CreditMemo>(objInvoice);
            else if (qbLog.OperationID ==  (int)MyEnums.QBOperations.Update)
                commonService.Update<CreditMemo>(objInvoice);
            return objInvoice.Id;
于 2014-11-17T10:06:05.583 回答