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

Define decimal places for node paths #64

Merged
merged 2 commits into from
May 29, 2024
Merged

Define decimal places for node paths #64

merged 2 commits into from
May 29, 2024

Conversation

horstoeko
Copy link
Owner

Related to #59

Reviewer: @danielmarschall

In some special cases, it may be necessary to define the number of decimal places for a specific XML path. This can now be done with an extension of the ZugferdSettings. An XML path is defined together with the number of digits of the number. This currently affects the serialization of

  • minimum\udt\AmountType
  • basic\udt\AmountType
  • basicwl\udt\AmountType
  • en16931\udt\AmountType
  • extended\udt\AmountType
  • basic\udt\QuantityType
  • basicwl\udt\QuantityType
  • en16931\udt\QuantityType
  • extended\udt\QuantityType
  • basic\udt\PercentType
  • basicwl\udt\PercentType
  • en16931\udt\PercentType
  • extended\udt\PercentType

The following methods have been added

  • getSpecialDecimalPlacesMaps
  • getSpecialDecimalPlacesMap
  • setSpecialDecimalPlacesMaps
  • addSpecialDecimalPlacesMap

Class customizations

  • ZugferdTypesHandler
    • serializeAmountType
    • serializeQuantityType
    • serializePercentType

@horstoeko horstoeko added the enhancement New feature or request label May 28, 2024
@horstoeko horstoeko self-assigned this May 28, 2024
Copy link

github-actions bot commented May 28, 2024

Unit Test Results

1 855 tests  +1   1 855 ✔️ +1   5s ⏱️ ±0s
       1 suites ±0          0 💤 ±0 
       1 files   ±0          0 ±0 

Results for commit a0f8b04. ± Comparison against base commit a42cdc6.

♻️ This comment has been updated with latest results.

@danielmarschall
Copy link
Contributor

danielmarschall commented May 28, 2024

Hello @horstoeko

Thank you for the fast work!

I noticed that you changed your mind regarding the method ZugferdSettings.setUnitAmountDecimals().

Your new solution allows much more flexibility, however, the developer needs to know and add the super long path strings. And if these path strings change in a profile, or there is a typo in them, then the decimals are wrong and nobody notices. So I have a split opinion here.

I would feel better if the php library takes care about the exact naming of the paths. As user of the php lib I don't want to be confronted with all these weird rsm: and ram: paths.

I have two suggestions.

(1) In addition to your code, can we please add the following method (just a setter, no getter)?

    /**
     * Set the number of decimals to use for unit single amount values
     *
     * @param  integer $amountDecimals
     * @return void
     */
    public static function setUnitAmountDecimals(int $amountDecimals): void
    {
        ZugferdSettings::addSpecialDecimalPlacesMap('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:IncludedSupplyChainTradeLineItem/ram:SpecifiedLineTradeAgreement/ram:GrossPriceProductTradePrice/ram:ChargeAmount', $amountDecimals);
        ZugferdSettings::addSpecialDecimalPlacesMap('/rsm:CrossIndustryInvoice/rsm:SupplyChainTradeTransaction/ram:IncludedSupplyChainTradeLineItem/ram:SpecifiedLineTradeAgreement/ram:NetPriceProductTradePrice/ram:ChargeAmount', $amountDecimals);
    }

(2) We need to change/extend the README.md. I can help with that, of course.

However, for the README.md I wonder if every method in ZugferdSettings should be described. For example, methods like setDecimalSeparator() should never be called by users, because changing the decimal separator (or thousand separator, etc.) will 100% break the XML file and make it invalid. So when nobody shall call it, why describe it in the README.md ?

@horstoeko
Copy link
Owner Author

Hi @danielmarschall,

(1) In addition to your code, can we please add the following method (just a setter, no getter)?

Good idea. I'll implement this

(2) We need to change/extend the README.md. I can help with that, of course.

I will remove the part of the configuration completely from the README.md and supplement the existing document in the wiki and provide it with special instructions (especially with regard to the ``setDecimalSeparator'' you mentioned).

I think that should be it. If you have no comments on the specific topic of “decimal places” (and please only on this topic), then I would merge the PR and make a new release as soon as possible.

@danielmarschall
Copy link
Contributor

Thank you very much!

I have reviewed everything and also verified on my code that the XML is created as expected when setUnitAmountDecimals is called.

@horstoeko horstoeko merged commit 0f4b2d5 into master May 29, 2024
7 checks passed
@horstoeko horstoeko deleted the Issue_59 branch May 29, 2024 11:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants