This commit is contained in:
jstaerk
2025-08-20 17:45:51 +02:00
parent 3f1634588f
commit 2e4ab561af
7 changed files with 65 additions and 20 deletions

View File

@@ -1,5 +1,5 @@
- added JSONIgnore for Products intra community supply, reverse charge and invoice's isValid (which rather means isComplete, by the way) - added JSONIgnore for Products intra community supply, reverse charge and invoice's isValid (which rather means isComplete, by the way)
- 917? - #917
2.19.0 2.19.0
======= =======

View File

@@ -39,9 +39,8 @@ public class Allowance extends Charge {
return totalAmount; return totalAmount;
} else if (percent!=null) { } else if (percent!=null) {
BigDecimal singlePrice=currentItem.getValue().multiply(BigDecimal.ONE.subtract(getPercent().divide(new BigDecimal(100)))); BigDecimal singlePrice=currentItem.getValue().multiply(BigDecimal.ONE.subtract(getPercent().divide(new BigDecimal(100))));
// BigDecimal singlePrice=currentItem.getValue().multiply(BigDecimal.ONE.subtract(getPercent().divide(new BigDecimal(100))));
BigDecimal singlePriceDiff=currentItem.getValue().subtract(singlePrice); BigDecimal singlePriceDiff=currentItem.getValue().subtract(singlePrice);
return singlePriceDiff; return singlePriceDiff.multiply(currentItem.getQuantity());
} else { } else {
throw new RuntimeException("percent must be set"); throw new RuntimeException("percent must be set");
} }

View File

@@ -145,9 +145,10 @@ public class Charge implements IZUGFeRDAllowanceCharge {
if(totalAmount != null) { if(totalAmount != null) {
return totalAmount; return totalAmount;
} else if (percent!=null) { } else if (percent!=null) {
BigDecimal factor=getPercent().divide(new BigDecimal(100), 18, RoundingMode.HALF_UP); BigDecimal singlePrice=currentItem.getValue().multiply(BigDecimal.ONE.subtract(getPercent().divide(new BigDecimal(100), 18, RoundingMode.HALF_UP)));
BigDecimal singlePrice=currentItem.getValue().multiply(factor); BigDecimal singlePriceDiff=currentItem.getValue().subtract(singlePrice);
return singlePrice; return singlePriceDiff.multiply(currentItem.getQuantity());
} else { } else {
throw new RuntimeException("percent must be set"); throw new RuntimeException("percent must be set");
} }

View File

@@ -203,9 +203,6 @@ public class Item implements IZUGFeRDExportableItem {
} }
if (amountString != null) { if (amountString != null) {
izac.setTotalAmount(new BigDecimal(amountString)); izac.setTotalAmount(new BigDecimal(amountString));
if (percentString != null && (!percentString.equals("0"))) {
izac.setTotalAmount(new BigDecimal(amountString).divide(getQuantity()));
}
} }
if (basisAmountString != null) { if (basisAmountString != null) {
izac.setBasisAmount(new BigDecimal(basisAmountString)); izac.setBasisAmount(new BigDecimal(basisAmountString));

View File

@@ -24,4 +24,7 @@ public interface IAbsoluteValueProvider {
public BigDecimal getValue(); public BigDecimal getValue();
default BigDecimal getQuantity() {
return BigDecimal.ONE;
}
} }

View File

@@ -24,26 +24,17 @@ public class LineCalculator {
if (currentItem.getItemAllowances() != null) { if (currentItem.getItemAllowances() != null) {
for (IZUGFeRDAllowanceCharge allowance : currentItem.getItemAllowances()) { for (IZUGFeRDAllowanceCharge allowance : currentItem.getItemAllowances()) {
BigDecimal factor=BigDecimal.ONE;
BigDecimal singleAllowance=allowance.getTotalAmount(currentItem); BigDecimal singleAllowance=allowance.getTotalAmount(currentItem);
addItemAllowance(singleAllowance); addItemAllowance(singleAllowance);
addAllowanceItemTotal(singleAllowance);
if ((allowance.getPercent()!=null)&&(allowance.getPercent().compareTo(BigDecimal.ZERO)!=0)) {
factor=currentItem.getQuantity();
}
addAllowanceItemTotal(singleAllowance.multiply(factor));
} }
} }
if (currentItem.getItemCharges() != null) { if (currentItem.getItemCharges() != null) {
for (IZUGFeRDAllowanceCharge charge : currentItem.getItemCharges()) { for (IZUGFeRDAllowanceCharge charge : currentItem.getItemCharges()) {
BigDecimal factor=BigDecimal.ONE;
BigDecimal singleCharge=charge.getTotalAmount(currentItem); BigDecimal singleCharge=charge.getTotalAmount(currentItem);
addItemCharge(singleCharge); addItemCharge(singleCharge);
if ((charge.getPercent()!=null)&&(charge.getPercent().compareTo(BigDecimal.ZERO)!=0)) { subtractAllowanceItemTotal(singleCharge);
factor=currentItem.getQuantity();
}
subtractAllowanceItemTotal(singleCharge.multiply(factor));
} }
} }

View File

@@ -302,6 +302,60 @@ public class CalculationTest extends ResourceCase {
assertEquals(new BigDecimal("4.95"), calculator.getGrandTotal().stripTrailingZeros()); assertEquals(new BigDecimal("4.95"), calculator.getGrandTotal().stripTrailingZeros());
} }
public void testSimpleItemPercentCharge() {
/***
* a product with net 1.10 and qty 5 and relative item allowance of 10% should return 5 as line and grand total
*/
SimpleDateFormat sqlDate = new SimpleDateFormat("yyyy-MM-dd");
Invoice invoice = new Invoice();
invoice.setDocumentName("Rechnung");
invoice.setNumber("777777");
try {
invoice.setIssueDate(sqlDate.parse("2020-12-31"));
invoice.setDetailedDeliveryPeriod(sqlDate.parse("2020-12-01 - 2020-12-31".split(" - ")[0]), sqlDate.parse("2020-12-01 - 2020-12-31".split(" - ")[1]));
invoice.setDeliveryDate(sqlDate.parse("2020-12-31"));
invoice.setDueDate(sqlDate.parse("2021-01-15"));
} catch (Exception e) {
LOGGER.error("Failed to set dates", e);
}
TradeParty sender = new TradeParty("Maier GmbH", "Musterweg 5", "11111", "Testung", "DE");
sender.addVATID("DE2222222222");
invoice.setSender(sender);
/* trade party (recipient) */
TradeParty recipient = new TradeParty("Teston GmbH" + " " + "Zentrale" + " " + "", "Testweg 5", "11111", "Testung", "DE");
recipient.setID("111111");
recipient.addVATID("DE111111111");
invoice.setRecipient(recipient);
/* item */
Product product;
Item item;
product = new Product("AAA", "", "H87", BigDecimal.ZERO);
item = new Item(product, new BigDecimal("1.10"), new BigDecimal(5.00));
item.addCharge(new Charge().setPercent(new BigDecimal(10)).setTaxPercent(BigDecimal.ZERO));
invoice.addItem(item);
ZUGFeRD2PullProvider zf2p = new ZUGFeRD2PullProvider();
zf2p.setProfile(Profiles.getByName("XRechnung"));
zf2p.generateXML(invoice);
String theXML = new String(zf2p.getXML());
assertThat(theXML).valueByXPath("//*[local-name()='ActualAmount']")
.asString()
.isEqualTo("0.55");// test for issue #917
TransactionCalculator calculator = new TransactionCalculator(invoice);
assertEquals(new BigDecimal("6.05"), calculator.getGrandTotal().stripTrailingZeros());
}
public void testSimpleDocumentPercentCharge() { public void testSimpleDocumentPercentCharge() {
String orgname = "Test company"; String orgname = "Test company";