-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproduction_drop.go
164 lines (137 loc) · 4.19 KB
/
production_drop.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
package feragstring
import "fmt"
// ProductionDrop is the struct for one production drop
// underneath a route
type ProductionDrop struct {
FeragMessage
agentName string
numberOfCopies int
ControlCharacters ControlCharacterSet
limit int
maxStack int
standard int
parameterN int
maxBundle int
parameterSz int
dontProduce bool
topsheetData string
productReferenceNumbers []int
}
// TopsheetData returns the formatted topsheet data segment
func (pd *ProductionDrop) TopsheetData() string {
if pd.topsheetData == "" {
return ""
}
tsd := pd.topsheetData
if len(tsd) > 5996 {
tsd = tsd[:5996]
}
tsdSegment := fmt.Sprintf("+58%s", tsd)
fm := FeragMessage{
messageStart: "2414",
messageEnd: "!",
}
message := fm.MessageTemplate()
return message(&fm, tsdSegment)
}
func (pd *ProductionDrop) MaxBundle() string {
return fmt.Sprintf("+34%04d", pd.maxBundle)
}
func (pd *ProductionDrop) SetMaxBundle(maxBundle int) {
pd.maxBundle = maxBundle
}
func (pd *ProductionDrop) ParameterN() string {
return fmt.Sprintf("+33%04d", pd.parameterN)
}
func (pd *ProductionDrop) SetParameterN(parameterN int) {
pd.parameterN = parameterN
}
func (pd *ProductionDrop) Standard() string {
return fmt.Sprintf("+32%04d", pd.standard)
}
func (pd *ProductionDrop) SetStandard(standard int) {
pd.standard = standard
}
func (pd *ProductionDrop) MaxStack() string {
return fmt.Sprintf("+31%04d", pd.maxStack)
}
func (pd *ProductionDrop) SetMaxStack(maxStack int) {
pd.maxStack = maxStack
}
func (pd *ProductionDrop) Limit() string {
return fmt.Sprintf("+30%04d", pd.limit)
}
func (pd *ProductionDrop) SetLimit(limit int) {
pd.limit = limit
}
func (pd *ProductionDrop) ParameterSz() string {
return fmt.Sprintf("+35%04d", pd.parameterSz)
}
func (pd *ProductionDrop) SetParameterSz(parameterSz int) {
pd.parameterSz = parameterSz
}
// SetTopsheetData sets the topsheet data to a given string
func (pd *ProductionDrop) SetTopsheetData(topsheetData string) {
pd.topsheetData = topsheetData
}
// ProductReferenceNumbers returns the string of TSL-formatted ProductReferenceNumbers
func (pd *ProductionDrop) ProductReferenceNumbers() string {
var prreffmt string
for _, pr := range pd.productReferenceNumbers {
prreffmt += fmt.Sprintf("+99141%03d", pr)
}
return prreffmt
}
// AddProductReferenceNumber adds a numeric ProductReferenceNumber to the production drop
func (pd *ProductionDrop) AddProductReferenceNumber(productReferenceNumber int) {
pd.productReferenceNumbers = append(pd.productReferenceNumbers, productReferenceNumber)
}
// NumberOfCopies returns the formatted number of copies in the route
func (pd *ProductionDrop) NumberOfCopies() string {
return fmt.Sprintf("+13%05d", pd.numberOfCopies)
}
// SetNumberOfCopies sets the number of copies in the production drop
func (pd *ProductionDrop) SetNumberOfCopies(numberOfCopies int) {
pd.numberOfCopies = numberOfCopies
}
// AgentName returns the formatted agent name
func (pd *ProductionDrop) AgentName() string {
return fmt.Sprintf("+12%-10s", pd.agentName)
}
// SetAgentName sets the agent name to a given string
func (pd *ProductionDrop) SetAgentName(agentName string) {
pd.agentName = agentName
}
// NewProductionDrop instantiates a new production drop
// struct and returns a pointer to it.
func NewProductionDrop() *ProductionDrop {
pd := ProductionDrop{
FeragMessage: FeragMessage{
messageStart: "2403",
messageEnd: "!",
},
ControlCharacters: ControlCharacterSet{},
}
return &pd
}
// Payload returns the formatted FERAG string
// for embedding in the message
func (pd *ProductionDrop) Payload() string {
data := pd.AgentName()
data += pd.NumberOfCopies()
data += pd.ControlCharacters.GetControlCharactersMessage()
data += pd.Limit()
data += pd.MaxStack()
data += pd.Standard()
data += pd.ParameterN()
data += pd.MaxBundle()
data += pd.ParameterSz()
data += pd.ProductReferenceNumbers()
return data
}
// Message returns the formatted FERAG string
// for the production drop
func (pd *ProductionDrop) Message() string {
message := pd.FeragMessage.MessageTemplate()
return message(&pd.FeragMessage, pd.Payload())
}