How To Add Purchase Order In Quickbook Desktop Using C#

Introduction

In this article, we will learn how to create a purchase order in Quickbook Desktop using C#.

If you have not seen Quickbook Desktop Installation then I recommend to see that first. in that article here.

First of all Install the Interop.QBFC13 package in your project.

Install Package

Right click of your project and select Manage Nuget Packages.

After search Interop.QBFC13 and install it.

The code is as below.

Create Item 

//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 Purchase Order

public void AddPurchaseOrder()
       {

           try
           {
               QBSessionManager sessionManager = new QBSessionManager();
               sessionManager.OpenConnection(@"Your Company File Path", "POAdd C# sample");
               sessionManager.BeginSession("", ENOpenMode.omDontCare);
               IMsgSetRequest requestSet = sessionManager.CreateMsgSetRequest("US", 13, 0);
               requestSet.Attributes.OnError = ENRqOnError.roeStop;
               IMsgSetResponse responseSet;
               IResponse response;
               responseSet = sessionManager.DoRequests(requestSet);
               DateTime duedate;
               duedate = DateTime.MinValue;
               string vendorName = "Sagar Rana";

               //create vendor
               IVendorAdd newVendor = requestSet.AppendVendorAddRq();
               newVendor.Name.SetValue(vendorName);
               responseSet = sessionManager.DoRequests(requestSet);
               requestSet.ClearRequests();


               //create purchase order
               IPurchaseOrderAdd PurchaseOrderAdd = requestSet.AppendPurchaseOrderAddRq();
               PurchaseOrderAdd.VendorRef.FullName.SetValue(vendorName);
               PurchaseOrderAdd.ORInventorySiteORShipToEntity.ShipToEntityRef.FullName.SetValue("sagar rana");//existing customer name
               PurchaseOrderAdd.TxnDate.SetValue(DateTime.Now);
               PurchaseOrderAdd.Other1.SetValue("31");
               PurchaseOrderAdd.TemplateRef.FullName.SetValue("Custom Purchase Order");

               //purchase order Item
               IORPurchaseOrderLineAdd PurchaseOrderLineAdd = PurchaseOrderAdd.ORPurchaseOrderLineAddList.Append();
               PurchaseOrderLineAdd.PurchaseOrderLineAdd.Other1.SetValue("");
               PurchaseOrderLineAdd.PurchaseOrderLineAdd.ItemRef.FullName.SetValue("Computer");//existing item name
               PurchaseOrderLineAdd.PurchaseOrderLineAdd.Quantity.SetValue(1);
               PurchaseOrderLineAdd.PurchaseOrderLineAdd.Desc.SetValue("");
               PurchaseOrderLineAdd.PurchaseOrderLineAdd.Rate.SetValue(1500);
               PurchaseOrderLineAdd.PurchaseOrderLineAdd.CustomerRef.FullName.SetValue("sagar rana");//existing customer name
               responseSet = sessionManager.DoRequests(requestSet);
               response = responseSet.ResponseList.GetAt(0);
               sessionManager.CloseConnection();
               sessionManager.EndSession();
               MessageBox.Show("New PurchaseOrder Import Successfully.");
           }
           catch (Exception ex)
           {

               MessageBox.Show(ex.Message);
           }
       }

If you have any questions about this article, please let me know and more information here.

Submit a Comment

Your email address will not be published. Required fields are marked *

Subscribe

Select Categories