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