Introduction
In this article, we will learn how to add sales orders in Quickbook Desktop using c#.
If you have not seen Quickbook Desktop Installation then I recommend seeing that first. in that article here.
A sales order is used to record a sale. It helps track items.
First of all Install the Interop.QBFC13 package in your project.
Install Package
Right click on your project and select Manage Nuget Packages.
After search Interop.QBFC13 and install it.
The code is as below.
private void CreateSalesOrder(object sender, EventArgs e) { try { string customerName = "Sagar Rana"; string itemName = "Computer"; double itemAmount = 1500; QBSessionManager sessionManager = new QBSessionManager(); IMsgSetRequest requestSet = sessionManager.CreateMsgSetRequest("US", 13, 0); requestSet.Attributes.OnError = ENRqOnError.roeStop; sessionManager.OpenConnection(@"Your Company File Path", "Quickbook Desktop Example"); sessionManager.BeginSession("", ENOpenMode.omDontCare); IMsgSetResponse responseSet; //create customer ICustomerAdd newcustomer = requestSet.AppendCustomerAddRq(); newcustomer.Name.SetValue(customerName); responseSet = sessionManager.DoRequests(requestSet); requestSet.ClearRequests(); //create item IItemNonInventoryAdd newitem = requestSet.AppendItemNonInventoryAddRq(); newitem.Name.SetValue(itemName); newitem.ORSalesPurchase.SalesAndPurchase.Type.Equals("Non-inventory Part"); newitem.ORSalesPurchase.SalesAndPurchase.PurchaseDesc.SetValue(""); newitem.ORSalesPurchase.SalesAndPurchase.SalesDesc.SetValue(""); newitem.ORSalesPurchase.SalesAndPurchase.PurchaseCost.SetValue(itemAmount); newitem.ORSalesPurchase.SalesAndPurchase.SalesPrice.SetValue(itemAmount); newitem.ORSalesPurchase.SalesAndPurchase.IncomeAccountRef.FullName.SetValue("Payroll Liabilities"); newitem.ORSalesPurchase.SalesAndPurchase.ExpenseAccountRef.FullName.SetValue("Payroll Liabilities"); responseSet = sessionManager.DoRequests(requestSet); requestSet.ClearRequests(); //create sales order ISalesOrderAdd SalesOrderAdd = requestSet.AppendSalesOrderAddRq(); SalesOrderAdd.CustomerRef.FullName.SetValue(customerName); IORSalesOrderLineAdd SalesOrderLineAdd = SalesOrderAdd.ORSalesOrderLineAddList.Append(); SalesOrderLineAdd.SalesOrderLineAdd.ItemRef.FullName.SetValue(itemName); SalesOrderLineAdd.SalesOrderLineAdd.Amount.SetValue(itemAmount); responseSet = sessionManager.DoRequests(requestSet); IResponse response = responseSet.ResponseList.GetAt(0); MessageBox.Show("Sales Order successfully created."); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
If you have any questions about this article, please let me know and more information here.