Imports OakLeaf.MM.Main.Data Imports OakLeaf.MM.Main.Collections Imports OakLeaf.MM.Main 'Test Class for Basic Invoice Generation from NTO Charges. Does not include updates to ARTransaction Table 'table or Billing Summary. Public Class InvoiceBusiness2 Inherits ABusinessObject Dim oInvoiceLinesBusiness As InvoiceLinesBusiness Sub New() Me.TableName = "Invoice" Me.PrimaryKey = "I_Pk" Me.UpdateSelectStatement = "SELECT * FROM Invoice" Me.AutoSaveOnParentSaved = True Me.RetrieveAutoIncrementPK = True 'Link the Invoice Line table biz obj Me.oInvoiceLinesBusiness = CType(New InvoiceLinesBusiness, InvoiceLinesBusiness) Me.RegisterChildBizObj(Me.oInvoiceLinesBusiness) Me.oInvoiceLinesBusiness.RegisterParentBizObj(CType(Me, InvoiceBusiness2)) End Sub Public Function GenerateInvoicesFromNTOCharges() As Integer 'Return the number of Charges Processed 'Set so the rows in the line items are not refreshed when NewRow called 'HELPED but only the last Invoice number was used as FK for ALL invoice Lines Me.oInvoiceLinesBusiness.AutoNewOnParentAdded = False Me.oInvoiceLinesBusiness.AutoEmptyOnParentAdded = False Me.AutoIncrementCustom = True 'Default Values Dim oNTOChargesBusiness As New NTOChargeBusiness 'Get the NtoCharges Dim dsNTOCharges As DataSet = oNTOChargesBusiness.GetNtoChargesNotInvoiced 'Check if there are charges to process If dsNTOCharges.Tables("NTOCharge").Rows.Count = 0 Then Return 0 End If 'Dim dsI As DataSet for Invoice header Me.GetEmptyDataSet() 'Dim dsIL As DataSet for invoice line items Me.oInvoiceLinesBusiness.GetEmptyDataSet() ' Now loop thru the NTOCharges to build the invoices Dim dtChg As DataTable = dsNTOCharges.Tables("NTOCharge") 'Place holder to test when client changes. Trigger Invoice header. Dim iN_pk As Integer = 0 'Running Invoice Amount. Set to 0 when client changes Dim iAmount As Integer Dim drChg As DataRow ' Charges Dim drI As DataRow ' Invoice header Dim drIL As DataRow ' Invoice Line Dim i As Integer For i = 0 To dtChg.Rows.Count - 1 drChg = dtChg.Rows(i) 'NTO Charges are ordered by Client pk when client PK changes add a new Invoice header record If iN_pk <> drChg("N_Pk") Then 'Add Invoice Header Record Me.NewRow() drI = Me.DataRow drI("I_N_Name") = drChg("N_Name") drI("I_N_Addr1") = drChg("N_Addr1") drI("I_N_Addr2") = drChg("N_Addr2") 'other values updated/\/\/\/\/\/ 'Save Client PK as place holder iN_pk = drChg("N_Pk") 'Reset the Running Invoice Total amount iAmount = 0 End If 'Add Invoice Line record Me.oInvoiceLinesBusiness.NewRow() drIL = Me.oInvoiceLinesBusiness.DataRow 'Invoice line detail drIL("ILitemdesc") = drChg("ncindesc") drIL("IlIn_Pk") = drChg("NcIn_pk") drIL("IlNt_pk") = drChg("NcNt_pk") drIL("IlQty") = drChg("NcQty") drIL("IlPrice") = drChg("NcPrice") 'Other columns updated/\/\/\/\/\\/ 'Set the running invoice amount iAmount += drIL("IlQty") * drIL("IlPrice") 'Add the running total to the invoice amount and balance drI("I_Amount") = iAmount Next 'This should call the save in the child biz objects Me.SaveDataSet() Return dsNTOCharges.Tables("NTOCharge").Rows.Count End Function End Class>Terry,