|
Create Invoice from Estimate |
Top Previous Next |
|
[Visual Basic] The following example demonstrates how to create and save a new Customer Invoice document from an existing Estimate document. (This example uses the CustomerInvoiceWebService.)
' ---------------------------------------- ' Step 1: Create an instance of the web service. ' ---------------------------------------- Dim estimateWs 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(estimateWs, PublicLoginKey)
' ---------------------------------------- ' Step 3: Populate a DataSet with the existing (copy from) document. ' For this example, we're retrieving an Estimate document, so we ' will use the ObjAcct.WebServices.DataSets.EstimateDataSet. ' ---------------------------------------- Dim estimateDs As DataSet = New WebServices.DataSets.EstimateDataSet() Dim docID As String = "EST5000"
' Retrieve the Estimate document. estimateDs = estimateWs.GetDocumentByDocumentID(docID, "", StdLib.DOCUMENT_Type_ESTIMATE, "", ReturnTypeEnum.Standard)
' Check for errors. If StdLib.GetErrorNumber(estimateDs) < 0 Then MsgBox(StdLib.GetErrorAsString(estimateDs)) Else ' ---------------------------------------- ' Step 4: Create an instance of the web service. ' ---------------------------------------- Dim invoiceWs As New WebServices.CustomerInvoiceWebService("http://localhost/objacctwebservices/")
' ---------------------------------------- ' Step 5: 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 6: Create and populate a DataSet with the new (copy to) 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("ReverseDocRowID") = estimateDs.Tables("Header").Rows(0).Item("RowID").ToString.Trim headerDr("AccountRowID") = "2.0" headerDr("BillToAddressRowID") = estimateDs.Tables("Header").Rows(0).Item("BillToAddressRowID") headerDr("ClassRowID") = estimateDs.Tables("Header").Rows(0).Item("ClassRowID") headerDr("CustomerRowID") = estimateDs.Tables("Header").Rows(0).Item("CustomerRowID") headerDr("DocDate") = Today.ToShortDateString headerDr("DocID") = "ESTIN5000" headerDr("EnteredDate") = Today.ToShortDateString headerDr("EntityDocDate") = Today.ToShortDateString ' Invoice Date. headerDr("JobRowID") = estimateDs.Tables("Header").Rows(0).Item("JobRowID") headerDr("JournalDocTypeRowID") = StdLib.DOCUMENT_Type_CUSTOMER_INVOICE headerDr("ShipToAddressRowID") = estimateDs.Tables("Header").Rows(0).Item("ShipToAddressRowID") headerDr("TermsRowID") = "4.0" headerDr("ToBePrinted") = 1
' Add the row to the Header table. invoiceDs.Tables("Header").Rows.Add(headerDr)
' ------------------- ' Transaction. ' ------------------- Dim invoiceTransDr As DataRow Dim estimateTransDr As DataRow
Dim i As Integer
For Each estimateTransDr In estimateDs.Tables("Transaction").Rows
invoiceTransDr = invoiceDs.Tables("Transaction").NewRow() invoiceTransDr("RowID") = StdLib.DOCUMENT_TEMP_ROWID_PREFIX & CStr(i)
' Populate the Customer Invoice transaction rows from the Customer Estimate transaction rows. invoiceTransDr("ClassRowID") = estimateTransDr("ClassRowID") invoiceTransDr("Description") = estimateTransDr("Description") invoiceTransDr("DisplayOrder") = estimateTransDr("DisplayOrder") invoiceTransDr("ItemRowID") = estimateTransDr("ItemRowID") invoiceTransDr("JobRowID") = estimateTransDr("JobRowID") invoiceTransDr("JobTaskRowID") = estimateTransDr("JobTaskRowID") invoiceTransDr("Quantity") = estimateTransDr("Quantity") invoiceTransDr("TransactionAmount") = estimateTransDr("TransactionAmount") invoiceTransDr("UnitRate") = estimateTransDr("UnitRate") invoiceTransDr("UnitRowID") = estimateTransDr("UnitRowID")
' Set the XRefJournalTranRowID to the RowID on the Customer Estimate transaction. invoiceTransDr("XRefJournalTranRowID") = estimateTransDr("RowID")
i += 1
' Add the row to the Transaction table. invoiceDs.Tables("Transaction").Rows.Add(invoiceTransDr)
Next
' ---------------------------------------- ' Step 7: Save the Customer Invoice (copy to) document. ' ---------------------------------------- Dim returnDs As DataSet = invoiceWs.SaveDocument(invoiceDs, CustomerInvoiceSaveType.ConvertEstimateToInvoice)
' Check for errors. If StdLib.GetErrorNumber(returnDs) < 0 Then MsgBox(StdLib.GetErrorAsString(returnDs)) End If End If |