distinguish in writing between item and product discounts/charges

This commit is contained in:
jstaerk
2025-06-06 15:51:19 +02:00
parent 56ca021e77
commit 1a699a63af
3 changed files with 35 additions and 12 deletions

View File

@@ -295,6 +295,16 @@ public class Item implements IZUGFeRDExportableItem {
return this; return this;
} }
@Override public IZUGFeRDAllowanceCharge[] getAllowances() {
IZUGFeRDAllowanceCharge[] izac=new IZUGFeRDAllowanceCharge[Allowances.size()];
return Allowances.toArray(izac);
}
@Override public IZUGFeRDAllowanceCharge[] getCharges() {
IZUGFeRDAllowanceCharge[] izac=new IZUGFeRDAllowanceCharge[Charges.size()];
return Charges.toArray(izac);
}
/*** /***
* BT 132 (issue https://github.com/ZUGFeRD/mustangproject/issues/247) * BT 132 (issue https://github.com/ZUGFeRD/mustangproject/issues/247)
* @return the line ID of the order (BT132) * @return the line ID of the order (BT132)
@@ -468,6 +478,7 @@ public class Item implements IZUGFeRDExportableItem {
* @return fluent setter * @return fluent setter
*/ */
public Item addAllowance(IZUGFeRDAllowanceCharge izac) { public Item addAllowance(IZUGFeRDAllowanceCharge izac) {
Allowances.add(izac); Allowances.add(izac);
return this; return this;
} }

View File

@@ -31,7 +31,7 @@ public class LineCalculator {
if ((allowance.getPercent()!=null)&&(allowance.getPercent().compareTo(BigDecimal.ZERO)!=0)) { if ((allowance.getPercent()!=null)&&(allowance.getPercent().compareTo(BigDecimal.ZERO)!=0)) {
factor=currentItem.getQuantity(); factor=currentItem.getQuantity();
} }
addLineAllowance(singleAllowance.multiply(factor)); addAllowanceItemTotal(singleAllowance.multiply(factor));
} }
} }
@@ -43,7 +43,7 @@ public class LineCalculator {
if ((charge.getPercent()!=null)&&(charge.getPercent().compareTo(BigDecimal.ZERO)!=0)) { if ((charge.getPercent()!=null)&&(charge.getPercent().compareTo(BigDecimal.ZERO)!=0)) {
factor=currentItem.getQuantity(); factor=currentItem.getQuantity();
} }
addLineCharge(singleCharge.multiply(factor)); subtractAllowanceItemTotal(singleCharge.multiply(factor));
} }
} }
@@ -69,7 +69,7 @@ public class LineCalculator {
price=currentItem.getPrice(); price=currentItem.getPrice();
priceGross=price; priceGross=price;
price=price.subtract(itemAllowance).add(itemCharge); // price=price.subtract(itemAllowance).add(itemCharge);
// BigDecimal delta=charge.subtract(allowanceItemTotal).subtract(allowance); // BigDecimal delta=charge.subtract(allowanceItemTotal).subtract(allowance);
// delta=delta.divide(currentItem.getQuantity(), 18, RoundingMode.HALF_UP); // delta=delta.divide(currentItem.getQuantity(), 18, RoundingMode.HALF_UP);
@@ -91,8 +91,8 @@ public class LineCalculator {
BigDecimal basisQuantity = currentItem.getBasisQuantity().compareTo(BigDecimal.ZERO) == 0 BigDecimal basisQuantity = currentItem.getBasisQuantity().compareTo(BigDecimal.ZERO) == 0
? BigDecimal.ONE.setScale(4) ? BigDecimal.ONE.setScale(4)
: currentItem.getBasisQuantity(); : currentItem.getBasisQuantity();
itemTotalNetAmount = quantity.multiply(priceGross).divide(basisQuantity, 18, RoundingMode.HALF_UP) itemTotalNetAmount = quantity.multiply(price).divide(basisQuantity, 18, RoundingMode.HALF_UP)
.add(lineCharge).subtract(lineAllowance).setScale(2, RoundingMode.HALF_UP); .add(lineCharge).subtract(lineAllowance).subtract(allowanceItemTotal).setScale(2, RoundingMode.HALF_UP);
itemTotalVATAmount = itemTotalNetAmount.multiply(multiplicator); itemTotalVATAmount = itemTotalNetAmount.multiply(multiplicator);
} }
@@ -135,5 +135,8 @@ public class LineCalculator {
public void addAllowanceItemTotal(BigDecimal b) { public void addAllowanceItemTotal(BigDecimal b) {
allowanceItemTotal = allowanceItemTotal.add(b); allowanceItemTotal = allowanceItemTotal.add(b);
} }
public void subtractAllowanceItemTotal(BigDecimal b) {
allowanceItemTotal = allowanceItemTotal.subtract(b);
}
} }

View File

@@ -432,24 +432,29 @@ public class ZUGFeRD2PullProvider implements IXMLProvider {
+ XMLTools.encodeXML(currentItem.getProduct().getBuyerAssignedID()) + "</ram:BuyerAssignedID>"; + XMLTools.encodeXML(currentItem.getProduct().getBuyerAssignedID()) + "</ram:BuyerAssignedID>";
} }
String allowanceChargeStr = ""; String allowanceChargeStr = "";
if (currentItem.getItemAllowances() != null && currentItem.getItemAllowances().length > 0) { if (currentItem.getProduct().getAllowances() != null && currentItem.getProduct().getAllowances().length > 0) {
for (final IZUGFeRDAllowanceCharge allowance : currentItem.getItemAllowances()) { for (final IZUGFeRDAllowanceCharge allowance : currentItem.getProduct().getAllowances()) {
allowanceChargeStr += getAllowanceChargeStr(allowance, currentItem); allowanceChargeStr += getAllowanceChargeStr(allowance, currentItem);
} }
} }
if (currentItem.getItemCharges() != null && currentItem.getItemCharges().length > 0) { if (currentItem.getProduct().getCharges() != null && currentItem.getProduct().getCharges().length > 0) {
for (final IZUGFeRDAllowanceCharge charge : currentItem.getItemCharges()) { for (final IZUGFeRDAllowanceCharge charge : currentItem.getProduct().getCharges()) {
allowanceChargeStr += getAllowanceChargeStr(charge, currentItem); allowanceChargeStr += getAllowanceChargeStr(charge, currentItem);
} }
} }
String itemTotalAllowanceChargeStr = ""; String itemTotalAllowanceChargeStr = "";
if (currentItem.getItemTotalAllowances() != null && currentItem.getItemTotalAllowances().length > 0) { if (currentItem.getAllowances() != null && currentItem.getAllowances().length > 0) {
for (final IZUGFeRDAllowanceCharge itemTotalAllowance : currentItem.getItemTotalAllowances()) { for (final IZUGFeRDAllowanceCharge itemTotalAllowance : currentItem.getAllowances()) {
itemTotalAllowanceChargeStr += getItemTotalAllowanceChargeStr(itemTotalAllowance, currentItem); itemTotalAllowanceChargeStr += getItemTotalAllowanceChargeStr(itemTotalAllowance, currentItem);
} }
} }
if (currentItem.getCharges() != null && currentItem.getCharges().length > 0) {
for (final IZUGFeRDAllowanceCharge itemTotalCharges : currentItem.getCharges()) {
itemTotalAllowanceChargeStr += getItemTotalAllowanceChargeStr(itemTotalCharges, currentItem);
}
}
xml += "<ram:Name>" + XMLTools.encodeXML(currentItem.getProduct().getName()) + "</ram:Name>"; xml += "<ram:Name>" + XMLTools.encodeXML(currentItem.getProduct().getName()) + "</ram:Name>";
if (currentItem.getProduct().getDescription() != null && currentItem.getProduct().getDescription().length() > 0) { if (currentItem.getProduct().getDescription() != null && currentItem.getProduct().getDescription().length() > 0) {
@@ -540,6 +545,11 @@ public class ZUGFeRD2PullProvider implements IXMLProvider {
+ "<ram:RateApplicablePercent>" + "<ram:RateApplicablePercent>"
+ vatFormat(currentItem.getProduct().getVATPercent()) + "</ram:RateApplicablePercent>" + vatFormat(currentItem.getProduct().getVATPercent()) + "</ram:RateApplicablePercent>"
+ "</ram:ApplicableTradeTax>"; + "</ram:ApplicableTradeTax>";
// item charges/allowances
if (!itemTotalAllowanceChargeStr.isEmpty()) {
xml += "<ram:SpecifiedTradeAllowanceCharge>"+ itemTotalAllowanceChargeStr +"</ram:SpecifiedTradeAllowanceCharge>";
}
if ((currentItem.getDetailedDeliveryPeriodFrom() != null) || (currentItem.getDetailedDeliveryPeriodTo() != null)) { if ((currentItem.getDetailedDeliveryPeriodFrom() != null) || (currentItem.getDetailedDeliveryPeriodTo() != null)) {
xml += "<ram:BillingSpecifiedPeriod>"; xml += "<ram:BillingSpecifiedPeriod>";
if (currentItem.getDetailedDeliveryPeriodFrom() != null) { if (currentItem.getDetailedDeliveryPeriodFrom() != null) {
@@ -551,7 +561,6 @@ public class ZUGFeRD2PullProvider implements IXMLProvider {
xml += "</ram:BillingSpecifiedPeriod>"; xml += "</ram:BillingSpecifiedPeriod>";
} }
xml += itemTotalAllowanceChargeStr;
xml += "<ram:SpecifiedTradeSettlementLineMonetarySummation>" xml += "<ram:SpecifiedTradeSettlementLineMonetarySummation>"
+ "<ram:LineTotalAmount>" + currencyFormat(lc.getItemTotalNetAmount()) + "<ram:LineTotalAmount>" + currencyFormat(lc.getItemTotalNetAmount())