Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

639 строки
30KB

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

Powered by TurnKey Linux.