From 8bb6310f3b8a15b8ff7833b1e1764269028c6807 Mon Sep 17 00:00:00 2001 From: Daniel Covington Date: Fri, 17 May 2024 15:53:56 -0400 Subject: [PATCH] Cleaned up some things and Got the inkjetexport process working --- ImportService/MMJOB.mjb | 4 +- ImportService/TrackingDataImport.vbs | 107 +++++++++++++++++++++------ 2 files changed, 85 insertions(+), 26 deletions(-) diff --git a/ImportService/MMJOB.mjb b/ImportService/MMJOB.mjb index c712abe..45d7a7a 100644 --- a/ImportService/MMJOB.mjb +++ b/ImportService/MMJOB.mjb @@ -31,7 +31,7 @@ PARALLEL=N WAIT=DEFAULT STARTTIME=DEFAULT SUPPRESSERRORS=Y -[EXPORT-6] +[EXPORT-5] LIST="\\Mm2012\apps\BCC\MM2010\Lists\tracking_Test.dbf" SETTINGS="Delimited: FROM_MM" -[TERMINATE-7] \ No newline at end of file +[TERMINATE-6] \ No newline at end of file diff --git a/ImportService/TrackingDataImport.vbs b/ImportService/TrackingDataImport.vbs index 4a1d2f9..0e28ef0 100644 --- a/ImportService/TrackingDataImport.vbs +++ b/ImportService/TrackingDataImport.vbs @@ -64,34 +64,66 @@ Function ExportInkjetFile(KitID) " LEFT JOIN [KitLabels] ON InkjetRecords.KitLabelID = KitLabels.ID" & _ " WHERE InkjetRecords.KitID =" & KitID & " ;") Dim JurisdictionRs:Set JurisdictionRs = oConn.Execute("SELECT * FROM Jurisdiction WHERE JCode ='" & KitRs("Jcode").Value & "';") - Dim ExportFileName:ExportFileName = objFSO.GetBaseName(KitRs("Filename")) & ".1up" + Dim ExportFileName:ExportFileName = objFSO.GetBaseName(KitRs("Filename")) & ".csv" If Not objFSO.FolderExists(ExportDirectory & KitRs("JobNumber").Value & "-" & JurisdictionRs("Name").value) Then:objFSO.CreateFolder(ExportDirectory & KitRs("JobNumber").Value & "-" & JurisdictionRs("Name").value):End If If objFSO.FileExists(ExportDirectory & KitRs("JobNumber").Value & "-" & JurisdictionRs("Name").value & "/" & ExportFileName) Then:objFSO.DeleteFile(ExportDirectory & KitRs("JobNumber").Value & "-" & JurisdictionRs("Name").value & "/" & ExportFileName):End If - Dim objExportFile:set objExportFile = objFSO.CreateTextFile(ExportDirectory & KitRs("JobNumber").Value & "-" & JurisdictionRs("Name").value & "/" & ExportFileName,2) Dim ElectionDate:ElectionDate=GetSetting("ElectionDate") - objExportFile.Writeline("Election Date") - objExportFile.Writeline("Full Name") - objExportFile.Writeline("Alternate 1 Address") - objExportFile.Writeline("Delivery Address") - objExportFile.Writeline("City St ZIP+4") - objExportFile.Writeline("") - objExportFile.Writeline("*Voter ID*") - objExportFile.Writeline("Precinct") - objExportFile.Writeline("Ballot Number") - objExportFile.Writeline("Clerk Name") - objExportFile.Writeline("City or Township Name") - objExportFile.Writeline("Return Address") - objExportFile.Writeline("Return CSZ") - objExportFile.Writeline("Jurisdiction IMB") - + + Dim objInkjetCSV:Set objInkJetCSV = CreateObject("Chilkat_9_5_0.Csv") + objInkjetCSV.HasColumnNames = 1 + objInkjetCSV.EnableQuotes = 1 + + objInkjetCSV.SetColumnName 0,"Full Name" + objInkjetCSV.SetColumnName 1,"Company" + objInkjetCSV.SetColumnName 2,"Alternate 1 Address" + objInkjetCSV.SetColumnName 3,"Delivery Address" + objInkjetCSV.SetColumnName 4,"City St ZIP+4" + objInkjetCSV.SetColumnName 5,"IM barcode Characters" + objInkjetCSV.SetColumnName 6,"Precinct" + objInkjetCSV.SetColumnName 7,"Ballot ID" + objInkjetCSV.SetColumnName 8,"Ballot Number" + objInkjetCSV.SetColumnName 9,"Jurisdiction code" + objInkjetCSV.SetColumnName 10,"Election Date" + objInkJetCSV.SetColumnName 11,"Combined Pct_Ballot Num" + objInkJetCSV.SetColumnName 12,"Voter ID" + objInkJetCSV.SetColumnName 13,"2D Matrix Barcode" + objInkJetCSV.SetColumnName 14,"G2 Full Name" + objInkJetCSV.SetColumnName 15,"G2 Company" + objInkJetCSV.SetColumnName 16,"G2 Alternate 1 Address" + objInkJetCSV.SetColumnName 17,"G2 Delivery Address" + objInkJetCSV.SetColumnName 18,"G2 City St ZIP+4" + objInkJetCSV.SetColumnName 19,"G2 IM barcode Characters" + objInkJetCSV.SetColumnName 20,"NEW Ballot No f" + +Dim AddressArray +Dim row:row = 0 While Not KitLabelsRs.EOF - objExportFile.Writeline(ElectionDate) - objExportFile.Writeline(KitLabelsRs("CassADDRESS1").Value) - objExportFile.Writeline("") - objExportFile.Writeline("*" & KitLabelsRs("VOTERID").Value & "*") + AddressArray = CompressArray(Array(KitLabelsRs("CassADDRESS1").Value,KitLabelsRs("CassADDRESS2").Value,KitLabelsRs("CassADDRESS3").Value,KitLabelsRs("CassADDRESS4").Value,KitLabelsRs("CassADDRESS5").Value)) + objInkjetCSV.SetCellByName row,"Full Name",AddressArray(0) + objInkjetCSV.SetCellByName row,"Company",AddressArray(1) + objInkjetCSV.SetCellByName row,"Alternate 1 Address",AddressArray(2) + objInkjetCSV.SetCellByName row,"Delivery Address",AddressArray(3) + objInkjetCSV.SetCellByName row,"City St ZIP+4",AddressArray(4) + objInkJetCSV.SetCellByName row,"IM barcode Characters",KitLabelsRs("OutboundIMBDigits").Value + objInkJetCSV.SetCellByName row,"Precinct",KitLabelsRs("PRECINCT").Value + objInkJetCSV.SetCellByName row,"Ballot ID",KitLabelsRs("VOTERID").Value + objInkJetCSV.SetCellByName row,"Jurisdiction code",KitRs("Jcode").Value + objInkJetCSV.SetCellByName row,"Election Date",ElectionDate + objInkJetCSV.SetCellByName row,"Combined Pct_Ballot Num",KitLabelsRs("PRECINCT").Value & KitLabelsRs("BALLOT_NUMBER").Value + objInkJetCSV.SetCellByName row,"Voter ID",KitLabelsRs("VOTERID").Value + objInkJetCSV.SetCellByName row,"2D Matrix Barcode",KitRs("Jcode").Value & KitLabelsRs("BALLOT_NUMBER").Value + objInkJetCSV.SetCellByName row,"G2 Full Name",JurisdictionRs("Name").Value + objInkJetCSV.SetCellByName row,"G2 Company",JurisdictionRs("Mailing_Address").Value + objInkJetCSV.SetCellByName row,"G2 Alternate 1 Address",JurisdictionRs("CSZ").Value + objInkJetCSV.SetCellByName row,"G2 Delivery Address","" + objInkJetCSV.SetCellByName row,"G2 City St ZIP+4","" + objInkJetCSV.SetCellByName row,"G2 IM barcode Characters",JurisdictionRs("IMB_Digits").Value + objInkJetCSV.SetCellByName row,"NEW Ballot No f",TrimLeadingZeros(KitLabelsRs("PRECINCT").Value) & TrimLeadingZeros(KitLabelsRs("BALLOT_NUMBER").Value) + 'Where do we put the roundtrip IMB + row = row + 1 KitLabelsRs.MoveNext Wend - + objInkjetCSV.SaveFile(ExportDirectory & KitRs("JobNumber").Value & "-" & JurisdictionRs("Name").value & "/" & ExportFileName) @@ -103,7 +135,7 @@ Function ExportInkjetFile(KitID) If JurisdictionRs.State = 1 Then:JurisdictionRs.Close:End If If oConn.State = 1 Then:oConn.Close:End If End Function - + Function CheckStatusFor(StatusString) If oConn.State = 0 Then:oConn.Open(ConnectionString):End If Dim rs:Set rs = oConn.Execute("Select TOP 1 [ID] FROM [Kit] Where Status ='" & StatusString & "' and JobType='Purple Envelopes';") @@ -269,6 +301,7 @@ Function CreateExportForSnailWorks(KitID) End Function Function createTrackingInfoForKit(KitID) +If oConn.State = 0 Then:oConn.Open(ConnectionString):End If oConn.Execute("UPDATE Kit SET Status ='Applying Serial Numbers' WHERE ID =" & KitID & ";") Dim KitRs:set KitRs = oConn.Execute("Select * from Kit Where ID =" & KitID & ";") Dim InkjetRs:Set InkjetRs = oConn.Execute("Select * from InkjetRecords Where KitID =" & KitID & ";") @@ -301,7 +334,7 @@ InkjetRs.MoveNext Wend oConn.Execute("UPDATE Settings Set [Value]='" & serialOffset + Counter & "' WHERE [Name] = 'SerialOffset';") oConn.Execute("UPDATE Kit Set [Status]='Ready For Export', LabelsPrinted=#" & Now() & "# WHERE [ID] =" & KitID &";") - + oConn.Close End Function Function GetSetting(settingName) @@ -569,4 +602,30 @@ Public Function Choice(ByVal cond, ByVal if_true, ByVal if_false) Else Assign Choice, if_false End If +End Function + +Function CompressArray(arr) + Dim temp,i,j + For i = LBound(arr) To UBound(arr) - 1 + For j = i + 1 To UBound(arr) + If arr(i) = "" Then + temp = arr(i) + arr(i) = arr(j) + arr(j) = temp + End If + Next + Next + CompressArray = arr +End Function + +Function TrimLeadingZeros(inputStr) + Dim i + For i = 1 To Len(inputStr) + If Mid(inputStr, i, 1) <> "0" Then + TrimLeadingZeros = Mid(inputStr, i) + Exit Function + End If + Next + ' If the input string is all zeros, return "0" + TrimLeadingZeros = "0" End Function \ No newline at end of file