選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

TrackingDataImport.vbs 33KB

4ヶ月前
4ヶ月前
4ヶ月前
5ヶ月前
5ヶ月前
6ヶ月前
5ヶ月前
6ヶ月前
4ヶ月前
4ヶ月前
4ヶ月前
4ヶ月前
4ヶ月前
4ヶ月前
4ヶ月前
4ヶ月前
4ヶ月前
4ヶ月前
6ヶ月前
4ヶ月前
4ヶ月前
4ヶ月前
7ヶ月前
7ヶ月前
7ヶ月前
6ヶ月前
5ヶ月前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713
  1. Option Explicit
  2. Dim dev:dev = False
  3. Dim outFile
  4. Dim WaitTime:WaitTime = 15000
  5. Dim DataDirectory
  6. Dim ExportDirectory
  7. Dim PurpleEnvelopeProofReport
  8. Dim WshShell:Set WshShell = WScript.CreateObject("Wscript.Shell")
  9. Dim oConn:Set oConn = WScript.CreateObject("ADODB.Connection")
  10. Dim ConnectionString
  11. Dim objFSO:Set objFSO = CreateObject("Scripting.FileSystemObject")
  12. Dim glob:set glob = CreateObject("Chilkat_9_5_0.Global")
  13. Dim success:success = glob.UnlockBundle("KENTCM.CB1022025_RGzBPM5J655e")
  14. If (success <> 1) Then
  15. WriteLine(glob.LastErrorText)
  16. WScript.Quit
  17. End If
  18. Dim objCSV:Set objCsv = CreateObject("Chilkat_9_5_0.Csv")
  19. Dim WorkingDirectory:WorkingDirectory = Replace(WScript.ScriptFullName,WScript.ScriptName,"")
  20. If dev Then
  21. DataDirectory = WorkingDirectory & "test"
  22. ExportDirectory = "\\kci-syn-cl01\PC Transfer\TrackingDataExport\"
  23. ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:Engine Type=5;Data Source=F:\Development\Tracking_Kits\Data\webdata - Copy.mdb;"
  24. PurpleEnvelopeProofReport = "F:\Development\Tracking_Kits\Data\Proofs.rep"
  25. set outFile = objFSO.CreateTextFile("\\kci-syn-cl01\PC Transfer\TrackingDataExport\temp.csv",True)
  26. Else
  27. DataDirectory = "\\kci-syn-cl01\PC Transfer\TrackingDataImport"
  28. ExportDirectory = "\\kci-syn-cl01\PC Transfer\TrackingDataExport\"
  29. ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:Engine Type=5;Data Source=C:\inetpub\Data\webdata - Copy.mdb;"
  30. PurpleEnvelopeProofReport ="C:\inetpub\tracking\Data\Proofs.rep"
  31. set outFile = objFSO.CreateTextFile("\\kci-syn-cl01\PC Transfer\TrackingDataExport\temp.csv",True)
  32. End If
  33. 'ToDo create a checkstatus function so I dont need four functions of create a case switch that responds to the status of jobs
  34. Dim KitID:CheckForFiles:KitID = CheckForJobsToCass()
  35. If KitID > 0 Then
  36. ExportMMCsv(KitID)
  37. RunMailManager
  38. ImportCass
  39. End If
  40. KitID = CheckStatusFor("Ready to Assign Labels"):If KitID > 0 Then:createTrackingInfoForKit(KitID):End If
  41. KitID = CheckStatusFor("Ready For Export"):If KitID > 0 Then:CreateExportForSnailWorks(KitID):End If
  42. KitID = CheckStatusFor("Ready to Proof"):If KitID > 0 Then:CreateProofForJurisdiction(KitID):End If
  43. KitID = CheckStatusFor("Ready For Inkjet Export"):If KitID > 0 Then:ExportInkjetFile(KitID):End If
  44. CheckSnailWorksPurpleEnvelopeExport
  45. CheckSnailWorksTrakingKitExport
  46. WScript.Quit
  47. Sub CheckSnailWorksPurpleEnvelopeExport
  48. Dim Sftp:set Sftp = CreateObject("Chilkat_9_5_0.SFtp")
  49. Dim objFolder
  50. Dim success
  51. Set objFolder = objFSO.GetFolder("\\kci-syn-cl01\PC Transfer\TrackingDataExport\Export Purple Envelopes")
  52. If objFolder.Files.Count > 0 Then
  53. success = Sftp.Connect("sftp.snailworks.com",22)
  54. success = Sftp.AuthenticatePw("KCIHotFolder2024FTPUser","Z!4WXLSQMM#f")
  55. success = Sftp.InitializeSftp()
  56. Dim file
  57. For Each file In objFolder.Files
  58. debug.WriteLine file.Path
  59. Dim handle:handle = Sftp.OpenFile(file.Name,"writeOnly","createTruncate")
  60. Sftp.UploadFile handle,file.Path
  61. Sftp.CloseHandle handle
  62. file.Delete
  63. Next
  64. End If
  65. End Sub
  66. Sub CheckSnailWorksTrakingKitExport
  67. Dim Sftp:set Sftp = CreateObject("Chilkat_9_5_0.SFtp")
  68. Dim objFolder
  69. Dim success
  70. Set objFolder = objFSO.GetFolder("\\kci-syn-cl01\PC Transfer\TrackingDataExport\Export Tracking Kits")
  71. If objFolder.Files.Count > 0 Then
  72. success = Sftp.Connect("sftp.snailworks.com",22)
  73. success = Sftp.AuthenticatePw("KCI2024Type2FTPUser","Z!NXVRV5SH#f")
  74. success = Sftp.InitializeSftp()
  75. Dim file
  76. For Each file In objFolder.Files
  77. debug.WriteLine file.Path
  78. Dim handle:handle = Sftp.OpenFile(file.Name,"writeOnly","createTruncate")
  79. Sftp.UploadFile handle,file.Path
  80. Sftp.CloseHandle handle
  81. file.Delete
  82. Next
  83. End If
  84. End Sub
  85. Function ExportInkjetFile(KitID)
  86. If oConn.State = 0 Then:oConn.Open(ConnectionString):End If
  87. Dim KitRs:set KitRs = oConn.Execute("Select * From [Kit] Where [ID] =" & KitID & ";")
  88. Dim KitLabelsRs: Set KitLabelsRs = oConn.Execute("Select * FROM (SELECT IIf(Len([PRECINCT]) = 1, '0' & [PRECINCT] & Right([BALLOT_NUMBER],4), [PRECINCT] & Right([BALLOT_NUMBER],4)) AS SORT_ORDER," &_
  89. "InkjetRecords.ID, InkjetRecords.KitID, InkjetRecords.VOTERID, InkjetRecords.LASTNAME," &_
  90. " InkjetRecords.FIRSTNAME, InkjetRecords.MIDDLENAME, InkjetRecords.SUFFIX, InkjetRecords.PRECINCT," &_
  91. " InkjetRecords.ADDRESS1, InkjetRecords.ADDRESS2, InkjetRecords.ADDRESS3, InkjetRecords.ADDRESS4," &_
  92. " InkjetRecords.ADDRESS5, InkjetRecords.APPSENT, InkjetRecords.APPRETURNED, InkjetRecords.BALSENT," &_
  93. " InkjetRecords.BALRETURNED, InkjetRecords.CountingBoard, InkjetRecords.UOCAVASTATUS, InkjetRecords.EMAILADDRESS," &_
  94. " InkjetRecords.PHONENUMBER, InkjetRecords.BALLOT_NUMBER, InkjetRecords.CassADDRESS1, InkjetRecords.CassADDRESS2," &_
  95. " InkjetRecords.CassADDRESS3, InkjetRecords.CassADDRESS4, InkjetRecords.CassADDRESS5, InkjetRecords.KitLabelID," &_
  96. " KitLabels.ID, KitLabels.KitID, KitLabels.OutboundSerial, KitLabels.InBoundSerial, KitLabels.OutboundIMB," &_
  97. " KitLabels.InBoundIMB, KitLabels.OutboundIMBDigits, KitLabels.InBoundIMBDigits, KitLabels.OutboundIMBPNG," &_
  98. " KitLabels.INBOUNDIMBPNG, KitLabels.SetNumber" &_
  99. " FROM InkjetRecords" &_
  100. " LEFT JOIN [KitLabels] ON InkjetRecords.KitLabelID = KitLabels.ID" & _
  101. " WHERE InkjetRecords.KitID =" & KitID & ") as [Data] Order By SORT_ORDER Desc;")
  102. Dim JurisdictionRs:Set JurisdictionRs = oConn.Execute("SELECT * FROM Jurisdiction WHERE JCode ='" & KitRs("Jcode").Value & "';")
  103. Dim ContactRs:Set ContactRs = oConn.Execute("SELECT * FROM Contacts WHERE [JURISCODE] ='" & KitRs("Jcode").Value & "';")
  104. Dim ExportFileName:ExportFileName = objFSO.GetBaseName(KitRs("Filename")) & ".csv"
  105. If Not objFSO.FolderExists(ExportDirectory & KitRs("JobNumber").Value & "-" & JurisdictionRs("Name").value) Then:objFSO.CreateFolder(ExportDirectory & KitRs("JobNumber").Value & "-" & JurisdictionRs("Name").value):End If
  106. If objFSO.FileExists(ExportDirectory & KitRs("JobNumber").Value & "-" & JurisdictionRs("Name").value & "/" & ExportFileName) Then:objFSO.DeleteFile(ExportDirectory & KitRs("JobNumber").Value & "-" & JurisdictionRs("Name").value & "/" & ExportFileName):End If
  107. Dim ElectionDate:ElectionDate=GetSetting("ElectionDate")
  108. Dim objInkjetCSV:Set objInkJetCSV = CreateObject("Chilkat_9_5_0.Csv")
  109. objInkjetCSV.HasColumnNames = 1
  110. objInkjetCSV.EnableQuotes = 1
  111. objInkjetCSV.SetColumnName 0,"Full Name"
  112. objInkjetCSV.SetColumnName 1,"Address 1"
  113. objInkjetCSV.SetColumnName 2,"Address 2"
  114. objInkjetCSV.SetColumnName 3,"Address 3"
  115. objInkjetCSV.SetColumnName 4,"Address 4"
  116. objInkjetCSV.SetColumnName 5,"IM barcode Characters"
  117. objInkjetCSV.SetColumnName 6,"Precinct"
  118. objInkjetCSV.SetColumnName 7,"Ballot ID"
  119. objInkjetCSV.SetColumnName 8,"Ballot Number"
  120. objInkjetCSV.SetColumnName 9,"Jurisdiction code"
  121. objInkjetCSV.SetColumnName 10,"Election Date"
  122. objInkJetCSV.SetColumnName 11,"Combined Pct_Ballot Num"
  123. objInkJetCSV.SetColumnName 12,"Title"
  124. objInkJetCSV.SetColumnName 13,"G2 Full Name"
  125. objInkJetCSV.SetColumnName 14,"G2 Company"
  126. objInkJetCSV.SetColumnName 15,"G2 Alternate 1 Address"
  127. objInkJetCSV.SetColumnName 16,"G2 Delivery Address"
  128. objInkJetCSV.SetColumnName 17,"G2 City St ZIP+4"
  129. objInkJetCSV.SetColumnName 18,"G2 IM barcode Characters"
  130. objInkJetCSV.SetColumnName 19,"Matching Code"
  131. Dim AddressArray
  132. Dim row:row = 0
  133. While Not KitLabelsRs.EOF
  134. AddressArray = CompressArray(Array(KitLabelsRs("CassADDRESS1").Value,KitLabelsRs("CassADDRESS2").Value,KitLabelsRs("CassADDRESS3").Value,KitLabelsRs("CassADDRESS4").Value,KitLabelsRs("CassADDRESS5").Value))
  135. objInkjetCSV.SetCellByName row,"Full Name",AddressArray(0)
  136. objInkjetCSV.SetCellByName row,"Address 1",AddressArray(1)
  137. objInkjetCSV.SetCellByName row,"Address 2",AddressArray(2)
  138. objInkjetCSV.SetCellByName row,"Address 3",AddressArray(3)
  139. objInkjetCSV.SetCellByName row,"Address 4",AddressArray(4)
  140. objInkJetCSV.SetCellByName row,"IM barcode Characters",KitLabelsRs("OutboundIMBDigits").Value
  141. objInkJetCSV.SetCellByName row,"Precinct",KitLabelsRs("PRECINCT").Value
  142. objInkJetCSV.SetCellByName row,"Ballot ID","*" & KitLabelsRs("VOTERID").Value & "*"
  143. objInkJetCSV.SetCellByName row,"Ballot Number",TrimLeadingZeros(KitLabelsRs("BALLOT_NUMBER").Value)
  144. objInkJetCSV.SetCellByName row,"Jurisdiction code",KitRs("Jcode").Value
  145. objInkJetCSV.SetCellByName row,"Election Date",ElectionDate
  146. objInkJetCSV.SetCellByName row,"Combined Pct_Ballot Num",KitLabelsRs("PRECINCT").Value & TrimLeadingZeros(KitLabelsRs("BALLOT_NUMBER").Value)
  147. objInkjetCSV.SetCellByName row,"Title",CleanNull(ContactRs("Title").Value)
  148. objInkJetCSV.SetCellByName row,"G2 Full Name",JurisdictionRs("Name").Value
  149. objInkJetCSV.SetCellByName row,"G2 Company",JurisdictionRs("Mailing_Address").Value
  150. objInkJetCSV.SetCellByName row,"G2 Alternate 1 Address",JurisdictionRs("CSZ").Value
  151. objInkJetCSV.SetCellByName row,"G2 Delivery Address",""
  152. objInkJetCSV.SetCellByName row,"G2 City St ZIP+4",""
  153. objInkJetCSV.SetCellByName row,"G2 IM barcode Characters",JurisdictionRs("IMB_Digits").Value
  154. objInkJetCSV.SetCellByName row,"Matching Code",KitRs("Jcode").Value & TrimLeadingZeros(KitLabelsRs("PRECINCT").Value) & TrimLeadingZeros(KitLabelsRs("BALLOT_NUMBER").Value)
  155. 'Where do we put the roundtrip IMB
  156. row = row + 1
  157. KitLabelsRs.MoveNext
  158. Wend
  159. objInkjetCSV.SaveFile(ExportDirectory & KitRs("JobNumber").Value & "-" & JurisdictionRs("Name").value & "/" & ExportFileName)
  160. oConn.Execute("UPDATE KIT SET [Status] ='Done',[InkJetJob]=1 WHERE [ID] =" & KitID & ";")
  161. If KitRs.State = 1 Then:KitRs.Close:End If
  162. If ContactRs.State =1 Then:ContactRs.Close:End If
  163. If KitLabelsRs.State = 1 Then:KitLabelsRs.Close: End If
  164. If JurisdictionRs.State = 1 Then:JurisdictionRs.Close:End If
  165. If oConn.State = 1 Then:oConn.Close:End If
  166. End Function
  167. Function CheckStatusFor(StatusString)
  168. If oConn.State = 0 Then:oConn.Open(ConnectionString):End If
  169. Dim rs:Set rs = oConn.Execute("Select TOP 1 [ID] FROM [Kit] Where Status ='" & StatusString & "' and JobType='Purple Envelopes';")
  170. If Not rs.EOF Then
  171. CheckStatusFor = rs("ID").value
  172. Else
  173. CheckStatusFor = 0
  174. End If
  175. If rs.State = 1 Then:rs.Close:End If
  176. If oConn.State = 1 Then:oConn.Close:End If
  177. End Function
  178. Function CreateProofForJurisdiction(KitID)
  179. Dim Qpdf:Set Qpdf = WScript.CreateObject("DebenuPDFLibraryAX1013.PDFLibrary")
  180. Dim Result:Result = Qpdf.UnlockKey("j564z3wi9i66k93cp3r798b3y")
  181. If oConn.State = 0 Then:oConn.Open(ConnectionString):End If
  182. Dim Rs:set Rs = oConn.Execute("SELECT MIN(ID) as [MIN],MAX(ID) as [MAX] FROM InkjetRecords WHERE KitID = " & KitID &";")
  183. Dim MIN:MIN = Rs("MIN").Value
  184. Dim MAX:MAX = Rs("MAX").Value
  185. Dim RecordCount:RecordCount = (MAX - MIN) + 1
  186. Rs.Close
  187. Dim KitRs:set KitRs = oConn.Execute("Select * From [Kit] Where [ID] =" & KitID & ";")
  188. Dim JurisdictionRs:set JurisdictionRs = oConn.Execute("SELECt * FROM [Jurisdiction] WHERE JCode='" & KitRs("Jcode").Value & "';")
  189. Dim ProofFileName:ProofFileName = objFSO.GetBaseName(KitRs("Filename")) & "-PROOF.PDF"
  190. If Not objFSO.FolderExists(ExportDirectory & KitRs("JobNumber").Value & "-" & JurisdictionRs("Name").value) Then:objFSO.CreateFolder(ExportDirectory & KitRs("JobNumber").Value & "-" & JurisdictionRs("Name").value):End If
  191. Dim reportManager:set reportManager = CreateObject("ReportMan.ReportManX")
  192. With reportManager
  193. .Preview = False
  194. .ShowProgress = False
  195. .ShowPrintDialog = False
  196. .filename = PurpleEnvelopeProofReport
  197. .SetDatabaseConnectionString "WEBDATA",ConnectionString
  198. .SetParamValue "PBKITID",KitID
  199. .SetParamValue "PBJCODE",KitRs("Jcode").Value
  200. Dim MAXRECORDS:MAXRECORDS = 3750
  201. If RecordCount > MAXRECORDS Then
  202. Dim i
  203. For i = 0 To RecordCount / MAXRECORDS
  204. Dim newMin:If MIN + (i * MAXRECORDS) > MIN Then:newMin = MIN + (i * MAXRECORDS) + 1:Else newMin = MIN:End If
  205. Dim newMax:If MIN + (i * MAXRECORDS) + MAXRECORDS > MAX Then:newMax = MAX:Else newMax = MIN + (i * MAXRECORDS) + MAXRECORDS:End If
  206. .SetParamValue "PBMIN",newMin
  207. .SetParamValue "PBMAX",newMax
  208. .SaveToPDF ExportDirectory & KitRs("JobNumber").Value & "-" & JurisdictionRs("Name").value & "\Part_" & i & "_" & ProofFileName,1
  209. Result = Qpdf.AddToFileList("Proofs",ExportDirectory & KitRs("JobNumber").Value & "-" & JurisdictionRs("Name").value & "\Part_" & i & "_" & ProofFileName)
  210. Next
  211. Result = Qpdf.MergeFileListFast("Proofs",ExportDirectory & KitRs("JobNumber").Value & "-" & JurisdictionRs("Name").value & "/" & ProofFileName)
  212. Dim test
  213. For test = 1 To Qpdf.FileListCount("Proofs")
  214. WshShell.Run "cmd.exe /c DEL /F /Q """ & Qpdf.FileListItem("Proofs",test) & """" ,0,True
  215. Next
  216. Else
  217. .SetParamValue "PBMIN",MIN
  218. .SetParamValue "PBMAX",MAX
  219. .SaveToPDF ExportDirectory & KitRs("JobNumber").Value & "-" & JurisdictionRs("Name").value & "/" & ProofFileName,1
  220. End If
  221. End With
  222. oConn.Execute("UPDATE KIT SET [Status] ='Ready For Inkjet Export' WHERE [ID] =" & KitID & ";")
  223. If KitRs.State = 1 Then:KitRs.Close:End If
  224. If JurisdictionRs.State = 1 Then:JurisdictionRs.Close:End If
  225. If oConn.State = 1 Then:oConn.Close:End If
  226. End Function
  227. Function CreateExportForSnailWorks(KitID)
  228. Dim State
  229. Dim ForeignTest
  230. If oConn.State = 0 Then:oConn.Open(ConnectionString):End If
  231. Dim KitRs:set KitRs = oConn.Execute("Select * From [Kit] Where [ID] =" & KitID & ";")
  232. Dim KitLabelsRs: Set KitLabelsRs = oConn.Execute("SELECT InkjetRecords.ID, InkjetRecords.KitID, InkjetRecords.VOTERID, InkjetRecords.LASTNAME," &_
  233. " InkjetRecords.FIRSTNAME, InkjetRecords.MIDDLENAME, InkjetRecords.SUFFIX, InkjetRecords.PRECINCT," &_
  234. " InkjetRecords.ADDRESS1, InkjetRecords.ADDRESS2, InkjetRecords.ADDRESS3, InkjetRecords.ADDRESS4," &_
  235. " InkjetRecords.ADDRESS5, InkjetRecords.APPSENT, InkjetRecords.APPRETURNED, InkjetRecords.BALSENT," &_
  236. " InkjetRecords.BALRETURNED, InkjetRecords.CountingBoard, InkjetRecords.UOCAVASTATUS, InkjetRecords.EMAILADDRESS," &_
  237. " InkjetRecords.PHONENUMBER, InkjetRecords.BALLOT_NUMBER, InkjetRecords.CassADDRESS1, InkjetRecords.CassADDRESS2," &_
  238. " InkjetRecords.CassADDRESS3, InkjetRecords.CassADDRESS4, InkjetRecords.CassADDRESS5, InkjetRecords.KitLabelID," &_
  239. " KitLabels.ID, KitLabels.KitID, KitLabels.OutboundSerial, KitLabels.InBoundSerial, KitLabels.OutboundIMB," &_
  240. " KitLabels.InBoundIMB, KitLabels.OutboundIMBDigits, KitLabels.InBoundIMBDigits, KitLabels.OutboundIMBPNG," &_
  241. " KitLabels.INBOUNDIMBPNG, KitLabels.SetNumber" &_
  242. " FROM InkjetRecords" &_
  243. " LEFT JOIN [KitLabels] ON InkjetRecords.KitLabelID = KitLabels.ID" & _
  244. " WHERE InkjetRecords.KitID =" & KitID & " ;")
  245. Dim JurisdictionRs:Set JurisdictionRs = oConn.Execute("SELECT * FROM Jurisdiction WHERE JCode ='" & KitRs("Jcode").Value & "';")
  246. Dim ExportFileName:ExportFileName = objFSO.GetBaseName(KitRs("Filename")) & "_SW_EXPORT.csv"
  247. If Not objFSO.FolderExists(ExportDirectory & KitRs("JobNumber").Value & "-" & JurisdictionRs("Name").value) Then:objFSO.CreateFolder(ExportDirectory & KitRs("JobNumber").Value & "-" & JurisdictionRs("Name").value):End If
  248. If objFSO.FileExists(ExportDirectory & KitRs("JobNumber").Value & "-" & JurisdictionRs("Name").value & "/" & ExportFileName) Then:objFSO.DeleteFile(ExportDirectory & KitRs("JobNumber").Value & "-" & JurisdictionRs("Name").value & "/" & ExportFileName):End If
  249. Dim objExportFile:set objExportFile = objFSO.CreateTextFile(ExportDirectory & KitRs("JobNumber").Value & "-" & JurisdictionRs("Name").value & "/" & ExportFileName,2)
  250. With objExportFile
  251. .Write("""H"",") 'Record Type Required value must be = "H" (Header)
  252. .Write(Truncate("5.2",5)) 'Version Required value must be ="5.2" for current release
  253. .Write(Truncate("KCIHotFolder2024FTPUser",50)) 'UserId Required
  254. .Write(Truncate(KitRs("Jcode").Value,50)) 'Client Name Required (will create new subaccount if not already defined) - We decideded to make this the juriscode
  255. .Write(Truncate("",50)) 'Parent Client Name Optional (use if 3-tier account structure)
  256. .Write(Truncate("Purple envelope - " & KitRs("JobNumber").Value,50)) 'Job Name Required
  257. .Write(Truncate("",50)) 'Job Description Optional
  258. .Write(Truncate("",50)) 'Split Name Optional � will default to �Default�
  259. .Write(Truncate("",80)) 'Split Description Optional
  260. .Write(Truncate("L",1)) 'Piece Type Required L-Letters, C-Cards, F-Flats
  261. .Write(Truncate(Year(Now()) & "/" &_
  262. Right("0" & Month(Now()), 2) & "/" & Right("0" & Day(Now()), 2),10)) 'MailDate Required (YYYY/MM/DD)
  263. .Write(Truncate("N",1)) 'UploadType Required N = New job, new split A = Append new split to existing job R = Replace existing split
  264. .Write(Truncate("",8)) 'TrackedQuantity Optional
  265. .Write(Truncate("",8)) 'PiecesMailed Optional � shown as Estimated Quantity
  266. .Write(Truncate("",10)) 'Target InHomeDateStart Optional (YYYY/MM/DD)
  267. .Write(Truncate("",10)) 'Target InHomeDateEnd Optional (YYYY/MM/DD)
  268. .Write(Truncate("danielc@kentcommunications.com",100)) 'ConfirmationEmail Optional
  269. .Write(Truncate("",9)) 'JobId (SW) Optional for previously created jobs SWJobId
  270. .Write(Truncate("",4)) 'SplitId (SW) Optional for previously created jobs SWJobId
  271. .Write(Truncate(Choice(IsNull(KitRs("InboundSTID")),"O","R"),1)) 'TypeofTracking Required Values: O- Outbound Only I-Inbound Only R-Round Trip
  272. .Write(Truncate("",11)) 'ReturnedPostalRoutingCode
  273. .Write(Truncate("",2)) 'ReportId1
  274. .Write(Truncate("",255)) 'Report1Email
  275. .Write(Truncate("",2)) 'ReportId2
  276. .Write(Truncate("",255)) 'Report2Email
  277. .Write("""N""") 'INFOONLY
  278. .Write(vbCrLf)
  279. While Not KitLabelsRs.EOF
  280. ForeignTest = KitLabelsRs("CassADDRESS5").Value & " " & KitLabelsRs("CassADDRESS4").Value
  281. State = Truncate(Mid(KitLabelsRs("CassADDRESS5").Value, _
  282. InStr(KitLabelsRs("CassADDRESS5").Value, ",") + 2, 2),2)
  283. State = Replace(State," ","")
  284. If CheckStringDoesNotHaveForiegnCountries(ForeignTest) And State <> """""," then
  285. 'If InStr(ForeignTest,"CANADA") = 0 And InStr(ForeignTest,"AUSTRALIA") = 0 And State <> "" Then " ",
  286. .Write("""D"",") 'RecordType Required value must be = �D� (Detail)
  287. .Write(Truncate("",20)) 'CustomerUniqueIdentifier Optional- any identifier you designate
  288. .Write(Truncate(KitLabelsRs("OutboundIMBDigits"),31)) 'IMB Required � Unencoded, numeric IMB
  289. .Write(Truncate("",10)) 'Greeting Optional
  290. .Write(Truncate("",50)) 'First Name Optional
  291. .Write(Truncate("",2)) 'MI Optional
  292. .Write(Truncate("",50)) 'Last Name Optional
  293. .Write(Truncate("",10)) 'Suffix Optional
  294. .Write(Truncate((KitLabelsRs("CassADDRESS1").Value),100)) 'Full Name Optional
  295. .Write(Truncate("",50)) 'Company Optional
  296. .Write(Truncate("",50)) 'Title Optional
  297. .Write(Truncate(KitLabelsRs("CassADDRESS3").Value,128)) 'Address1 Optional
  298. .Write(Truncate(KitLabelsRs("CassADDRESS4").Value,128)) 'Address2 Optional
  299. .Write(Truncate(Left(KitLabelsRs("CassADDRESS5").Value, _
  300. InStr(KitLabelsRs("CassADDRESS5").Value, ",") - 1),50)) 'City Optional
  301. .Write(State) 'State Optional
  302. .Write Choice(InStr(KitLabelsRs("CassADDRESS5").Value,"-"),Truncate(Right(KitLabelsRs("CassADDRESS5").Value,11),11),Truncate(Right(KitLabelsRs("CassADDRESS5").Value,5),5)) 'Zip Optional
  303. .Write(Truncate(KitRs("Jcode"),100)) 'UserDefined1 Optional - Summary fields only
  304. .Write(Truncate("",100)) 'UserDefined2 Optional - Summary fields only
  305. .Write(Truncate("",100)) 'UserDefined3 Optional - Summary fields only
  306. .Write(Truncate(KitLabelsRs("PRECINCT").Value &_
  307. KitLabelsRs("BALLOT_NUMBER"),80)) 'UserDefinedIdentifier4 Optional � Allows for unique identifiers
  308. .Write(Truncate(KitLabelsRs("VOTERID").Value,80)) 'UserDefinedIdentifier5 Optional � Allows for unique identifiers
  309. .Write(Truncate("",1)) 'SeedIndicator Optional - if true provide �Y�
  310. .Write(Truncate("",80)) 'InductionPoint Optional
  311. .Write(Truncate("",10)) 'InductionDate Optional � Valid date format, ex. MM/DD/YYYY
  312. .Write(Truncate(Choice(IsNull(KitRs("InboundSTID")),"", _
  313. KitLabelsRs("InBoundIMBDigits").Value),31)) 'InboundIMB Optional � numeric IMB for Round trip jobs only
  314. .Write(Truncate("",24)) 'IMCB Optional � Container Barcode
  315. .Write("""""") 'IMTB Optional � Tray Barcode
  316. .Write(vbCrLf)
  317. End If
  318. KitLabelsRs.MoveNext
  319. Wend
  320. .Close
  321. End With
  322. oConn.Execute("UPDATE KIT SET [Status] ='Ready to Proof',[ExportedToSnailWorks] =#" & Now() & "# WHERE [ID] =" & KitID & ";")
  323. If KitRs.State = 1 Then:KitRs.Close:End If
  324. If KitLabelsRs.State = 1 Then:KitLabelsRs.Close: End If
  325. If JurisdictionRs.State = 1 Then:JurisdictionRs.Close:End If
  326. If oConn.State = 1 Then:oConn.Close:End If
  327. End Function
  328. Function createTrackingInfoForKit(KitID)
  329. If oConn.State = 0 Then:oConn.Open(ConnectionString):End If
  330. oConn.Execute("UPDATE Kit SET Status ='Applying Serial Numbers' WHERE ID =" & KitID & ";")
  331. Dim KitRs:set KitRs = oConn.Execute("Select * from Kit Where ID =" & KitID & ";")
  332. Dim InkjetRs:Set InkjetRs = oConn.Execute("Select * from InkjetRecords Where KitID =" & KitID & ";")
  333. Dim JurisRs:set JurisRs = oConn.Execute("Select Right(IMB_Digits,9) as IMBZip FROM Jurisdiction Where JCode ='" & KitRs("Jcode") & "';"):Dim Jcode:Jcode = JurisRs("IMBZip"):JurisRs.Close
  334. Dim SerialNumberStart:SerialNumberStart = GetSetting("SerialNumberStart")
  335. Dim serialOffset:serialOffset = GetSetting("SerialOffset")
  336. Dim serialStart:serialStart = CLng(GetSetting("SerialNumberStart")) + CLng(GetSetting("SerialOffset"))
  337. Dim Counter:Counter=0
  338. Dim KitLabelID
  339. Dim KitLabelRs
  340. Dim Mid:Mid = GetSetting("MailingID")
  341. Dim Step : If KitRs("InboundSTID") <> "" Then : Step = 2 : Else Step = 1
  342. serialStart = PadLeft(serialStart + CLng(Counter),9,"0")
  343. Dim oRsKitLabels : Set oRsKitLabels = CreateObject("ADODB.Recordset"):oRsKitLabels.Open "Select * FROM [KitLabels] Where KitID =" & KitID & ";",oConn,3,3
  344. While Not InkjetRs.EOF
  345. oRsKitLabels.AddNew
  346. KitLabelID = oRsKitLabels("ID").value
  347. If Step = 1 Then
  348. oRsKitLabels("KitID") = KitID
  349. oRsKitLabels("OutboundSerial") = serialStart
  350. oRsKitLabels("OutboundIMBDigits") = KitRs("OutBoundSTID").Value & Mid & serialStart
  351. Else
  352. oRsKitLabels("KitID") = KitID
  353. oRsKitLabels("OutboundSerial") = serialStart
  354. oRsKitLabels("InBoundSerial") = serialStart + 1
  355. oRsKitLabels("OutboundIMBDigits") = KitRs("OutBoundSTID").Value & Mid & serialStart
  356. oRsKitLabels("InBoundIMBDigits") = KitRs("InboundSTID").Value & Mid & serialStart + 1 & Jcode
  357. End If
  358. oRsKitLabels.Update
  359. oConn.Execute("UPDATE InkjetRecords Set [KitLabelID]=" & KitLabelID & " WHERE ID=" & InkjetRs("ID") & ";")
  360. Counter = Counter + Step
  361. serialStart = serialStart + Step
  362. InkjetRs.MoveNext
  363. Wend
  364. oRsKitLabels.Update
  365. oRsKitLabels.Close
  366. oConn.Execute("UPDATE Settings Set [Value]='" & serialOffset + Counter & "' WHERE [Name] = 'SerialOffset';")
  367. oConn.Execute("UPDATE Kit Set [Status]='Ready For Export', LabelsPrinted=#" & Now() & "# WHERE [ID] =" & KitID &";")
  368. oConn.Close
  369. End Function
  370. Function GetSetting(settingName)
  371. Dim rs:Set rs = oConn.Execute("Select Value From [Settings] Where [Name] = '" & settingName & "';")
  372. If Not rs.EOF Then
  373. GetSetting = rs(0).value
  374. rs.Close
  375. Else
  376. SetSetting = 0
  377. rs.Close
  378. End If
  379. End Function
  380. Function CheckForFiles()
  381. If objFSO.FolderExists(DataDirectory) Then
  382. Dim objFolder:Set objFolder = objFSO.GetFolder(DataDirectory)
  383. If objFolder.Files.Count > 0 Then
  384. 'WScript.Echo "Files found in directory: " & DataDirectory
  385. Dim objFile
  386. For Each objFile In objFolder.Files
  387. Dim CsvString:CsvString = ConvertCsvToString(objFile.Path)
  388. If ValidImportCSV(CsvString) Then
  389. SetupKit CsvString,objFile.Name
  390. objFSO.MoveFile objFile.Path, DataDirectory & "\import\" & objFile.Name
  391. End If
  392. Next
  393. Else
  394. 'WScript.Echo "No files found in directory: " & DataDirectory
  395. End If
  396. End If
  397. End Function
  398. Function ValidJcode(jcode)
  399. Dim oConn
  400. Set oConn = WScript.CreateObject("ADODB.Connection")
  401. oConn.ConnectionString = ConnectionString
  402. oConn.Open
  403. Dim oRs
  404. set oRs = oConn.Execute("Select * from Jurisdiction Where [JCode] = '" & jcode & "';")
  405. If oRs.EOF Then
  406. ValidJcode = 0
  407. Else
  408. ValidJcode = 1
  409. End If
  410. oRs.Close
  411. oConn.Close
  412. End Function
  413. Function CheckStringDoesNotHaveForiegnCountries(StringToCheck)
  414. Dim Countries
  415. Countries = Array("UNITED KINGDOM","NORWAY","AUSTRALIA","FRANCE","UK LL","KENT ENGLAND","CANADA","NETHERLANDS","GERMANY","TAIWAN","NICARAGUA","IREL")
  416. Dim Country
  417. For Each Country In Countries
  418. If InStr(StringToCheck,Country) Then
  419. CheckStringDoesNotHaveForiegnCountries = False
  420. Exit For
  421. End If
  422. CheckStringDoesNotHaveForiegnCountries = True
  423. Next
  424. End Function
  425. Function SetupKit(CsvString,FileName)
  426. Dim JobNumber:JobNumber = Mid(FileName,9,6)
  427. Dim JCode:JCode = Left(Filename,5)
  428. If IsNumeric(JobNumber) Then
  429. If ValidJcode(JCode) Then
  430. WScript.Echo FileName & " Is a Valid CSV for Importing"
  431. Dim oConn:Set oConn = WScript.CreateObject("ADODB.Connection")
  432. oConn.ConnectionString = ConnectionString
  433. oConn.Open
  434. oConn.Execute("Insert Into Kit ([JobNumber], [Jcode], [CreatedOn], [JobType],[Filename],[Status]) VALUES ('" & JobNumber & "','" & JCode & "',#" & Now() & "#,'Purple Envelopes','" & FileName & "','Importing');")
  435. Dim rs : set rs = oConn.Execute("Select TOP 1 ID from Kit ORDER BY ID DESC")
  436. Dim kitId : kitId = rs("ID").value
  437. rs.close
  438. Dim i
  439. For i = 1 To objCSV.NumRows -1
  440. oConn.Execute("Insert Into [InkjetRecords] (KitID,VOTERID,LASTNAME,FIRSTNAME,MIDDLENAME" & _
  441. ",SUFFIX,PRECINCT,ADDRESS1,ADDRESS2,ADDRESS3,ADDRESS4,ADDRESS5,APPSENT,APPRETURNED,BALSENT,BALRETURNED" & _
  442. ",CountingBoard,UOCAVASTATUS,EMAILADDRESS,PHONENUMBER,BALLOT_NUMBER) VALUES (" & kitId & _
  443. ",'" & Replace(objCSV.GetCell(i,0),"'","''") & _
  444. "','" & objCsv.GetCell(i,1) & _
  445. "','" & Replace(objCSV.GetCell(i,2),"'","''") & _
  446. "','" & Replace(objCSV.GetCell(i,3),"'","''") & _
  447. "','" & Replace(objCSV.GetCell(i,4),"'","''") & _
  448. "','" & Replace(objCSV.GetCell(i,5),"'","''") & _
  449. "','" & Replace(objCSV.GetCell(i,6),"'","''") & _
  450. "','" & Replace(objCSV.GetCell(i,7),"'","''") & _
  451. "','" & Replace(objCSV.GetCell(i,8),"'","''") & _
  452. "','" & Replace(objCSV.GetCell(i,9),"'","''") & _
  453. "','" & Replace(objCSV.GetCell(i,10),"'","''") & _
  454. "','" & Replace(objCSV.GetCell(i,11),"'","''") & _
  455. "','" & Replace(objCSV.GetCell(i,12),"'","''") & _
  456. "','" & Replace(objCsv.GetCell(i,13),"'","''") & _
  457. "','" & objCsv.GetCell(i,14) & _
  458. "','" & objCsv.GetCell(i,15) & _
  459. "','" & objCsv.GetCell(i,16) & _
  460. "','" & objCsv.GetCell(i,17) & _
  461. "','" & objCsv.GetCell(i,18) & _
  462. "','" & objCsv.GetCell(i,19) & _
  463. "')")
  464. Next
  465. oConn.Execute("Update Kit SET [Status] = 'Ready to Cass' Where ID = " & kitId &";")
  466. 'oConn.Close
  467. End If
  468. End If
  469. End Function
  470. Function ConvertCsvToString(FilePath)
  471. Dim objFSO:Set objFSO = CreateObject("Scripting.FileSystemObject")
  472. Dim objCsvFile:set objCsvFile = objFSO.OpenTextFile(FilePath)
  473. Dim strContent:strContent = ""
  474. Dim intLineCount:intLineCount = 0
  475. Do Until objCsvFile.AtEndOfStream Or intLineCount >= 3
  476. objCsvFile.SkipLine
  477. intLineCount = intLineCount + 1
  478. Loop
  479. ' Read the remaining content into a string
  480. Do Until objCsvFile.AtEndOfStream
  481. Dim strLine:strLine = objCsvFile.ReadLine
  482. strContent = strContent & strLine & vbCrLf
  483. Loop
  484. ConvertCsvToString = strContent
  485. End Function
  486. Function ValidImportCSV(CsvFileAsString)
  487. objCSV.LoadFromString(CsvFileAsString)
  488. If objCSV.NumColumns = 20 Then
  489. ValidImportCSV = True
  490. Else
  491. ValidImportCSV = False
  492. End If
  493. End Function
  494. Sub ImportCass
  495. Dim currentRow
  496. objCsv.LoadFile("\\kci-syn-cl01\PC Transfer\TrackingDataExport\FROM_MM.CSV")
  497. For currentRow = 0 To objCsv.NumRows -1
  498. oConn.Execute("UPDATE InkJetRecords SET CassADDRESS1 = '" & Replace(objCsv.GetCell(currentRow,1),"'","''") & "', " &_
  499. "CassADDRESS2 = '" & Replace(objCSV.GetCell(currentRow,3),"'","''") & "', " &_
  500. "CassADDRESS3 = '" & Replace(objCSV.GetCell(currentRow,4),"'","''") & "', " &_
  501. "CassADDRESS4 = '" & Replace(objCSV.GetCell(currentRow,5),"'","''") & "', " &_
  502. "CassADDRESS5 = '" & Replace(objCsv.GetCell(currentRow,6) & ", " & objCsv.GetCell(currentRow,7) & " " & objCsv.GetCell(currentRow,8),"'","''") & "'" &_
  503. " WHERE ID = " & objCSV.GetCell(currentRow,0) & ";")
  504. Next
  505. oConn.Execute("UPDATE Kit SET Status ='Ready To Assign STIDS' WHERE ID =" & KitID & ";")
  506. oConn.Execute("UPDATE Kit SET [Cass] = 1 WHERE ID =" & KitID & ";")
  507. End Sub
  508. Sub RunMailManager
  509. WshShell.Run "PsExec64.exe -i -e -u ntp\danielc -p SunBrightShine! \\MarkH2 ""\\MM2012\APPS\BCC\MM2010\mailman.exe"" -p -j MMJOB.mjb -u DAN",1,True
  510. End Sub
  511. Sub ExportMMCsv(KitId)
  512. Dim success
  513. objCsv.HasColumnNames = 1
  514. objCSV.EnableQuotes = 1
  515. success = objCsv.SetColumnName(0,"ID")
  516. success = objCsv.SetColumnName(1,"NAME")
  517. success = objCsv.SetColumnName(2,"ADDRESS1")
  518. success = objCsv.SetColumnName(3,"ADDRESS2")
  519. success = objCsv.SetColumnName(4,"ADDRESS3")
  520. success = objCsv.SetColumnName(5,"ADDRESS4")
  521. success = objCsv.SetColumnName(6,"ADDRESS5")
  522. Dim rs : Set rs = oConn.Execute("Select ID," & _
  523. "IIF(FIRSTNAME IS NULL,'',FIRSTNAME & ' ') & " & _
  524. "IIF(MIDDLENAME IS NULL,'',MIDDLENAME & ' ') & " & _
  525. "IIF(LASTNAME IS NULL,'',LASTNAME & ' ') & " & _
  526. "IIF(SUFFIX IS NULL,'',SUFFIX & ' ') " & _
  527. "AS NAME, ADDRESS1,ADDRESS2,ADDRESS3,ADDRESS4,ADDRESS5 FROM InkjetRecords WHERE KitID =" & KitID & " ORDER By ID;")
  528. Dim CurrentRow:CurrentRow = 0
  529. While Not rs.EOF
  530. objCSV.SetCell CurrentRow,0,rs("ID").value
  531. objCSV.SetCell CurrentRow,1,rs("NAME").value
  532. objCSV.SetCell CurrentRow,2,rs("ADDRESS1").value
  533. objCSV.SetCell CurrentRow,3,rs("ADDRESS2").value
  534. objCSV.SetCell CurrentRow,4,rs("ADDRESS3").value
  535. objCSV.SetCell CurrentRow,5,rs("ADDRESS4").value
  536. objCSV.SetCell CurrentRow,6,rs("ADDRESS5").value
  537. rs.MoveNext
  538. CurrentRow = CurrentRow +1
  539. Wend
  540. Dim CsvString:CsvString = objCSV.SaveToString()
  541. outFile.WriteLine CsvString
  542. outFile.Close
  543. End Sub
  544. Function CheckForJobsToCass()
  545. oConn.ConnectionString = ConnectionString
  546. oConn.Open
  547. 'oConn.Open
  548. Dim rs : set rs = oConn.Execute("Select TOP 1 ID from Kit Where Status ='Ready to Cass' ORDER BY ID DESC;")
  549. If Not rs.EOF Then
  550. Dim kitId : kitId = rs("ID").value
  551. rs.Close
  552. CheckForJobsToCass = KitID
  553. oConn.Execute("UPDATE Kit SET Status ='Cassing' WHERE ID =" & KitID & ";")
  554. Else
  555. CheckForJobsToCass = 0
  556. End If
  557. 'oConn.Close
  558. End Function
  559. Public Function PadLeft(originalString,desiredLength,Char)
  560. Dim padLength
  561. padLength = desiredLength - Len(originalString)
  562. If padLength > 0 Then
  563. ' Left pad the string with zeros
  564. PadLeft = String(padLength, Char) & originalString
  565. Else
  566. ' If the original string is already longer or equal to the desired length, no padding is needed
  567. PadLeft = originalString
  568. End If
  569. End Function
  570. Function Truncate(inputString, size)
  571. If Len(inputString) > size Then:Truncate = """" & Left(inputString,size) & """,":Else Truncate = """" & inputString & """,":End If
  572. End Function
  573. Function PadString(inputString, size)
  574. Dim paddedString
  575. Dim inputLength
  576. Dim i
  577. If IsNull(inputString) Then:inputString = ""
  578. ' Get the length of the input string
  579. inputLength = Len(inputString)
  580. ' If the input string is already equal to or longer than the specified size, return it as is
  581. If inputLength >= size Then
  582. PadString = inputString
  583. Exit Function
  584. End If
  585. ' Initialize the padded string with the input string
  586. paddedString = inputString
  587. ' Pad spaces to the right of the input string until it reaches the specified size
  588. For i = 1 To (size - inputLength)
  589. paddedString = paddedString & " "
  590. Next
  591. ' Return the padded string
  592. PadString = paddedString
  593. End Function
  594. Function CleanNull(StringToClean)
  595. If IsNull(StringToClean) Then:CleanNull = "":Else CleanNull = StringToClean:End If
  596. End Function
  597. Public Sub Assign(ByRef var, ByVal val)
  598. If IsObject(val) Then
  599. Set var = val
  600. Else
  601. var = val
  602. End If
  603. End Sub
  604. Public Function Choice(ByVal cond, ByVal if_true, ByVal if_false)
  605. If cond Then
  606. Assign Choice, if_true
  607. Else
  608. Assign Choice, if_false
  609. End If
  610. End Function
  611. Function CompressArray(arr)
  612. Dim temp,i,j
  613. For i = LBound(arr) To UBound(arr) - 1
  614. For j = i + 1 To UBound(arr)
  615. If arr(i) = "" Then
  616. temp = arr(i)
  617. arr(i) = arr(j)
  618. arr(j) = temp
  619. End If
  620. Next
  621. Next
  622. CompressArray = arr
  623. End Function
  624. Function TrimLeadingZeros(inputStr)
  625. Dim i
  626. For i = 1 To Len(inputStr)
  627. If Mid(inputStr, i, 1) <> "0" Then
  628. TrimLeadingZeros = Mid(inputStr, i)
  629. Exit Function
  630. End If
  631. Next
  632. ' If the input string is all zeros, return "0"
  633. TrimLeadingZeros = "0"
  634. End Function

Powered by TurnKey Linux.