diff --git a/src/Generator/traits/ItemPrice.php b/src/Generator/traits/ItemPrice.php index 63d1ece..703a0d9 100755 --- a/src/Generator/traits/ItemPrice.php +++ b/src/Generator/traits/ItemPrice.php @@ -22,15 +22,17 @@ trait ItemPrice * @param $value * @param int $priceBase * @param string $priceBaseUnit + * @param int $decimals + * @param string $format * @return array */ - public static function addPRISegment($qualifier, $value, $priceBase = 1, $priceBaseUnit = 'PCE') + public static function addPRISegment($qualifier, $value, $priceBase = 1, $priceBaseUnit = 'PCE', $decimals = 2, $format = EdiFactNumber::DECIMAL_COMMA) { return [ 'PRI', [ $qualifier, - EdiFactNumber::convert($value), + EdiFactNumber::convert($value, $decimals, $format), '', '', (string)$priceBase, @@ -49,11 +51,13 @@ public function getGrossPrice() /** * @param string $grossPrice + * @param string $format + * @param int $decimals * @return $this */ - public function setGrossPrice($grossPrice) + public function setGrossPrice($grossPrice, $format = EdiFactNumber::DECIMAL_COMMA, $decimals = 2) { - $this->grossPrice = self::addPRISegment('AAB', $grossPrice); + $this->grossPrice = self::addPRISegment('AAB', $grossPrice, 1, 'PCE', $decimals, $format); $this->addKeyToCompose('grossPrice'); return $this; @@ -69,11 +73,13 @@ public function getNetPrice() /** * @param string $netPrice + * @param string $format + * @param int $decimals * @return $this */ - public function setNetPrice($netPrice) + public function setNetPrice($netPrice, $format = EdiFactNumber::DECIMAL_COMMA, $decimals = 2) { - $this->netPrice = self::addPRISegment('AAA', $netPrice); + $this->netPrice = self::addPRISegment('AAA', $netPrice, 1, 'PCE', $decimals, $format); $this->addKeyToCompose('netPrice'); return $this; diff --git a/tests/GeneratorTest/EdifactNumberTest.php b/tests/GeneratorTest/EdifactNumberTest.php index e9d4656..76e31ee 100755 --- a/tests/GeneratorTest/EdifactNumberTest.php +++ b/tests/GeneratorTest/EdifactNumberTest.php @@ -51,4 +51,20 @@ public function testNumberNegative() EdiFactNumber::convert('-100,223') ); } + + public function testDecimalSeparator() + { + $this->assertEquals( + '100.22', + EdiFactNumber::convert('100,223', 2, '.') + ); + } + + public function testDecimals() + { + $this->assertEquals( + '100,2230', + EdiFactNumber::convert('100,223', 4) + ); + } } diff --git a/tests/GeneratorTest/OrdersTest.php b/tests/GeneratorTest/OrdersTest.php index 0f63ba4..e0dc383 100755 --- a/tests/GeneratorTest/OrdersTest.php +++ b/tests/GeneratorTest/OrdersTest.php @@ -180,6 +180,25 @@ public function testOrders96AEancom() } } + public function testUSAStyle() + { + $interchange = new Interchange('UNB-Identifier-Sender','UNB-Identifier-Receiver'); + $interchange->setCharset('UNOA', '2'); + $orders = new Orders(); + + $item = new Orders\Item(); + $item->setNetPrice('1,8562', '.'); + $orders->addItem($item); + + $orders->compose(); + $encoder = new Encoder($interchange->addMessage($orders)->getComposed(), true); + $encoder->setUNA(":+.? '"); + + $message = str_replace("'", "'\n", $encoder->get()); + $this->assertStringContainsString('PRI+AAA:1.86:::1:PCE', $message); + + } + public function testFreeText() {