Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

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

Powered by TurnKey Linux.