Skip to content

Commit 506bb52

Browse files
authored
Merge pull request #8 from Napp/feature/orders
Add support for orders & invoice
2 parents c73c732 + 1757bb5 commit 506bb52

55 files changed

Lines changed: 4880 additions & 500 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitattributes

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Path-based git attributes
2+
# https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html
3+
4+
# Ignore all test and documentation with "export-ignore".
5+
/.gitattributes export-ignore
6+
/.gitignore export-ignore
7+
/.travis.yml export-ignore
8+
/phpunit.xml export-ignore
9+
/tests export-ignore
10+
/.editorconfig export-ignore
11+
/phpunit.gitlab.xml export-ignore
12+
/gitlab-test-mysql.sh export-ignore
13+
/.gitlab-ci.yml export-ignore

.gitignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
.idea/
2+
codeCoverage/
3+
vendor/
4+
composer.lock
5+
.php_cs.cache
6+
_ide_helper.php
7+
.phpstorm.meta.php
8+
coverage
9+
coverage.xml
10+
phpunit.local.xml
11+
composer.lock
12+
/tests/_output

composer.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@
77
"autoload": {
88
"psr-4": {
99
"EDI\\Generator\\": "src/Generator/"
10-
}
10+
},
11+
"classmap": [
12+
"src/"
13+
]
14+
},
15+
"require": {
16+
"sabas/edifact": "^0.4.1",
17+
"friendsofphp/php-cs-fixer": "^2.14"
18+
},
19+
"require-dev": {
20+
"phpunit/phpunit": "6.1.*"
1121
}
1222
}

phpunit.xml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit backupGlobals="false"
3+
backupStaticAttributes="false"
4+
bootstrap="vendor/autoload.php"
5+
colors="true"
6+
convertErrorsToExceptions="true"
7+
convertNoticesToExceptions="true"
8+
convertWarningsToExceptions="true"
9+
processIsolation="false"
10+
stopOnFailure="false">
11+
<testsuites>
12+
<testsuite name="EdiFact-Generator">
13+
<directory>./tests/GeneratorTest</directory>
14+
</testsuite>
15+
</testsuites>
16+
<filter>
17+
<whitelist processUncoveredFilesFromWhitelist="true">
18+
<directory suffix=".php">./src</directory>
19+
</whitelist>
20+
</filter>
21+
</phpunit>

src/Generator/Base.php

Lines changed: 235 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,235 @@
1+
<?php
2+
3+
namespace EDI\Generator;
4+
5+
/**
6+
* Class Base
7+
*
8+
* @package EDI\Generator
9+
*/
10+
class Base
11+
{
12+
13+
/** @var array */
14+
protected $messageContent = [];
15+
16+
/** @var array */
17+
protected $composed;
18+
19+
/** @var string */
20+
protected $sender;
21+
22+
/** @var string */
23+
protected $receiver;
24+
25+
/** @var string */
26+
// protected $managingOrganisation = '89';
27+
28+
/**
29+
* @param $keyName
30+
*/
31+
public function addKeyToCompose($keyName)
32+
{
33+
$this->composeKeys[] = $keyName;
34+
}
35+
36+
/**
37+
* compose message by keys givven in an ordered array
38+
*
39+
* @param array $keys
40+
*
41+
* @return array
42+
* @throws EdifactException
43+
*/
44+
public function composeByKeys($keys = null)
45+
{
46+
if ($keys === null) {
47+
$keys = $this->composeKeys;
48+
}
49+
foreach ($keys as $key) {
50+
if (property_exists($this, $key)) {
51+
if ($this->{$key} !== null) {
52+
$value = $this->{$key};
53+
if ($value) {
54+
$this->messageContent[] = $value;
55+
} else {
56+
throw new EdifactException("key " . $key . " returns no array structure");
57+
}
58+
}
59+
} else {
60+
throw new EdifactException(
61+
'key: ' . $key . ' not found for composeByKeys in ' . get_class($this) . '->' .
62+
debug_backtrace()[1]['function']
63+
);
64+
}
65+
}
66+
67+
return $this->messageContent;
68+
}
69+
70+
/**
71+
* @return array
72+
*/
73+
public function getComposed()
74+
{
75+
return $this->composed;
76+
}
77+
78+
/**
79+
* @return string
80+
*/
81+
public function getSender()
82+
{
83+
return $this->sender;
84+
}
85+
86+
/**
87+
* @param string $sender
88+
*
89+
* @return $this
90+
*/
91+
public function setSender($sender)
92+
{
93+
$this->sender = $sender;
94+
95+
return $this;
96+
}
97+
98+
/**
99+
* @return string
100+
*/
101+
public function getReceiver()
102+
{
103+
return $this->receiver;
104+
}
105+
106+
/**
107+
* @param string $receiver
108+
*
109+
* @return $this
110+
*/
111+
public function setReceiver($receiver)
112+
{
113+
$this->receiver = $receiver;
114+
115+
return $this;
116+
}
117+
118+
119+
/**
120+
* @param string, $functionCode
121+
* @param $identifier
122+
*
123+
* @return array|bool
124+
*/
125+
protected function addRFFSegment($functionCode, $identifier)
126+
{
127+
if (empty($identifier)) {
128+
return false;
129+
}
130+
131+
return [
132+
'RFF',
133+
[
134+
$functionCode,
135+
self::maxChars($identifier, 35),
136+
],
137+
];
138+
}
139+
140+
/**
141+
* @param $dateString
142+
* @param $type
143+
* @param int $formatQualifier
144+
*
145+
* @see http://www.unece.org/trade/untdid/d96a/trsd/trsddtm.htm
146+
* @return array
147+
* @throws EdifactException
148+
*/
149+
protected function addDTMSegment($dateString, $type, $formatQualifier = EdifactDate::DATE)
150+
{
151+
$data = [];
152+
$data[] = (string)$type;
153+
if (!empty($dateString)) {
154+
$data[] = EdifactDate::get($dateString, $formatQualifier);
155+
$data[] = (string)$formatQualifier;
156+
}
157+
158+
return ['DTM', $data];
159+
}
160+
161+
/**
162+
* @param $documentNumber
163+
* @param $type
164+
*
165+
* @return array
166+
*/
167+
public static function addBGMSegment($documentNumber, $type)
168+
{
169+
return [
170+
'BGM',
171+
[
172+
$type,
173+
'',
174+
'89',
175+
],
176+
$documentNumber,
177+
];
178+
}
179+
180+
/**
181+
* Crop String to max char length
182+
*
183+
* @param string $string
184+
* @param int $length
185+
*
186+
* @return string
187+
*/
188+
protected static function maxChars($string, $length = 35)
189+
{
190+
if (empty($string)) {
191+
return '';
192+
}
193+
194+
return mb_substr($string, 0, $length);
195+
}
196+
197+
/**
198+
*
199+
* @param $value
200+
* @param $array
201+
* @param null $errorMessage
202+
*
203+
* @throws EdifactException
204+
*/
205+
protected function isAllowed($value, $array, $errorMessage = null)
206+
{
207+
if ($errorMessage === null) {
208+
$errorMessage = 'value: ' . $value . ' is not in allowed values: ' .
209+
' [' . implode(', ', $array) . '] in ' . get_class($this) . '->' .
210+
debug_backtrace()[1]['function'];
211+
}
212+
if (!in_array($value, $array, true)) {
213+
throw new EdifactException($errorMessage);
214+
}
215+
}
216+
217+
218+
/**
219+
* @param $qualifier
220+
* @param $value
221+
*
222+
* @return array
223+
*/
224+
public static function addMOASegment($qualifier, $value)
225+
{
226+
return [
227+
'MOA',
228+
[
229+
'',
230+
(string)$qualifier,
231+
EdiFactNumber::convert($value),
232+
],
233+
];
234+
}
235+
}

0 commit comments

Comments
 (0)