Quantcast
Channel: Microsoft Dynamics GP
Viewing all articles
Browse latest Browse all 59474

Forum Post: RE: Sales Invoice Unit Pricing

$
0
0

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

       }


Viewing all articles
Browse latest Browse all 59474

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>