allow relative =percentual item allowances/charges

This commit is contained in:
Jochen Stärk
2020-09-21 21:45:03 +02:00
parent 4081c6a7f7
commit 9bf1097bac
10 changed files with 192 additions and 125 deletions

View File

@@ -1,6 +1,7 @@
package org.mustangproject;
import org.mustangproject.ZUGFeRD.IZUGFeRDAllowanceCharge;
import org.mustangproject.ZUGFeRD.IZUGFeRDExportableItem;
import java.math.BigDecimal;
@@ -16,11 +17,12 @@ public class Charge implements IZUGFeRDAllowanceCharge {
}
public Charge(BigDecimal totalAmount, BigDecimal taxPercent, String reason, String categoryCode) {
/***
* creates a item level or invoice level charge
* @param totalAmount (the absolute amount)
*/
public Charge(BigDecimal totalAmount) {
this.totalAmount = totalAmount;
this.taxPercent = taxPercent;
this.reason = reason;
this.categoryCode = categoryCode;
}
@@ -52,11 +54,21 @@ public class Charge implements IZUGFeRDAllowanceCharge {
@Override
public BigDecimal getTotalAmount() {
return totalAmount;
public BigDecimal getTotalAmount(IZUGFeRDExportableItem currentItem) {
if (totalAmount!=null) {
return totalAmount;
} else if (percent!=null) {
return currentItem.getPrice().multiply(getPercent().divide(new BigDecimal(100)));
} else {
throw new RuntimeException("Either totalAmount or percent must be set");
}
}
public BigDecimal getPercent() {
return percent;
}
@Override
public BigDecimal getTaxPercent() {
return taxPercent;