Merge pull request #275 from davidmager/positionsRabatt
appliance of price adjustments on line item total level
This commit is contained in:
@@ -132,5 +132,14 @@ public interface IZUGFeRDExportableItem extends IAbsoluteValueProvider{
|
||||
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;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -228,6 +228,31 @@ public class ZUGFeRD2PullProvider implements IXMLProvider {
|
||||
"</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) {
|
||||
@@ -356,7 +381,13 @@ 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())
|
||||
+ "</ram:Description>"
|
||||
@@ -422,7 +453,9 @@ public class ZUGFeRD2PullProvider implements IXMLProvider {
|
||||
}
|
||||
xml += "</ram:BillingSpecifiedPeriod>";
|
||||
}
|
||||
|
||||
|
||||
xml += itemTotalAllowanceChargeStr;
|
||||
|
||||
xml += "<ram:SpecifiedTradeSettlementLineMonetarySummation>"
|
||||
+ "<ram:LineTotalAmount>" + currencyFormat(lc.getItemTotalNetAmount())
|
||||
+ "</ram:LineTotalAmount>" // currencyID=\"EUR\"
|
||||
|
||||
Reference in New Issue
Block a user