Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6de14b5

Browse files
committed
Fixing 855 generation process.
1 parent f00f854 commit 6de14b5

File tree

6 files changed

+247
-42
lines changed

6 files changed

+247
-42
lines changed

src/X12/Generator.php

Lines changed: 147 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
use Aonach\X12\Generator\Po1Generator;
1414
use Aonach\X12\Generator\SeGenerator;
1515
use Aonach\X12\Generator\StGenerator;
16-
16+
use Aonach\X12\Generator\DtmGenerator;
1717
use Aonach\X12\Generator\Product;
1818
use Faker\Provider\Base;
1919

@@ -52,10 +52,7 @@ class Generator
5252
* @var $isaGenerator isaGenerator
5353
*/
5454
private $isaGenerator;
55-
/**
56-
* @var
57-
*/
58-
private $n1Generator;
55+
5956
/**
6057
* @var
6158
*/
@@ -69,6 +66,11 @@ class Generator
6966
*/
7067
private $stGenerator;
7168

69+
/**
70+
* @var array
71+
*/
72+
private $dtmGenerator;
73+
7274
/**
7375
* @var
7476
*/
@@ -107,12 +109,10 @@ public function generate()
107109
$this->initGsGenerator();
108110
$this->initStGenerator();
109111
$this->initBakGenerator();
110-
// $this->initN1Generator();
111112

112-
foreach ($this->productsData as $product) {
113-
$this->setPo1Generator(new Po1Generator($product));
114-
$this->initAckGenerator($product);
115-
}
113+
$this->initPo1Generator();
114+
115+
$this->initAckGenerator();
116116

117117
$this->initCttGenerator();
118118
$this->initSeGenerator();
@@ -154,11 +154,15 @@ private function __generate()
154154
$fileContent[] = $this->getGsGenerator()->__toString();
155155
$fileContent[] = $this->getStGenerator()->__toString();
156156
$fileContent[] = $this->getBakGenerator()->__toString();
157-
// $fileContent[] = $this->getN1Generator()->__toString();
158157

159158
for ($i = 0; $i < count($this->getPo1Generator()); $i++) {
160159
$fileContent[] = $this->getPo1Generator()[$i]->__toString();
161160
$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+
}
162166
}
163167
$fileContent[] = $this->getCttGenerator()->__toString();
164168
$fileContent[] = $this->getSeGenerator()->__toString();
@@ -219,22 +223,15 @@ private function initBakGenerator()
219223
{
220224
$this->setBakGenerator(
221225
new BakGenerator(
222-
$this->getExtraInformation()['acknowledgment_type'],
223226
$this->getExtraInformation()['855_data']->purchase_order_number,
224227
$this->getExtraInformation()['855_data']->date)
225228
);
226229
}
227230

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+
}
238235

239236
/**
240237
*
@@ -283,25 +280,127 @@ private function initIeaGenerator()
283280
));
284281
}
285282

286-
private function initAckGenerator($product)
283+
/**
284+
*
285+
*/
286+
private function initPo1Generator()
287287
{
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();
289313

290314
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()) {
293337
$ackObj->setLineItemStatusCode('IR');
294-
$ackObj->setIndustryCode('03');
295338
$this->setAckGenerator($ackObj);
296-
return;
339+
$itemsIncluded[] = $item->buyer_product_id;
340+
break;
297341
}
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');
300399
$this->setAckGenerator($ackObj);
301-
return;
302400
}
303401
}
304402
}
403+
305404

306405
/**
307406
* @return int
@@ -527,6 +626,23 @@ public function setProductsData($productsData): void
527626
$this->productsData = $productsData;
528627
}
529628

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+
530646
/**
531647
* @return mixed
532648
*/

src/X12/Generator/AckGenerator.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ class AckGenerator implements SegmentGeneratorInterface
113113
*/
114114
public function __construct(Product $product)
115115
{
116+
$this->setProductId($product->getProductId());
117+
$this->setProductIdQualifier($product->getProductIdQualifier());
118+
116119
$this->setQuantity($product->getQuantityOrdered());
117120
$this->setBasisMeasurementCode($product->getMeasurementCode());
118121
}
@@ -287,6 +290,7 @@ public function setIndustryCode($industryCode): void
287290
}
288291

289292

293+
290294
/**
291295
* @return mixed
292296
*/

src/X12/Generator/BakGenerator.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class BakGenerator implements SegmentGeneratorInterface
5353
*
5454
* @var null $acknowledgmentType
5555
*/
56-
private $acknowledgmentType = null;
56+
private $acknowledgmentType = 'AC';
5757

5858
/**
5959
* BAK03
@@ -88,9 +88,8 @@ class BakGenerator implements SegmentGeneratorInterface
8888
/**
8989
* PurchaseOrderAcknowledgment constructor.
9090
*/
91-
public function __construct($acknowledgmentType, $purchaseOrderNumber = null, $date = null)
91+
public function __construct($purchaseOrderNumber = null, $date = null)
9292
{
93-
$this->setAcknowledgmentType($acknowledgmentType);
9493
$this->setPurchaseOrderNumber($purchaseOrderNumber);
9594
$this->setDate($date);
9695
}

0 commit comments

Comments
 (0)