From 7d58bdbe1c55f2bc3ba9f8dec3b8fd9e3ff69898 Mon Sep 17 00:00:00 2001 From: Daniel Covington Date: Fri, 24 May 2024 16:08:08 -0400 Subject: [PATCH] SailWorks export from tracking kits now works --- App/Controllers/Kit/KitController.asp | 94 ++++++++++--- App/DomainModels/SnailWorksRepository.asp | 163 ++++++++++++++++++++++ App/include_all.asp | 3 +- 3 files changed, 243 insertions(+), 17 deletions(-) create mode 100644 App/DomainModels/SnailWorksRepository.asp diff --git a/App/Controllers/Kit/KitController.asp b/App/Controllers/Kit/KitController.asp index ca8269c..cfba396 100644 --- a/App/Controllers/Kit/KitController.asp +++ b/App/Controllers/Kit/KitController.asp @@ -116,24 +116,86 @@ Class KitController Public Sub DownloadTrackingkitSnailWorks dim id : id = Request.QueryString("Id") - dim Labels : Set Labels = KitLabelsRepository.Find(Array("KitID=?",id),empty) - - - 'Response.Buffer = False - Dim objStream:Set objStream = Server.CreateObject("ADODB.Stream") - objStream.Type = 1 'adTypeBinary - objStream.Open - objStream.LoadFromFile(server.mappath("/uploads/MI Jurisdictions with IMB.csv")) - 'Response.Flush - Response.ContentType = "application/octet-stream" - Response.Addheader "Content-Disposition", "attachment; filename=" & "MI Jurisdictions with IMB.csv" - Response.BinaryWrite objStream.Read - 'Response.End - objStream.Close - Set objStream = Nothing - + dim export: set export = SnailWorksRepository.GetSnailWorksExportById(id) + + if export.DetailRecords.Count > 0 Then + dim objExportFile: Set objExportFile = Server.CreateObject("Scripting.FileSystemObject").CreateTextFile(server.mappath("/uploads/" & id & ".csv"),2) + With objExportFile + .Write """" & export.Header.RecordType & """," + .Write """" & export.Header.Version & """," + .Write """" & export.Header.UserId & """," + .Write """" & export.Header.ClientName & """," + .Write """" & export.Header.ParentClientName & """," + .Write """" & export.Header.JobName & """," + .Write """" & export.Header.JobDescription & """," + .Write """" & export.Header.SplitName & """," + .Write """" & export.Header.SplitDescription & """," + .Write """" & export.Header.PieceType & """," + .Write """" & export.Header.MailDate & """," + .Write """" & export.Header.UploadType & """," + .Write """" & export.Header.TrackedQuanity & """," + .Write """" & export.Header.PiecesMailed & """," + .Write """" & export.Header.TargetInHomeDateStart & """," + .Write """" & export.Header.TargetInHomeDateEnd & """," + .Write """" & export.Header.ConfirmationEmail & """," + .Write """" & export.Header.JobId & """," + .Write """" & export.Header.SplitId & """," + .Write """" & export.Header.TypeOfTracking & """," + .Write """" & export.Header.ReturnedPostalRoutingCode & """," + .Write """" & export.Header.ReportId1 & """," + .Write """" & export.Header.Report1Email & """," + .Write """" & export.Header.ReportId2 & """," + .Write """" & export.Header.Report2Email & """," + .Write """" & export.Header.INFOONLY & """" + .Write vbCrLf + dim it:set it = export.DetailRecords.Iterator + dim records + while it.HasNext + set records = it.GetNext() + .Write """" & records.RecordType & """," + .Write """" & records.CustomerUniqueIdentifier & """," + .Write """" & records.IMB & """," + .Write """" & records.Greeting & """," + .Write """" & records.FirstName & """," + .Write """" & records.MI & """," + .Write """" & records.LastName & """," + .Write """" & records.Suffix & """," + .Write """" & records.FullName & """," + .Write """" & records.Company & """," + .Write """" & records.Title & """," + .Write """" & records.Address1 & """," + .Write """" & records.Address2 & """," + .Write """" & records.City & """," + .Write """" & records.State & """," + .Write """" & records.Zip & """," + .Write """" & records.UserDefined1 & """," + .Write """" & records.UserDefined2 & """," + .Write """" & records.UserDefined3 & """," + .Write """" & records.UserDefinedIdentifier4 & """," + .Write """" & records.UserDefinedIdentifier5 & """," + .Write """" & records.SeedIndicator & """," + .Write """" & records.InductionPoint & """," + .Write """" & records.InductionDate & """," + .Write """" & records.InBoundIMB & """," + .Write """" & records.IMCB & """," + .Write """" & records.IMTB & """" & vbCRLF + Wend + End With + objExportFile.Close + Dim objStream:Set objStream = Server.CreateObject("ADODB.Stream") + objStream.Type = 1 'adTypeBinary + objStream.Open + objStream.LoadFromFile(server.mappath("/uploads/" & id & ".csv")) + Response.ContentType = "application/octet-stream" + Response.Addheader "Content-Disposition", "attachment; filename=" & id & ".csv" + Response.BinaryWrite objStream.Read + objStream.Close + Set objStream = Nothing + + End If End Sub + Public Sub Edit dim id : id = Request.QueryString("Id") diff --git a/App/DomainModels/SnailWorksRepository.asp b/App/DomainModels/SnailWorksRepository.asp new file mode 100644 index 0000000..fe7819e --- /dev/null +++ b/App/DomainModels/SnailWorksRepository.asp @@ -0,0 +1,163 @@ +<% +'======================================================================================================================= +' Settings Model +'======================================================================================================================= + +Class SnailWorksExportModel_Class + Public Header + Public DetailRecords +End Class + +Class SnailWorksExportHeaderModel_Class + Public Class_Get_Properties + + Public RecordType + Public Version + Public UserId + Public ClientName + Public ParentClientName + Public JobName + Public JobDescription + Public SplitName + Public SplitDescription + Public PieceType + Public MailDate + Public UploadType + Public TrackedQuanity + Public PiecesMailed + Public TargetInHomeDateStart + Public TargetInHomeDateEnd + Public ConfirmationEmail + Public JobId + Public SplitId + Public TypeOfTracking + Public ReturnedPostalRoutingCode + Public ReportId1 + Public Report1Email + Public ReportId2 + Public Report2Email + Public INFOONLY + + Private Sub Class_Initialize + 'ValidateExitsts Me, "","" + Class_Get_Properties = Array("RecordType","Version","UserId","ClientName","ParentClientName","JobName" _ + ,"JobDescription","SplitName","SplitDescription","PieceType","MailDate","UploadType" _ + ,"TrackedQuanity","PiecesMailed","TargetInHomeDateStart","TargetInHomeDateEnd","ConfirmationEmail","JobId" _ + ,"SplitId","TypeOfTracking","ReturnedPostalRoutingCode","ReportId1","Report1Email","ReportId2","Report2Email","INFOONLY") + End Sub + +End CLass + +Class SnailWorksExportDetailModel_Class + + Public Class_Get_Properties + + Public RecordType + Public CustomerUniqueIdentifier + Public IMB + Public Greeting + Public FirstName + Public MI + Public LastName + Public Suffix + Public FullName + Public Company + Public Title + Public Address1 + Public Address2 + Public City + Public State + Public Zip + Public UserDefined1 + Public UserDefined2 + Public UserDefined3 + Public UserDefinedIdentifier4 + Public UserDefinedIdentifier5 + Public SeedIndicator + Public InductionPoint + Public InductionDate + Public InBoundIMB + Public IMCB + Public IMTB + + Private Sub Class_Initialize + 'ValidateExitsts Me, "","" + Class_Get_Properties = Array("RecordType","CustomerUniqueIdentifier","IMB","Greeting","FirstName" _ + ,"MI","LastName","Suffix","FullName","Company","Title","Address1","Address2","City","State","Zip" _ + ,"UserDefined1","UserDefined2","UserDefined3","UserDefinedIdentifier4","UserDefinedIdentifier5" _ + ,"SeedIndicator","InductionPoint","InductionDate","InBoundIMB","IMCB","IMTB") + End Sub +End Class + +'======================================================================================================================= +' SnailWorks Repository +'======================================================================================================================= + +Class SnailWorksRepository_Class + + Public Function GetSnailWorksExportById(id) + dim SnailWorksExport:set SnailWorksExport = new SnailWorksExportModel_Class + set SnailWorksExport.Header = GetSnailWorksHeaderByKitId(id) + set SnailWorksExport.DetailRecords = FindSnailWorksDetailRecordsByKitId(id) + set GetSnailWorksExportById = SnailWorksExport + End Function + + Private Function GetSnailWorksHeaderByKitId(id) + + Dim Header:Set Header = New SnailWorksExportHeaderModel_Class + dim sql : sql = "SELECT ""H"" as RecordType,""5.1"" as Version, ""KCI"" as UserId,[Jcode] as ClientName,"""" as ParentClientName," &_ + """Tracking Kit - "" & [JobNumber] as JobName,"""" as JobDescription,"""" as SplitName,"""" as SplitDescription,""L"" as PieceType," &_ + "Year(Now()) & ""/"" & RIGHT(""0"" & Month(Now()),2) & ""/"" & RIGHT(""0"" & Day(Now()),2) as MailDate,""N"" as UploadType,"""" as TrackedQuanity," &_ + """"" as PiecesMailed,"""" as TargetInHomeDateStart,"""" as TargetInHomeDateEnd,"""" as ConfirmationEmail,"""" as JobId," &_ + """"" as SplitId,""R"" as TypeofTracking,"""" as ReturnedPostalRoutingCode,"""" as ReportId1," &_ + """"" as Report1Email,"""" as ReportId2,"""" as Report2Email,"""" as INFOONLY From Kit WHERE ID =?;" + + dim rs : set rs = DAL.Query(sql,id) + If rs.EOF then + Err.Raise 1, "GetSnailWorksHeaderByKitId", "SnailWorksHeaderByKitId was not found with Id of: " & id + Else + Set GetSnailWorksHeaderByKitId = Automapper.AutoMap(rs,"SnailWorksExportHeaderModel_Class") + Destroy rs + End If + + End Function + + Private Function FindSnailWorksDetailRecordsByKitId(id) + dim sql : sql = "SELECT ""D"" as RecordType, OutboundSerial as CustomerUniqueIdentifier, OutboundIMBDigits as IMB, """" as Greeting , """" as FirstName," &_ + """"" as MI, """" as LastName,"""" as Suffix,"""" as FullName,"""" as Address1,"""" as Address2,"""" as City,"""" as State," &_ + """"" as Zip,Jcode as UserDefined1,"""" as UserDefined2,"""" as UserDefined3,"""" as UserDefinedIdentifier4,"""" as UserDefinedIdentifier5,"""" as SeedIndicator," &_ + """"" as InductionPoint,"""" as InductionDate,InBoundIMBDigits as InboundIMB,"""" as IMCB,"""" as IMTB " &_ + "FROM (InkjetRecords RIGHT JOIN [KitLabels] ON InkjetRecords.KitLabelID = KitLabels.ID) INNER JOIN Kit On Kit.ID = KitLabels.KitID WHERE KitLabels.KitID = ?" + + dim rs : set rs = DAL.Query(sql,id) + If rs.EOF then + Err.Raise 1,"FindSnailWorksDetailRecordsByKitId","FindSnailWorksDetailRecordsByKitId was not ound with Id of: " & id + Else + set FindSnailWorksDetailRecordsByKitId = SnailWorksDetailRecordList(rs) + Destroy rs + End If + End Function + + Private Function SnailWorksDetailRecordList(rs) + dim list : set list = new LinkedList_Class + dim model + + Do until rs.EOF + set model = new SnailWorksExportDetailModel_Class + list.Push Automapper.AutoMap(rs, model) + rs.MoveNext + Loop + set SnailWorksDetailRecordList = list + End Function +End Class + + +dim SnailWorksRepository__Singleton +Function SnailWorksRepository() + If IsEmpty(SnailWorksRepository__Singleton) then + set SnailWorksRepository__Singleton = new SnailWorksRepository_Class + End If + set SnailWorksRepository = SnailWorksRepository__Singleton +End Function + +%> \ No newline at end of file diff --git a/App/include_all.asp b/App/include_all.asp index 09096e7..792b07b 100644 --- a/App/include_all.asp +++ b/App/include_all.asp @@ -6,4 +6,5 @@ - \ No newline at end of file + + \ No newline at end of file