You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

925 line
86KB

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

Powered by TurnKey Linux.