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 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@
/phpunit.gitlab.xml export-ignore
/gitlab-test-mysql.sh export-ignore
/.gitlab-ci.yml export-ignore
codeCoverage/
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ coverage
coverage.xml
phpunit.local.xml
.phpunit.result.cache
.phpunit.cache/
composer.lock
/tests/_output
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"codestyle:lint": "vendor/bin/php-cs-fixer fix --dry-run"
},
"require-dev": {
"sabas/edifact": "^0.4.1",
"phpunit/phpunit": "~8.0",
"sabas/edifact": "^1.0",
"phpunit/phpunit": "~11.0",
"friendsofphp/php-cs-fixer": "^3.9.5"
}
}
30 changes: 11 additions & 19 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="EdiFact-Generator">
<directory>./tests/GeneratorTest</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src</directory>
</whitelist>
</filter>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.4/phpunit.xsd" bootstrap="vendor/autoload.php" colors="true" processIsolation="false" stopOnFailure="false" cacheDirectory=".phpunit.cache" requireCoverageMetadata="false" beStrictAboutCoverageMetadata="true" displayDetailsOnTestsThatTriggerDeprecations="true" displayDetailsOnTestsThatTriggerErrors="true" displayDetailsOnTestsThatTriggerNotices="true" displayDetailsOnTestsThatTriggerWarnings="true">
<testsuites>
<testsuite name="EdiFact-Generator">
<directory>./tests/GeneratorTest</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory suffix=".php">./src</directory>
</include>
</source>
</phpunit>
135 changes: 6 additions & 129 deletions src/Generator/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,25 @@

namespace EDI\Generator;

use EDI\Generator\Traits\Segments;

/**
* Class Base
*
* @package EDI\Generator
*/
class Base
{
use Segments;

/** @var array */
protected $messageContent = [];

/** @var array */
protected $composed;

/** @var string */
protected $sender;

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

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

/**
* @param $keyName
Expand All @@ -34,7 +31,7 @@ public function addKeyToCompose($keyName)
}

/**
* compose message by keys givven in an ordered array
* compose message by keys given in an ordered array
*
* @param array $keys
*
Expand Down Expand Up @@ -75,108 +72,6 @@ public function getComposed()
return $this->composed;
}

/**
* @return string
*/
public function getSender()
{
return $this->sender;
}

/**
* @param string $sender
*
* @return $this
*/
public function setSender($sender)
{
$this->sender = $sender;

return $this;
}

/**
* @return string
*/
public function getReceiver()
{
return $this->receiver;
}

/**
* @param string $receiver
*
* @return $this
*/
public function setReceiver($receiver)
{
$this->receiver = $receiver;

return $this;
}


/**
* @param string, $functionCode
* @param $identifier
*
* @return array|bool
*/
protected function addRFFSegment($functionCode, $identifier)
{
if (empty($identifier)) {
return false;
}

return [
'RFF',
[
$functionCode,
self::maxChars($identifier, 35),
],
];
}

/**
* @param string|\DateTime $date
* @param string $type
* @param int $formatQualifier
*
* @return array
* @throws EdifactException
* @see http://www.unece.org/trade/untdid/d96a/trsd/trsddtm.htm
*/
protected function addDTMSegment($date, $type, $formatQualifier = EdifactDate::DATE)
{
$data = [];
$data[] = (string)$type;
if (!empty($date)) {
$data[] = EdifactDate::get($date, $formatQualifier);
$data[] = (string)$formatQualifier;
}

return ['DTM', $data];
}

/**
* @param $documentNumber
* @param $type
*
* @return array
*/
public static function addBGMSegment($documentNumber, $type)
{
return [
'BGM',
[
$type,
'',
'89',
],
$documentNumber,
];
}

/**
* Crop String to max char length
*
Expand Down Expand Up @@ -214,22 +109,4 @@ protected function isAllowed($value, $array, $errorMessage = null)
}
}


/**
* @param $qualifier
* @param $value
*
* @return array
*/
public static function addMOASegment($qualifier, $value)
{
return [
'MOA',
[
'',
(string)$qualifier,
EdiFactNumber::convert($value),
],
];
}
}
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();
}
}
25 changes: 22 additions & 3 deletions src/Generator/Interchange.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,19 @@ public function setCharset($identifier, $version)
return $this;
}

/**
* Set the application reference
* $appref Application reference
* @param $appref
* @return $this
*/
public function setApplicationReference($appref)
{
$this->appref = $appref;

return $this;
}


/**
* Add a Message to the Interchange
* @param $msg
Expand All @@ -85,6 +90,15 @@ public function addMessage($msg)
return $this;
}

/**
* Return the messages array
* @return array
*/
public function getMessages()
{
return $this->messages;
}

/**
* Format the Interchange segments
* @return $this
Expand All @@ -94,12 +108,17 @@ public function compose()
$temp = [];
$unb = ['UNB', $this->charset, $this->sender, $this->receiver, [$this->date, $this->time], $this->interchangeCode];
if ($this->appref !== null) {
$unb[] = '';
$unb[] = $this->appref;
}
d($this->appref);

$temp[] = $unb;
foreach ($this->messages as $msg) {
foreach ($msg->getComposed() as $i) {
$msgContent = $msg->getComposed();
if ($msgContent === null) {
$msgContent = $msg->compose()->getComposed();
}
foreach ($msgContent as $i) {
$temp[] = $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
Loading