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

Setting allowances and charges generate invalid xml #660

Open
ozonni opened this issue Jan 9, 2025 · 11 comments
Open

Setting allowances and charges generate invalid xml #660

ozonni opened this issue Jan 9, 2025 · 11 comments

Comments

@ozonni
Copy link

ozonni commented Jan 9, 2025

Hello team,

i'm setting allowances and charges for each line item

lineItem.addCharge(new Charge()
                            .setPercent(surcharge.getPercent())
                            .setTotalAmount(surcharge.getTotalAmount())
                            .setTaxPercent(lineItem.getProduct().getVATPercent())
                            .setReasonCode("ZZZ")
                            .setCategoryCode(TaxCategoryCodeTypeConstants.STANDARDRATE)
                            .setReason(surcharge.getReason()));

When i take xml result and validate online, i get the following errors:
image

Looking here:

protected String getAllowanceChargeStr(IZUGFeRDAllowanceCharge allowance, IAbsoluteValueProvider item) {

there is no CategoryTradeTax | TypeCode | ActualTradeCurrencyExchange added

@jstaerk
Copy link
Collaborator

jstaerk commented Jan 10, 2025

sounds similar to #640 do you have source code and/or xml for me to reproduce as
library\src\test\java\org\mustangproject\ZUGFeRD\ZF2PushTest.java:testItemChargesAllowancesExport seems to deliver a valid result?

@ozonni
Copy link
Author

ozonni commented Jan 10, 2025

var lineItems = new ArrayList<IZUGFeRDExportableItem>();
var lineItem = new Item(new Product(item.getDescription(), "", "C62", new BigDecimal(item.getVat())),
                    item.getUnitPrice(),
                    item.getQuantity()
            );

lineItem.addAllowance(new Allowance()
                            .setPercent(allowance.getPercent())
                            .setTotalAmount(allowance.getTotalAmount())
                            .setTaxPercent(lineItem.getProduct().getVATPercent())
                            .setReasonCode("95")
                            .setCategoryCode(TaxCategoryCodeTypeConstants.STANDARDRATE)
                            .setReason(allowance.getReason()));

Invoice i = new Invoice();
i.setZFItems(lineItems);

ZUGFeRD2PullProvider zf2p = new ZUGFeRD2PullProvider();
zf2p.setProfile(Profiles.getByName("XRECHNUNG"));
zf2p.generateXML(i);
<ram:AppliedTradeAllowanceCharge>
            <ram:ChargeIndicator>
              <udt:Indicator>false</udt:Indicator>
            </ram:ChargeIndicator>
            <ram:ActualAmount>2.0000</ram:ActualAmount>
            <ram:Reason>WAT Reason 120</ram:Reason>
            <ram:ReasonCode>95</ram:ReasonCode>
          </ram:AppliedTradeAllowanceCharge>

@FrankHossfeld
Copy link

FrankHossfeld commented Jan 10, 2025

This is my code, which I use to generate a allowance:

invoice.addAllowance(new Allowance(model.getTotalAmount()).setReason(model.getText())
                                                                         .setPercent(model.getValue())
                                                                         .setTaxPercent(model.getSteuersatz())
                                                                         .setReasonCode("95"));

Try not setting the category code.

@ozonni
Copy link
Author

ozonni commented Jan 10, 2025

@FrankHossfeld but that way you set allowance on the invoice level, meaning it's global allowance not related to any line item. What i'm doing is setting allowance for specific line item lineItem.addAllowance

@FrankHossfeld
Copy link

FrankHossfeld commented Jan 10, 2025

@ozonni Thanks for clarifying. I was triggered by @jstaerk's comment. And yes, the problem inside the other issue is related to charges and allowance of document level. But I am remember seeing this error also. Playing around with the input helped solving the problem

@ozonni
Copy link
Author

ozonni commented Jan 10, 2025

@FrankHossfeld did you have the same error before? can you explain how you fixed it?

@FrankHossfeld
Copy link

With the latest update (2.26.0) the reasoncode "95"/"104" does no longer work.

no, sorry, can't remember. It was just in the beginning as I tried to get the electronic invoice running.

@FrankHossfeld
Copy link

FrankHossfeld commented Jan 10, 2025

looking at your code:

lineItem.addAllowance(new Allowance()
                            .setPercent(allowance.getPercent())
                            .setTotalAmount(allowance.getTotalAmount())
                            .setTaxPercent(lineItem.getProduct().getVATPercent())
                            .setReasonCode("95")
                            .setCategoryCode(TaxCategoryCodeTypeConstants.STANDARDRATE)
                            .setReason(allowance.getReason()));

I am a little bit surprised to see things like: setPercent(allowance.getPercent()). I am sure, this is an allowance created just before. HAve you tired to set percent to BigDecimal.TEN? I, in your place, would just play around and see, if the validation result change.

Update

"95" is no valid value for reason code and will create a validation error in 2.26.0.

@ozonni
Copy link
Author

ozonni commented Jan 10, 2025

@ozonni
Copy link
Author

ozonni commented Jan 10, 2025

if (currentItem.getItemTotalAllowances() != null && currentItem.getItemTotalAllowances().length > 0) {

this code is never executed since getItemTotalAllowances always returns null in the default implementation in the interface.

Tbh i'm lost now and don't understand how mustang handles allowances. Seems like allowances and charges are not support atm by this library.

@jstaerk
Copy link
Collaborator

jstaerk commented Feb 17, 2025

Hi

lineItem.addAllowance(new Allowance()
.setPercent(allowance.getPercent())
.setTotalAmount(allowance.getTotalAmount())
.setTaxPercent(lineItem.getProduct().getVATPercent())
.setReasonCode("95")
.setCategoryCode(TaxCategoryCodeTypeConstants.STANDARDRATE)
.setReason(allowance.getReason()));

please either use a absolute (setTotalAmount) or a relative (setPercent) Allowance

kind regards
Jochen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants