Skip to content

Commit

Permalink
Merge pull request ZUGFeRD#275 from davidmager/positionsRabatt
Browse files Browse the repository at this point in the history
appliance of price adjustments on line item total level
  • Loading branch information
jstaerk authored Jun 16, 2022
2 parents b5e0fb8 + 2239b6b commit e460974
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,5 +132,14 @@ default Date getDetailedDeliveryPeriodFrom() {
default Date getDetailedDeliveryPeriodTo() {
return null;
}

/***
* specify allowances amount for the line item total, i.e. after item price is multiplied
* by amount
* @return
*/
default IZUGFeRDAllowanceCharge[] getItemTotalAllowances() {
return null;
};

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class LineCalculator {
private BigDecimal itemTotalVATAmount;
private BigDecimal allowance = BigDecimal.ZERO;
private BigDecimal charge = BigDecimal.ZERO;
private BigDecimal allowanceItemTotal = BigDecimal.ZERO;

public LineCalculator(IZUGFeRDExportableItem currentItem) {

Expand All @@ -26,11 +27,17 @@ public LineCalculator(IZUGFeRDExportableItem currentItem) {
addCharge(charge.getTotalAmount(currentItem));
}
}
if (currentItem.getItemTotalAllowances() != null && currentItem.getItemTotalAllowances().length > 0) {
for (final IZUGFeRDAllowanceCharge itemTotalAllowance : currentItem.getItemTotalAllowances()) {
addAllowanceItemTotal(itemTotalAllowance.getTotalAmount(currentItem));
}
}

BigDecimal multiplicator = currentItem.getProduct().getVATPercent().divide(BigDecimal.valueOf(100));
priceGross = currentItem.getPrice(); // see https://github.com/ZUGFeRD/mustangproject/issues/159
price = priceGross.subtract(allowance).add(charge);
itemTotalNetAmount = currentItem.getQuantity().multiply(getPrice()).divide(currentItem.getBasisQuantity())
.setScale(2, BigDecimal.ROUND_HALF_UP);
.subtract(allowanceItemTotal).setScale(2, BigDecimal.ROUND_HALF_UP);
itemTotalVATAmount = itemTotalNetAmount.multiply(multiplicator);

}
Expand Down Expand Up @@ -63,5 +70,8 @@ public void addCharge(BigDecimal b) {
charge = charge.add(b);
}

public void addAllowanceItemTotal(BigDecimal b) {
allowanceItemTotal = allowanceItemTotal.add(b);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,31 @@ protected String getAllowanceChargeStr(IZUGFeRDAllowanceCharge allowance, IAbsol
"</ram:AppliedTradeAllowanceCharge>";
return allowanceChargeStr;
}

/***
* returns the XML for a charge or allowance on item total level
* @param allowance
* @param item
* @return
*/
protected String getItemTotalAllowanceChargeStr(IZUGFeRDAllowanceCharge allowance, IAbsoluteValueProvider item) {
String percentage = "";
String chargeIndicator = "false";
if ((allowance.getPercent() != null) && (profile == Profiles.getByName("Extended"))) {
percentage = "<ram:CalculationPercent>" + vatFormat(allowance.getPercent()) + "</ram:CalculationPercent>";
percentage += "<ram:BasisAmount>" + item.getValue() + "</ram:BasisAmount>";
}
if (allowance.isCharge()) {
chargeIndicator = "true";
}

final String itemTotalAllowanceChargeStr = "<ram:SpecifiedTradeAllowanceCharge><ram:ChargeIndicator><udt:Indicator>" +
chargeIndicator + "</udt:Indicator></ram:ChargeIndicator>" + percentage +
"<ram:ActualAmount>" + currencyFormat(allowance.getTotalAmount(item)) + "</ram:ActualAmount>" +
"<ram:Reason>" + XMLTools.encodeXML(allowance.getReason()) + "</ram:Reason>" +
"</ram:SpecifiedTradeAllowanceCharge>";
return itemTotalAllowanceChargeStr;
}

@Override
public void generateXML(IExportableTransaction trans) {
Expand Down Expand Up @@ -356,7 +381,13 @@ public void generateXML(IExportableTransaction trans) {
}
}


String itemTotalAllowanceChargeStr = "";
if (currentItem.getItemTotalAllowances() != null && currentItem.getItemTotalAllowances().length > 0) {
for (final IZUGFeRDAllowanceCharge itemTotalAllowance : currentItem.getItemTotalAllowances()) {
itemTotalAllowanceChargeStr += getItemTotalAllowanceChargeStr(itemTotalAllowance, currentItem);
}
}

xml += "<ram:Name>" + XMLTools.encodeXML(currentItem.getProduct().getName()) + "</ram:Name>"
+ "<ram:Description>" + XMLTools.encodeXML(currentItem.getProduct().getDescription())
+ "</ram:Description>"
Expand Down Expand Up @@ -422,7 +453,9 @@ public void generateXML(IExportableTransaction trans) {
}
xml += "</ram:BillingSpecifiedPeriod>";
}


xml += itemTotalAllowanceChargeStr;

xml += "<ram:SpecifiedTradeSettlementLineMonetarySummation>"
+ "<ram:LineTotalAmount>" + currencyFormat(lc.getItemTotalNetAmount())
+ "</ram:LineTotalAmount>" // currencyID=\"EUR\"
Expand Down

0 comments on commit e460974

Please sign in to comment.