Create Invoice

Top  Previous  Next

[Visual Basic] The following example demonstrates how to create and save a new Customer Invoice document. (This example uses the CustomerInvoiceWebService.)

 

' ----------------------------------------

' Step 1: Create an instance of the web service.

' ----------------------------------------

Dim invoiceWs As New WebServices.CustomerInvoiceWebService("http://localhost/objacctwebservices/")

 

' ----------------------------------------

' Step 2: Set the LoginKey. (Use Login.GetLoginKey to

' login to a specific company and generate a LoginKey.)

' For this example, the LoginKey is being stored in a 

' public variable called PublicLoginKey.

' ----------------------------------------

StdLib.PopulateObjAcctSoapHeader(invoiceWs, PublicLoginKey)

 

' ----------------------------------------

' Step 3: Create and populate a DataSet with the new document.

' For this example, we're creating a new Customer Invoice document, so

' we will use the ObjAcct.WebServices.DataSets.CustomerInvoiceDataSet.

' ----------------------------------------

Dim invoiceDs As DataSet = New WebServices.DataSets.CustomerInvoiceDataSet()

 

' -------------------

' Document Header.

' -------------------

Dim headerDr As DataRow = invoiceDs.Tables("Header").NewRow

 

headerDr("RowID") = ""

headerDr("AccountRowID") = "2.0"

headerDr("BillToAddressRowID") = "2.0"

headerDr("ClassRowID") = "11.0" 

headerDr("CustomerRowID") = "2.0"

headerDr("DocDate") = Today.ToShortDateString

headerDr("DocID") = "IN5000"

headerDr("EnteredDate") = Today.ToShortDateString

headerDr("EntityDocDate") = Today.ToShortDateString        ' Invoice Date.

headerDr("JournalDocTypeRowID") = StdLib.DOCUMENT_Type_CUSTOMER_INVOICE

headerDr("SalesPersonRowID") = "2.0"

headerDr("SalesTaxRowID") = "3.0"

headerDr("ShippingMethodRowID") = "1.0"

headerDr("ShipToAddressRowID") = "1721.0"

headerDr("TermsRowID") = "4.0"

headerDr("ToBePrinted") = 1

 

' Add the row to the Header table.

invoiceDs.Tables("Header").Rows.Add(headerDr)

 

' -------------------

' Transaction.

' -------------------

Dim transDr As DataRow

 

transDr = invoiceDs.Tables("Transaction").NewRow

 

transDr("RowID") = ""

transDr("ClassRowID") = "17.0"

transDr("Description") = "Accounting Software"

transDr("DisplayOrder") = 1

transDr("ItemRowID") = "4.0"

transDr("Quantity") = 5

transDr("Taxable") = 1

transDr("TransactionAmount") = 2500

transDr("UnitRate") = 500

transDr("UnitRowID") = "2.0"

 

' Add the row to the Transaction table.

invoiceDs.Tables("Transaction").Rows.Add(transDr)

 

transDr = invoiceDs.Tables("Transaction").NewRow

 

transDr("RowID") = ""

transDr("ClassRowID") = "5.0"

transDr("Description") = "Brochure"

transDr("DisplayOrder") = 2

transDr("ItemRowID") = "55.0"

transDr("Quantity") = 5

transDr("Taxable") = 1

transDr("TransactionAmount") = 25

transDr("UnitRate") = 5

transDr("UnitRowID") = "2.0"

 

' Add the row to the Transaction table.

invoiceDs.Tables("Transaction").Rows.Add(transDr)

 

transDr = invoiceDs.Tables("Transaction").NewRow

 

transDr("RowID") = ""

transDr("ClassRowID") = "2.0"

transDr("Description") = "User Training"

transDr("DisplayOrder") = 3

transDr("ItemRowID") = "5.0"

transDr("Quantity") = 2

transDr("Taxable") = 0

transDr("TransactionAmount") = 300

transDr("UnitRate") = 150.00

 

' Add the row to the Transaction table.

invoiceDs.Tables("Transaction").Rows.Add(transDr)

 

' ----------------------------------------

' Step 4: Save the document.

' ----------------------------------------

Dim returnDs As DataSet = invoiceWs.SaveDocument(invoiceDs, CustomerInvoiceSaveType.StandardSave)

 

' Check for errors.

If StdLib.GetErrorNumber(returnDs) < 0 Then

       MsgBox(StdLib.GetErrorAsString(returnDs))

End If