Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] ZugferdSettings::setUnitAmountDecimals() only works for the first item #73

Closed
dennisnissle opened this issue May 30, 2024 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@dennisnissle
Copy link

Describe the bug
The newly introduced setter to set amount decimals for a specific schema does only work for the first item added to the document. The next item will have a different node path, e.g.:

First item

/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:IncludedSupplyChainTradeLineItem/ram:SpecifiedLineTradeAgreement/ram:GrossPriceProductTradePrice/ram:ChargeAmount

Second item

/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:IncludedSupplyChainTradeLineItem[2]/ram:SpecifiedLineTradeAgreement/ram:GrossPriceProductTradePrice/ram:ChargeAmount

Mind the [2] within IncludedSupplyChainTradeLineItem. This way calling ZugferdSettings::setUnitAmountDecimals() will only affect the first item as the schema within the setter is explicitly set to /rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:IncludedSupplyChainTradeLineItem/ram:SpecifiedLineTradeAgreement/ram:GrossPriceProductTradePrice/ram:ChargeAmount

To Reproduce
Use:

ZugferdSettings::setUnitAmountDecimals( 5 );
$document = ZugferdDocumentBuilder::CreateNew( ZugferdProfiles::PROFILE_XRECHNUNG_2_3 );

for ( $i = 1; $i <= 10; $i++ ) {
    $document->addNewPosition( $i );

    $document->setDocumentPositionGrossPrice( 10.22552 );
    $document->setDocumentPositionNetPrice( 10.22552 );
    $document->setDocumentPositionLineSummation( 10.23 );
}

echo $document->getContent();
exit();

See how prices starting with the second item will be rounded to 2 decimals in the output xml file.

Expected behavior
Should work for all the items added.

Best,
Dennis

@dennisnissle dennisnissle added the bug Something isn't working label May 30, 2024
@danielmarschall
Copy link
Contributor

danielmarschall commented May 30, 2024

Good catch! I suggest to remove all [\d+] from the path using regex. @horstoeko what do you think?

@horstoeko
Copy link
Owner

horstoeko commented May 30, 2024

Hi @danielmarschall

I think the regex \[\d+\] should be good. just try it. Test it locally and make a PR.

P.S.: But as you can see, new features always bring such crude problems. And now you know why I was actually very reluctant to implement this... :-)

@danielmarschall
Copy link
Contributor

Fixed :-)

PHPUnit tests passed. And example above now works.

I am very happy that setUnitAmountDecimals() exists. @dennisnissle has the same problem like me with the rounding problems when being forced from converting from gross to net.

@horstoeko
Copy link
Owner

Hi @danielmarschall,

Nice! Many thanks....

I am very happy that setUnitAmountDecimals() exists

Sure :-)

Best regards

horstoeko added a commit that referenced this issue May 30, 2024
Fixed problem with ZugferdSettings special decimal places. Fixes #73
Repository owner locked as resolved and limited conversation to collaborators May 30, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants