php-edifact / edifact-generator

Formatter for EDI messages
GNU Lesser General Public License v3.0
36 stars 29 forks source link

LOC segment is not generating in Codeco\Container #19

Closed mahsa92 closed 2 years ago

mahsa92 commented 2 years ago

I wrote a code like belows:

$oContainer = (new \EDI\Generator\Codeco\Container())
        ->setContainer('test', '45G1', 1, 4)
        ->setLocation('SESTO')
    ;

But it's not generating LOC segment in output, I noticed it hasn't been added to compose function.

https://github.com/php-edifact/edifact-generator/blob/9b422febe366ab5ff3d77be29374a8a43e2e18d4/src/Generator/Codeco/Container.php#L136

proposed function:

/**
 * @return array
 */
public function compose()
{
    $composed = [$this->cntr];
    if ($this->bkg !== null) {
        $composed[] = $this->bkg;
    }
    $composed[] = $this->effectiveDate;
    if ($this->weight !== null) {
        $composed[] = $this->weight;
    }
    if ($this->seal !== null) {
        $composed[] = $this->seal;
    }
    if ($this->modeOfTransport !== null) {
        $composed[] = $this->modeOfTransport;
    }
    if ($this->destination !== null) {
        $composed[] = $this->destination;
    }
    return $composed;
}
sabas commented 2 years ago

I think it should go between DTM and MEA, because in that position it would make required modeOfTransport and in your sample it isn't set... What do you think?

image

mahsa92 commented 2 years ago

Yes. You are right. So it should be like this:

 /**
   * @return array
 */
  public function compose()
 {
       $composed = [$this->cntr];
       if ($this->bkg !== null) {
            $composed[] = $this->bkg;
        }
       $composed[] = $this->effectiveDate;
       if ($this->destination !== null) {
               $composed[] = $this->destination;
        }
       if ($this->weight !== null) {
             $composed[] = $this->weight;
        }
        if ($this->seal !== null) {
              $composed[] = $this->seal;
         }
        if ($this->modeOfTransport !== null) {
               $composed[] = $this->modeOfTransport;
         }

        return $composed;
   }