From 4e615784fe081c67cc0c8dbca04b8aa25ded1bf3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mads=20M=C3=B8ller?= Date: Mon, 25 Mar 2019 10:45:44 +0100 Subject: [PATCH 1/7] handle VAT and Currency --- src/Generator/EdifactCurrency.php | 29 +++++ src/Generator/traits/VatAndCurrency.php | 144 ++++++++++++++++++++++++ 2 files changed, 173 insertions(+) create mode 100644 src/Generator/EdifactCurrency.php create mode 100644 src/Generator/traits/VatAndCurrency.php diff --git a/src/Generator/EdifactCurrency.php b/src/Generator/EdifactCurrency.php new file mode 100644 index 0000000..b56f5c8 --- /dev/null +++ b/src/Generator/EdifactCurrency.php @@ -0,0 +1,29 @@ +vatNumber; + } + + /** + * @param string $vatNumber + * + * @return $this + */ + public function setVatNumber($vatNumber) + { + $this->vatNumber = self::addRFFSegment('VA', str_replace(' ', '', $vatNumber)); + + return $this; + } + + /** + * @return array + */ + public function getCurrency() + { + return $this->currency; + } + + /** + * @param string $currency + * @param string $qualifier + * @return $this + */ + public function setCurrency($currency = 'EUR', $qualifier = EdifactCurrency::CURRENCY_ORDER) + { + $this->currency = [ + 'CUX', + [ + '2', + $currency, + $qualifier + ] + ]; + + return $this; + } + + /** + * @param string $currency + * @return $this + */ + public function setSupplierCurrency($currency = 'EUR') + { + $this->setCurrency($currency, EdifactCurrency::CURRENCY_SUPPLIER); + + return $this; + } + + /** + * @param string $currency + * @return $this + */ + public function setInvoiceCurrency($currency = 'EUR') + { + $this->setCurrency($currency, EdifactCurrency::CURRENCY_INVOICING); + + return $this; + } + + /** + * @param string $currency + * @return $this + */ + public function setQuotationCurrency($currency = 'EUR') + { + $this->setCurrency($currency, EdifactCurrency::CURRENCY_QUOTATION); + + return $this; + } + + /** + * @param string $currency + * @return $this + */ + public function setAccountCurrency($currency = 'EUR') + { + $this->setCurrency($currency, EdifactCurrency::CURRENCY_ACCOUNT); + + return $this; + } + + /** + * @param string $currency + * @return $this + */ + public function setPaymentCurrency($currency = 'EUR') + { + $this->setCurrency($currency, EdifactCurrency::CURRENCY_PAYMENT); + + return $this; + } + + /** + * @return array + */ + public function getExcludingVatText() + { + return $this->excludingVatText; + } + + /** + * @param string $excludingVatText + * + * @return $this + */ + public function setExcludingVatText($excludingVatText) + { + $this->excludingVatText = self::addFTXSegment($excludingVatText, 'OSI', 'ROU'); + + return $this; + } +} \ No newline at end of file From b8630754c8b60968dcff2a48b8570d70461096f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mads=20M=C3=B8ller?= Date: Mon, 25 Mar 2019 10:46:10 +0100 Subject: [PATCH 2/7] extend the NAD section --- src/Generator/traits/NameAndAddress.php | 412 ++++++++++++++++++++++++ 1 file changed, 412 insertions(+) diff --git a/src/Generator/traits/NameAndAddress.php b/src/Generator/traits/NameAndAddress.php index 480e56e..ea959a8 100755 --- a/src/Generator/traits/NameAndAddress.php +++ b/src/Generator/traits/NameAndAddress.php @@ -9,6 +9,83 @@ */ trait NameAndAddress { + /** @var array */ + protected $buyerAddress; + /** @var array */ + protected $buyerAddressContactPerson; + /** @var array */ + protected $buyerAddressMailAddress; + /** @var array */ + protected $buyerAddressPhoneNumber; + /** @var array */ + protected $buyerAddressFaxNumber; + + /** @var array */ + protected $consigneeAddress; + /** @var array */ + protected $consigneeAddressContactPerson; + /** @var array */ + protected $consigneeAddressMailAddress; + /** @var array */ + protected $consigneeAddressPhoneNumber; + /** @var array */ + protected $consigneeAddressFaxNumber; + + /** @var array */ + protected $deliveryPartyAddress; + /** @var array */ + protected $deliveryPartyAddressContactPerson; + /** @var array */ + protected $deliveryPartyAddressMailAddress; + /** @var array */ + protected $deliveryPartyAddressPhoneNumber; + /** @var array */ + protected $deliveryPartyAddressFaxNumber; + + /** @var array */ + protected $messageRecipientAddress; + /** @var array */ + protected $messageRecipientAddressContactPerson; + /** @var array */ + protected $messageRecipientAddressMailAddress; + /** @var array */ + protected $messageRecipientAddressPhoneNumber; + /** @var array */ + protected $messageRecipientAddressFaxNumber; + + /** @var array */ + protected $documentMessageSenderAddress; + /** @var array */ + protected $documentMessageSenderAddressContactPerson; + /** @var array */ + protected $documentMessageSenderAddressMailAddress; + /** @var array */ + protected $documentMessageSenderAddressPhoneNumber; + /** @var array */ + protected $documentMessageSenderAddressFaxNumber; + + /** @var array */ + protected $storeKeeperAddress; + /** @var array */ + protected $storeKeeperAddressContactPerson; + /** @var array */ + protected $storeKeeperSenderAddressMailAddress; + /** @var array */ + protected $storeKeeperSenderAddressPhoneNumber; + /** @var array */ + protected $storeKeeperSenderAddressFaxNumber; + + /** @var array */ + protected $supplierAddress; + /** @var array */ + protected $supplierAddressContactPerson; + /** @var array */ + protected $supplierAddressMailAddress; + /** @var array */ + protected $supplierAddressPhoneNumber; + /** @var array */ + protected $supplierAddressFaxNumber; + /** @var array */ protected $manufacturerAddress; /** @var array */ @@ -117,6 +194,341 @@ public function addNameAndAddress( ]; } + /** + * @return array + */ + public function getBuyerAddress() + { + return $this->buyerAddress; + } + + /** + * @param string $name1 + * @param string $name2 + * @param string $name3 + * @param string $street + * @param string $zipCode + * @param string $city + * @param string $countryCode + * @param string $managingOrganisation + * @param string $sender + * + * @return $this + */ + public function setBuyerAddress( + $name1, + $name2 = '', + $name3 = '', + $street = '', + $zipCode = '', + $city = '', + $countryCode = 'DE', + $managingOrganisation = 'ZZZ', + $sender = null + ) { + $this->buyerAddress = $this->addNameAndAddress( + $name1, + $name2, + $name3, + $street, + $zipCode, + $city, + $countryCode, + $managingOrganisation, + 'BY', + $sender ?? '' + ); + + return $this; + } + + /** + * @return array + */ + public function getConsigneeAddress() + { + return $this->consigneeAddress; + } + + /** + * @param string $name1 + * @param string $name2 + * @param string $name3 + * @param string $street + * @param string $zipCode + * @param string $city + * @param string $countryCode + * @param string $managingOrganisation + * @param string $sender + * + * @return $this + */ + public function setConsigneeAddress( + $name1, + $name2 = '', + $name3 = '', + $street = '', + $zipCode = '', + $city = '', + $countryCode = 'DE', + $managingOrganisation = 'ZZZ', + $sender = null + ) { + $this->consigneeAddress = $this->addNameAndAddress( + $name1, + $name2, + $name3, + $street, + $zipCode, + $city, + $countryCode, + $managingOrganisation, + 'CN', + $sender ?? '' + ); + + return $this; + } + + /** + * @return array + */ + public function getDeliveryPartyAddress() + { + return $this->deliveryPartyAddress; + } + + /** + * @param string $name1 + * @param string $name2 + * @param string $name3 + * @param string $street + * @param string $zipCode + * @param string $city + * @param string $countryCode + * @param string $managingOrganisation + * @param string $sender + * + * @return $this + */ + public function setDeliveryPartyAddress( + $name1, + $name2 = '', + $name3 = '', + $street = '', + $zipCode = '', + $city = '', + $countryCode = 'DE', + $managingOrganisation = 'ZZZ', + $sender = null + ) { + $this->deliveryPartyAddress = $this->addNameAndAddress( + $name1, + $name2, + $name3, + $street, + $zipCode, + $city, + $countryCode, + $managingOrganisation, + 'DP', + $sender ?? '' + ); + + return $this; + } + + /** + * @return array + */ + public function getMessageRecipientAddress() + { + return $this->messageRecipientAddress; + } + + /** + * @param string $name1 + * @param string $name2 + * @param string $name3 + * @param string $street + * @param string $zipCode + * @param string $city + * @param string $countryCode + * @param string $managingOrganisation + * @param string $sender + * + * @return $this + */ + public function setMessageRecipientAddress( + $name1, + $name2 = '', + $name3 = '', + $street = '', + $zipCode = '', + $city = '', + $countryCode = 'DE', + $managingOrganisation = 'ZZZ', + $sender = null + ) { + $this->messageRecipientAddress = $this->addNameAndAddress( + $name1, + $name2, + $name3, + $street, + $zipCode, + $city, + $countryCode, + $managingOrganisation, + 'MR', + $sender ?? '' + ); + + return $this; + } + + /** + * @return array + */ + public function getDocumentMessageSenderAddress() + { + return $this->documentMessageSenderAddress; + } + + /** + * @param string $name1 + * @param string $name2 + * @param string $name3 + * @param string $street + * @param string $zipCode + * @param string $city + * @param string $countryCode + * @param string $managingOrganisation + * @param string $sender + * + * @return $this + */ + public function setDocumentMessageSenderAddress( + $name1, + $name2 = '', + $name3 = '', + $street = '', + $zipCode = '', + $city = '', + $countryCode = 'DE', + $managingOrganisation = 'ZZZ', + $sender = null + ) { + $this->documentMessageSenderAddress = $this->addNameAndAddress( + $name1, + $name2, + $name3, + $street, + $zipCode, + $city, + $countryCode, + $managingOrganisation, + 'MS', + $sender ?? '' + ); + + return $this; + } + + /** + * @return array + */ + public function getStoreKeeperAddress() + { + return $this->storeKeeperAddress; + } + + /** + * @param string $name1 + * @param string $name2 + * @param string $name3 + * @param string $street + * @param string $zipCode + * @param string $city + * @param string $countryCode + * @param string $managingOrganisation + * @param string $sender + * + * @return $this + */ + public function setStoreKeeperAddress( + $name1, + $name2 = '', + $name3 = '', + $street = '', + $zipCode = '', + $city = '', + $countryCode = 'DE', + $managingOrganisation = 'ZZZ', + $sender = null + ) { + $this->storeKeeperAddress = $this->addNameAndAddress( + $name1, + $name2, + $name3, + $street, + $zipCode, + $city, + $countryCode, + $managingOrganisation, + 'SN', + $sender ?? '' + ); + + return $this; + } + + /** + * @return array + */ + public function getSupplierAddress() + { + return $this->supplierAddress; + } + + /** + * @param string $name1 + * @param string $name2 + * @param string $name3 + * @param string $street + * @param string $zipCode + * @param string $city + * @param string $countryCode + * @param string $managingOrganisation + * @param string $sender + * + * @return $this + */ + public function setSupplierAddress( + $name1, + $name2 = '', + $name3 = '', + $street = '', + $zipCode = '', + $city = '', + $countryCode = 'DE', + $managingOrganisation = 'ZZZ', + $sender = null + ) { + $this->supplierAddress = $this->addNameAndAddress( + $name1, + $name2, + $name3, + $street, + $zipCode, + $city, + $countryCode, + $managingOrganisation, + 'SU', + $sender ?? '' + ); + + return $this; + } /** * @return array From b268944384c411096ca9990475cac741345f6160 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mads=20M=C3=B8ller?= Date: Mon, 25 Mar 2019 10:46:38 +0100 Subject: [PATCH 3/7] use trait --- src/Generator/Invoic.php | 70 ++-------------------------------------- 1 file changed, 2 insertions(+), 68 deletions(-) diff --git a/src/Generator/Invoic.php b/src/Generator/Invoic.php index 44f64f6..0866d22 100755 --- a/src/Generator/Invoic.php +++ b/src/Generator/Invoic.php @@ -5,6 +5,7 @@ use EDI\Generator\Invoic\Item; use EDI\Generator\Traits\ContactPerson; use EDI\Generator\Traits\NameAndAddress; +use EDI\Generator\traits\VatAndCurrency; /** * Class Invoic @@ -13,9 +14,7 @@ */ class Invoic extends Message { - use - ContactPerson, - NameAndAddress; + use ContactPerson, NameAndAddress, VatAndCurrency; const TYPE_INVOICE = '380'; const TYPE_CREDIT_NOTE = '381'; @@ -34,13 +33,7 @@ class Invoic extends Message /** @var array */ protected $reductionOfFeesText; /** @var array */ - protected $excludingVatText; - /** @var array */ protected $invoiceDescription; - /** @var array */ - protected $vatNumber; - /** @var array */ - protected $currency; /** @var array */ protected $composeKeys = [ @@ -229,23 +222,7 @@ public function setReductionOfFeesText($reductionOfFeesText) return $this; } - /** - * @return array - */ - public function getExcludingVatText() - { - return $this->excludingVatText; - } - /** - * @param string $excludingVatText - * @return Invoic - */ - public function setExcludingVatText($excludingVatText) - { - $this->excludingVatText = self::addFTXSegment($excludingVatText, 'OSI', 'ROU'); - return $this; - } /** * @return array @@ -265,49 +242,6 @@ public function setInvoiceDescription($invoiceDescription) return $this; } - /** - * @return array - */ - public function getVatNumber() - { - return $this->vatNumber; - } - - /** - * @param string $vatNumber - * @return Invoic - */ - public function setVatNumber($vatNumber) - { - $this->vatNumber = self::addRFFSegment('VA', str_replace(' ', '', $vatNumber)); - return $this; - } - - /** - * @return array - */ - public function getCurrency() - { - return $this->currency; - } - - /** - * @param string $currency - * @return Invoic - */ - public function setCurrency($currency = 'EUR') - { - $this->currency = [ - 'CUX', - [ - '2', - $currency - ] - ]; - return $this; - } - - /** * @return Invoic */ From 68f8afb47fa7a55b40397f3e90f449bfaedd6b2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mads=20M=C3=B8ller?= Date: Mon, 25 Mar 2019 11:45:53 +0100 Subject: [PATCH 4/7] ifx unit test for currency --- tests/GeneratorTest/InvoicTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/GeneratorTest/InvoicTest.php b/tests/GeneratorTest/InvoicTest.php index 21efa0d..a297b78 100755 --- a/tests/GeneratorTest/InvoicTest.php +++ b/tests/GeneratorTest/InvoicTest.php @@ -43,7 +43,7 @@ public function testFreeText() public function testCurrency() { $this->assertEquals( - 'CUX+2:EUR\'', + 'CUX+2:EUR:9\'', (new Encoder([ (new Invoic)->setCurrency()->getCurrency()]))->get() ); From d261f9ec027c137adabc81f9140fbf40db8a4ceb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mads=20M=C3=B8ller?= Date: Mon, 25 Mar 2019 11:48:56 +0100 Subject: [PATCH 5/7] extend ORDERS with lots of properties, separator and order item control --- src/Generator/Orders.php | 113 +++++++++++++++++++++++++++-- src/Generator/Orders/Item.php | 1 + src/Generator/traits/Item.php | 1 - src/Generator/traits/ItemPrice.php | 13 ++-- tests/GeneratorTest/OrdersTest.php | 107 ++++++++++++++++++++++++++- 5 files changed, 221 insertions(+), 14 deletions(-) diff --git a/src/Generator/Orders.php b/src/Generator/Orders.php index d24fe31..46853b7 100755 --- a/src/Generator/Orders.php +++ b/src/Generator/Orders.php @@ -6,6 +6,7 @@ use EDI\Generator\Traits\ContactPerson; use EDI\Generator\Traits\NameAndAddress; use EDI\Generator\Traits\TransportData; +use EDI\Generator\traits\VatAndCurrency; /** * Class Orders @@ -16,44 +17,78 @@ class Orders extends Message { use ContactPerson, NameAndAddress, - TransportData; + TransportData, + VatAndCurrency; /** @var array */ protected $orderNumber; + /** @var array */ protected $orderDate; + + /** @var array */ + protected $documentDate; + /** @var array */ protected $deliveryDate; + + /** @var array */ + protected $deliveryDateLatest; + + /** @var array */ + protected $deliveryDateEarliest; + /** @var array */ protected $collectiveOrderNumber; + /** @var array */ protected $internalIdentifier; + /** @var array */ protected $objectNumber; + /** @var array */ protected $objectDescription1; + /** @var array */ protected $objectDescription2; + /** @var array */ protected $orderDescription; + /** @var array */ protected $orderNotification; + /** @var array */ protected $deliveryTerms; /** @var array */ protected $items; + /** @var array */ protected $composeKeys = [ 'orderNumber', 'orderDate', + 'documentDate', 'deliveryDate', + 'deliveryDateLatest', + 'deliveryDateEarliest', + 'buyerAddress', + 'consigneeAddress', + 'deliveryPartyAddress', + 'messageRecipientAddress', + 'documentMessageSenderAddress', + 'storeKeeperAddress', + 'invoiceAddress', + 'supplierAddress', 'orderDescription', 'orderNotification', 'internalIdentifier', 'objectNumber', 'objectDescription1', 'objectDescription2', + 'vatNumber', + 'currency', 'manufacturerAddress', 'wholesalerAddress', 'contactPerson', @@ -65,7 +100,6 @@ class Orders extends Message 'deliveryTerms', ]; - /** * Orders constructor. * @param null $messageId @@ -117,6 +151,10 @@ public function compose() } } + // Segment Group 11 : Separator & Control Total + $this->messageContent[] = ['UNS', 'S']; + $this->messageContent[] = ['CNT', '2', (string)count($this->items)]; + parent::compose(); return $this; } @@ -151,7 +189,7 @@ public function setOrderNumber($orderNumber, $documentType = '120') '248', '447' ]); - $this->orderNumber = ['BGM', $documentType, $orderNumber]; + $this->orderNumber = ['BGM', $documentType, $orderNumber, '9']; return $this; } @@ -174,6 +212,26 @@ public function setOrderDate($orderDate) return $this; } + /** + * @return array + */ + public function getDocumentDate() + { + return $this->documentDate; + } + + /** + * @param string|\DateTime $documentDate + * @param int $formatQuantifier + * @return $this + * @throws \EDI\Generator\EdifactException + */ + public function setDocumentDate($documentDate, $formatQuantifier = EdifactDate::DATETIME) + { + $this->documentDate = $this->addDTMSegment($documentDate, '137', $formatQuantifier); + return $this; + } + /** * @return array */ @@ -184,15 +242,58 @@ public function getDeliveryDate() /** * @param string|\DateTime $deliveryDate + * @param int $formatQuantifier * @return $this - * @throws EdifactException + * @throws \EDI\Generator\EdifactException + */ + public function setDeliveryDate($deliveryDate, $formatQuantifier = EdifactDate::DATETIME) + { + $this->deliveryDate = $this->addDTMSegment($deliveryDate, '2', $formatQuantifier); + return $this; + } + + /** + * @return array + */ + public function getDeliveryDateLatest() + { + return $this->deliveryDateLatest; + } + + /** + * @param $deliveryDate + * @param int $formatQuantifier + * @return $this + * @throws \EDI\Generator\EdifactException */ - public function setDeliveryDate($deliveryDate) + public function setDeliveryDateLatest($deliveryDate, $formatQuantifier = EdifactDate::DATETIME) { - $this->deliveryDate = $this->addDTMSegment($deliveryDate, '2'); + $this->deliveryDateLatest = $this->addDTMSegment($deliveryDate, '63', $formatQuantifier); return $this; } + /** + * @return array + */ + public function getDeliveryDateEarliest() + { + return $this->deliveryDateEarliest; + } + + /** + * @param string|\DateTime $deliveryDateEarliest + * @param int $formatQuantifier + * @return $this + * @throws \EDI\Generator\EdifactException + */ + public function setDeliveryDateEarliest($deliveryDateEarliest, $formatQuantifier = EdifactDate::DATETIME) + { + $this->deliveryDateEarliest = $this->addDTMSegment($deliveryDateEarliest, '64', $formatQuantifier); + return $this; + } + + + /** * @return array */ diff --git a/src/Generator/Orders/Item.php b/src/Generator/Orders/Item.php index 9b6172e..8a5393d 100755 --- a/src/Generator/Orders/Item.php +++ b/src/Generator/Orders/Item.php @@ -11,4 +11,5 @@ class Item extends Base { use \EDI\Generator\Traits\Item; + use \EDI\Generator\Traits\ItemPrice; } diff --git a/src/Generator/traits/Item.php b/src/Generator/traits/Item.php index fe4e2c2..c479022 100755 --- a/src/Generator/traits/Item.php +++ b/src/Generator/traits/Item.php @@ -144,7 +144,6 @@ public function setQuantity($quantity, $unit = 'PCE') [ '12', (string)$quantity, - // EdiFactNumber::convert($quantity, 3, EdiFactNumber::DECIMAL_POINT), $unit, ], ]; diff --git a/src/Generator/traits/ItemPrice.php b/src/Generator/traits/ItemPrice.php index 8471197..63d1ece 100755 --- a/src/Generator/traits/ItemPrice.php +++ b/src/Generator/traits/ItemPrice.php @@ -6,13 +6,14 @@ /** * Trait ItemPrice + * @url http://www.unece.org/trade/untdid/d96b/uncl/uncl5125.htm * @package EDI\Generator\Traits */ trait ItemPrice { - /** @var array */ protected $grossPrice; + /** @var array */ protected $netPrice; @@ -32,7 +33,7 @@ public static function addPRISegment($qualifier, $value, $priceBase = 1, $priceB EdiFactNumber::convert($value), '', '', - $priceBase, + (string)$priceBase, $priceBaseUnit ] ]; @@ -48,11 +49,11 @@ public function getGrossPrice() /** * @param string $grossPrice - * @return \EDI\Generator\Traits\ItemPrice + * @return $this */ public function setGrossPrice($grossPrice) { - $this->grossPrice = self::addPRISegment('GRP', $grossPrice); + $this->grossPrice = self::addPRISegment('AAB', $grossPrice); $this->addKeyToCompose('grossPrice'); return $this; @@ -68,11 +69,11 @@ public function getNetPrice() /** * @param string $netPrice - * @return \EDI\Generator\Traits\ItemPrice + * @return $this */ public function setNetPrice($netPrice) { - $this->netPrice = self::addPRISegment('NTP', $netPrice); + $this->netPrice = self::addPRISegment('AAA', $netPrice); $this->addKeyToCompose('netPrice'); return $this; diff --git a/tests/GeneratorTest/OrdersTest.php b/tests/GeneratorTest/OrdersTest.php index ef1ef0a..f9d3f32 100755 --- a/tests/GeneratorTest/OrdersTest.php +++ b/tests/GeneratorTest/OrdersTest.php @@ -68,7 +68,112 @@ public function testOrders() $message = str_replace("'", "'\n", $encoder->get()); //fwrite(STDOUT, "\n\nORDERS\n" . $message); - $this->assertContains('UNT+20', $message); + $this->assertContains('UNT+22', $message); + } catch (EdifactException $e) { + fwrite(STDOUT, "\n\nORDERS\n" . $e->getMessage()); + } + } + + public function testOrders96AEancom() + { + $interchange = new Interchange( + 'UNB-Identifier-Sender', + 'UNB-Identifier-Receiver', + null, + null, + 'Control1' + ); + $interchange + ->setCharset('UNOA', '2'); + $orders = new Orders(null, 'ORDERS', 'D', '96A', 'UN', 'EAN008'); + + try { + $orders + ->setDeliveryDate(new \DateTime()) + ->setDocumentDate(new \DateTime()) + ->setDeliveryDateLatest(new \DateTime()) + ->setDeliveryDateEarliest(new \DateTime()) + ->setBuyerAddress( + 'Supplier 123' + ) + ->setSupplierAddress( + 'Napp', + '', + '', + 'Vestagervej 1', + '2100', + 'Copenhagen', + 'DK', + '9' + ) + ->setDeliveryPartyAddress( + 'Jens Jensen' + ) + ->setInvoiceAddress( + 'Customer Name 1', + '', + '', + 'Streetname 22', + '2200', + 'cph', + 'DK' + ) + ->setVatNumber('DK22003344') + ->setCurrency('EUR') + ->setOrderNumber('AB76104') + ->setDeliveryAddress( + 'Customer Name 1', + '', + '', + 'Streetname 22', + '2200', + 'cph', + 'DK' + ) + ->setDeliveryTerms('CAF'); + + $item = new Orders\Item(); + $item + ->setPosition( + '1', + '8290123', + 'EN' + ) + ->setQuantity('3') + ->setNetPrice(1222); + $orders->addItem($item); + + $item = new Orders\Item(); + $item + ->setPosition( + '2', + '313122', + 'EN' + ) + ->setQuantity('213') + ->setGrossPrice(22.12); + $orders->addItem($item); + + $item = new Orders\Item(); + $item + ->setPosition( + '3', + '44557711qa', + 'EN' + ) + ->setQuantity('1') + ->setGrossPrice(99); + $orders->addItem($item); + + + $orders->compose(); + $encoder = new Encoder($interchange->addMessage($orders)->getComposed(), true); + $encoder->setUNA(":+,? '"); + + $message = str_replace("'", "'\n", $encoder->get()); + //fwrite(STDOUT, "\n\nORDERS\n" . $message); + + $this->assertContains('UNT+26', $message); } catch (EdifactException $e) { fwrite(STDOUT, "\n\nORDERS\n" . $e->getMessage()); } From 323113411c871f4c2d774fba71f4de3e1c6fb804 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mads=20M=C3=B8ller?= Date: Mon, 25 Mar 2019 12:02:28 +0100 Subject: [PATCH 6/7] update PhpUnit --- .gitignore | 1 + composer.json | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 31e21a9..4ce94aa 100755 --- a/.gitignore +++ b/.gitignore @@ -8,5 +8,6 @@ _ide_helper.php coverage coverage.xml phpunit.local.xml +.phpunit.result.cache composer.lock /tests/_output \ No newline at end of file diff --git a/composer.json b/composer.json index ca45859..bbc7cf3 100644 --- a/composer.json +++ b/composer.json @@ -13,10 +13,10 @@ ] }, "require": { - "sabas/edifact": "^0.4.1", - "friendsofphp/php-cs-fixer": "^2.14" }, "require-dev": { - "phpunit/phpunit": "6.1.*" + "sabas/edifact": "^0.4.1", + "phpunit/phpunit": "~8.0", + "friendsofphp/php-cs-fixer": "^2.14" } } From f0cc56c246fd5a621a5819bb7a7ff251b8e1ab65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mads=20M=C3=B8ller?= Date: Mon, 25 Mar 2019 13:44:01 +0100 Subject: [PATCH 7/7] add to samples --- SAMPLES.md | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 65 insertions(+), 2 deletions(-) diff --git a/SAMPLES.md b/SAMPLES.md index 2d92a95..caee8bc 100644 --- a/SAMPLES.md +++ b/SAMPLES.md @@ -164,7 +164,7 @@ UNT+31+M5C5201079DE48' UNZ+1+I5C5201079DADD' ``` -``` + CODECO ------ Container move report. Multiple containers per message. Each message can be for gate in or for gate out. @@ -335,7 +335,7 @@ COHAOR ------ Container special handling order message -``` +```php $oInterchange = (new \EDI\Generator\Interchange('ME', 'YOU')); $sMessageReferenceNumber = 'ROW' . str_pad(1, 11, 0, STR_PAD_LEFT); @@ -490,3 +490,66 @@ CNT+16:1' UNT+12+ROW00000000001' UNZ+1+I5C51F7D31CFF8' ``` + + +ORDERS +------ +Purchase order. + +```php +$interchange = new \EDI\Generator\Interchange('UNB-Identifier-Sender','UNB-Identifier-Receiver'); +$interchange->setCharset('UNOC', '3'); + +$orders = new \EDI\Generator\Orders(); +$orders + ->setOrderNumber('AB76104') + ->setContactPerson('John Doe') + ->setMailAddress('john.doe@company.com') + ->setPhoneNumber('+49123456789') + ->setDeliveryDate(new \DateTime()) + ->setDeliveryAddress( + 'Name 1', + 'Name 2', + 'Name 3', + 'Street', + '99999', + 'city', + 'DE' + ) + ->setDeliveryTerms('CAF'); + +// adding order items +$item = new \EDI\Generator\Orders\Item(); +$item->setPosition('1', '8290123', 'EN')->setQuantity(3); +$orders->addItem($item); + +$item = new \EDI\Generator\Orders\Item(); +$item->setPosition('2', 'AB992233', 'EN')->setQuantity(1); +$orders->addItem($item); + +$orders->compose(); + +$encoder = new \EDI\Encoder($interchange->addMessage($orders)->getComposed(), true); +$encoder->setUNA(":+,? '"); +echo $encoder->get(); +``` + +``` +UNB+UNOC:3+UNB-Identifier-Sender+UNB-Identifier-Receiver+190325:1242+I5C98CCC536C91' +UNH+M5C98CCC536CA2+ORDERS:D:96B:UN:ITEK35' +BGM+120+AB76104+9' +DTM+2:201903251242:203' +CTA++:John Doe' +COM+john.doe@company.com:EM' +COM+?+49123456789:TE' +NAD+ST+::ZZZ++Name 1:Name 2:Name 3+Street+city++99999+DE' +TOD+6++CAF' +LIN+1++8290123:EN' +QTY+12:3:PCE' +LIN+2++AB992233:EN' +QTY+12:1:PCE' +UNS+S' +CNT+2+2' +UNT+15+M5C98CCC536CA2' +UNZ+1+I5C98CCC536C91' +``` \ No newline at end of file