-
Notifications
You must be signed in to change notification settings - Fork 3
/
form.go
122 lines (110 loc) · 4.35 KB
/
form.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
// Copyright 2020 The Moov Authors
// Use of this source code is governed by an Apache License
// license that can be found in the LICENSE file.
package pdf_generator
import (
"encoding/xml"
"github.com/moov-io/1120x/pkg/utils"
"regexp"
)
type FormApplicationProperties struct {
Text string `xml:",chardata"`
FormHeaderGeneric string `xml:"FormHeaderGeneric"`
FormHeaderOriginalData string `xml:"FormHeaderOriginalData"`
SystemMode string `xml:"SystemMode"`
PrintoutWindowResizable bool `xml:"PrintoutWindowResizable"`
}
type FormView struct {
Text string `xml:",chardata"`
ShowReturnSummaryOnStartup bool `xml:"ShowReturnSummaryOnStartup"`
DefaultZoomLevel string `xml:"DefaultZoomLevel"`
ReturnTreeMouseoverBgColor string `xml:"ReturnTreeMouseoverBgColor"`
ReturnTreeSelectedItemBgColor string `xml:"ReturnTreeSelectedItemBgColor"`
ErrorFieldBgColor string `xml:"ErrorFieldBgColor"`
ChangedFieldBgColor string `xml:"ChangedFieldBgColor"`
TableHeaderBgColor string `xml:"TableHeaderBgColor"`
TableRow1BgColor string `xml:"TableRow1BgColor"`
TableRow2BgColor string `xml:"TableRow2BgColor"`
SingleReturnAutoDisplay bool `xml:"SingleReturnAutoDisplay"`
StartUpDataStage string `xml:"StartUpDataStage"`
}
type FormUserPreferences struct {
Text string `xml:",chardata"`
View FormView `xml:"View"`
}
type FormParameters struct {
Text string `xml:",chardata"`
Stage string `xml:"Stage"`
DLN string `xml:"DLN"`
DLNLatest string `xml:"DLNLatest"`
DLNChanged string `xml:"DLNChanged"`
TIN string `xml:"TIN"`
TINLatest string `xml:"TINLatest"`
TINChanged string `xml:"TINChanged"`
TaxpayerPrint bool `xml:"TaxpayerPrint"`
Print string `xml:"Print"`
DocumentId string `xml:"DocumentId"`
ReturnVersion string `xml:"ReturnVersion"`
ZoomLevel string `xml:"ZoomLevel"`
DisplayName string `xml:"DisplayName"`
Regulation string `xml:"Regulation"`
Location string `xml:"Location"`
LocationSeq string `xml:"LocationSeq"`
SubmissionVersion string `xml:"SubmissionVersion"`
SubmissionType string `xml:"SubmissionType"`
}
type FormSubmissionHeaderAndDocument struct {
Text string `xml:",chardata"`
ReturnHeader interface{} `xml:"ReturnHeader"`
SubmissionDocument interface{} `xml:"SubmissionDocument"`
}
type FormData struct {
XMLName xml.Name `xml:"AppData"`
Text string `xml:",chardata"`
ApplicationProperties FormApplicationProperties `xml:"ApplicationProperties"`
UserPreferences FormUserPreferences `xml:"UserPreferences"`
Parameters FormParameters `xml:"Parameters"`
SubmissionHeaderAndDocument FormSubmissionHeaderAndDocument `xml:"SubmissionHeaderAndDocument"`
}
type XMLParameters struct {
Parameters FormParameters
Properties FormApplicationProperties
View FormView
}
// Converting the struct to String format.
func (r *FormData) String() string {
buf, err := xml.Marshal(r)
if err != nil {
return ""
}
buf, err = utils.FormatXML(buf)
if err != nil {
return ""
}
re := regexp.MustCompile(`(?m)^\s*$[\r\n]*|[\r\n]+\s+\z`)
return re.ReplaceAllString(string(buf), "")
}
type FormDataCreator struct {
SubmissionVersion string
SubmissionYear int
SubmissionType string
Header interface{}
Data []utils.ReturnInspectData
}
func (r *FormDataCreator) GenerateXMLDocument(params *XMLParameters) []XMLDocument {
var data []XMLDocument
for _, returnData := range r.Data {
formData := FormData{}
if params != nil {
formData.Parameters = params.Parameters
formData.UserPreferences.View = params.View
formData.ApplicationProperties = params.Properties
}
formData.Parameters.SubmissionVersion = r.SubmissionVersion
formData.Parameters.SubmissionType = r.SubmissionType
formData.SubmissionHeaderAndDocument.ReturnHeader = r.Header
formData.SubmissionHeaderAndDocument.SubmissionDocument = returnData
data = append(data, XMLDocument{XML: []byte(formData.String()), Type: returnData.DataType, Year: r.SubmissionYear})
}
return data
}