0

在 GP 2013 上使用 Dynamics GP Web 服务 API,如何将付款应用到销售发票?我在主题行中收到错误。这是我的代码:

        static void CreateInvoice()
    {

        CompanyKey companyKey;
        Context context;
        SalesInvoice salesInvoice;
        SalesDocumentTypeKey salesInvoiceType;
        CustomerKey customerKey;
        BatchKey batchKey;
        SalesInvoiceLine salesInvoiceLine;
        ItemKey invoiceItem;
        Quantity invoiceCount;
        Policy salesInvoiceCreatePolicy;

        // Create an instance of the service
        DynamicsGP wsDynamicsGP = new DynamicsGP();

        // Be sure the default credentials are used
        wsDynamicsGP.UseDefaultCredentials = true;

        // Create a context with which to call the service
        context = new Context();

        // Specify which company to use (sample company)
        companyKey = new CompanyKey();
        companyKey.Id = (-1);

        // Set up the context object
        context.OrganizationKey = (OrganizationKey)companyKey;

        // Create a sales invoice object
        salesInvoice = new SalesInvoice();

        // Create a sales document type key for the sales invoice
        salesInvoiceType = new SalesDocumentTypeKey();
        salesInvoiceType.Type = SalesDocumentType.Invoice;

        // Populate the document type key for the sales invoice
        salesInvoice.DocumentTypeKey = salesInvoiceType;

        // Create a customer key
        customerKey = new CustomerKey();
        customerKey.Id = "ADMINISTRATORGL";

        // Set the customer key property of the sales invoice
        salesInvoice.CustomerKey = customerKey;

        // Create a batch key
        batchKey = new BatchKey();
        batchKey.Id = "SALES INVOICES";

        // Set the batch key property of the sales invoice object
        salesInvoice.BatchKey = batchKey;

        // Create a sales invoice line to specify the invoiced item
        salesInvoiceLine = new SalesInvoiceLine();

        // Create an item key
        invoiceItem = new ItemKey();
        invoiceItem.Id = "ADI123";

        // Set the item key property of the sales invoice line object
        salesInvoiceLine.ItemKey = invoiceItem;

        // Create a sales invoice quatity object
        invoiceCount = new Quantity();
        invoiceCount.Value = 2;

        // Set the quantity of the sales invoice line object
        salesInvoiceLine.Quantity = invoiceCount;

        salesInvoiceLine.WarehouseKey = new WarehouseKey { Id = "NORTH" };


        // Create an array of sales invoice lines
        // Initialize the array with the sales invoice line object
        SalesInvoiceLine[] invoiceLines = { salesInvoiceLine };

        // Add the sales invoice line array to the sales line object
        salesInvoice.Lines = invoiceLines;

        //salesInvoice.LineTotalAmount = new MoneyAmount { Value = 399.96M };

        salesInvoice.DepositAmount = new MoneyAmount { Value = 399.96M };

        salesInvoice.PaymentAmount = new MoneyAmount { Value = 399.96M };

        // Get the create policy for the sales invoice object
        salesInvoiceCreatePolicy = wsDynamicsGP.GetPolicyByOperation("CreateSalesInvoice", context);

        // Create the sales invoice
        wsDynamicsGP.CreateSalesInvoice(salesInvoice, context, salesInvoiceCreatePolicy);
    }
4

1 回答 1

0

我必须创建一个客户并将信用额度设置为无限制。

            //assign unlimited class
        CustomerCreditLimit cc = new CustomerCreditLimit();
        cc.Item = CreditLimitSpecialAmount.UnlimitedCredit;
        customer.CreditLimit = cc;

我的博客文章有更多关于代码的细节:

http://www.jmawebtechnologies.com/company-blog/may-2013/appying-payments-to-sales-invoices-and-sales-order

于 2013-05-24T14:15:57.337 回答