Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rebase from fork #1

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
87 changes: 44 additions & 43 deletions src/Generator/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ class Base

/** @var string */
protected $receiver;
protected $composeKeys;

/** @var string */
// protected $managingOrganisation = '89';
// protected $managingOrganisation = '89';

/**
* @param $keyName
Expand Down Expand Up @@ -115,6 +114,46 @@ public function setReceiver($receiver)
return $this;
}

/**
* Crop String to max char length
*
* @param string $string
* @param int $length
*
* @return string
*/
protected static function maxChars($string, $length = 35)
{
if (empty($string)) {
return '';
}

return mb_substr($string, 0, $length);
}

/**
*
* @param $value
* @param $array
* @param $errorMessage
*
* @throws EdifactException
*/
protected function isAllowed($value, $array, $errorMessage = null)
{
if ($errorMessage === null) {
$errorMessage = 'value: ' . $value . ' is not in allowed values: ' .
' [' . implode(', ', $array) . '] in ' . get_class($this) . '->' .
debug_backtrace()[1]['function'];
}
if (!in_array($value, $array, true)) {
throw new EdifactException($errorMessage);
}
}

/**
* SEGMENT UTILITIES
*/

/**
* @param string, $functionCode
Expand Down Expand Up @@ -149,10 +188,10 @@ protected function addRFFSegment($functionCode, $identifier)
protected function addDTMSegment($date, $type, $formatQualifier = EdifactDate::DATE)
{
$data = [];
$data[] = (string)$type;
$data[] = (string) $type;
if (!empty($date)) {
$data[] = EdifactDate::get($date, $formatQualifier);
$data[] = (string)$formatQualifier;
$data[] = (string) $formatQualifier;
}

return ['DTM', $data];
Expand All @@ -177,44 +216,6 @@ public static function addBGMSegment($documentNumber, $type)
];
}

/**
* Crop String to max char length
*
* @param string $string
* @param int $length
*
* @return string
*/
protected static function maxChars($string, $length = 35)
{
if (empty($string)) {
return '';
}

return mb_substr($string, 0, $length);
}

/**
*
* @param $value
* @param $array
* @param $errorMessage
*
* @throws EdifactException
*/
protected function isAllowed($value, $array, $errorMessage = null)
{
if ($errorMessage === null) {
$errorMessage = 'value: ' . $value . ' is not in allowed values: ' .
' [' . implode(', ', $array) . '] in ' . get_class($this) . '->' .
debug_backtrace()[1]['function'];
}
if (!in_array($value, $array, true)) {
throw new EdifactException($errorMessage);
}
}


/**
* @param $qualifier
* @param $value
Expand All @@ -227,7 +228,7 @@ public static function addMOASegment($qualifier, $value)
'MOA',
[
'',
(string)$qualifier,
(string) $qualifier,
EdiFactNumber::convert($value),
],
];
Expand Down
59 changes: 46 additions & 13 deletions src/Generator/Iftmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,16 @@ public function setDeliveryDateRange($earliest, $latest)
return $this;
}

/**
* @param $date
* @return $this
*/
public function setDeliveryDate($date)
{
$this->deliveryDate = self::dtmSegment(2, $date);
return $this;
}

/**
* $currency ISO 4217-3
* @param $price
Expand Down Expand Up @@ -202,23 +212,46 @@ public function compose(?string $sMessageFunctionCode = "5", ?string $sDocumentN
$this->messageContent[] = $this->messageSender;
$this->messageContent[] = $this->messageSenderInformation;
$this->messageContent[] = $this->dtmSend;
$this->messageContent[] = $this->pickupDate[0];
$this->messageContent[] = $this->pickupDate[1];
$this->messageContent[] = $this->deliveryDate[0];
$this->messageContent[] = $this->deliveryDate[1];
$this->messageContent[] = $this->agreedAmount;
$this->messageContent[] = $this->freeTextInstructions;
$this->messageContent[] = $this->weight;
$this->messageContent[] = $this->cargoNature;
$this->messageContent[] = $this->transportOrderNumber;
$this->messageContent[] = $this->booking;
if (isset($this->pickupDate)) {
$this->messageContent[] = $this->pickupDate[0];
$this->messageContent[] = $this->pickupDate[1];
}
if (isset($this->deliveryDate)) {
if (count($this->deliveryDate) > 2) {
$this->messageContent[] = $this->deliveryDate[0];
$this->messageContent[] = $this->deliveryDate[1];
} else {
$this->messageContent[] = $this->deliveryDate;
}
}
if ($this->agreedAmount !== null) {
$this->messageContent[] = $this->agreedAmount;
}
if ($this->freeTextInstructions !== null) {
$this->messageContent[] = $this->freeTextInstructions;
}
if ($this->weight !== null) {
$this->messageContent[] = $this->weight;
}
if ($this->cargoNature !== null) {
$this->messageContent[] = $this->cargoNature;
}
if ($this->transportOrderNumber !== null) {
$this->messageContent[] = $this->transportOrderNumber;
}
if ($this->booking !== null) {
$this->messageContent[] = $this->booking;
}
if ($this->bookingSequence !== null) {
$this->messageContent[] = $this->bookingSequence;
}
$this->messageContent[] = $this->vessel;

$this->messageContent[] = $this->weightKg;
if ($this->vessel !== null) {
$this->messageContent[] = $this->vessel;

}
if ($this->weightKg !== null) {
$this->messageContent[] = $this->weightKg;
}
return parent::compose();
}
}
2 changes: 1 addition & 1 deletion src/Generator/Interchange.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function compose()
if ($this->appref !== null) {
$unb[] = $this->appref;
}
d($this->appref);

$temp[] = $unb;
foreach ($this->messages as $msg) {
foreach ($msg->getComposed() as $i) {
Expand Down
2 changes: 1 addition & 1 deletion src/Generator/Invoic/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* Class Item
* @package EDI\Generator\Invoic
*/
#[\AllowDynamicProperties]
class Item extends Base
{
use ItemTrait;
Expand Down Expand Up @@ -119,7 +120,6 @@ public function addDiscount($value, $discountType = self::DISCOUNT_TYPE_PERCENT)
$index = 'discount' . $this->discountIndex++;
$this->{$index} = [
'ALC',
'',
floatval($value) > 0 ? 'C' : 'A',
'',
'',
Expand Down
18 changes: 15 additions & 3 deletions src/Generator/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,23 @@ public function __construct(
} else {
$this->messageID = $messageID;
}

$this->messageContent = [];
}

public function setMessageContent($messageContent)
{
$this->messageContent = $messageContent;
return $this;
}

public function addSegment($segment)
{
if ($segment instanceof \EDI\Generator\Segment) {
$segment = $segment->compose()->getComposed();
}
$this->messageContent[] = $segment;
return $this;
}

public function getMessageID()
Expand Down Expand Up @@ -94,7 +106,7 @@ public function compose()
*/
public static function dtmSegment($type, $dtmString, $format = 203)
{
return ['DTM', [$type, $dtmString, $format]];
return self::addDTMSegment($dtmString, $type, $format);
}

/**
Expand All @@ -107,7 +119,7 @@ public static function dtmSegment($type, $dtmString, $format = 203)
*/
public static function rffSegment($functionCode, $identifier)
{
return ['RFF', [$functionCode, $identifier]];
return self::addRFFSegment($functionCode, $identifier);
}

/**
Expand All @@ -117,7 +129,7 @@ public static function rffSegment($functionCode, $identifier)
* $secondaryLoc = preferred [locode, 139, 6] (if needed)
* @param $qualifier
* @param $firstLoc
*@param $secondaryLoc
* @param $secondaryLoc
* @return array
*/
public static function locSegment($qualifier, $firstLoc, $secondaryLoc = null)
Expand Down
10 changes: 10 additions & 0 deletions src/Generator/Segment.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,14 @@ public function setComposed(array $aComposed): void
{
$this->aComposed = $aComposed;
}

/**
* Compose.
*
* @return self
*/
public function compose(): self
{
return $this;
}
}
Loading