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.

865 lines
81KB

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

Powered by TurnKey Linux.