php-edifact / edifact-generator

Formatter for EDI messages
GNU Lesser General Public License v3.0
33 stars 28 forks source link

Decimals in Item prices #12

Closed SinisaStrbac closed 5 years ago

SinisaStrbac commented 5 years ago

Hello again. I can not set item price properly , if I set UNA to ":+.? '" item price is not "10.03" (dot) but "10,03" (comma). And my order is refused by my supplier... So i can see that we can not set decimal count for formatting ( ex : 0.254 ) too

SinisaStrbac commented 5 years ago

Any solution ?

sabas commented 5 years ago

seems strange, could you post an example?

/cc @viezel

SinisaStrbac commented 5 years ago

`<?php

$interchange = new \EDI\Generator\Interchange( 'UNB-Identifier-Sender' , 'UNB-Identifier-Receiver' );

$interchange->setCharset( 'UNOA', '2' );

$orders = new \EDI\Generator\Orders( null , 'ORDERS' , 'D' , '96A' , 'UN' , 'EAN008' );

$orders ->setCustomOrderNumber( "O1234564" ) ->setOrderDate( "2019-01-01 00:00:00" ) ->setContactPerson( "XXXXXX" ) ->setMailAddress( "xxxx@xx.com" ) ->setPhoneNumber( "0388000000" ) ->setDeliveryDate( new \DateTime() )//->setDeliveryTerms( 'CAF' ) ->setDeliveryPartyAddress( "xxxxx", "", "Mr xxx", "Addressssssss", "67000", "STRASBOURG", "FR" ) ->setInvoiceAddress( "xxxxx", "", "Mr xxx", "Addressssssss", "67000", "STRASBOURG", "FR" ) ->setSupplierAddress( "xxxxx", "", "Mr xxx", "Addressssssss", "67000", "STRASBOURG", "FR" );

$item = new \EDI\Generator\Orders\Item(); $item ->setPosition( "1" , "12345678911234" , 'EN' ) ->setAdditionalProductId( '5' , "REF_supplier" , 'IN' ) ->setQuantity( "12" ) ->setNetPrice( "150.26" );

$orders->addItem( $item );

$item = new \EDI\Generator\Orders\Item(); $item ->setPosition( "2" , "12345678912345" , 'EN' ) ->setAdditionalProductId( '5' , "REF_supplier_transport_costs" , 'IN' ) ->setQuantity( "10" ) ->setNetPrice( "1.856" );

$orders->addItem( $item );

$orders->compose();

$encoder = new \EDI\Encoder( $interchange->addMessage( $orders )->getComposed(), true ); $encoder->setUNA( ":+.? '" );

echo $encoder->get(); ?>`

And the result is : UNA:+.? ' UNB+UNOA:2+UNB-Identifier-Sender+UNB-Identifier-Receiver+190514:0851+I5CDA6562C9B1F' UNH+M5CDA6562CA3D3+ORDERS:D:96A:UN:EAN008' BGM+220+O1234564+9' DTM+4:20190101:102' DTM+2:201905140851:203' NAD+DP+::ZZZ++xxxxx:Mr xxx+Addressssssss+STRASBOURG++67000+FR' NAD+IV+::ZZZ++xxxxx:Mr xxx+Addressssssss+STRASBOURG++67000+FR' NAD+SU+::ZZZ++xxxxx:Mr xxx+Addressssssss+STRASBOURG++67000+FR' CTA++:XXXXXX' COM+xxxx@xx.com:EM' COM+0388000000:TE' LIN+1++12345678911234:EN' PIA+5+REF_supplier:IN' QTY+12:12:PCE' PRI+AAA:150,26:::1:PCE' LIN+2++12345678912345:EN' PIA+5+REF_supplier_transport_costs:IN' QTY+12:10:PCE' PRI+AAA:1,86:::1:PCE' UNS+S' CNT+2+2' UNT+21+M5CDA6562CA3D3' UNZ+1+I5CDA6562C9B1F'

viezel commented 5 years ago

@sabas I think the issue here is the Encoder. It sets the UNA and thereby the decimal separator. In EDI\Encoder it says:

/**
 * @var string : dec separator character (no use but here) (default .)
 */
 private $sepDec;

So i dont think the encoder supports this. Am I wrong?

viezel commented 5 years ago

@SinisaStrbac I have pushed a small hotfix for now (version 1.0.5) - to keep you moving. ive added two optional arguments to setNetPrice and setGrossPrice - format and decimals

->setNetPrice('150.26', '.');

// output: PRI+AAA:156.26:::1:PCE
->setNetPrice('150.2634', '.', 4);

// output: PRI+AAA:156.2634:::1:PCE
viezel commented 5 years ago

see https://github.com/php-edifact/edifact-generator/releases/tag/1.0.5