@@ -38,6 +38,13 @@ trait Item
3838 /** @var array */
3939 protected $ deliveryNotePosition ;
4040
41+
42+ /** @var array */
43+ protected $ qli ;
44+
45+ /** @var array */
46+ protected $ appendedSegments = [];
47+
4148 /** @var array IMD ZU */
4249 protected $ additionalText ;
4350
@@ -62,14 +69,21 @@ trait Item
6269 'orderPosition ' ,
6370 'deliveryNoteNumber ' ,
6471 'deliveryNotePosition ' ,
72+ 'qli ' ,
6573 ];
6674
6775 /**
6876 * @return array
6977 */
7078 public function compose ()
7179 {
72- return $ this ->composeByKeys ($ this ->composeKeys );
80+ $ content = $ this ->composeByKeys ($ this ->composeKeys );
81+
82+ foreach ($ this ->appendedSegments as $ segment ) {
83+ $ content [] = $ segment ;
84+ }
85+
86+ return $ content ;
7387 }
7488
7589 /**
@@ -171,14 +185,88 @@ public function setQuantity($quantity, $unit = 'PCE', $qualifier = '21')
171185 ]
172186 );
173187
188+ $ qty = [
189+ (string ) $ qualifier ,
190+ (string ) $ quantity ,
191+ ];
192+
193+ if ((string ) $ qualifier !== '1 ' ) {
194+ $ qty [] = $ unit ;
195+ }
196+
174197 $ this ->quantity = [
175198 'QTY ' ,
199+ $ qty ,
200+ ];
201+
202+ return $ this ;
203+ }
204+
205+ /**
206+ * Add item information line (IMD).
207+ *
208+ * @param string $code
209+ * @param string $information
210+ * @return $this
211+ */
212+ public function addInformation ($ code , $ information )
213+ {
214+ return $ this ->addDynamicSegment ([
215+ 'IMD ' ,
216+ 'L ' ,
217+ (string ) $ code ,
176218 [
177- (string )$ qualifier ,
178- (string )$ quantity ,
179- $ unit ,
219+ '' ,
220+ '' ,
221+ '' ,
222+ (string ) $ information ,
180223 ],
181- ];
224+ ]);
225+ }
226+
227+ /**
228+ * Add item details line (GIR).
229+ *
230+ * @param int $index
231+ * @param string $lloLocationCode
232+ * @param string $lfnPurchaseFundCode
233+ * @param string $lcvDecimalPrice
234+ * @param string|null $lsqFundCode
235+ * @return $this
236+ */
237+ public function addGir ($ index , $ lloLocationCode , $ lfnPurchaseFundCode , $ lcvDecimalPrice , $ lsqFundCode = '' )
238+ {
239+ return $ this ->addDynamicSegment ([
240+ 'GIR ' ,
241+ str_pad ((string ) $ index , 3 , '0 ' , STR_PAD_LEFT ),
242+ [
243+ (string ) $ lloLocationCode ,
244+ 'LLO ' ,
245+ ],
246+ [
247+ (string ) ($ lsqFundCode ?? '' ),
248+ 'LSQ ' ,
249+ ],
250+ [
251+ (string ) $ lfnPurchaseFundCode ,
252+ 'LFN ' ,
253+ ],
254+ [
255+ (string ) $ lcvDecimalPrice ,
256+ 'LCV ' ,
257+ ],
258+ ]);
259+ }
260+
261+ /**
262+ * Register a dynamic segment key while preserving insertion order.
263+ *
264+ * @param array $segment
265+ * @return $this
266+ */
267+ private function addDynamicSegment ($ segment )
268+ {
269+ $ this ->appendedSegments [] = $ segment ;
182270
183271 return $ this ;
184272 }
@@ -294,11 +382,9 @@ public function setFeaturesText($text)
294382 private function splitTexts ($ varName , $ text , $ maxLength , $ lineLength , $ type = 'ZU ' )
295383 {
296384 $ this ->{$ varName } = str_split (mb_substr ($ text , 0 , $ maxLength ), $ lineLength );
297- $ nr = 0 ;
385+
298386 foreach ($ this ->{$ varName } as $ line ) {
299- $ property = $ varName . $ nr ++;
300- $ this ->{$ property } = self ::addIMDSegment ($ line , $ type );
301- $ this ->addKeyToCompose ($ property );
387+ $ this ->addDynamicSegment (self ::addIMDSegment ($ line , $ type ));
302388 }
303389
304390 return $ this ;
@@ -365,6 +451,19 @@ public function setOrderPosition($orderPosition)
365451 return $ this ;
366452 }
367453
454+
455+ /**
456+ * Set quote/order line identifier.
457+ *
458+ * @param string $orderPosition
459+ * @return $this
460+ */
461+ public function setQli ($ orderPosition )
462+ {
463+ $ this ->qli = $ this ->addRFFSegment ('QLI ' , $ orderPosition );
464+
465+ return $ this ;
466+ }
368467 /**
369468 * @return array
370469 */
0 commit comments