diff --git a/app/controllers/HouseholdController.asp b/app/controllers/HouseholdController.asp new file mode 100644 index 0000000..b0900a2 --- /dev/null +++ b/app/controllers/HouseholdController.asp @@ -0,0 +1,397 @@ +<% +' HouseholdController - CRUD controller for Households +' NorthTerritory app +' +' Dependencies: +' - app/models/POBO_Households.asp +' - app/models/HouseholdsRepository.asp +' - app/models/POBO_HouseholderNames.asp +' - app/models/HouseholderNamesRepository.asp +%> + + + + +<% + +Class HouseholdController_Class + Private m_useLayout + Private m_title + + ' Public properties for views + Public households ' LinkedList for Index + Public household ' Single POBO for Show/Edit + Public territoriesList ' For dropdown + Public territoryNamesById ' Dictionary for territory labels + Public householderNames ' LinkedList for Show + + ' Pagination properties + Public currentPage + Public pageCount + Public recordCount + Public perPage + Public searchTerm + Public filterTerritoryId + Public filterDoNotCall + + Private Sub Class_Initialize() + m_useLayout = True + m_title = "Households" + currentPage = 1 + pageCount = 0 + recordCount = 0 + perPage = 25 + searchTerm = "" + filterTerritoryId = 0 + filterDoNotCall = -1 + End Sub + + Public Property Get useLayout + useLayout = m_useLayout + End Property + + Public Property Let useLayout(v) + m_useLayout = v + End Property + + Public Property Get Title + Title = m_title + End Property + + Public Property Let Title(v) + m_title = v + End Property + + '------------------------------------------------------------------------------------------------------------------- + ' Index - List all households with pagination, search, and territory filter + '------------------------------------------------------------------------------------------------------------------- + Public Sub Index() + ' Get pagination params + If Request.QueryString("page") <> "" And IsNumeric(Request.QueryString("page")) Then + currentPage = CInt(Request.QueryString("page")) + If currentPage < 1 Then currentPage = 1 + End If + + ' Get search param + searchTerm = Trim(Request.QueryString("q") & "") + + ' Get territory filter + If Request.QueryString("territory") <> "" And IsNumeric(Request.QueryString("territory")) Then + filterTerritoryId = CInt(Request.QueryString("territory")) + End If + + If Request.QueryString("dnc") <> "" Then + If Request.QueryString("dnc") = "1" Then + filterDoNotCall = 1 + ElseIf Request.QueryString("dnc") = "0" Then + filterDoNotCall = 0 + End If + End If + + ' Load territories for filter dropdown + Set territoriesList = TerritoriesRepository.GetAll(Empty) + Set territoryNamesById = BuildTerritoryNamesById(territoriesList) + + ' Fetch households with pagination + If searchTerm <> "" And filterDoNotCall <> -1 Then + Set households = HouseholdsRepository.SearchTablePagedByDoNotCall( _ + Array("Address", "StreetName"), _ + searchTerm, _ + filterDoNotCall, _ + Empty, _ + perPage, _ + currentPage, _ + pageCount, _ + recordCount _ + ) + ElseIf searchTerm <> "" Then + ' Search in Address and StreetName columns + Set households = HouseholdsRepository.SearchTablePaged( _ + Array("Address", "StreetName"), _ + searchTerm, _ + Empty, _ + perPage, _ + currentPage, _ + pageCount, _ + recordCount _ + ) + ElseIf filterTerritoryId > 0 And filterDoNotCall <> -1 Then + Set households = HouseholdsRepository.FindPagedByTerritoryAndDoNotCall( _ + filterTerritoryId, _ + filterDoNotCall, _ + Empty, _ + perPage, _ + currentPage, _ + pageCount, _ + recordCount _ + ) + ElseIf filterTerritoryId > 0 Then + ' Filter by territory + Set households = HouseholdsRepository.FindPaged( _ + Array("TerritoryId", filterTerritoryId), _ + Empty, _ + perPage, _ + currentPage, _ + pageCount, _ + recordCount _ + ) + ElseIf filterDoNotCall <> -1 Then + Set households = HouseholdsRepository.FindPaged( _ + Array("DoNotCall", filterDoNotCall), _ + Empty, _ + perPage, _ + currentPage, _ + pageCount, _ + recordCount _ + ) + Else + Set households = HouseholdsRepository.FindPaged( _ + Empty, _ + Empty, _ + perPage, _ + currentPage, _ + pageCount, _ + recordCount _ + ) + End If + + %> <% + End Sub + + '------------------------------------------------------------------------------------------------------------------- + ' Show - Display a single household + '------------------------------------------------------------------------------------------------------------------- + Public Sub Show(id) + On Error Resume Next + Set household = HouseholdsRepository.FindByID(id) + If Err.Number <> 0 Or household Is Nothing Then + On Error GoTo 0 + Flash().AddError "Household not found." + Response.Redirect "/households" + Exit Sub + End If + On Error GoTo 0 + + ' Load householder names for this household + Set householderNames = HouseholderNamesRepository.Find( _ + Array("HouseholdId", id), _ + "Name" _ + ) + + %> <% + End Sub + + '------------------------------------------------------------------------------------------------------------------- + ' MarkReturned - Quick action to mark a householder name as returned + '------------------------------------------------------------------------------------------------------------------- + Public Sub MarkReturned(id) + Dim householderId, hn, householdId + householderId = Request.Form("householder_id") + + If householderId = "" Or Not IsNumeric(householderId) Then + Flash().Error = "Invalid householder ID." + Response.Redirect "/households/" & id + Exit Sub + End If + + On Error Resume Next + Set hn = HouseholderNamesRepository.FindByID(CLng(householderId)) + If Err.Number <> 0 Or hn Is Nothing Then + On Error GoTo 0 + Flash().Error = "Householder name not found." + Response.Redirect "/households/" & id + Exit Sub + End If + On Error GoTo 0 + + ' Toggle the returned status + If hn.LetterReturned = 1 Then + hn.LetterReturned = 0 + hn.ReturnDate = #1/1/1970# + Else + hn.LetterReturned = 1 + hn.ReturnDate = Now() + End If + + HouseholderNamesRepository.Update hn + + If hn.LetterReturned = 1 Then + Flash().Success = "Marked as returned." + Else + Flash().Success = "Marked as not returned." + End If + Response.Redirect "/households/" & id + End Sub + + '------------------------------------------------------------------------------------------------------------------- + ' Create - Display form for new household + '------------------------------------------------------------------------------------------------------------------- + Public Sub Create() + Set household = New POBO_Households + + ' Pre-fill territory if passed in query string + If Request.QueryString("territory") <> "" And IsNumeric(Request.QueryString("territory")) Then + household.TerritoryId = CInt(Request.QueryString("territory")) + End If + + ' Load territories for dropdown + Set territoriesList = TerritoriesRepository.GetAll(Empty) + + %> <% + End Sub + + '------------------------------------------------------------------------------------------------------------------- + ' Store - Save new household + '------------------------------------------------------------------------------------------------------------------- + Public Sub Store() + Set household = New POBO_Households + household.Address = Trim(Request.Form("Address")) + household.StreetNumber = Request.Form("StreetNumber") + household.StreetName = Trim(Request.Form("StreetName")) + household.Latitude = Trim(Request.Form("Latitude")) + household.Longitude = Trim(Request.Form("Longitude")) + household.IsBusiness = IIf(Request.Form("IsBusiness") = "1", 1, 0) + household.DoNotCall = IIf(Request.Form("DoNotCall") = "1", 1, 0) + household.DoNotCallNotes = Trim(Request.Form("DoNotCallNotes")) + household.DoNotCallPrivateNotes = Trim(Request.Form("DoNotCallPrivateNotes")) + household.TerritoryId = Request.Form("TerritoryId") + + If Request.Form("DoNotCallDate") <> "" Then + household.DoNotCallDate = CDate(Request.Form("DoNotCallDate")) + ElseIf household.DoNotCall = 1 Then + household.DoNotCallDate = Date() + Else + household.DoNotCallDate = Null + End If + + ' Validation + If household.Address = "" Then + Flash().AddError "Address is required." + Response.Redirect "/households/new" + Exit Sub + End If + + If Not IsNumeric(household.TerritoryId) Or CInt(household.TerritoryId) < 1 Then + Flash().AddError "Please select a territory." + Response.Redirect "/households/new" + Exit Sub + End If + + HouseholdsRepository.AddNew household + + Flash().Success = "Household created successfully." + Response.Redirect "/households/" & household.Id + End Sub + + '------------------------------------------------------------------------------------------------------------------- + ' Edit - Display form to edit household + '------------------------------------------------------------------------------------------------------------------- + Public Sub Edit(id) + On Error Resume Next + Set household = HouseholdsRepository.FindByID(id) + If Err.Number <> 0 Or household Is Nothing Then + On Error GoTo 0 + Flash().AddError "Household not found." + Response.Redirect "/households" + Exit Sub + End If + On Error GoTo 0 + + ' Load territories for dropdown + Set territoriesList = TerritoriesRepository.GetAll(Empty) + + %> <% + End Sub + + '------------------------------------------------------------------------------------------------------------------- + ' Update - Save changes to household + '------------------------------------------------------------------------------------------------------------------- + Public Sub Update(id) + On Error Resume Next + Set household = HouseholdsRepository.FindByID(id) + If Err.Number <> 0 Or household Is Nothing Then + On Error GoTo 0 + Flash().AddError "Household not found." + Response.Redirect "/households" + Exit Sub + End If + On Error GoTo 0 + + household.Address = Trim(Request.Form("Address")) + household.StreetNumber = Request.Form("StreetNumber") + household.StreetName = Trim(Request.Form("StreetName")) + household.Latitude = Trim(Request.Form("Latitude")) + household.Longitude = Trim(Request.Form("Longitude")) + household.IsBusiness = IIf(Request.Form("IsBusiness") = "1", 1, 0) + household.DoNotCall = IIf(Request.Form("DoNotCall") = "1", 1, 0) + household.DoNotCallNotes = Trim(Request.Form("DoNotCallNotes")) + household.DoNotCallPrivateNotes = Trim(Request.Form("DoNotCallPrivateNotes")) + household.TerritoryId = Request.Form("TerritoryId") + + If Request.Form("DoNotCallDate") <> "" Then + household.DoNotCallDate = CDate(Request.Form("DoNotCallDate")) + ElseIf household.DoNotCall = 1 Then + If IsNull(household.DoNotCallDate) Then + household.DoNotCallDate = Date() + ElseIf Trim(CStr(household.DoNotCallDate)) = "" Then + household.DoNotCallDate = Date() + End If + Else + household.DoNotCallDate = Null + End If + + ' Validation + If household.Address = "" Then + Flash().AddError "Address is required." + Response.Redirect "/households/" & id & "/edit" + Exit Sub + End If + + HouseholdsRepository.Update household + + Flash().Success = "Household updated successfully." + Response.Redirect "/households/" & id + End Sub + + '------------------------------------------------------------------------------------------------------------------- + ' Delete - Remove a household + '------------------------------------------------------------------------------------------------------------------- + Public Sub Delete(id) + On Error Resume Next + Set household = HouseholdsRepository.FindByID(id) + If Err.Number <> 0 Or household Is Nothing Then + On Error GoTo 0 + Flash().AddError "Household not found." + Response.Redirect "/households" + Exit Sub + End If + On Error GoTo 0 + + HouseholdsRepository.Delete id + + Flash().Success = "Household deleted successfully." + Response.Redirect "/households" + End Sub + + Private Function BuildTerritoryNamesById(territories) + Dim dict : Set dict = Server.CreateObject("Scripting.Dictionary") + Dim iter, territory + Set iter = territories.Iterator() + Do While iter.HasNext() + Set territory = iter.GetNext() + dict(CStr(territory.Id)) = territory.Name & "" + Loop + Set BuildTerritoryNamesById = dict + End Function + +End Class + +' Singleton instance +Dim HouseholdController_Class__Singleton +Function HouseholdController() + If IsEmpty(HouseholdController_Class__Singleton) Then + Set HouseholdController_Class__Singleton = New HouseholdController_Class + End If + Set HouseholdController = HouseholdController_Class__Singleton +End Function +%> diff --git a/app/controllers/HouseholderNameController.asp b/app/controllers/HouseholderNameController.asp new file mode 100644 index 0000000..16672f2 --- /dev/null +++ b/app/controllers/HouseholderNameController.asp @@ -0,0 +1,284 @@ +<% +' HouseholderNameController - CRUD controller for HouseholderNames +' NorthTerritory app +' +' Dependencies (all included via HouseholdController which loads first): +' - app/models/POBO_HouseholderNames.asp +' - app/models/HouseholderNamesRepository.asp +' - app/models/POBO_Households.asp +' - app/models/HouseholdsRepository.asp + +Class HouseholderNameController_Class + Private m_useLayout + Private m_title + + ' Public properties for views + Public householderNames ' LinkedList for Index + Public householderName ' Single POBO for Show/Edit + Public household ' Parent household + Public householdsList ' For dropdown + + ' Pagination properties + Public currentPage + Public pageCount + Public recordCount + Public perPage + Public searchTerm + Public filterHouseholdId + + Private Sub Class_Initialize() + m_useLayout = True + m_title = "Householder Names" + currentPage = 1 + pageCount = 0 + recordCount = 0 + perPage = 25 + searchTerm = "" + filterHouseholdId = 0 + End Sub + + Public Property Get useLayout + useLayout = m_useLayout + End Property + + Public Property Let useLayout(v) + m_useLayout = v + End Property + + Public Property Get Title + Title = m_title + End Property + + Public Property Let Title(v) + m_title = v + End Property + + '------------------------------------------------------------------------------------------------------------------- + ' Index - List all householder names with pagination, search, and household filter + '------------------------------------------------------------------------------------------------------------------- + Public Sub Index() + ' Get pagination params + If Request.QueryString("page") <> "" And IsNumeric(Request.QueryString("page")) Then + currentPage = CInt(Request.QueryString("page")) + If currentPage < 1 Then currentPage = 1 + End If + + ' Get search param + searchTerm = Trim(Request.QueryString("q") & "") + + ' Get household filter + If Request.QueryString("household") <> "" And IsNumeric(Request.QueryString("household")) Then + filterHouseholdId = CLng(Request.QueryString("household")) + End If + + ' Fetch householder names with pagination + If searchTerm <> "" Then + ' Search in Name column + Set householderNames = HouseholderNamesRepository.SearchTablePaged( _ + Array("Name"), _ + searchTerm, _ + Empty, _ + perPage, _ + currentPage, _ + pageCount, _ + recordCount _ + ) + ElseIf filterHouseholdId > 0 Then + ' Filter by household + Set householderNames = HouseholderNamesRepository.FindPaged( _ + Array("HouseholdId", filterHouseholdId), _ + Empty, _ + perPage, _ + currentPage, _ + pageCount, _ + recordCount _ + ) + ' Load parent household for context + On Error Resume Next + Set household = HouseholdsRepository.FindByID(filterHouseholdId) + On Error GoTo 0 + Else + Set householderNames = HouseholderNamesRepository.FindPaged( _ + Empty, _ + Empty, _ + perPage, _ + currentPage, _ + pageCount, _ + recordCount _ + ) + End If + + %> <% + End Sub + + '------------------------------------------------------------------------------------------------------------------- + ' Show - Display a single householder name + '------------------------------------------------------------------------------------------------------------------- + Public Sub Show(id) + On Error Resume Next + Set householderName = HouseholderNamesRepository.FindByID(id) + If Err.Number <> 0 Or householderName Is Nothing Then + On Error GoTo 0 + Flash().Error = "Householder name not found." + Response.Redirect "/householder-names" + Exit Sub + End If + On Error GoTo 0 + + ' Load parent household + On Error Resume Next + Set household = HouseholdsRepository.FindByID(householderName.HouseholdId) + On Error GoTo 0 + + %> <% + End Sub + + '------------------------------------------------------------------------------------------------------------------- + ' Create - Display form for new householder name + '------------------------------------------------------------------------------------------------------------------- + Public Sub Create() + Set householderName = New POBO_HouseholderNames + householderName.Created = Now() + householderName.LetterReturned = 0 + + ' Pre-fill household if passed in query string + If Request.QueryString("household") <> "" And IsNumeric(Request.QueryString("household")) Then + householderName.HouseholdId = CLng(Request.QueryString("household")) + ' Load parent household for context + On Error Resume Next + Set household = HouseholdsRepository.FindByID(householderName.HouseholdId) + On Error GoTo 0 + End If + + %> <% + End Sub + + '------------------------------------------------------------------------------------------------------------------- + ' Store - Save new householder name + '------------------------------------------------------------------------------------------------------------------- + Public Sub Store() + Set householderName = New POBO_HouseholderNames + householderName.Name = Trim(Request.Form("Name")) + householderName.HouseholdId = Request.Form("HouseholdId") + householderName.LetterReturned = IIf(Request.Form("LetterReturned") = "1", 1, 0) + householderName.Created = Now() + + If Request.Form("ReturnDate") <> "" Then + On Error Resume Next + householderName.ReturnDate = CDate(Request.Form("ReturnDate")) + On Error GoTo 0 + End If + + ' Validation + If householderName.Name = "" Then + Flash().Error = "Name is required." + Response.Redirect "/householder-names/new?household=" & householderName.HouseholdId + Exit Sub + End If + + If Not IsNumeric(householderName.HouseholdId) Or CLng(householderName.HouseholdId) < 1 Then + Flash().Error = "Please select a household." + Response.Redirect "/householder-names/new" + Exit Sub + End If + + HouseholderNamesRepository.AddNew householderName + + Flash().Success = "Householder name created successfully." + Response.Redirect "/householder-names/" & householderName.Id + End Sub + + '------------------------------------------------------------------------------------------------------------------- + ' Edit - Display form to edit householder name + '------------------------------------------------------------------------------------------------------------------- + Public Sub Edit(id) + On Error Resume Next + Set householderName = HouseholderNamesRepository.FindByID(id) + If Err.Number <> 0 Or householderName Is Nothing Then + On Error GoTo 0 + Flash().Error = "Householder name not found." + Response.Redirect "/householder-names" + Exit Sub + End If + On Error GoTo 0 + + ' Load parent household for context + On Error Resume Next + Set household = HouseholdsRepository.FindByID(householderName.HouseholdId) + On Error GoTo 0 + + %> <% + End Sub + + '------------------------------------------------------------------------------------------------------------------- + ' Update - Save changes to householder name + '------------------------------------------------------------------------------------------------------------------- + Public Sub Update(id) + On Error Resume Next + Set householderName = HouseholderNamesRepository.FindByID(id) + If Err.Number <> 0 Or householderName Is Nothing Then + On Error GoTo 0 + Flash().Error = "Householder name not found." + Response.Redirect "/householder-names" + Exit Sub + End If + On Error GoTo 0 + + householderName.Name = Trim(Request.Form("Name")) + householderName.LetterReturned = IIf(Request.Form("LetterReturned") = "1", 1, 0) + + If Request.Form("ReturnDate") <> "" Then + On Error Resume Next + householderName.ReturnDate = CDate(Request.Form("ReturnDate")) + On Error GoTo 0 + Else + householderName.ReturnDate = #1/1/1970# + End If + + ' Validation + If householderName.Name = "" Then + Flash().Error = "Name is required." + Response.Redirect "/householder-names/" & id & "/edit" + Exit Sub + End If + + HouseholderNamesRepository.Update householderName + + Flash().Success = "Householder name updated successfully." + Response.Redirect "/householder-names/" & id + End Sub + + '------------------------------------------------------------------------------------------------------------------- + ' Delete - Remove a householder name + '------------------------------------------------------------------------------------------------------------------- + Public Sub Delete(id) + On Error Resume Next + Set householderName = HouseholderNamesRepository.FindByID(id) + If Err.Number <> 0 Or householderName Is Nothing Then + On Error GoTo 0 + Flash().Error = "Householder name not found." + Response.Redirect "/householder-names" + Exit Sub + End If + On Error GoTo 0 + + Dim householdId + householdId = householderName.HouseholdId + + HouseholderNamesRepository.Delete id + + Flash().Success = "Householder name deleted successfully." + Response.Redirect "/householder-names?household=" & householdId + End Sub + +End Class + +' Singleton instance +Dim HouseholderNameController_Class__Singleton +Function HouseholderNameController() + If IsEmpty(HouseholderNameController_Class__Singleton) Then + Set HouseholderNameController_Class__Singleton = New HouseholderNameController_Class + End If + Set HouseholderNameController = HouseholderNameController_Class__Singleton +End Function +%> diff --git a/app/controllers/TerritoryController.asp b/app/controllers/TerritoryController.asp new file mode 100644 index 0000000..54a02a1 --- /dev/null +++ b/app/controllers/TerritoryController.asp @@ -0,0 +1,226 @@ +<% +' TerritoryController - CRUD controller for Territories +' Generated for NorthTerritory app +' +' Dependencies: +' - app/models/POBO_Territories.asp +' - app/models/TerritoriesRepository.asp +%> + + +<% + +Class TerritoryController_Class + Private m_useLayout + Private m_title + + ' Public properties for views + Public territories ' LinkedList for Index + Public territory ' Single POBO for Show/Edit + Public territoryHouseholdCounts + Public territoryStreets ' LinkedList of street names for Show + + ' Pagination properties + Public currentPage + Public pageCount + Public recordCount + Public perPage + Public searchTerm + + Private Sub Class_Initialize() + m_useLayout = True + m_title = "Territories" + currentPage = 1 + pageCount = 0 + recordCount = 0 + perPage = 20 + searchTerm = "" + Set territoryHouseholdCounts = Nothing + End Sub + + Public Property Get useLayout + useLayout = m_useLayout + End Property + + Public Property Let useLayout(v) + m_useLayout = v + End Property + + Public Property Get Title + Title = m_title + End Property + + Public Property Let Title(v) + m_title = v + End Property + + '------------------------------------------------------------------------------------------------------------------- + ' Index - List all territories with pagination and search + '------------------------------------------------------------------------------------------------------------------- + Public Sub Index() + ' Get pagination params + If Request.QueryString("page") <> "" And IsNumeric(Request.QueryString("page")) Then + currentPage = CInt(Request.QueryString("page")) + If currentPage < 1 Then currentPage = 1 + End If + + ' Get search param + searchTerm = Trim(Request.QueryString("q") & "") + + ' Fetch territories with pagination + If searchTerm <> "" Then + ' Search in Name and Description columns + Set territories = TerritoriesRepository.SearchTablePaged( _ + Array("Name", "Description"), _ + searchTerm, _ + Empty, _ + perPage, _ + currentPage, _ + pageCount, _ + recordCount _ + ) + Else + Set territories = TerritoriesRepository.FindPaged( _ + Empty, _ + Empty, _ + perPage, _ + currentPage, _ + pageCount, _ + recordCount _ + ) + End If + + Set territoryHouseholdCounts = HouseholdsRepository.GetCountsByTerritory() + + %> <% + End Sub + + '------------------------------------------------------------------------------------------------------------------- + ' Show - Display a single territory + '------------------------------------------------------------------------------------------------------------------- + Public Sub Show(id) + On Error Resume Next + Set territory = TerritoriesRepository.FindByID(id) + If Err.Number <> 0 Or territory Is Nothing Then + On Error GoTo 0 + Flash().AddError "Territory not found." + Response.Redirect "/territories" + Exit Sub + End If + On Error GoTo 0 + + ' Load distinct street names for this territory + Set territoryStreets = HouseholdsRepository.GetDistinctStreetsByTerritory(id) + + %> <% + End Sub + + '------------------------------------------------------------------------------------------------------------------- + ' Create - Display form for new territory + '------------------------------------------------------------------------------------------------------------------- + Public Sub Create() + Set territory = New POBO_Territories + %> <% + End Sub + + '------------------------------------------------------------------------------------------------------------------- + ' Store - Save new territory + '------------------------------------------------------------------------------------------------------------------- + Public Sub Store() + Set territory = New POBO_Territories + territory.Name = Trim(Request.Form("Name")) + territory.Description = Trim(Request.Form("Description")) + territory.Coordinates = Trim(Request.Form("Coordinates")) + + ' Validation + If territory.Name = "" Then + Flash().AddError "Name is required." + Response.Redirect "/territories/new" + Exit Sub + End If + + TerritoriesRepository.AddNew territory + + Flash().Success = "Territory created successfully." + Response.Redirect "/territories/" & territory.Id + End Sub + + '------------------------------------------------------------------------------------------------------------------- + ' Edit - Display form to edit territory + '------------------------------------------------------------------------------------------------------------------- + Public Sub Edit(id) + On Error Resume Next + Set territory = TerritoriesRepository.FindByID(id) + If Err.Number <> 0 Or territory Is Nothing Then + On Error GoTo 0 + Flash().AddError "Territory not found." + Response.Redirect "/territories" + Exit Sub + End If + On Error GoTo 0 + + %> <% + End Sub + + '------------------------------------------------------------------------------------------------------------------- + ' Update - Save changes to territory + '------------------------------------------------------------------------------------------------------------------- + Public Sub Update(id) + On Error Resume Next + Set territory = TerritoriesRepository.FindByID(id) + If Err.Number <> 0 Or territory Is Nothing Then + On Error GoTo 0 + Flash().AddError "Territory not found." + Response.Redirect "/territories" + Exit Sub + End If + On Error GoTo 0 + + territory.Name = Trim(Request.Form("Name")) + territory.Description = Trim(Request.Form("Description")) + territory.Coordinates = Trim(Request.Form("Coordinates")) + + ' Validation + If territory.Name = "" Then + Flash().AddError "Name is required." + Response.Redirect "/territories/" & id & "/edit" + Exit Sub + End If + + TerritoriesRepository.Update territory + + Flash().Success = "Territory updated successfully." + Response.Redirect "/territories/" & id + End Sub + + '------------------------------------------------------------------------------------------------------------------- + ' Delete - Remove a territory + '------------------------------------------------------------------------------------------------------------------- + Public Sub Delete(id) + On Error Resume Next + Set territory = TerritoriesRepository.FindByID(id) + If Err.Number <> 0 Or territory Is Nothing Then + On Error GoTo 0 + Flash().AddError "Territory not found." + Response.Redirect "/territories" + Exit Sub + End If + On Error GoTo 0 + + TerritoriesRepository.Delete id + + Flash().Success = "Territory deleted successfully." + Response.Redirect "/territories" + End Sub + +End Class + +' Singleton instance +Dim TerritoryController_Class__Singleton +Function TerritoryController() + If IsEmpty(TerritoryController_Class__Singleton) Then + Set TerritoryController_Class__Singleton = New TerritoryController_Class + End If + Set TerritoryController = TerritoryController_Class__Singleton +End Function +%> diff --git a/app/controllers/autoload_controllers.asp b/app/controllers/autoload_controllers.asp index 425e8a9..671990b 100644 --- a/app/controllers/autoload_controllers.asp +++ b/app/controllers/autoload_controllers.asp @@ -1,2 +1,5 @@ + - \ No newline at end of file + + + \ No newline at end of file diff --git a/app/models/HouseholderNamesRepository.asp b/app/models/HouseholderNamesRepository.asp new file mode 100644 index 0000000..d625bc9 --- /dev/null +++ b/app/models/HouseholderNamesRepository.asp @@ -0,0 +1,176 @@ +<% +' Auto-generated Repository for table [HouseholderNames] +' Generated on 1/17/2026 7:59:02 PM +' Generator: GenerateRepo.vbs v1.0 +' +' Dependencies: +' - core/lib.DAL.asp (DAL singleton for database access) +' - core/lib.AutoMapper.asp (Automapper for object mapping) +' - core/lib.Collections.asp (LinkedList_Class) +' - core/lib.helpers.asp (KVUnzip, BuildOrderBy, QI, Destroy) + + +Class HouseholderNamesRepository_Class + + Public Function FindByID(id) + Dim sql : sql = "Select [Created], [HouseholdId], [Id], [LetterReturned], [Name], [ReturnDate] FROM [HouseholderNames] WHERE [Id] = ?" + Dim rs : Set rs = DAL.Query(sql, Array(id)) + If rs.EOF Then + Err.Raise 1, "HouseholderNamesRepository_Class", RecordNotFoundException("Id", id) + Else + Set FindByID = Automapper.AutoMap(rs, "POBO_HouseholderNames") + End If + Destroy rs + End Function + + Public Function GetAll(orderBy) + Set GetAll = Find(Empty, orderBy) + End Function + + Public Function Find(where_kvarray, order_string_or_array) + Dim sql : sql = "Select [Created], [HouseholdId], [Id], [LetterReturned], [Name], [ReturnDate] FROM [HouseholderNames]" + Dim where_keys, where_values, i + If Not IsEmpty(where_kvarray) Then + KVUnzip where_kvarray, where_keys, where_values + If Not IsEmpty(where_keys) Then + sql = sql & " WHERE " + For i = 0 To UBound(where_keys) + If i > 0 Then sql = sql & " AND " + sql = sql & " " & QI(where_keys(i)) & " = ?" + Next + End If + End If + sql = sql & BuildOrderBy(order_string_or_array, "[Id]") + Dim rs : Set rs = DAL.Query(sql, where_values) + Dim list : Set list = new LinkedList_Class + Do Until rs.EOF + list.Push Automapper.AutoMap(rs, "POBO_HouseholderNames") + rs.MoveNext + Loop + Set Find = list + Destroy rs + End Function + + Public Function FindPaged(where_kvarray, order_string_or_array, per_page, page_num, ByRef page_count, ByRef record_count) + Dim sql : sql = "Select [Created], [HouseholdId], [Id], [LetterReturned], [Name], [ReturnDate] FROM [HouseholderNames]" + Dim where_keys, where_values, i + If Not IsEmpty(where_kvarray) Then + KVUnzip where_kvarray, where_keys, where_values + If Not IsEmpty(where_keys) Then + sql = sql & " WHERE " + For i = 0 To UBound(where_keys) + If i > 0 Then sql = sql & " AND " + sql = sql & " " & QI(where_keys(i)) & " = ?" + Next + End If + End If + sql = sql & BuildOrderBy(order_string_or_array, "[Id]") + Dim rs : Set rs = DAL.PagedQuery(sql, where_values, per_page, page_num) + If Not rs.EOF Then + rs.PageSize = per_page + rs.AbsolutePage = page_num + page_count = rs.PageCount + record_count = rs.RecordCount + End If + Set FindPaged = PagedList(rs, per_page) + Destroy rs + End Function + + Public Function SearchTablePaged(columns_array, search_value, order_string_or_array, per_page, page_num, ByRef page_count, ByRef record_count) + Dim sql : sql = "Select [Created], [HouseholdId], [Id], [LetterReturned], [Name], [ReturnDate] FROM [HouseholderNames]" + Dim i, params() + If IsArray(columns_array) And UBound(columns_array) >= 0 Then + sql = sql & " WHERE " + ReDim params(UBound(columns_array)) + For i = 0 To UBound(columns_array) + If i > 0 Then sql = sql & " OR " + sql = sql & " " & QI(columns_array(i)) & " LIKE ?" + params(i) = "%" & search_value & "%" + Next + End If + sql = sql & BuildOrderBy(order_string_or_array, "[Id]") + Dim rs : Set rs = DAL.PagedQuery(sql, params, per_page, page_num) + If Not rs.EOF Then + rs.PageSize = per_page + rs.AbsolutePage = page_num + page_count = rs.PageCount + record_count = rs.RecordCount + End If + Set SearchTablePaged = PagedList(rs, per_page) + Destroy rs + End Function + + Private Function PagedList(rs, per_page) + Dim list : Set list = new LinkedList_Class + Dim x : x = 0 + Do While (per_page <= 0 Or x < per_page) And Not rs.EOF + list.Push Automapper.AutoMap(rs, "POBO_HouseholderNames") + x = x + 1 + rs.MoveNext + Loop + Set PagedList = list + End Function + + Public Sub AddNew(ByRef model) + Dim sql : sql = "INSERT INTO [HouseholderNames] ([Created], [HouseholdId], [LetterReturned], [Name], [ReturnDate]) VALUES (?, ?, ?, ?, ?)" + DAL.[Execute] sql, Array(model.Created, model.HouseholdId, model.LetterReturned, model.Name, model.ReturnDate) + + ' Retrieve the newly inserted ID + On Error Resume Next + Dim rsId : Set rsId = DAL.Query("SELECT @@IDENTITY AS NewID", Empty) + If Err.Number <> 0 Then + ' Fallback for Access databases + Err.Clear + Set rsId = DAL.Query("SELECT TOP 1 [Id] FROM [HouseholderNames] ORDER BY [Id] DESC", Empty) + End If + On Error GoTo 0 + + If Not rsId.EOF Then + If Not IsNull(rsId(0)) Then model.Id = rsId(0) + End If + Destroy rsId + End Sub + + Public Sub Update(model) + Dim sql : sql = "UPDATE [HouseholderNames] SET [Created] = ?, [HouseholdId] = ?, [LetterReturned] = ?, [Name] = ?, [ReturnDate] = ? WHERE [Id] = ?" + DAL.[Execute] sql, Array(model.Created, model.HouseholdId, model.LetterReturned, model.Name, model.ReturnDate, model.Id) + End Sub + + Public Sub Delete(id) + Dim sql : sql = "DELETE FROM [HouseholderNames] WHERE [Id] = ?" + DAL.[Execute] sql, Array(id) + End Sub + + Private Function RecordNotFoundException(ByVal field_name, ByVal field_val) + RecordNotFoundException = "HouseholderNames record was not found with " & field_name & " = '" & field_val & "'." + End Function + + Private Function QI(name) + QI = "[" & Replace(CStr(name), "]", "]]") & "]" + End Function + + Private Function BuildOrderBy(orderArg, defaultCol) + Dim s : s = "" + If IsEmpty(orderArg) Or IsNull(orderArg) Or orderArg = "" Then + s = " ORDER BY " & defaultCol & " ASC" + ElseIf IsArray(orderArg) Then + Dim i : s = " ORDER BY " + For i = 0 To UBound(orderArg) + If i > 0 Then s = s & ", " + s = s & QI(orderArg(i)) + Next + Else + s = " ORDER BY " & QI(orderArg) + End If + BuildOrderBy = s + End Function +End Class + +Dim HouseholderNamesRepository__Singleton +Function HouseholderNamesRepository() + If IsEmpty(HouseholderNamesRepository__Singleton) Then + Set HouseholderNamesRepository__Singleton = new HouseholderNamesRepository_Class + End If + Set HouseholderNamesRepository = HouseholderNamesRepository__Singleton +End Function +%> diff --git a/app/models/HouseholdsRepository.asp b/app/models/HouseholdsRepository.asp new file mode 100644 index 0000000..9da2b2a --- /dev/null +++ b/app/models/HouseholdsRepository.asp @@ -0,0 +1,243 @@ +<% +' Auto-generated Repository for table [Households] +' Generator: GenerateRepo.vbs v1.0 +' +' Dependencies: +' - core/lib.DAL.asp (DAL singleton for database access) +' - core/lib.AutoMapper.asp (Automapper for object mapping) +' - core/lib.Collections.asp (LinkedList_Class) +' - core/lib.helpers.asp (KVUnzip, BuildOrderBy, QI, Destroy) + + +Class HouseholdsRepository_Class + + Public Function FindByID(id) + Dim sql : sql = "Select [Address], [DoNotCall], [DoNotCallDate], [DoNotCallNotes], [DoNotCallPrivateNotes], [Id], [IsBusiness], [Latitude], [Longitude], [StreetName], [StreetNumber], [TerritoryId] FROM [Households] WHERE [Id] = ?" + Dim rs : Set rs = DAL.Query(sql, Array(id)) + If rs.EOF Then + Err.Raise 1, "HouseholdsRepository_Class", RecordNotFoundException("Id", id) + Else + Set FindByID = Automapper.AutoMap(rs, "POBO_Households") + End If + Destroy rs + End Function + + Public Function GetAll(orderBy) + Set GetAll = Find(Empty, orderBy) + End Function + + Public Function Find(where_kvarray, order_string_or_array) + Dim sql : sql = "Select [Address], [DoNotCall], [DoNotCallDate], [DoNotCallNotes], [DoNotCallPrivateNotes], [Id], [IsBusiness], [Latitude], [Longitude], [StreetName], [StreetNumber], [TerritoryId] FROM [Households]" + Dim where_keys, where_values, i + If Not IsEmpty(where_kvarray) Then + KVUnzip where_kvarray, where_keys, where_values + If Not IsEmpty(where_keys) Then + sql = sql & " WHERE " + For i = 0 To UBound(where_keys) + If i > 0 Then sql = sql & " AND " + sql = sql & " " & QI(where_keys(i)) & " = ?" + Next + End If + End If + sql = sql & BuildOrderBy(order_string_or_array, "[Id]") + Dim rs : Set rs = DAL.Query(sql, where_values) + Dim list : Set list = new LinkedList_Class + Do Until rs.EOF + list.Push Automapper.AutoMap(rs, "POBO_Households") + rs.MoveNext + Loop + Set Find = list + Destroy rs + End Function + + Public Function FindPaged(where_kvarray, order_string_or_array, per_page, page_num, ByRef page_count, ByRef record_count) + Dim sql : sql = "Select [Address], [DoNotCall], [DoNotCallDate], [DoNotCallNotes], [DoNotCallPrivateNotes], [Id], [IsBusiness], [Latitude], [Longitude], [StreetName], [StreetNumber], [TerritoryId] FROM [Households]" + Dim where_keys, where_values, i + If Not IsEmpty(where_kvarray) Then + KVUnzip where_kvarray, where_keys, where_values + If Not IsEmpty(where_keys) Then + sql = sql & " WHERE " + For i = 0 To UBound(where_keys) + If i > 0 Then sql = sql & " AND " + sql = sql & " " & QI(where_keys(i)) & " = ?" + Next + End If + End If + sql = sql & BuildOrderBy(order_string_or_array, "[Id]") + Dim rs : Set rs = DAL.PagedQuery(sql, where_values, per_page, page_num) + If Not rs.EOF Then + rs.PageSize = per_page + rs.AbsolutePage = page_num + page_count = rs.PageCount + record_count = rs.RecordCount + End If + Set FindPaged = PagedList(rs, per_page) + Destroy rs + End Function + + Public Function SearchTablePaged(columns_array, search_value, order_string_or_array, per_page, page_num, ByRef page_count, ByRef record_count) + Dim sql : sql = "Select [Address], [DoNotCall], [DoNotCallDate], [DoNotCallNotes], [DoNotCallPrivateNotes], [Id], [IsBusiness], [Latitude], [Longitude], [StreetName], [StreetNumber], [TerritoryId] FROM [Households]" + Dim i, params() + If IsArray(columns_array) And UBound(columns_array) >= 0 Then + sql = sql & " WHERE " + ReDim params(UBound(columns_array)) + For i = 0 To UBound(columns_array) + If i > 0 Then sql = sql & " OR " + sql = sql & " " & QI(columns_array(i)) & " LIKE ?" + params(i) = "%" & search_value & "%" + Next + End If + sql = sql & BuildOrderBy(order_string_or_array, "[Id]") + Dim rs : Set rs = DAL.PagedQuery(sql, params, per_page, page_num) + If Not rs.EOF Then + rs.PageSize = per_page + rs.AbsolutePage = page_num + page_count = rs.PageCount + record_count = rs.RecordCount + End If + Set SearchTablePaged = PagedList(rs, per_page) + Destroy rs + End Function + + Public Function SearchTablePagedByDoNotCall(columns_array, search_value, doNotCallValue, order_string_or_array, per_page, page_num, ByRef page_count, ByRef record_count) + Dim sql : sql = "Select [Address], [DoNotCall], [DoNotCallDate], [DoNotCallNotes], [DoNotCallPrivateNotes], [Id], [IsBusiness], [Latitude], [Longitude], [StreetName], [StreetNumber], [TerritoryId] FROM [Households] WHERE [DoNotCall] = ?" + Dim i, params() + If IsArray(columns_array) And UBound(columns_array) >= 0 Then + ReDim params(UBound(columns_array) + 1) + params(0) = doNotCallValue + sql = sql & " AND (" + For i = 0 To UBound(columns_array) + If i > 0 Then sql = sql & " OR " + sql = sql & " " & QI(columns_array(i)) & " LIKE ?" + params(i + 1) = "%" & search_value & "%" + Next + sql = sql & ")" + Else + ReDim params(0) + params(0) = doNotCallValue + End If + sql = sql & BuildOrderBy(order_string_or_array, "[Id]") + Dim rs : Set rs = DAL.PagedQuery(sql, params, per_page, page_num) + If Not rs.EOF Then + rs.PageSize = per_page + rs.AbsolutePage = page_num + page_count = rs.PageCount + record_count = rs.RecordCount + End If + Set SearchTablePagedByDoNotCall = PagedList(rs, per_page) + Destroy rs + End Function + + Public Function FindPagedByTerritoryAndDoNotCall(territoryId, doNotCallValue, order_string_or_array, per_page, page_num, ByRef page_count, ByRef record_count) + Dim sql : sql = "Select [Address], [DoNotCall], [DoNotCallDate], [DoNotCallNotes], [DoNotCallPrivateNotes], [Id], [IsBusiness], [Latitude], [Longitude], [StreetName], [StreetNumber], [TerritoryId] FROM [Households] WHERE [TerritoryId] = ? AND [DoNotCall] = ?" + Dim rs : Set rs = DAL.PagedQuery(sql & BuildOrderBy(order_string_or_array, "[Id]"), Array(territoryId, doNotCallValue), per_page, page_num) + If Not rs.EOF Then + rs.PageSize = per_page + rs.AbsolutePage = page_num + page_count = rs.PageCount + record_count = rs.RecordCount + End If + Set FindPagedByTerritoryAndDoNotCall = PagedList(rs, per_page) + Destroy rs + End Function + + Private Function PagedList(rs, per_page) + Dim list : Set list = new LinkedList_Class + Dim x : x = 0 + Do While (per_page <= 0 Or x < per_page) And Not rs.EOF + list.Push Automapper.AutoMap(rs, "POBO_Households") + x = x + 1 + rs.MoveNext + Loop + Set PagedList = list + End Function + + Public Function GetCountsByTerritory() + Dim sql : sql = "SELECT [TerritoryId], COUNT(*) AS [HouseholdCount] FROM [Households] GROUP BY [TerritoryId]" + Dim rs : Set rs = DAL.Query(sql, Empty) + Dim dict : Set dict = Server.CreateObject("Scripting.Dictionary") + Do Until rs.EOF + If Not IsNull(rs("TerritoryId")) Then + dict(CLng(rs("TerritoryId"))) = CLng(rs("HouseholdCount")) + End If + rs.MoveNext + Loop + Set GetCountsByTerritory = dict + Destroy rs + End Function + + Public Function GetDistinctStreetsByTerritory(territoryId) + Dim sql : sql = "SELECT DISTINCT [StreetName] FROM [Households] WHERE [TerritoryId] = ? AND [StreetName] IS NOT NULL AND [StreetName] <> '' ORDER BY [StreetName]" + Dim rs : Set rs = DAL.Query(sql, Array(territoryId)) + Dim list : Set list = new LinkedList_Class + Do Until rs.EOF + list.Push rs("StreetName") & "" + rs.MoveNext + Loop + Set GetDistinctStreetsByTerritory = list + Destroy rs + End Function + + Public Sub AddNew(ByRef model) + Dim sql : sql = "INSERT INTO [Households] ([Address], [DoNotCall], [DoNotCallDate], [DoNotCallNotes], [DoNotCallPrivateNotes], [IsBusiness], [Latitude], [Longitude], [StreetName], [StreetNumber], [TerritoryId]) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" + DAL.[Execute] sql, Array(model.Address, model.DoNotCall, model.DoNotCallDate, model.DoNotCallNotes, model.DoNotCallPrivateNotes, model.IsBusiness, model.Latitude, model.Longitude, model.StreetName, model.StreetNumber, model.TerritoryId) + + ' Retrieve the newly inserted ID + On Error Resume Next + Dim rsId : Set rsId = DAL.Query("SELECT @@IDENTITY AS NewID", Empty) + If Err.Number <> 0 Then + ' Fallback for Access databases + Err.Clear + Set rsId = DAL.Query("SELECT TOP 1 [Id] FROM [Households] ORDER BY [Id] DESC", Empty) + End If + On Error GoTo 0 + + If Not rsId.EOF Then + If Not IsNull(rsId(0)) Then model.Id = rsId(0) + End If + Destroy rsId + End Sub + + Public Sub Update(model) + Dim sql : sql = "UPDATE [Households] SET [Address] = ?, [DoNotCall] = ?, [DoNotCallDate] = ?, [DoNotCallNotes] = ?, [DoNotCallPrivateNotes] = ?, [IsBusiness] = ?, [Latitude] = ?, [Longitude] = ?, [StreetName] = ?, [StreetNumber] = ?, [TerritoryId] = ? WHERE [Id] = ?" + DAL.[Execute] sql, Array(model.Address, model.DoNotCall, model.DoNotCallDate, model.DoNotCallNotes, model.DoNotCallPrivateNotes, model.IsBusiness, model.Latitude, model.Longitude, model.StreetName, model.StreetNumber, model.TerritoryId, model.Id) + End Sub + + Public Sub Delete(id) + Dim sql : sql = "DELETE FROM [Households] WHERE [Id] = ?" + DAL.[Execute] sql, Array(id) + End Sub + + Private Function RecordNotFoundException(ByVal field_name, ByVal field_val) + RecordNotFoundException = "Households record was not found with " & field_name & " = '" & field_val & "'." + End Function + + Private Function QI(name) + QI = "[" & Replace(CStr(name), "]", "]]") & "]" + End Function + + Private Function BuildOrderBy(orderArg, defaultCol) + Dim s : s = "" + If IsEmpty(orderArg) Or IsNull(orderArg) Or orderArg = "" Then + s = " ORDER BY " & defaultCol & " ASC" + ElseIf IsArray(orderArg) Then + Dim i : s = " ORDER BY " + For i = 0 To UBound(orderArg) + If i > 0 Then s = s & ", " + s = s & QI(orderArg(i)) + Next + Else + s = " ORDER BY " & QI(orderArg) + End If + BuildOrderBy = s + End Function +End Class + +Dim HouseholdsRepository__Singleton +Function HouseholdsRepository() + If IsEmpty(HouseholdsRepository__Singleton) Then + Set HouseholdsRepository__Singleton = new HouseholdsRepository_Class + End If + Set HouseholdsRepository = HouseholdsRepository__Singleton +End Function +%> diff --git a/app/models/POBO_HouseholderNames.asp b/app/models/POBO_HouseholderNames.asp new file mode 100644 index 0000000..f3d91bf --- /dev/null +++ b/app/models/POBO_HouseholderNames.asp @@ -0,0 +1,133 @@ +<% +' Auto-generated POBO for table [HouseholderNames] +' Generated on 1/17/2026 7:59:02 PM +' Generator: GenerateRepo.vbs v1.0 +' +' Dependencies: core/helpers.asp (QuoteValue function) + + +Class POBO_HouseholderNames + ' Public array of all property names + Public Properties + + Private pCreated + Private pHouseholdId + Private pId + Private pLetterReturned + Private pName + Private pReturnDate + + Private Sub Class_Initialize() + pCreated = #1/1/1970# + pHouseholdId = 0 + pId = 0 + pLetterReturned = 0 + pName = Null + pReturnDate = #1/1/1970# + Properties = Array("Created","HouseholdId","Id","LetterReturned","Name","ReturnDate") + End Sub + + Public Property Get PrimaryKey() + PrimaryKey = "Id" + End Property + + Public Property Get TableName() + TableName = "HouseholderNames" + End Property + + Public Property Get Created() + Created = pCreated + End Property + + Public Property Let Created(val) + On Error Resume Next + pCreated = CDate(val) + If Err.Number <> 0 Then + Err.Raise Err.Number, "POBO_HouseholderNames.Created", "Invalid value for Created: " & Err.Description + End If + On Error GoTo 0 + End Property + + Public Property Get HouseholdId() + HouseholdId = pHouseholdId + End Property + + Public Property Let HouseholdId(val) + On Error Resume Next + If IsNumeric(val) Then + pHouseholdId = CDbl(val) + Else + pHouseholdId = val + End If + If Err.Number <> 0 Then + Err.Raise Err.Number, "POBO_HouseholderNames.HouseholdId", "Invalid value for HouseholdId: " & Err.Description + End If + On Error GoTo 0 + End Property + + Public Property Get Id() + Id = pId + End Property + + Public Property Let Id(val) + On Error Resume Next + If IsNumeric(val) Then + pId = CDbl(val) + Else + pId = val + End If + If Err.Number <> 0 Then + Err.Raise Err.Number, "POBO_HouseholderNames.Id", "Invalid value for Id: " & Err.Description + End If + On Error GoTo 0 + End Property + + Public Property Get LetterReturned() + LetterReturned = pLetterReturned + End Property + + Public Property Let LetterReturned(val) + On Error Resume Next + If IsNumeric(val) Then + pLetterReturned = CDbl(val) + Else + pLetterReturned = val + End If + If Err.Number <> 0 Then + Err.Raise Err.Number, "POBO_HouseholderNames.LetterReturned", "Invalid value for LetterReturned: " & Err.Description + End If + On Error GoTo 0 + End Property + + Public Property Get Name() + Name = pName + End Property + + Public Property Let Name(val) + On Error Resume Next + If IsNumeric(val) Then + pName = CDbl(val) + Else + pName = val + End If + If Err.Number <> 0 Then + Err.Raise Err.Number, "POBO_HouseholderNames.Name", "Invalid value for Name: " & Err.Description + End If + On Error GoTo 0 + End Property + + Public Property Get ReturnDate() + ReturnDate = pReturnDate + End Property + + Public Property Let ReturnDate(val) + On Error Resume Next + pReturnDate = CDate(val) + If Err.Number <> 0 Then + Err.Raise Err.Number, "POBO_HouseholderNames.ReturnDate", "Invalid value for ReturnDate: " & Err.Description + End If + On Error GoTo 0 + End Property + +End Class +%> diff --git a/app/models/POBO_Households.asp b/app/models/POBO_Households.asp new file mode 100644 index 0000000..5332b20 --- /dev/null +++ b/app/models/POBO_Households.asp @@ -0,0 +1,172 @@ +<% +' Auto-generated POBO for table [Households] +' Generator: GenerateRepo.vbs v1.0 +' +' Dependencies: core/helpers.asp (QuoteValue function) + + +Class POBO_Households + ' Public array of all property names + Public Properties + + Private pAddress + Private pDoNotCall + Private pDoNotCallDate + Private pDoNotCallNotes + Private pDoNotCallPrivateNotes + Private pId + Private pIsBusiness + Private pLatitude + Private pLongitude + Private pStreetName + Private pStreetNumber + Private pTerritoryId + + Private Sub Class_Initialize() + pAddress = Null + pDoNotCall = 0 + pDoNotCallDate = Null + pDoNotCallNotes = Null + pDoNotCallPrivateNotes = Null + pId = 0 + pIsBusiness = 0 + pLatitude = Null + pLongitude = Null + pStreetName = Null + pStreetNumber = 0 + pTerritoryId = 0 + Properties = Array("Address","DoNotCall","DoNotCallDate","DoNotCallNotes","DoNotCallPrivateNotes","Id","IsBusiness","Latitude","Longitude","StreetName","StreetNumber","TerritoryId") + End Sub + + Public Property Get PrimaryKey() + PrimaryKey = "Id" + End Property + + Public Property Get TableName() + TableName = "Households" + End Property + + Public Property Get Address() + Address = pAddress + End Property + + Public Property Let Address(val) + pAddress = val + End Property + + Public Property Get DoNotCall() + DoNotCall = pDoNotCall + End Property + + Public Property Let DoNotCall(val) + If IsNumeric(val) Then + pDoNotCall = CLng(val) + Else + pDoNotCall = val + End If + End Property + + Public Property Get DoNotCallDate() + DoNotCallDate = pDoNotCallDate + End Property + + Public Property Let DoNotCallDate(val) + If IsNull(val) Then + pDoNotCallDate = Null + ElseIf Trim(CStr(val)) = "" Then + pDoNotCallDate = Null + Else + pDoNotCallDate = CDate(val) + End If + End Property + + Public Property Get DoNotCallNotes() + DoNotCallNotes = pDoNotCallNotes + End Property + + Public Property Let DoNotCallNotes(val) + pDoNotCallNotes = val + End Property + + Public Property Get DoNotCallPrivateNotes() + DoNotCallPrivateNotes = pDoNotCallPrivateNotes + End Property + + Public Property Let DoNotCallPrivateNotes(val) + pDoNotCallPrivateNotes = val + End Property + + Public Property Get Id() + Id = pId + End Property + + Public Property Let Id(val) + If IsNumeric(val) Then + pId = CLng(val) + Else + pId = val + End If + End Property + + Public Property Get IsBusiness() + IsBusiness = pIsBusiness + End Property + + Public Property Let IsBusiness(val) + If IsNumeric(val) Then + pIsBusiness = CLng(val) + Else + pIsBusiness = val + End If + End Property + + Public Property Get Latitude() + Latitude = pLatitude + End Property + + Public Property Let Latitude(val) + pLatitude = val + End Property + + Public Property Get Longitude() + Longitude = pLongitude + End Property + + Public Property Let Longitude(val) + pLongitude = val + End Property + + Public Property Get StreetName() + StreetName = pStreetName + End Property + + Public Property Let StreetName(val) + pStreetName = val + End Property + + Public Property Get StreetNumber() + StreetNumber = pStreetNumber + End Property + + Public Property Let StreetNumber(val) + If IsNumeric(val) Then + pStreetNumber = CLng(val) + Else + pStreetNumber = val + End If + End Property + + Public Property Get TerritoryId() + TerritoryId = pTerritoryId + End Property + + Public Property Let TerritoryId(val) + If IsNumeric(val) Then + pTerritoryId = CLng(val) + Else + pTerritoryId = val + End If + End Property + +End Class +%> diff --git a/app/models/POBO_Territories.asp b/app/models/POBO_Territories.asp new file mode 100644 index 0000000..937cd2a --- /dev/null +++ b/app/models/POBO_Territories.asp @@ -0,0 +1,103 @@ +<% +' Auto-generated POBO for table [Territories] +' Generated on 1/17/2026 2:53:15 PM +' Generator: GenerateRepo.vbs v1.0 +' +' Dependencies: core/helpers.asp (QuoteValue function) + + +Class POBO_Territories + ' Public array of all property names + Public Properties + + Private pCoordinates + Private pDescription + Private pId + Private pName + + Private Sub Class_Initialize() + pCoordinates = Null + pDescription = Null + pId = 0 + pName = Null + Properties = Array("Coordinates","Description","Id","Name") + End Sub + + Public Property Get PrimaryKey() + PrimaryKey = "Id" + End Property + + Public Property Get TableName() + TableName = "Territories" + End Property + + Public Property Get Coordinates() + Coordinates = pCoordinates + End Property + + Public Property Let Coordinates(val) + On Error Resume Next + If IsNumeric(val) Then + pCoordinates = CDbl(val) + Else + pCoordinates = val + End If + If Err.Number <> 0 Then + Err.Raise Err.Number, "POBO_Territories.Coordinates", "Invalid value for Coordinates: " & Err.Description + End If + On Error GoTo 0 + End Property + + Public Property Get Description() + Description = pDescription + End Property + + Public Property Let Description(val) + On Error Resume Next + If IsNumeric(val) Then + pDescription = CDbl(val) + Else + pDescription = val + End If + If Err.Number <> 0 Then + Err.Raise Err.Number, "POBO_Territories.Description", "Invalid value for Description: " & Err.Description + End If + On Error GoTo 0 + End Property + + Public Property Get Id() + Id = pId + End Property + + Public Property Let Id(val) + On Error Resume Next + If IsNumeric(val) Then + pId = CDbl(val) + Else + pId = val + End If + If Err.Number <> 0 Then + Err.Raise Err.Number, "POBO_Territories.Id", "Invalid value for Id: " & Err.Description + End If + On Error GoTo 0 + End Property + + Public Property Get Name() + Name = pName + End Property + + Public Property Let Name(val) + On Error Resume Next + If IsNumeric(val) Then + pName = CDbl(val) + Else + pName = val + End If + If Err.Number <> 0 Then + Err.Raise Err.Number, "POBO_Territories.Name", "Invalid value for Name: " & Err.Description + End If + On Error GoTo 0 + End Property + +End Class +%> diff --git a/app/models/TerritoriesRepository.asp b/app/models/TerritoriesRepository.asp new file mode 100644 index 0000000..895e23e --- /dev/null +++ b/app/models/TerritoriesRepository.asp @@ -0,0 +1,176 @@ +<% +' Auto-generated Repository for table [Territories] +' Generated on 1/17/2026 2:53:15 PM +' Generator: GenerateRepo.vbs v1.0 +' +' Dependencies: +' - core/lib.DAL.asp (DAL singleton for database access) +' - core/lib.AutoMapper.asp (Automapper for object mapping) +' - core/lib.Collections.asp (LinkedList_Class) +' - core/lib.helpers.asp (KVUnzip, BuildOrderBy, QI, Destroy) + + +Class TerritoriesRepository_Class + + Public Function FindByID(id) + Dim sql : sql = "Select [Coordinates], [Description], [Id], [Name] FROM [Territories] WHERE [Id] = ?" + Dim rs : Set rs = DAL.Query(sql, Array(id)) + If rs.EOF Then + Err.Raise 1, "TerritoriesRepository_Class", RecordNotFoundException("Id", id) + Else + Set FindByID = Automapper.AutoMap(rs, "POBO_Territories") + End If + Destroy rs + End Function + + Public Function GetAll(orderBy) + Set GetAll = Find(Empty, orderBy) + End Function + + Public Function Find(where_kvarray, order_string_or_array) + Dim sql : sql = "Select [Coordinates], [Description], [Id], [Name] FROM [Territories]" + Dim where_keys, where_values, i + If Not IsEmpty(where_kvarray) Then + KVUnzip where_kvarray, where_keys, where_values + If Not IsEmpty(where_keys) Then + sql = sql & " WHERE " + For i = 0 To UBound(where_keys) + If i > 0 Then sql = sql & " AND " + sql = sql & " " & QI(where_keys(i)) & " = ?" + Next + End If + End If + sql = sql & BuildOrderBy(order_string_or_array, "[Id]") + Dim rs : Set rs = DAL.Query(sql, where_values) + Dim list : Set list = new LinkedList_Class + Do Until rs.EOF + list.Push Automapper.AutoMap(rs, "POBO_Territories") + rs.MoveNext + Loop + Set Find = list + Destroy rs + End Function + + Public Function FindPaged(where_kvarray, order_string_or_array, per_page, page_num, ByRef page_count, ByRef record_count) + Dim sql : sql = "Select [Coordinates], [Description], [Id], [Name] FROM [Territories]" + Dim where_keys, where_values, i + If Not IsEmpty(where_kvarray) Then + KVUnzip where_kvarray, where_keys, where_values + If Not IsEmpty(where_keys) Then + sql = sql & " WHERE " + For i = 0 To UBound(where_keys) + If i > 0 Then sql = sql & " AND " + sql = sql & " " & QI(where_keys(i)) & " = ?" + Next + End If + End If + sql = sql & BuildOrderBy(order_string_or_array, "[Id]") + Dim rs : Set rs = DAL.PagedQuery(sql, where_values, per_page, page_num) + If Not rs.EOF Then + rs.PageSize = per_page + rs.AbsolutePage = page_num + page_count = rs.PageCount + record_count = rs.RecordCount + End If + Set FindPaged = PagedList(rs, per_page) + Destroy rs + End Function + + Public Function SearchTablePaged(columns_array, search_value, order_string_or_array, per_page, page_num, ByRef page_count, ByRef record_count) + Dim sql : sql = "Select [Coordinates], [Description], [Id], [Name] FROM [Territories]" + Dim i, params() + If IsArray(columns_array) And UBound(columns_array) >= 0 Then + sql = sql & " WHERE " + ReDim params(UBound(columns_array)) + For i = 0 To UBound(columns_array) + If i > 0 Then sql = sql & " OR " + sql = sql & " " & QI(columns_array(i)) & " LIKE ?" + params(i) = "%" & search_value & "%" + Next + End If + sql = sql & BuildOrderBy(order_string_or_array, "[Id]") + Dim rs : Set rs = DAL.PagedQuery(sql, params, per_page, page_num) + If Not rs.EOF Then + rs.PageSize = per_page + rs.AbsolutePage = page_num + page_count = rs.PageCount + record_count = rs.RecordCount + End If + Set SearchTablePaged = PagedList(rs, per_page) + Destroy rs + End Function + + Private Function PagedList(rs, per_page) + Dim list : Set list = new LinkedList_Class + Dim x : x = 0 + Do While (per_page <= 0 Or x < per_page) And Not rs.EOF + list.Push Automapper.AutoMap(rs, "POBO_Territories") + x = x + 1 + rs.MoveNext + Loop + Set PagedList = list + End Function + + Public Sub AddNew(ByRef model) + Dim sql : sql = "INSERT INTO [Territories] ([Coordinates], [Description], [Name]) VALUES (?, ?, ?)" + DAL.[Execute] sql, Array(model.Coordinates, model.Description, model.Name) + + ' Retrieve the newly inserted ID + On Error Resume Next + Dim rsId : Set rsId = DAL.Query("SELECT @@IDENTITY AS NewID", Empty) + If Err.Number <> 0 Then + ' Fallback for Access databases + Err.Clear + Set rsId = DAL.Query("SELECT TOP 1 [Id] FROM [Territories] ORDER BY [Id] DESC", Empty) + End If + On Error GoTo 0 + + If Not rsId.EOF Then + If Not IsNull(rsId(0)) Then model.Id = rsId(0) + End If + Destroy rsId + End Sub + + Public Sub Update(model) + Dim sql : sql = "UPDATE [Territories] SET [Coordinates] = ?, [Description] = ?, [Name] = ? WHERE [Id] = ?" + DAL.[Execute] sql, Array(model.Coordinates, model.Description, model.Name, model.Id) + End Sub + + Public Sub Delete(id) + Dim sql : sql = "DELETE FROM [Territories] WHERE [Id] = ?" + DAL.[Execute] sql, Array(id) + End Sub + + Private Function RecordNotFoundException(ByVal field_name, ByVal field_val) + RecordNotFoundException = "Territories record was not found with " & field_name & " = '" & field_val & "'." + End Function + + Private Function QI(name) + QI = "[" & Replace(CStr(name), "]", "]]") & "]" + End Function + + Private Function BuildOrderBy(orderArg, defaultCol) + Dim s : s = "" + If IsEmpty(orderArg) Or IsNull(orderArg) Or orderArg = "" Then + s = " ORDER BY " & defaultCol & " ASC" + ElseIf IsArray(orderArg) Then + Dim i : s = " ORDER BY " + For i = 0 To UBound(orderArg) + If i > 0 Then s = s & ", " + s = s & QI(orderArg(i)) + Next + Else + s = " ORDER BY " & QI(orderArg) + End If + BuildOrderBy = s + End Function +End Class + +Dim TerritoriesRepository__Singleton +Function TerritoriesRepository() + If IsEmpty(TerritoriesRepository__Singleton) Then + Set TerritoriesRepository__Singleton = new TerritoriesRepository_Class + End If + Set TerritoriesRepository = TerritoriesRepository__Singleton +End Function +%> diff --git a/app/views/Household/create.asp b/app/views/Household/create.asp new file mode 100644 index 0000000..a7c7f3a --- /dev/null +++ b/app/views/Household/create.asp @@ -0,0 +1,153 @@ +
| ID | +Address | +Type | +DNC | +Street | +Territory | +Actions | +
|---|---|---|---|---|---|---|
| + <% If HouseholdController.searchTerm <> "" Then %> + No households found matching "<%= Server.HTMLEncode(HouseholdController.searchTerm) %>" + <% ElseIf HouseholdController.filterTerritoryId > 0 Then %> + No households found in this territory. + <% Else %> + No households found. Create one + <% End If %> + | +||||||
| <%= h.Id %> | +<%= Server.HTMLEncode(h.Address) %> | ++ <% If h.IsBusiness = 1 Then %> + Business + <% Else %> + Residential + <% End If %> + | +
+ <% If h.DoNotCall = 1 Then %>
+ Do Not Call
+ <% If IsDate(h.DoNotCallDate) Then %>
+ <%= FormatDateTime(h.DoNotCallDate, 2) %>
+ <% End If %>
+ <% Else %>
+ No
+ <% End If %>
+ |
+ <%= h.StreetNumber %> <%= Server.HTMLEncode(h.StreetName) %> | ++ + <% + If HouseholdController.territoryNamesById.Exists(CStr(h.TerritoryId)) Then + Response.Write Server.HTMLEncode(HouseholdController.territoryNamesById(CStr(h.TerritoryId))) + Else + Response.Write "Territory " & h.TerritoryId + End If + %> + + | ++ View + Edit + + | +
+ Page <%= HouseholdController.currentPage %> of <%= HouseholdController.pageCount %> +
+ <% End If %> +| Name | +Type | +Letter Status | +Actions | +
|---|---|---|---|
| + <%= Server.HTMLEncode(hn.Name & "") %> + | ++ <% If HouseholdController.household.IsBusiness = 1 Then %> + Business + <% Else %> + Residential + <% End If %> + | ++ + | ++ Edit + | +
Name: The name of the person or business at this address.
+Type: Business/Residential is now stored on the household, not the name.
+Letter Returned: Check if a letter sent to this name was returned as undeliverable.
+Permanently delete this householder name.
+ +| ID | +Name | +Type | +Letter Returned | +Created | +Actions | +
|---|---|---|---|---|---|
| + <% If HouseholderNameController.searchTerm <> "" Then %> + No householder names found matching "<%= Server.HTMLEncode(HouseholderNameController.searchTerm) %>" + <% ElseIf HouseholderNameController.filterHouseholdId > 0 Then %> + No householder names for this household. Add one + <% Else %> + No householder names found. Create one + <% End If %> + | +|||||
| <%= hn.Id %> | +<%= Server.HTMLEncode(hn.Name & "") %> | ++ Household + | ++ <% If hn.LetterReturned = 1 Then %> + Returned + <% If Year(hn.ReturnDate) > 1970 Then %> + <%= FormatDateTime(hn.ReturnDate, 2) %> + <% End If %> + <% Else %> + No + <% End If %> + | +<%= FormatDateTime(hn.Created, 2) %> | ++ View + Edit + + | +
+ Page <%= HouseholderNameController.currentPage %> of <%= HouseholderNameController.pageCount %> +
+ <% End If %> +| ID | +Name | +Description | +Households | +Actions | +
|---|---|---|---|---|
| + <% If TerritoryController.searchTerm <> "" Then %> + No territories found matching "<%= Server.HTMLEncode(TerritoryController.searchTerm) %>" + <% Else %> + No territories found. Create one + <% End If %> + | +||||
| <%= t.Id %> | +<%= Server.HTMLEncode(t.Name) %> | +<%= Server.HTMLEncode(Left(t.Description & "", 50)) %><% If Len(t.Description & "") > 50 Then Response.Write "..." End If %> | + <% + Dim householdCount + householdCount = 0 + If IsObject(TerritoryController.territoryHouseholdCounts) Then + If TerritoryController.territoryHouseholdCounts.Exists(CLng(t.Id)) Then + householdCount = TerritoryController.territoryHouseholdCounts(CLng(t.Id)) + End If + End If + %> +<%= householdCount %> | ++ View + Edit + + | +
+ Page <%= TerritoryController.currentPage %> of <%= TerritoryController.pageCount %> +
+ <% End If %> +