Philipp dd32514938 Fix percentage-based allowance/charge calculations (EN16931 compliance)
Two arithmetic bugs caused wrong line totals when percentage-based allowances
or charges were used:

Bug A — Product-level (product.allowances): The percent discount was computed
as (price * pct/100) * quantity (line total), then subtracted from the unit
price and multiplied by quantity again — discount applied twice.

Bug B — Item-level (itemAllowances) with basisQuantity != 1: The percent was
applied to price * quantity instead of price * quantity / basisQuantity.

Fix: LineCalculator and XML pull providers now pass context-appropriate
IAbsoluteValueProvider wrappers (perUnitProvider for product-level,
itemBasisProvider for item-level). Allowance.java uses RoundingMode.HALF_UP
in getPercent().divide(100). BasisAmount in XML is formatted via
currencyFormat().

Files changed:
- LineCalculator.java: perUnitProvider, itemBasisProvider in allowance/charge loops
- Allowance.java: RoundingMode.HALF_UP, scale 18
- ZUGFeRD2PullProvider.java: correct providers, format BasisAmount
- OXPullProvider.java, DAPullProvider.java: perUnitProvider for product-level
- CalculationTest.java: @Test on 5 methods, 4 new regression tests

Verification: mvn test -pl library -Dtest=CalculationTest

Full PR description with before/after XML proof: see .project/PR-allowance-charge-fix.md
(Test evidence files in C:\temp\mustang-test\ are for PR attachment only, not in repo.)

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-04-27 18:09:13 +02:00
2024-07-09 19:52:08 +02:00
2019-04-07 13:26:38 +02:00
2020-02-20 20:08:37 +01:00
2026-04-23 17:46:59 +02:00
2020-02-13 21:54:20 +01:00
2020-02-13 21:54:20 +01:00
2019-04-06 22:05:46 +02:00
2023-08-14 11:07:13 +02:00
2026-03-24 13:30:03 +01:00
2026-02-04 14:49:54 +01:00
2025-03-05 11:23:50 +01:00

Mustangproject

Source code repository for the Mustang project open source java PDF invoice metadata library in ZUGFeRD format.

Build

These are the recommended dependencies for the project:

  • OpenJDK 21.0.2 2024-01-16
  • Apache Maven 3.9.6

You can build the project with:

mvn clean install

This will run the tests, build the project artefacts, and install the artifacts to the local cache. After that the mustang JAR can be used.

More information on how to develop on mustang:

Usage

If you set up a Maven project, you can reference the mustang artifact like this:

<dependency>
    <groupId>org.mustangproject</groupId>
    <artifactId>validator</artifactId>
    <version>2.22.0</version>
    <classifier>shaded</classifier>
</dependency>

Further docs on how to develop with mustang:

Contact

Developer: Jochen Stärk. For questions please contact Jochen at jstaerk [at] usegroup.de

License

Subject to the Apache-2.0 license.

Description
No description provided
Readme Multiple Licenses 30 MiB
Languages
XSLT 96%
Java 2.9%
HTML 1.1%