diff --git a/App/Controllers/Jurisdiction/JurisdictionController.asp b/App/Controllers/Jurisdiction/JurisdictionController.asp index a7a2dbf..5d159f6 100644 --- a/App/Controllers/Jurisdiction/JurisdictionController.asp +++ b/App/Controllers/Jurisdiction/JurisdictionController.asp @@ -649,7 +649,7 @@ Class JurisdictionController End Function Private Function BuildIMBDigits(mailerId, zipPlusFour) - Dim cleanMailerId, cleanZip + Dim cleanMailerId, cleanZip, inboundStid cleanMailerId = DigitsOnly(mailerId) cleanZip = DigitsOnly(zipPlusFour) @@ -657,7 +657,8 @@ Class JurisdictionController If Len(cleanMailerId) = 0 Or Len(cleanZip) = 0 Then BuildIMBDigits = "" Else - BuildIMBDigits = "00778" & cleanMailerId & "000000" & cleanZip + inboundStid = SettingsRepository.FindByName("Inbound STID") + BuildIMBDigits = inboundStid & cleanMailerId & "000000" & cleanZip End If End Function diff --git a/App/Controllers/Kit/KitController.asp b/App/Controllers/Kit/KitController.asp index 83ad95a..a76476e 100644 --- a/App/Controllers/Kit/KitController.asp +++ b/App/Controllers/Kit/KitController.asp @@ -99,13 +99,173 @@ Class KitController set Model.Kit = KitRepository.SwitchBoardPurpleEnvelopeEditFindById(id) set Model.StidDropDown = SettingsRepository.GetStidDropDownRS() set Model.ColorsDropDown = ColorsRepository.GetColorsDropDownRS() - set Model.Precincts = InkjetRecordsRepository.GetDistinctPrecinctsByKitId(id) + set Model.Precincts = SortPrecinctColorRows(InkjetRecordsRepository.GetDistinctPrecinctsByKitId(id)) + set Model.PrecinctBallotRanges = SortPrecinctBallotRangeRows(InkjetRecordsRepository.GetPrecinctBallotRangesByKitId(id)) + On Error Resume Next + Model.PurpleEnvelopeElectionLabel = FormatPurpleEnvelopeElectionLabel(SettingsRepository.FindByName("Electiondate")) + If Err.Number <> 0 Then + Model.PurpleEnvelopeElectionLabel = "" + Err.Clear + End If + On Error GoTo 0 Model.Title = "Purple Envelopes for " HTMLSecurity.SetAntiCSRFToken "KitEditForm" HTMLSecurity.SetAntiCSRFToken "ColorAssignForm" %> <% End Sub + Private Function FormatPurpleEnvelopeElectionLabel(ByVal rawValue) + FormatPurpleEnvelopeElectionLabel = Trim(rawValue & "") + If Len(FormatPurpleEnvelopeElectionLabel) = 0 Then Exit Function + + On Error Resume Next + dim parsedDate : parsedDate = CDate(rawValue) + If Err.Number = 0 Then + FormatPurpleEnvelopeElectionLabel = MonthName(Month(parsedDate), True) & "-" & CStr(Year(parsedDate)) + Else + Err.Clear + End If + On Error GoTo 0 + End Function + + Private Function SortPrecinctColorRows(ByVal rs) + dim list : set list = new LinkedList_Class + If rs.EOF Then + set SortPrecinctColorRows = list + Exit Function + End If + + dim items() + dim itemCount : itemCount = -1 + Do Until rs.EOF + itemCount = itemCount + 1 + ReDim Preserve items(itemCount) + + dim row : set row = new PrecinctColorRow_ViewModel_Class + row.PRECINCT = rs("PRECINCT") + If IsNull(rs("ColorId")) Then + row.ColorId = "" + Else + row.ColorId = rs("ColorId") + End If + Set items(itemCount) = row + rs.MoveNext + Loop + + SortPrecinctItems items + + dim i + For i = 0 To UBound(items) + list.Push items(i) + Next + + set SortPrecinctColorRows = list + End Function + + Private Function SortPrecinctBallotRangeRows(ByVal rs) + dim list : set list = new LinkedList_Class + If rs.EOF Then + set SortPrecinctBallotRangeRows = list + Exit Function + End If + + dim items() + dim itemCount : itemCount = -1 + Do Until rs.EOF + itemCount = itemCount + 1 + ReDim Preserve items(itemCount) + + dim row : set row = new PrecinctBallotRangeRow_ViewModel_Class + row.PRECINCT = rs("PRECINCT") + row.LowBallotNumber = rs("LowBallotNumber") + row.HighBallotNumber = rs("HighBallotNumber") + Set items(itemCount) = row + rs.MoveNext + Loop + + SortPrecinctItems items + + dim i + For i = 0 To UBound(items) + list.Push items(i) + Next + + set SortPrecinctBallotRangeRows = list + End Function + + Private Sub SortPrecinctItems(ByRef items) + If Not IsArray(items) Then Exit Sub + + dim i, j + For i = 0 To UBound(items) - 1 + For j = i + 1 To UBound(items) + If PrecinctSortsBefore(items(j).PRECINCT, items(i).PRECINCT) Then + dim temp : set temp = items(i) + Set items(i) = items(j) + Set items(j) = temp + End If + Next + Next + End Sub + + Private Function PrecinctSortsBefore(ByVal leftPrecinct, ByVal rightPrecinct) + dim leftType, leftNumber, leftSuffix, leftNormalized + dim rightType, rightNumber, rightSuffix, rightNormalized + + ParsePrecinctSortParts leftPrecinct, leftType, leftNumber, leftSuffix, leftNormalized + ParsePrecinctSortParts rightPrecinct, rightType, rightNumber, rightSuffix, rightNormalized + + If leftType <> rightType Then + PrecinctSortsBefore = (leftType < rightType) + Exit Function + End If + + If leftType = 0 Then + If leftNumber <> rightNumber Then + PrecinctSortsBefore = (leftNumber < rightNumber) + Exit Function + End If + + If leftSuffix <> rightSuffix Then + PrecinctSortsBefore = (leftSuffix < rightSuffix) + Exit Function + End If + End If + + If leftNormalized <> rightNormalized Then + PrecinctSortsBefore = (leftNormalized < rightNormalized) + Else + PrecinctSortsBefore = (UCase(Trim(leftPrecinct & "")) < UCase(Trim(rightPrecinct & ""))) + End If + End Function + + Private Sub ParsePrecinctSortParts(ByVal precinct, ByRef precinctType, ByRef numericPart, ByRef suffixPart, ByRef normalizedText) + dim rawPrecinct : rawPrecinct = Trim(precinct & "") + dim leadingDigits : leadingDigits = "" + dim i, currentChar + + For i = 1 To Len(rawPrecinct) + currentChar = Mid(rawPrecinct, i, 1) + If currentChar >= "0" And currentChar <= "9" Then + leadingDigits = leadingDigits & currentChar + Else + Exit For + End If + Next + + If Len(leadingDigits) > 0 Then + precinctType = 0 + numericPart = CLng(leadingDigits) + suffixPart = UCase(Trim(Mid(rawPrecinct, Len(leadingDigits) + 1))) + normalizedText = CStr(numericPart) & "|" & suffixPart + Else + precinctType = 1 + numericPart = 0 + suffixPart = UCase(rawPrecinct) + normalizedText = suffixPart + End If + End Sub + Public Sub Index dim page_size : page_size = 10 diff --git a/App/DomainModels/InkjetRecordsRepository.asp b/App/DomainModels/InkjetRecordsRepository.asp index ad271b8..9ae3346 100644 --- a/App/DomainModels/InkjetRecordsRepository.asp +++ b/App/DomainModels/InkjetRecordsRepository.asp @@ -340,6 +340,16 @@ Class InkjetRecordsRepository_Class set GetDistinctPrecinctsByKitId = rs End Function + Public Function GetPrecinctBallotRangesByKitId(KitID) + dim sql : sql = "SELECT [PRECINCT], MIN(VAL([BALLOT_NUMBER])) AS [LowBallotNumber], MAX(VAL([BALLOT_NUMBER])) AS [HighBallotNumber] " &_ + "FROM [InkjetRecords] " &_ + "WHERE [KitID] = ? " &_ + "GROUP BY [PRECINCT] " &_ + "ORDER BY VAL([PRECINCT]) ASC, [PRECINCT] ASC" + dim rs : set rs = DAL.Query(sql, KitID) + set GetPrecinctBallotRangesByKitId = rs + End Function + Public Sub UpdateColorForKit(KitID, ColorId) dim sql : sql = "UPDATE [InkjetRecords] SET [ColorId] = ? WHERE [KitID] = ?" DAL.Execute sql, Array(ColorId, KitID) diff --git a/App/DomainModels/KitLabelsRepository.asp b/App/DomainModels/KitLabelsRepository.asp index 934ec0a..6f0b995 100644 --- a/App/DomainModels/KitLabelsRepository.asp +++ b/App/DomainModels/KitLabelsRepository.asp @@ -201,6 +201,7 @@ Class KitLabelsRepository_Class Dim SerialNumberStart:SerialNumberStart = SettingsRepository.Find(Array("Name =?","SerialNumberStart"),empty).pop().Value Dim serialOffset:serialOffset = SettingsRepository.Find(Array("Name =?","SerialOffset"),empty).pop().Value Dim SerialStart:SerialStart = CLng(SerialNumberStart) + CLng(serialOffset) + Dim InboundStid : InboundStid = SettingsRepository.FindByName("Inbound STID") dim i,s s = 1 for i = 0 to (Amount * 2) - 2 Step 2 @@ -211,7 +212,7 @@ Class KitLabelsRepository_Class NewKitLabel.OutboundSerial = PadLeft(SerialStart + i,9,"0") NewKitLabel.InBoundSerial = PadLeft(SerialStart + i + 1,9,"0") NewKitLabel.OutboundIMBDigits ="00716" & MailingID & NewKitLabel.OutboundSerial - NewKitLabel.InBoundIMBDigits = "00778" & MailingID & NewKitLabel.InBoundSerial & right(Jurisdiction.IMB_Digits,9) + NewKitLabel.InBoundIMBDigits = InboundStid & MailingID & NewKitLabel.InBoundSerial & right(Jurisdiction.IMB_Digits,9) dim imbJson : imbJson = rest.FullRequestNoBody("get","/ppro-tools-api/imb/encode?imb=" & NewKitLabel.OutboundIMBDigits) json.loadJSON(imbJson) diff --git a/App/ViewModels/KitViewModels.asp b/App/ViewModels/KitViewModels.asp index 67e3881..ca86e49 100644 --- a/App/ViewModels/KitViewModels.asp +++ b/App/ViewModels/KitViewModels.asp @@ -22,6 +22,19 @@ Class SwitchBoard_ViewModel_Class Public StidDropDown Public ColorsDropDown Public Precincts + Public PrecinctBallotRanges + Public PurpleEnvelopeElectionLabel +End Class + +Class PrecinctColorRow_ViewModel_Class + Public PRECINCT + Public ColorId +End Class + +Class PrecinctBallotRangeRow_ViewModel_Class + Public PRECINCT + Public LowBallotNumber + Public HighBallotNumber End Class Class SwitchBoard_PurpleEnvelopesViewModel_Class diff --git a/App/Views/Kit/SwitchBoardPurpleEnvelopeEdit.asp b/App/Views/Kit/SwitchBoardPurpleEnvelopeEdit.asp index e3c51bf..6b47c56 100644 --- a/App/Views/Kit/SwitchBoardPurpleEnvelopeEdit.asp +++ b/App/Views/Kit/SwitchBoardPurpleEnvelopeEdit.asp @@ -1,6 +1,92 @@
| Precinct | +Low Ballot Number | +High Ballot Number | +
|---|---|---|
| <%= H(ballotRangeRow.PRECINCT) %> | +<%= H(ballotRangeRow.LowBallotNumber) %> | +<%= H(ballotRangeRow.HighBallotNumber) %> | +
| No precinct ballot data found for this kit. | +||