diff --git a/Utils/EDI/AnsiX12/EDIAbstract.php b/Utils/EDI/AnsiX12/EDIAbstract.php new file mode 100644 index 000000000..2aecc8305 --- /dev/null +++ b/Utils/EDI/AnsiX12/EDIAbstract.php @@ -0,0 +1,45 @@ + + * @author Dennis Eichhorn + * @copyright Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +declare(strict_types=1); + +namespace phpOMS\Utils\EDI\AnsiX12\Purchase\PurchaseOrder; + +/** + * EDI + * + * @category Framework + * @package phpOMS\Utils\Converter + * @author OMS Development Team + * @author Dennis Eichhorn + * @license OMS License 1.0 + * @link http://orange-management.com + * @since 1.0.0 + */ +abstract class EDIAbstract +{ + private $header = null; + + private $heading = null; + + private $detail = null; + + private $summary = null; + + public function __construct() + { + $this->header = new Header(); + } +} \ No newline at end of file diff --git a/Utils/EDI/AnsiX12/FunctionalGroupHeader.php b/Utils/EDI/AnsiX12/FunctionalGroupHeader.php index 005533ec2..8e7d2ee3c 100644 --- a/Utils/EDI/AnsiX12/FunctionalGroupHeader.php +++ b/Utils/EDI/AnsiX12/FunctionalGroupHeader.php @@ -32,5 +32,149 @@ class FunctionalGroupHedaer { private $functionalGroupHeader = 'GS'; - private $functionIdentiferCode = FunctionalIdentifierCode::PO; + private $functionalIdentifierCode = FunctionalIdentifierCode::PO; + + private $applicationSenderCode = ''; + + private $appicationReceiverCode = ''; + + private $date = null; + + private $groupControlNumber = 0; + + private $responsibleAgencyCode = ''; + + private $version = ''; + + public function __construct() + { + $this->date = new \DateTime(); + } + + public function getFunctionalGroupHeader() : string + { + return $this->functionalGroupHeader; + } + + public function getFunctionalIdentifierCode() : string + { + return $this->functionalIdentifierCode; + } + + public function setFunctionalIdentifierCode(string $code) /* : void */ + { + if(!FunctionalIdentifierCode::isValidValue($code)) { + throw \Exception(); + } + + $this->functionalIdentifierCode = $code; + } + + public function getApplicationSenderCode() : string + { + return str_pad((string) $this->applicationSenderCode, 2, '0', STR_PAD_LEFT); + } + + public function setApplicationSenderCode(string $code) /* : void */ + { + if(strlen($code) < 2 || strlen($code) > 15) { + throw new \Exception(); + } + + $this->applicationSenderCode = $code; + } + + public function getApplicationReceiverCode() : string + { + return str_pad((string) $this->applicationReceiverCode, 2, '0', STR_PAD_LEFT); + } + + public function setApplicationReceiverCode(string $code) /* : void */ + { + if(strlen($code) < 2 || strlen($code) > 15) { + throw new \Exception(); + } + + $this->applicationReceiverCode = $code; + } + + public function setDate(\DateTime $date) /* : void */ + { + $this->date = $date; + } + + public function getDate() : string + { + return $this->date->format('d:m:y'); + } + + public function getTime() : string + { + return $this->date->format('d:m:y'); + } + + public function getGroupControlNumber() : int + { + return $this->groupControlNumber; + } + + public function setGroupControlNumber(int $number) /* : void */ + { + if($number < 0) { + throw new \Exception(); + } + + $this->groupControlNumber = $number; + } + + public function getResponsibleAgencyCode() : int + { + return $this->responsibleAgencyCode; + } + + public function setResponsibleAgencyCode(int $code) /* : void */ + { + if($code < 0 || $code > 99) { + throw new \Exception(); + } + + $this->responsibleAgencyCode = $code; + } + + public function getVersion() : string + { + return $this->version; + } + + public function setVersion(string $version) /* : void */ + { + $this->version = $version; + } + + public function serialize() + { + return $this->functionalGroupHeader . '*' + . $this->getfunctionalIdentifierCode() . '*' + . $this->getApplicationSenderCode() . '*' + . $this->getApplicationReceiverCode() . '*' + . $this->getDate() . '*' + . $this->getTime() . '*' + . $this->getGroupControlNumber() . '*' + . $this->getResponsibleAgencyCode() . '*' + . $this->getVersion() . '*' . self::COMPONENT_ELEMENT_SEPARATOR; + } + + public function unserialize($raw) + { + $split = explode($raw); + + $this->setFunctionalGroupHeader(trim($split[0])); + $this->setFunctionalIdentifierCode(trim($split[1])); + $this->setApplicationSenderCode(trim($split[2])); + $this->setApplicationReceiverCode(trim($split[3])); + $this->setDate(new \DateTime(trim($split[4]) . '-' . trim($split[5]))); + $this->setGroupControlNumber(trim($split[6])); + $this->setResponsibleAgencyCode((int) trim($split[7])); + $this->setVersion(trim($split[8])); + } } diff --git a/Utils/EDI/AnsiX12/FunctionalIdentifierCode.php b/Utils/EDI/AnsiX12/FunctionalIdentifierCode.php new file mode 100644 index 000000000..e69de29bb diff --git a/Utils/EDI/AnsiX12/Header.php b/Utils/EDI/AnsiX12/Header.php index eae56c9d5..9337825f2 100644 --- a/Utils/EDI/AnsiX12/Header.php +++ b/Utils/EDI/AnsiX12/Header.php @@ -32,5 +32,11 @@ class Header { private $interchangeControlHeader = null; - private $functionGroupHeader = null; + private $functionalGroupHeader = null; + + public function __construct() + { + $this->interchangeControlHeader = new InterchangeControlHeader(); + $this->functionalGroupHeader = new FunctionalGroupHeader(); + } } diff --git a/Utils/EDI/AnsiX12/Purchase/PurchaseOrder/EDI850.php b/Utils/EDI/AnsiX12/Purchase/PurchaseOrder/EDI850.php index a825ba422..88a13d1a5 100644 --- a/Utils/EDI/AnsiX12/Purchase/PurchaseOrder/EDI850.php +++ b/Utils/EDI/AnsiX12/Purchase/PurchaseOrder/EDI850.php @@ -17,6 +17,8 @@ declare(strict_types=1); namespace phpOMS\Utils\EDI\AnsiX12\Purchase\PurchaseOrder; +use phpOMS\Utils\EDI\AnsiX12\EDIAbstract; + /** * EDI 850 - Purchase order. * @@ -28,13 +30,13 @@ namespace phpOMS\Utils\EDI\AnsiX12\Purchase\PurchaseOrder; * @link http://orange-management.com * @since 1.0.0 */ -class EDI850 +class EDI850 extends EDIAbstract { - private $header = null; - - private $heading = null; - - private $detail = []; - - private $summary = null; + public function __construct() + { + parent::__construct(); + $this->heading = new EDIT850Heading(); + $this->detail = new EDIT850Detail(); + $this->summary = new EDI850Summary(); + } } diff --git a/Utils/EDI/AnsiX12/Purchase/PurchaseOrder/EDI850BeginningSegment.php b/Utils/EDI/AnsiX12/Purchase/PurchaseOrder/EDI850BeginningSegment.php new file mode 100644 index 000000000..e69de29bb diff --git a/Utils/EDI/AnsiX12/Purchase/PurchaseOrder/EDI850Heading.php b/Utils/EDI/AnsiX12/Purchase/PurchaseOrder/EDI850Heading.php index bbe6027f6..07a78a5e0 100644 --- a/Utils/EDI/AnsiX12/Purchase/PurchaseOrder/EDI850Heading.php +++ b/Utils/EDI/AnsiX12/Purchase/PurchaseOrder/EDI850Heading.php @@ -30,9 +30,9 @@ namespace phpOMS\Utils\EDI\AnsiX12\Purchase; */ class EDI850Heading { - private $headingTransactionSetHeader = ''; + private $headingTransactionSetHeader = null; - private $headingBeginningSegmentPO = ''; + private $headingBeginningSegmentPO = null; private $headingCurrency = ''; @@ -47,4 +47,9 @@ class EDI850Heading private $headingMarksNumbers = 0; private $headingLoopId = []; + + public function __construct() + { + $this->headingTransactionSetHeader = new TransactionSetHeader(); + } } diff --git a/Utils/EDI/AnsiX12/Purchase/PurchaseOrder/TransactionSetHeader.php b/Utils/EDI/AnsiX12/Purchase/PurchaseOrder/TransactionSetHeader.php index e69de29bb..3f166448b 100644 --- a/Utils/EDI/AnsiX12/Purchase/PurchaseOrder/TransactionSetHeader.php +++ b/Utils/EDI/AnsiX12/Purchase/PurchaseOrder/TransactionSetHeader.php @@ -0,0 +1,77 @@ + + * @author Dennis Eichhorn + * @copyright Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +declare(strict_types=1); + +namespace phpOMS\Utils\EDI\AnsiX12\Purchase\PurchaseOrder; + +/** + * EDI 850 - Purchase order. + * + * @category Framework + * @package phpOMS\Utils\Converter + * @author OMS Development Team + * @author Dennis Eichhorn + * @license OMS License 1.0 + * @link http://orange-management.com + * @since 1.0.0 + */ +class TransactionSetHeader +{ + const IDENTIFIER = 'ST'; + + private $transactionSetIdentifierCode = 850; + + private $transactionSetControlNumber = ''; + + public function getTransactionSetIdentiferCode() : int + { + return $this->transactionSetIdentifierCode; + } + + public function setTransactionIdentifierCode(int $code) /* : void */ + { + $this->transactionSetIdentifierCode = $code; + } + + public function getTransactionSetControlNumber() : string + { + return str_pad((string) $this->transactionSetControlNumber, 9, '0', STR_PAD_LEFT); + } + + public function setTransactionSetControlNumber(string $number) /* : void */ + { + if(strlen($number) < 4 || strlen($number) > 9) { + throw new \Exception(); + } + + $this->transactionSetControlNumber = $number; + } + + public function unserialize($raw) + { + $split = explode($raw); + + $this->setTransactionSetIdentifierCode((int) trim($split[1])); + $this->setTransactionSetControlNumber(trim($split[2])); + } + + public function serialize() + { + return self::IDENTIFIER . '*' + . $this->getTransactionSetIdentifierCode() . '*' + . $this->getTransactionSetControlNumber(); + } +}