13
13
use Aonach \X12 \Generator \Po1Generator ;
14
14
use Aonach \X12 \Generator \SeGenerator ;
15
15
use Aonach \X12 \Generator \StGenerator ;
16
-
16
+ use Aonach \ X12 \ Generator \ DtmGenerator ;
17
17
use Aonach \X12 \Generator \Product ;
18
18
use Faker \Provider \Base ;
19
19
@@ -52,10 +52,7 @@ class Generator
52
52
* @var $isaGenerator isaGenerator
53
53
*/
54
54
private $ isaGenerator ;
55
- /**
56
- * @var
57
- */
58
- private $ n1Generator ;
55
+
59
56
/**
60
57
* @var
61
58
*/
@@ -69,6 +66,11 @@ class Generator
69
66
*/
70
67
private $ stGenerator ;
71
68
69
+ /**
70
+ * @var array
71
+ */
72
+ private $ dtmGenerator ;
73
+
72
74
/**
73
75
* @var
74
76
*/
@@ -107,12 +109,10 @@ public function generate()
107
109
$ this ->initGsGenerator ();
108
110
$ this ->initStGenerator ();
109
111
$ this ->initBakGenerator ();
110
- // $this->initN1Generator();
111
112
112
- foreach ($ this ->productsData as $ product ) {
113
- $ this ->setPo1Generator (new Po1Generator ($ product ));
114
- $ this ->initAckGenerator ($ product );
115
- }
113
+ $ this ->initPo1Generator ();
114
+
115
+ $ this ->initAckGenerator ();
116
116
117
117
$ this ->initCttGenerator ();
118
118
$ this ->initSeGenerator ();
@@ -154,11 +154,15 @@ private function __generate()
154
154
$ fileContent [] = $ this ->getGsGenerator ()->__toString ();
155
155
$ fileContent [] = $ this ->getStGenerator ()->__toString ();
156
156
$ fileContent [] = $ this ->getBakGenerator ()->__toString ();
157
- // $fileContent[] = $this->getN1Generator()->__toString();
158
157
159
158
for ($ i = 0 ; $ i < count ($ this ->getPo1Generator ()); $ i ++) {
160
159
$ fileContent [] = $ this ->getPo1Generator ()[$ i ]->__toString ();
161
160
$ fileContent [] = $ this ->getAckGenerator ()[$ i ]->__toString ();
161
+ if ($ this ->getAckGenerator ()[$ i ]->getLineItemStatusCode () == 'IA ' || $ this ->getAckGenerator ()[$ i ]->getLineItemStatusCode () == 'IQ ' ){
162
+ $ this ->initDtmGenerator ($ this ->extraInformation ["855_data " ]->dtm [1 ]->date );
163
+ $ this ->getDtmGenerator ()->build ();
164
+ $ fileContent [] = $ this ->getDtmGenerator ()->__toString ();
165
+ }
162
166
}
163
167
$ fileContent [] = $ this ->getCttGenerator ()->__toString ();
164
168
$ fileContent [] = $ this ->getSeGenerator ()->__toString ();
@@ -219,22 +223,15 @@ private function initBakGenerator()
219
223
{
220
224
$ this ->setBakGenerator (
221
225
new BakGenerator (
222
- $ this ->getExtraInformation ()['acknowledgment_type ' ],
223
226
$ this ->getExtraInformation ()['855_data ' ]->purchase_order_number ,
224
227
$ this ->getExtraInformation ()['855_data ' ]->date )
225
228
);
226
229
}
227
230
228
- /**
229
- *
230
- */
231
- private function initN1Generator ()
232
- {
233
- $ this ->setN1Generator (new N1Generator (
234
- 'RNO1 ' ,
235
- 'RNO1 '
236
- ));
237
- }
231
+ private function initDtmGenerator ($ date )
232
+ {
233
+ $ this ->setDtmGenerator (new DtmGenerator ($ date ));
234
+ }
238
235
239
236
/**
240
237
*
@@ -283,25 +280,127 @@ private function initIeaGenerator()
283
280
));
284
281
}
285
282
286
- private function initAckGenerator ($ product )
283
+ /**
284
+ *
285
+ */
286
+ private function initPo1Generator ()
287
287
{
288
- $ ackObj = new AckGenerator ($ product );
288
+ foreach ($ this ->getExtraInformation ()['855_data ' ]->po1 as $ item ) {
289
+ $ product = new Product ();
290
+
291
+ $ product ->setAssignedIdentification ($ item ->assigned_identification );
292
+ $ product ->setQuantityOrdered ($ item ->quantity_ordered );
293
+ $ product ->setMeasurementCode ('EA ' ); //Fixed value for Amazon
294
+ $ product ->setUnitPrice ($ item ->unit_price );
295
+ $ product ->setBasisUnitPriceCode (null );
296
+ $ product ->setProductIdQualifier ('EN ' ); //Fixed value for Amazon
297
+ $ product ->setProductId ($ item ->buyer_product_id );
298
+
299
+ $ po1Obj = new Po1Generator ($ product );
300
+
301
+ $ this ->setPo1Generator ($ po1Obj );
302
+
303
+ }
304
+ }
305
+
306
+ /**
307
+ *
308
+ */
309
+ private function initAckGenerator ()
310
+ {
311
+
312
+ $ itemsIncluded = array ();
289
313
290
314
foreach ($ this ->getExtraInformation ()['855_data ' ]->po1 as $ item ) {
291
- if ($ item ->buyer_product_id == $ product ->getProductId ()){
292
- if ($ item ->quantity_ordered > $ product ->getQuantityOrdered ()){
315
+ //Shipping Items
316
+ foreach ($ this ->productsData as $ product ){
317
+ $ ackObj = new AckGenerator ($ product );
318
+
319
+ if ($ item ->buyer_product_id == $ product ->getProductId ()) {
320
+ if ($ item ->quantity_ordered > $ product ->getQuantityOrdered ()){
321
+ $ ackObj ->setLineItemStatusCode ('IQ ' );
322
+ $ this ->setAckGenerator ($ ackObj );
323
+ $ itemsIncluded [] = $ item ->buyer_product_id ;
324
+ break ;
325
+ }
326
+ $ ackObj ->setLineItemStatusCode ('IA ' );
327
+ $ this ->setAckGenerator ($ ackObj );
328
+ $ itemsIncluded [] = $ item ->buyer_product_id ;
329
+ break ;
330
+ }
331
+ }
332
+
333
+ //Rejected Items
334
+ foreach ($ this ->getExtraInformation ()['rejectedItems ' ] as $ rejectedItem ) {
335
+ $ ackObj = new AckGenerator ($ rejectedItem );
336
+ if ($ item ->buyer_product_id == $ rejectedItem ->getProductId ()) {
293
337
$ ackObj ->setLineItemStatusCode ('IR ' );
294
- $ ackObj ->setIndustryCode ('03 ' );
295
338
$ this ->setAckGenerator ($ ackObj );
296
- return ;
339
+ $ itemsIncluded [] = $ item ->buyer_product_id ;
340
+ break ;
297
341
}
298
- $ ackObj ->setLineItemStatusCode ('IA ' );
299
- $ ackObj ->setIndustryCode ('00 ' );
342
+ }
343
+
344
+ // Missing Items;
345
+ $ isOn = false ;
346
+ foreach ($ this ->getExtraInformation ()['rejectedItems ' ] as $ rejectedItem ) {
347
+ if ($ item ->buyer_product_id == $ rejectedItem ->getProductId ()) {
348
+ $ isOn = true ;
349
+ break ;
350
+ } else {
351
+ foreach ($ this ->getProductsData () as $ product ){
352
+ if ($ item ->buyer_product_id == $ product ->getProductId ()) {
353
+ $ isOn = true ;
354
+ break ;
355
+ }
356
+ }
357
+ }
358
+ }
359
+
360
+ if (!$ isOn ){
361
+ $ product = new Product ();
362
+
363
+ $ product ->setAssignedIdentification ($ item ->assigned_identification );
364
+ $ product ->setQuantityOrdered ($ item ->quantity_ordered );
365
+ $ product ->setMeasurementCode ('EA ' ); //Fixed value for Amazon
366
+ $ product ->setUnitPrice ($ item ->unit_price );
367
+ $ product ->setBasisUnitPriceCode (null );
368
+ $ product ->setProductIdQualifier ('EN ' ); //Fixed value for Amazon
369
+ $ product ->setProductId ($ item ->buyer_product_id );
370
+
371
+ $ ackObj = new AckGenerator ($ product );
372
+ $ ackObj ->setLineItemStatusCode ('R2 ' );
373
+
374
+ $ this ->setAckGenerator ($ ackObj );
375
+ }
376
+ }
377
+
378
+ $ allIncludedProducts = array ();
379
+
380
+ foreach ($ this ->getAckGenerator () as $ ackItem ) {
381
+ $ allIncludedProducts [] = $ ackItem ->getProductId ();
382
+ }
383
+
384
+ foreach ($ this ->getExtraInformation ()['855_data ' ]->po1 as $ item ) {
385
+ if (!in_array ($ item ->buyer_product_id , $ allIncludedProducts )){
386
+ $ product = new Product ();
387
+
388
+ $ product ->setAssignedIdentification ($ item ->assigned_identification );
389
+ $ product ->setQuantityOrdered ($ item ->quantity_ordered );
390
+ $ product ->setMeasurementCode ('EA ' ); //Fixed value for Amazon
391
+ $ product ->setUnitPrice ($ item ->unit_price );
392
+ $ product ->setBasisUnitPriceCode (null );
393
+ $ product ->setProductIdQualifier ('EN ' ); //Fixed value for Amazon
394
+ $ product ->setProductId ($ item ->buyer_product_id );
395
+
396
+ $ ackObj = new AckGenerator ($ product );
397
+
398
+ $ ackObj ->setLineItemStatusCode ('R2 ' );
300
399
$ this ->setAckGenerator ($ ackObj );
301
- return ;
302
400
}
303
401
}
304
402
}
403
+
305
404
306
405
/**
307
406
* @return int
@@ -527,6 +626,23 @@ public function setProductsData($productsData): void
527
626
$ this ->productsData = $ productsData ;
528
627
}
529
628
629
+ /**
630
+ * @return mixed
631
+ */
632
+ public function getDtmGenerator ()
633
+ {
634
+ return $ this ->dtmGenerator ;
635
+ }
636
+
637
+ /**
638
+ * @param mixed $dtmGenerator
639
+ */
640
+ public function setDtmGenerator ($ dtmGenerator ): void
641
+ {
642
+ $ this ->dtmGenerator = $ dtmGenerator ;
643
+ }
644
+
645
+
530
646
/**
531
647
* @return mixed
532
648
*/
0 commit comments