appliance of price adjustments on line item total level

This commit is contained in:
damg
2022-06-10 14:37:22 +02:00
parent 473ba88c85
commit 2239b6bcd1
3 changed files with 55 additions and 3 deletions

View File

@@ -133,4 +133,13 @@ public interface IZUGFeRDExportableItem extends IAbsoluteValueProvider{
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;
};
}

View File

@@ -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) {
@@ -26,11 +27,17 @@ public class LineCalculator {
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);
}
@@ -63,5 +70,8 @@ public class LineCalculator {
charge = charge.add(b);
}
public void addAllowanceItemTotal(BigDecimal b) {
allowanceItemTotal = allowanceItemTotal.add(b);
}
}

View File

@@ -229,6 +229,31 @@ public class ZUGFeRD2PullProvider implements IXMLProvider {
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) {
this.trans = trans;
@@ -356,6 +381,12 @@ public class ZUGFeRD2PullProvider implements IXMLProvider {
}
}
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())
@@ -423,6 +454,8 @@ public class ZUGFeRD2PullProvider implements IXMLProvider {
xml += "</ram:BillingSpecifiedPeriod>";
}
xml += itemTotalAllowanceChargeStr;
xml += "<ram:SpecifiedTradeSettlementLineMonetarySummation>"
+ "<ram:LineTotalAmount>" + currencyFormat(lc.getItemTotalNetAmount())
+ "</ram:LineTotalAmount>" // currencyID=\"EUR\"