您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

723 行
68KB

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

Powered by TurnKey Linux.