Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

759 rindas
71KB

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

Powered by TurnKey Linux.