Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

691 Zeilen
32KB

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

Powered by TurnKey Linux.