0

我正在使用 Microsoft Dynamics GP 2015。我们有一个 C# .Net 项目来通过 Web 服务创建销售发票。会计有以下要求:“我们想将 {an item} 的收入编码为 GL 代码 xx-xx-xxxx。” 查看用于创建销售发票的代码,我看不到任何设置 GL 代码的地方。我建议可以在 GP 中的项目上设置 GL 代码,但被告知“查看是否可以在创建时设置分配或帐户代码”。无论如何在销售发票上设置 GL 代码?如果是这样,设置GL代码的代码是什么?

这是我正在修改的代码:

private string createGPSalesInvoice(ItemReceived itemsReceived, DateTime salesOrderDate)
    {
        CompanyKey companyKey;
        companyKey = new CompanyKey();

        Context context;
        SalesInvoice salesInvoice;
        SalesDocumentTypeKey salesInvoiceType;

        CustomerKey customerKey;
        customerKey = new CustomerKey();

        BatchKey batchKey;
        SalesInvoiceLine salesInvoiceLine;
        ItemKey invoiceItem;
        Quantity invoiceCount;

        Policy salesInvoiceCreatePolicy;
        salesInvoiceCreatePolicy = new Policy();

        string salesInvoiceNumber = "";

        try
        {
            // Create an instance of the service
            DynamicsGPClient wsDynamicsGP = new DynamicsGPClient();

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

            // Specify which company to use (sample company)

            companyKey.Id = xxx;

            // 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.Id = xxx;

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

            salesInvoice.PostedDate = parms.endDate;

            // Create a batch key
            batchKey = new BatchKey();
            batchKey.Id = xxx;

            // 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 = itemsReceived.GPPartNumber;

            // 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 = itemsReceived.Quantity;


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

            MoneyAmount unitCost = new MoneyAmount()
            {
                Value = itemsReceived.CostEach
            };

            salesInvoiceLine.UnitPrice = unitCost;

            // 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;

            try
            {
                // Get the create policy for the sales invoice object
                salesInvoiceCreatePolicy = wsDynamicsGP.GetPolicyByOperation("CreateSalesInvoice", context);
            }
            catch (Exception ex)
            {
                throw ex;
            }

            try
            {
                // Create the sales invoice
                wsDynamicsGP.CreateSalesInvoice(salesInvoice, context, salesInvoiceCreatePolicy);
            }
            catch (Exception ex)
            {
                throw ex;
            }

            //CREATE A RESTRICION OF THE BATCH ID TO FIND THE SALES DOC JUST CREATED
            LikeRestrictionOfstring batchKeyRestriction = new LikeRestrictionOfstring();
            batchKeyRestriction.EqualValue = batchKey.Id;

            //CREATE SEARCH CRITERIA
            SalesDocumentCriteria salesDocumentCriteria = new SalesDocumentCriteria();
            salesDocumentCriteria.BatchId = batchKeyRestriction;

            try
            {
                SalesDocumentSummary[] salesDocumentSummary = wsDynamicsGP.GetSalesDocumentList(salesDocumentCriteria, context);
                salesInvoiceNumber = salesDocumentSummary.FirstOrDefault().Key.Id;
            }
            catch (Exception ex)
            {
                throw ex;
            }

            // Close the service
            if (wsDynamicsGP.State != CommunicationState.Faulted)
            {
                wsDynamicsGP.Close();
            }

            return salesInvoiceNumber;
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
4

0 回答 0