如何添加发票或销售收据 Quickbooks Rest API v3.0

问题描述 投票:0回答:1

如何使用 QuickBooks API Rest v3 添加发票或销售收据?最好是在.NET 中。我之前对 v2 很感兴趣,但显然它很快就会被取代。我似乎在 .NET 中找不到任何示例代码来添加版本 3 的销售收据或发票。提供一个提供最少数据的简单示例将不胜感激。

.net rest intuit-partner-platform quickbooks-online
1个回答
4
投票

您可以尝试以下代码片段。

   public void AddInvoice()
   {
       OAuthRequestValidator reqValidator = new OAuthRequestValidator(accessToken, accessTokenSecret, consumerKey, consumerKeySecret);
       ServiceContext context = new ServiceContext(realmId, IntuitServicesType.QBO, reqValidator);

       Invoice added = Helper.Add<Invoice>(qboContextoAuth, CreateInvoice(qboContextoAuth));

   }

   internal Invoice CreateInvoice(ServiceContext context)
    {
        Customer customer = FindorAdd<Customer>(context, new Customer());
        TaxCode taxCode = FindorAdd<TaxCode>(context, new TaxCode());
        Account account = FindOrADDAccount(context, AccountTypeEnum.AccountsReceivable, AccountClassificationEnum.Liability);

        Invoice invoice = new Invoice();
        invoice.Deposit = new Decimal(0.00);
        invoice.DepositSpecified = true;
        invoice.AllowIPNPayment = false;
        invoice.AllowIPNPaymentSpecified = true;

        invoice.CustomerRef = new ReferenceType()
        {
            name = customer.DisplayName,
            Value = customer.Id
        };
        invoice.DueDate = DateTime.UtcNow.Date;
        invoice.DueDateSpecified = true;
        invoice.GlobalTaxCalculation = GlobalTaxCalculationEnum.TaxExcluded;
        invoice.GlobalTaxCalculationSpecified = true;
        invoice.TotalAmt = new Decimal(0.00);
        invoice.TotalAmtSpecified = true;
        invoice.ApplyTaxAfterDiscount = false;
        invoice.ApplyTaxAfterDiscountSpecified = true;

        invoice.PrintStatus = PrintStatusEnum.NotSet;
        invoice.PrintStatusSpecified = true;
        invoice.EmailStatus = EmailStatusEnum.NotSet;
        invoice.EmailStatusSpecified = true;
        invoice.ARAccountRef = new ReferenceType()
        {
            type = Enum.GetName(typeof(objectNameEnumType), objectNameEnumType.Account),
            name = "Account Receivable",
            Value = "QB:37"
        };
        invoice.Balance = new Decimal(0.00);
        invoice.BalanceSpecified = true;

        List<Line> lineList = new List<Line>();
        Line line = new Line();
        line.Description = "Description";
        line.Amount = new Decimal(100.00);
        line.AmountSpecified = true;

        line.DetailType = LineDetailTypeEnum.DescriptionOnly;
        line.DetailTypeSpecified = true;

        lineList.Add(line);
        invoice.Line = lineList.ToArray();
        TxnTaxDetail txnTaxDetail = new TxnTaxDetail();
        txnTaxDetail.DefaultTaxCodeRef = new ReferenceType()
        {
            Value = taxCode.Id,
            type = Enum.GetName(typeof(objectNameEnumType), objectNameEnumType.Customer),
            name = taxCode.Name
        };

        txnTaxDetail.TotalTax = new Decimal(0.00);
        txnTaxDetail.TotalTaxSpecified = true;


        return invoice;
    }

V3 发票文档参考 - https://developer.intuit.com/docs/0025_quickbooksapi/0050_data_services/v3/030_entity_services_reference/invoice 希望对您有用。

谢谢

© www.soinside.com 2019 - 2024. All rights reserved.