Skip to content

Commit

Permalink
add orders, invoice
Browse files Browse the repository at this point in the history
  • Loading branch information
Mads Møller committed Mar 21, 2019
1 parent e6a87ff commit 114b474
Show file tree
Hide file tree
Showing 34 changed files with 3,778 additions and 69 deletions.
13 changes: 13 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Path-based git attributes
# https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html

# Ignore all test and documentation with "export-ignore".
/.gitattributes export-ignore
/.gitignore export-ignore
/.travis.yml export-ignore
/phpunit.xml export-ignore
/tests export-ignore
/.editorconfig export-ignore
/phpunit.gitlab.xml export-ignore
/gitlab-test-mysql.sh export-ignore
/.gitlab-ci.yml export-ignore
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.idea/
codeCoverage/
vendor/
composer.lock
.php_cs.cache
_ide_helper.php
.phpstorm.meta.php
coverage
coverage.xml
phpunit.local.xml
composer.lock
/tests/_output
11 changes: 10 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@
"autoload": {
"psr-4": {
"EDI\\Generator\\": "src/Generator/"
}
},
"classmap": [
"src/"
]
},
"require": {
"sabas/edifact": "^0.4.1"
},
"require-dev": {
"phpunit/phpunit": "6.1.*"
}
}
21 changes: 21 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?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>
224 changes: 224 additions & 0 deletions src/Generator/Base.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,224 @@
<?php

namespace EDI\Generator;

/**
* Class Base
*
* @package EDI\Generator
*/
class Base {

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

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

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

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

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

/**
* @param $keyName
*/
public function addKeyToCompose($keyName)
{
$this->composeKeys[] = $keyName;
}

/**
* compose message by keys givven in an ordered array
*
* @param array $keys
*
* @return array
* @throws EdifactException
*/
public function composeByKeys($keys = null)
{
if ($keys === null) {
$keys = $this->composeKeys;
}
foreach ($keys as $key) {
if (property_exists($this, $key)) {
if ($this->{$key} !== null) {
$value = $this->{$key};
if ($value) {
$this->messageContent[] = $value;
} else {
throw new EdifactException("key " . $key . " returns no array structure");
}
}
} else {
throw new EdifactException(
'key: ' . $key . ' not found for composeByKeys in ' . get_class($this) . '->' .
debug_backtrace()[1]['function']
);
}
}

return $this->messageContent;
}

/**
* @return array
*/
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 $dateString
* @param $type
* @param int $formatQualifier
*
* @see https://www.stylusstudio.com/edifact/D94A/2379.htm
* @return array
* @throws EdifactException
*/
protected function addDTMSegment($dateString, $type, $formatQualifier = EdifactDate::DATE) {
$data = [];
$data[] = (string) $type;
if (!empty($dateString)) {
$data[] = EdifactDate::get($dateString , $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
*
* @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 null $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
*
* @return array
*/
public static function addMOASegment($qualifier, $value) {
return [
'MOA',
[
'',
(string) $qualifier,
EdiFactNumber::convert($value),
],
];
}

}
12 changes: 6 additions & 6 deletions src/Generator/Calinf.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function __construct(
$this->dtmSend = self::dtmSegment(137, date('YmdHi'));
}

/*
/**
* Date of the message submission
*
*/
Expand All @@ -49,7 +49,7 @@ public function setDTMMessageSendingTime($dtm)
return $this;
}

/*
/**
* Message sender (usually the vessel agent)
*
*/
Expand All @@ -60,7 +60,7 @@ public function setSender($code, $name)
return $this;
}

/*
/**
* Message receiver (usually the terminal)
*
*/
Expand All @@ -71,7 +71,7 @@ public function setReceiver($code, $name)
return $this;
}

/*
/**
* Vessel call information
*
*/
Expand All @@ -83,7 +83,7 @@ public function setVessel($extVoyage, $line, $imoNumber, $vslName, $callsign)
return $this;
}

/*
/**
* Estimated Time of Arrival
*
*/
Expand All @@ -94,7 +94,7 @@ public function setEta($dtm)
return $this;
}

/*
/**
* Estimated Time of Departure
*
*/
Expand Down
4 changes: 2 additions & 2 deletions src/Generator/Codeco.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function __construct(
$sMessageControllingAgencyCoded, $sMessageReferenceNumber, $sAssociationAssignedCode);
}

/*
/**
*
*/
public function setSenderAndReceiver($sender, $receiver)
Expand All @@ -43,7 +43,7 @@ public function setSenderAndReceiver($sender, $receiver)
return $this;
}

/*
/**
* $line: Master Liner Codes List
*/
public function setCarrier($line)
Expand Down
Loading

0 comments on commit 114b474

Please sign in to comment.