尝试使用IPP.NET插入QBO Credit Memo

时间:2013-02-28 18:05:12

标签: intuit-partner-platform quickbooks-online

我正在使用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(尽管它包含发票)。

3 个答案:

答案 0 :(得分:4)

答案 1 :(得分:0)

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

答案 2 :(得分:-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;