Hi,
I am using the Web Service API to create a Sales Invoice. For some reason, my unit cost is $750 and my extended price is the same. The correct price is $1500. Where is this $750 coming from?
*This post is locked for comments
Hi,
I am using the Web Service API to create a Sales Invoice. For some reason, my unit cost is $750 and my extended price is the same. The correct price is $1500. Where is this $750 coming from?
*This post is locked for comments
Here is my code:
public void CreateSalesInvoice(JMAOrder ord, string batchK, string customerID)
{
SalesInvoice salesInvoice;
SalesDocumentTypeKey salesInvoiceType;
CustomerKey customerKey;
BatchKey batchKey;
SalesInvoiceLine salesInvoiceLine;
ItemKey invoiceItem;
Quantity invoiceCount;
// 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;
GPCustomers gp = new GPCustomers(wsDynamicsGP, context);
customerKey = gp.CreateGPCustomer(ord, customerID);
// Set the customer key property of the sales order object
salesInvoice.CustomerKey = customerKey;
// Create a batch key
batchKey = new BatchKey();
batchKey.Id = batchK;
// Set the batch key property of the sales invoice object
salesInvoice.BatchKey = batchKey;
List<SalesInvoiceLine> soLines = new List<SalesInvoiceLine>();
foreach (JMAOrderDetail jd in ord.OrderDetails)
{
GPItems gpi = new GPItems(wsDynamicsGP, jma, context, errorMessageDataSource);
ItemKey ik = gpi.CreateInventoryItem(jd.Product);
// Create a sales order line to specify the ordered item
salesInvoiceLine = new SalesInvoiceLine();
// Set the item key property of the sales order line object
salesInvoiceLine.ItemKey = ik;
//salesInvoiceLine.UnitPrice = new MoneyAmount { Value = jd.PriceExclTax };
//salesInvoiceLine.ExtendedCost = new MoneyAmount { Value = jd.PriceExclTax };
salesInvoiceLine.IsNonInventory = false;
salesInvoiceLine.UnitCost = null;
salesInvoiceLine.WarehouseKey = new WarehouseKey { Id = jma.MSDynamicsGPDefaultWarehouse };
// Create a sales order quantity object
invoiceCount = new Quantity();
invoiceCount.Value = jd.Quantity;
// Set the quantity of the sales order line object
salesInvoiceLine.Quantity = invoiceCount;
soLines.Add(salesInvoiceLine);
}
// Add the sales invoice line array to the sales line object
salesInvoice.Lines = soLines.ToArray();
List<SalesPayment> payments = new List<SalesPayment>();
SalesPayment sp = new SalesPayment();
sp.PaymentAmount = new MoneyAmount { Value = ord.Total };
//- Invalid PaymentType. 4=Cash Payment, 5=Check Payment, or 6=Credit Card Payment are valid values.
sp.Type = SalesPaymentType.PaymentCardPayment;
sp.Date = DateTime.Now;
PaymentCardType[] cList = wsDynamicsGP.GetPaymentCardTypeList(new PaymentCardTypeCriteria(), context);
sp.PaymentCardTypeKey = cList.FirstOrDefault().Key;
payments.Add(sp);
salesInvoice.Payments = payments.ToArray();
// Get the create policy for the sales invoice object
salesInvoiceCreatePolicy = wsDynamicsGP.GetPolicyByOperation("CreateSalesInvoice", context);
// Create the sales invoice
wsDynamicsGP.CreateSalesInvoice(salesInvoice, context, salesInvoiceCreatePolicy);
}
André Arnaud de Cal...
292,516
Super User 2025 Season 1
Martin Dráb
231,409
Most Valuable Professional
nmaenpaa
101,156