Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics GP (Archived)

Tax on line items

Posted on by 285

Hi, I want to insert the tax for individuql line item in invoice through GP web service.

I used the following code  :

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

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

                wsDynamicsGP.UseDefaultCredentials = true;
                // Create a context with which to call the web 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;
                context.CultureName = "en-US";

                // 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 sales document key for the sales invoice
                salesInvoice.Key = new SalesDocumentKey();
                salesInvoice.Key.Id = "XX55";

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

                // 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 a key on the invoice line to reference in the tax information
                salesInvoiceLine.Key = new SalesLineKey();
                salesInvoiceLine.Key.LineSequenceNumber = 16384;

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

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

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

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

                // Create a sales invoice unit price object
                invoicePrice = new MoneyAmount();
                invoicePrice.Value = 39.95M;
                invoicePrice.Currency = "USD";

                // Set the unit price of the sales invoice line object
                salesInvoiceLine.UnitPrice = invoicePrice;

                // Create a sales invoice extended price object
                invoiceExtended = new MoneyAmount();
                invoiceExtended.Value = 79.90M;
                invoiceExtended.Currency = "USD";

                // Set the extended price of the sales invoice line object
                salesInvoiceLine.TotalAmount = invoiceExtended;

              
           

                // Set the tax information on the line
                salesInvoiceLine.TaxScheduleKey = new TaxScheduleKey();
                salesInvoiceLine.TaxScheduleKey.Id = "TAXSC1";
                salesInvoiceLine.TaxAmount = new MoneyAmount();
                salesInvoiceLine.TaxAmount.Value = 6.60M;
                salesInvoiceLine.TaxAmount.Currency = "USD";

                // Create the tax detail information
                SalesLineTax lineTax1 = new SalesLineTax();
                lineTax1.Key = new SalesLineTaxKey();
                lineTax1.Key.SalesLineKey = salesInvoiceLine.Key;
                lineTax1.Key.TaxDetailKey = new TaxDetailKey();
                lineTax1.Key.TaxDetailKey.Id = "TAXCODE1";
                lineTax1.TotalAmount = new MoneyAmount();
                lineTax1.TotalAmount.Value = 79.90M;
                lineTax1.TotalAmount.Currency = "USD";
                lineTax1.TaxableAmount = new MoneyAmount();
                lineTax1.TaxableAmount.Value = 79.90M;
                lineTax1.TaxableAmount.Currency = "USD";
                lineTax1.TaxAmount = new MoneyAmount();
                lineTax1.TaxAmount.Value = 6.60M;
                lineTax1.TaxAmount.Currency = "USD";

                //SalesLineTax lineTax2 = new SalesLineTax();
                //lineTax2.Key = new SalesLineTaxKey();
                //lineTax2.Key.SalesLineKey = salesInvoiceLine.Key;
                //lineTax2.Key.TaxDetailKey = new TaxDetailKey();
                //lineTax2.Key.TaxDetailKey.Id = "TAXCODE1";
                //lineTax2.TotalAmount = new MoneyAmount();
                //lineTax2.TotalAmount.Value = 79.90M;
                //lineTax2.TotalAmount.Currency = "USD";
                //lineTax2.TaxableAmount = new MoneyAmount();
                //lineTax2.TaxableAmount.Value = 79.90M;
                //lineTax2.TaxableAmount.Currency = "USD";
                //lineTax2.TaxAmount = new MoneyAmount();
                //lineTax2.TaxAmount.Value = 0.80M;
                //lineTax2.TaxAmount.Currency = "USD";

                // Create an array of sales line taxes and populate with the detail objects
                //SalesLineTax[] lineTaxes = new SalesLineTax[2];
                SalesLineTax[] lineTaxes = new SalesLineTax[1];
                lineTaxes[0] = lineTax1;
                //lineTaxes[1] = lineTax2;

                // Set the line item's taxes object to the line taxes array
                salesInvoiceLine.Taxes = lineTaxes;

                // 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.Date = DateTime.Now.Date;
                // Get the create policy for the sales invoice object
                salesInvoiceCreatePolicy = wsDynamicsGP.GetPolicyByOperation("CreateSalesInvoice", context);

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

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

                //// Create the sales invoice
                //wsDynamicsGP.UpdateSalesInvoice(salesInvoice, context, salesInvoiceCreatePolicy);

 

After running the code,

 Tax amount is displayed  in calculated tax textbox in item details window and taxschedule id in shiptoTaxSchedule textbox

But no tax code populated in teh item details window.

So, tax is not calculated in the Tax textbox in the bottom fields .

Please help me.

 

Thanks.

 

*This post is locked for comments

  • nitin kumar Profile Picture
    nitin kumar 285 on at
    Re: Tax on line items

    gf

  • Suggested answer
    nitin kumar Profile Picture
    nitin kumar 285 on at
    Re: Tax on line items

    gh

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans