support item level allowances
This commit is contained in:
@@ -13,4 +13,9 @@ public class Allowance extends Charge implements IZUGFeRDAllowanceCharge {
|
||||
super(totalAmount, taxPercent, reason, categoryCode);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCharge() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,6 +62,11 @@ public class Charge implements IZUGFeRDAllowanceCharge {
|
||||
return taxPercent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCharge() {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public Charge setCategoryCode(String categoryCode) {
|
||||
this.categoryCode = categoryCode;
|
||||
|
||||
@@ -34,4 +34,5 @@ public interface IZUGFeRDAllowanceCharge {
|
||||
return TaxCategoryCodeTypeConstants.STANDARDRATE;
|
||||
}
|
||||
|
||||
public boolean isCharge();
|
||||
}
|
||||
|
||||
@@ -4,19 +4,34 @@ import java.math.BigDecimal;
|
||||
|
||||
public class LineCalc {
|
||||
private BigDecimal totalGross;
|
||||
private BigDecimal price;
|
||||
private BigDecimal priceGross;
|
||||
private BigDecimal itemTotalNetAmount;
|
||||
private BigDecimal itemTotalVATAmount;
|
||||
private BigDecimal allowance=new BigDecimal(0);
|
||||
|
||||
public LineCalc(IZUGFeRDExportableItem currentItem) {
|
||||
|
||||
if (currentItem.getItemAllowances()!=null && currentItem.getItemAllowances().length>0) {
|
||||
for (IZUGFeRDAllowanceCharge allowance:currentItem.getItemAllowances()) {
|
||||
addAllowance(allowance.getTotalAmount());
|
||||
}
|
||||
}
|
||||
BigDecimal multiplicator = currentItem.getProduct().getVATPercent().divide(new BigDecimal(100))
|
||||
.add(new BigDecimal(1));
|
||||
priceGross = currentItem.getPrice(); // see https://github.com/ZUGFeRD/mustangproject/issues/159
|
||||
totalGross = currentItem.getQuantity().multiply(currentItem.getPrice()).divide(currentItem.getBasisQuantity())
|
||||
price = priceGross.subtract(allowance);
|
||||
totalGross = currentItem.getQuantity().multiply(getPrice()).divide(currentItem.getBasisQuantity())
|
||||
.multiply(multiplicator);
|
||||
itemTotalNetAmount = currentItem.getQuantity().multiply(currentItem.getPrice()).divide(currentItem.getBasisQuantity())
|
||||
itemTotalNetAmount = currentItem.getQuantity().multiply(getPrice()).divide(currentItem.getBasisQuantity())
|
||||
.setScale(2, BigDecimal.ROUND_HALF_UP);
|
||||
itemTotalVATAmount = totalGross.subtract(itemTotalNetAmount);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public BigDecimal getPrice() {
|
||||
return price;
|
||||
}
|
||||
|
||||
public BigDecimal getItemTotalNetAmount() {
|
||||
@@ -28,12 +43,16 @@ public class LineCalc {
|
||||
}
|
||||
|
||||
public BigDecimal getItemTotalGrossAmount() {
|
||||
return itemTotalVATAmount;
|
||||
return itemTotalNetAmount;
|
||||
}
|
||||
|
||||
public BigDecimal getPriceGross() {
|
||||
return priceGross;
|
||||
}
|
||||
public void addAllowance(BigDecimal b) {
|
||||
allowance=b;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ import org.dom4j.DocumentException;
|
||||
import org.dom4j.DocumentHelper;
|
||||
import org.dom4j.io.OutputFormat;
|
||||
import org.dom4j.io.XMLWriter;
|
||||
import org.mustangproject.Charge;
|
||||
import org.mustangproject.XMLTools;
|
||||
|
||||
public class ZUGFeRD2PullProvider implements IXMLProvider, IProfileProvider {
|
||||
@@ -121,7 +122,7 @@ public class ZUGFeRD2PullProvider implements IXMLProvider, IProfileProvider {
|
||||
BigDecimal res = new BigDecimal(0);
|
||||
for (IZUGFeRDExportableItem currentItem : trans.getZFItems()) {
|
||||
LineCalc lc = new LineCalc(currentItem);
|
||||
res = res.add(lc.getItemTotalNetAmount());
|
||||
res = res.add(lc.getItemTotalGrossAmount());
|
||||
}
|
||||
return res;
|
||||
}
|
||||
@@ -286,6 +287,19 @@ public class ZUGFeRD2PullProvider implements IXMLProvider, IProfileProvider {
|
||||
xml = xml + " <ram:BuyerAssignedID>"
|
||||
+ XMLTools.encodeXML(currentItem.getProduct().getBuyerAssignedID()) + "</ram:BuyerAssignedID>\n";
|
||||
}
|
||||
|
||||
String allowanceStr=" <ram:BasisQuantity unitCode=\"" + XMLTools.encodeXML(currentItem.getProduct().getUnit())
|
||||
+ "\">" + quantityFormat(currentItem.getBasisQuantity()) +"</ram:BasisQuantity>\n";
|
||||
if (currentItem.getItemAllowances()!=null && currentItem.getItemAllowances().length>0) {
|
||||
for (IZUGFeRDAllowanceCharge allowance:currentItem.getItemAllowances()) {
|
||||
if (allowance.isCharge()) {
|
||||
throw new RuntimeException("Item level charges are not yet implemented");
|
||||
} else {
|
||||
allowanceStr= "<ram:AppliedTradeAllowanceCharge><ram:ChargeIndicator><udt:Indicator>false</udt:Indicator></ram:ChargeIndicator><ram:ActualAmount>"+priceFormat(allowance.getTotalAmount())+"</ram:ActualAmount></ram:AppliedTradeAllowanceCharge>";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
xml = xml + " <ram:Name>" + XMLTools.encodeXML(currentItem.getProduct().getName()) + "</ram:Name>\n" //$NON-NLS-2$
|
||||
+ " <ram:Description>" + XMLTools.encodeXML(currentItem.getProduct().getDescription())
|
||||
+ "</ram:Description>\n"
|
||||
@@ -295,8 +309,7 @@ public class ZUGFeRD2PullProvider implements IXMLProvider, IProfileProvider {
|
||||
+ " <ram:GrossPriceProductTradePrice>\n"
|
||||
+ " <ram:ChargeAmount>" + priceFormat(lc.getPriceGross())
|
||||
+ "</ram:ChargeAmount>\n" //currencyID=\"EUR\"
|
||||
+ " <ram:BasisQuantity unitCode=\"" + XMLTools.encodeXML(currentItem.getProduct().getUnit())
|
||||
+ "\">" + quantityFormat(currentItem.getBasisQuantity()) +"</ram:BasisQuantity>\n"
|
||||
+ allowanceStr
|
||||
// + " <AppliedTradeAllowanceCharge>\n"
|
||||
// + " <ChargeIndicator>false</ChargeIndicator>\n"
|
||||
// + " <ActualAmount currencyID=\"EUR\">0.6667</ActualAmount>\n"
|
||||
@@ -304,7 +317,7 @@ public class ZUGFeRD2PullProvider implements IXMLProvider, IProfileProvider {
|
||||
// + " </AppliedTradeAllowanceCharge>\n"
|
||||
+ " </ram:GrossPriceProductTradePrice>\n"
|
||||
+ " <ram:NetPriceProductTradePrice>\n"
|
||||
+ " <ram:ChargeAmount>" + priceFormat(currentItem.getPrice())
|
||||
+ " <ram:ChargeAmount>" + priceFormat(lc.getPrice())
|
||||
+ "</ram:ChargeAmount>\n" // currencyID=\"EUR\"
|
||||
+ " <ram:BasisQuantity unitCode=\"" + XMLTools.encodeXML(currentItem.getProduct().getUnit())
|
||||
+ "\">" + quantityFormat(currentItem.getBasisQuantity()) +"</ram:BasisQuantity>\n"
|
||||
|
||||
Reference in New Issue
Block a user