|
Create Invoice from Time & Expense |
Top Previous Next |
|
[Visual Basic] The following example demonstrates how to create and save a new Customer Invoice document from existing Time and Expense transactions. (This example uses the CustomerInvoiceWebService and the TimeEntryWebService.)
' ---------------------------------------- ' Step 1: Create an instance of the web service. ' ---------------------------------------- Dim billableTimeListWs 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(billableTimeListWs, PublicLoginKey)
' ---------------------------------------- ' Step 3: Populate a DataSet with the existing (copy from) transactions list. ' For this example, we're retrieving a list of billable Time and Expense ' transactions for a specific Customer. ' ---------------------------------------- Dim billableTimeListDs As DataSet Dim customerRowID As String = "4.0"
' Retrieve the billable Time and Expense transactions list. billableTimeListDs = billableTimeListWs.GetBillableTransactionList(customerRowID, "", "DocDate", ReturnTypeEnum.Standard)
' Check for errors. If StdLib.GetErrorNumber(billableTimeListDs) < 0 Then MsgBox(StdLib.GetErrorAsString(billableTimeListDs)) Else ' ---------------------------------------- ' Step 4: Add a 'Use' column to billableTimeListDs and select the applicable Time and ' Expense transactions that will be used to create the Customer Invoice document. ' ---------------------------------------- StdLib.AddColumn(billableTimeListDs.Tables("List"), "Use", StdLib.DATA_Type_INT16, True)
Dim billableTimeListDr As DataRow
' Select only those Time and Expense transactions billable to a specific Job. For Each billableTimeListDr In billableTimeListDs.Tables("List").Rows If billableTimeListDr("JobRowID") = "43.0" Then billableTimeListDr("Use") = 1 End If Next
billableTimeListDs.AcceptChanges()
' ---------------------------------------- ' Step 5: Create an instance of the web service. ' ---------------------------------------- Dim timeEntryWs As New WebServices.TimeEntryWebService("http://localhost/objacctwebservices/")
' ---------------------------------------- ' Step 6: 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(timeEntryWs, PublicLoginKey)
' ---------------------------------------- ' Step 7: Create and populate a DataSet with the selected Time and ' Expense transactions that will be saved with a billed status. ' ---------------------------------------- Dim timeEntryDs As DataSet
Dim billableTimeDr As DataRow Dim timeEntryDr As DataRow
' Add the List Table to the DataSet. timeEntryDs.Tables.Add("List") timeEntryDs.Tables("List").Columns.Add("RowID", Type.GetType("System.String")) timeEntryDs.AcceptChanges()
For Each billableTimeDr In billableTimeListDs.Tables("List").Rows
If billableTimeDr("Use") = 1 Then timeEntryDr = timeEntryDs.Tables("List").NewRow() timeEntryDr("RowID") = billableTimeDr("RowID")
' Add the row to the List table. timeEntryDs.Tables("List").Rows.Add(timeEntryDr) End If
Next
timeEntryDs.AcceptChanges()
' ---------------------------------------- ' Step 8: Save the billed Time and Expense transactions. ' ---------------------------------------- Dim returnDs As DataSet = timeEntryWs.SaveBilledTransactions(timeEntryDs)
' Check for errors. If StdLib.GetErrorNumber(returnDs) < 0 Then MsgBox(StdLib.GetErrorAsString(returnDs)) Else ' ---------------------------------------- ' Step 9: Create an instance of the web service. ' ---------------------------------------- Dim invoiceWs As New WebServices.CustomerInvoiceWebService("http://localhost/objacctwebservices/")
' ---------------------------------------- ' Step 10: 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 11: 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("AccountRowID") = "2.0" headerDr("BillToAddressRowID") = "2.0" headerDr("ClassRowID") = "11.0" headerDr("CustomerRowID") = "4.0" headerDr("DocDate") = Today.ToShortDateString headerDr("DocID") = "TMIN5000" 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 itemDr As DataRow Dim timeListDr As DataRow Dim transDr As DataRow
Dim i As Integer
For Each timeListDr In billableTimeListDs.Tables("List").Rows
If timeListDr("Use") = 1 Then transDr = invoiceDs.Tables("Transaction").NewRow
transDr("RowID") = StdLib.GetTempRowID & CStr(i)
' Expenses. If timeListDr("GroupType") = "E" Then If COMPANYSETUP("UseReimbursableExpenseItemAccount") = 1 And timeListDr("GroupType") = "E" Then transDr("AccountRowID") = timeListDr("AccountRowID") End If Else transDr("AccountRowID") = timeListDr("AccountRowID") End If
transDr("ClassRowID") = timeListDr("ClassRowID") transDr("Description") = timeListDr("ItemDescription") transDr("DescriptionLine") = 0
If timeListDr("ItemRowID") = "" And timeListDr("GroupType") = "E" Then transDr("ItemRowID") = COMPANYSETUP("ReimbursableExpenseItemRowID") Else transDr("ItemRowID") = timeListDr("ItemRowID") End If
transDr("JobRowID") = timeListDr("JobRowID") transDr("JobTaskRowID") = timeListDr("JobTaskRowID") transDr("Quantity") = timeListDr("Quantity") transDr("Taxable") = 0 transDr("UnitRowID") = timeListDr("UnitRowID")
' Locate the Item in ITEM_DATASET. itemDr = ITEM_DATASET.Tables(0).Rows.Find(transDr("ItemRowID")) If Not itemDr Is Nothing Then transDr("UnitRate") = itemDr("UnitPrice") Else transDr("UnitRate") = 0 End If
' Expenses. If timeListDr("GroupType") = "E" Then transDr("TransactionAmount") = timeListDr("TransactionAmount")
' Items. ElseIf timeListDr("GroupType") = "I" Then If transDr("UnitPrice") > 0 Then transDr("TransactionAmount") = transDr("Quantity") * transDr("UnitRate") Else transDr("TransactionAmount") = timeListDr("TransactionAmount") End If
' Time. ElseIf timeListDr("GroupType") = "T" Then If transDr("UnitPrice") > 0 Then transDr("TransactionAmount") = transDr("Quantity") * transDr("UnitRate") Else transDr("TransactionAmount") = timeListDr("TransactionAmount") End If End If
i += 1 transDr("DisplayOrder") = i
' Add the row to the Transaction table. invoiceDs.Tables("Transaction").Rows.Add(transDr) End If Next
invoiceDs.AcceptChanges()
' ---------------------------------------- ' Step 12: Save the Customer Invoice (copy to) document. ' ---------------------------------------- Dim saveReturnDs As DataSet = invoiceWs.SaveDocument(invoiceDs, CustomerInvoiceSaveType.StandardSave)
' Check for errors. If StdLib.GetErrorNumber(saveReturnDs) < 0 Then MsgBox(StdLib.GetErrorAsString(saveReturnDs)) End If End If End If |