1+ <?php
2+
3+ namespace EDI \Generator \Segment ;
4+
5+ use EDI \Generator \Segment ;
6+
7+ /**
8+ * Beginning of Message.
9+ *
10+ * @see https://service.unece.org/trade/untdid/d17b/trsd/trsdbgm.htm
11+ */
12+ class BeginningOfMessage extends Segment
13+ {
14+ public const SEGMENT_NAME = 'BGM ' ;
15+
16+ protected $ aDocument = [];
17+ protected $ aDocumentIdentification = [];
18+ protected $ sMessageFunctionCode ;
19+ protected $ sResponseTypeCode ;
20+ protected $ sDocumentStatusCode ;
21+ protected $ sLanguageNameCode ;
22+
23+ /**
24+ * Set Document (C002).
25+ *
26+ * @param string|null $sDocumentNameCode
27+ * @param string|null $sCodeListIdentificationCode
28+ * @param string|null $sCodeListResponsibleAgencyCode
29+ * @param string|null $sDocumentName
30+ *
31+ * @return self
32+ */
33+ public function setDocument (
34+ ?string $ sDocumentNameCode = null ,
35+ ?string $ sCodeListIdentificationCode = null ,
36+ ?string $ sCodeListResponsibleAgencyCode = null ,
37+ ?string $ sDocumentName = null
38+ ): self {
39+ $ aDocument = [];
40+
41+ if ($ sDocumentNameCode !== null ) {
42+ $ aDocument [] = $ sDocumentNameCode ;
43+ }
44+
45+ if ($ sCodeListIdentificationCode !== null ) {
46+ $ aDocument [] = $ sCodeListIdentificationCode ;
47+ }
48+
49+ if ($ sCodeListResponsibleAgencyCode !== null ) {
50+ $ aDocument [] = $ sCodeListResponsibleAgencyCode ;
51+ }
52+
53+ if ($ sDocumentName !== null ) {
54+ $ aDocument [] = $ sDocumentName ;
55+ }
56+
57+ $ this ->aDocument = $ aDocument ;
58+
59+ return $ this ;
60+ }
61+
62+ /**
63+ * Set Document Identification (C106).
64+ *
65+ * @param string|null $sDocumentIdentifier
66+ * @param string|null $sVersionIdentifier
67+ * @param string|null $sRevisionIdentifier
68+ *
69+ * @return self
70+ */
71+ public function setDocumentIdentification (
72+ ?string $ sDocumentIdentifier = null ,
73+ ?string $ sVersionIdentifier = null ,
74+ ?string $ sRevisionIdentifier = null
75+ ): self {
76+ $ aDocumentIdentification = [];
77+
78+ if ($ sDocumentIdentifier !== null ) {
79+ $ aDocumentIdentification [] = $ sDocumentIdentifier ;
80+ }
81+
82+ if ($ sVersionIdentifier !== null ) {
83+ $ aDocumentIdentification [] = $ sVersionIdentifier ;
84+ }
85+
86+ if ($ sRevisionIdentifier !== null ) {
87+ $ aDocumentIdentification [] = $ sRevisionIdentifier ;
88+ }
89+
90+ $ this ->aDocumentIdentification = $ aDocumentIdentification ;
91+
92+ return $ this ;
93+ }
94+
95+ /**
96+ * Set Message Function Code.
97+ *
98+ * @param string $sMessageFunctionCode
99+ *
100+ * @return self
101+ */
102+ public function setMessageFunctionCode (string $ sMessageFunctionCode ): self
103+ {
104+ $ this ->sMessageFunctionCode = $ sMessageFunctionCode ;
105+
106+ return $ this ;
107+ }
108+
109+ /**
110+ * Set Response Type Code.
111+ *
112+ * @param string $sResponseTypeCode
113+ *
114+ * @return self
115+ */
116+ public function setResponseTypeCode (string $ sResponseTypeCode ): self
117+ {
118+ $ this ->sResponseTypeCode = $ sResponseTypeCode ;
119+
120+ return $ this ;
121+ }
122+
123+ /**
124+ * Set Document Status Code.
125+ *
126+ * @param string $sDocumentStatusCode
127+ *
128+ * @return self
129+ */
130+ public function setDocumentStatusCode (string $ sDocumentStatusCode ): self
131+ {
132+ $ this ->sDocumentStatusCode = $ sDocumentStatusCode ;
133+
134+ return $ this ;
135+ }
136+
137+ /**
138+ * Set Language Name Code.
139+ *
140+ * @param string $sLanguageNameCode
141+ *
142+ * @return self
143+ */
144+ public function setLanguageNameCode (string $ sLanguageNameCode ): self
145+ {
146+ $ this ->sLanguageNameCode = $ sLanguageNameCode ;
147+
148+ return $ this ;
149+ }
150+
151+ /**
152+ * Compose.
153+ *
154+ * @return self
155+ */
156+ public function compose (): self
157+ {
158+ $ aComposed = [self ::SEGMENT_NAME ];
159+
160+ if (!empty ($ this ->aDocument )) {
161+ $ aComposed [] = $ this ->aDocument ;
162+ }
163+
164+ if (!empty ($ this ->aDocumentIdentification )) {
165+ $ aComposed [] = $ this ->aDocumentIdentification ;
166+ }
167+
168+ if ($ this ->sMessageFunctionCode !== null ) {
169+ $ aComposed [] = $ this ->sMessageFunctionCode ;
170+ }
171+
172+ if ($ this ->sResponseTypeCode !== null ) {
173+ $ aComposed [] = $ this ->sResponseTypeCode ;
174+ }
175+
176+ if ($ this ->sDocumentStatusCode !== null ) {
177+ $ aComposed [] = $ this ->sDocumentStatusCode ;
178+ }
179+
180+ if ($ this ->sLanguageNameCode !== null ) {
181+ $ aComposed [] = $ this ->sLanguageNameCode ;
182+ }
183+
184+ $ this ->setComposed ($ aComposed );
185+
186+ return $ this ;
187+ }
188+ }
0 commit comments