diff --git a/mustang/src/main/java/org/mustangproject/ZUGFeRD/IZUGFeRDExportableItem.java b/mustang/src/main/java/org/mustangproject/ZUGFeRD/IZUGFeRDExportableItem.java index 49622a54..8054c70c 100644 --- a/mustang/src/main/java/org/mustangproject/ZUGFeRD/IZUGFeRDExportableItem.java +++ b/mustang/src/main/java/org/mustangproject/ZUGFeRD/IZUGFeRDExportableItem.java @@ -14,11 +14,7 @@ public interface IZUGFeRDExportableItem { IZUGFeRDExportableProduct getProduct(); - /** - * The price of one item incl. taxes - * @return - */ - BigDecimal getPriceGross(); + /** * The price of one item excl. taxes @@ -32,10 +28,6 @@ public interface IZUGFeRDExportableItem { */ BigDecimal getQuantity(); - /** - * The price of quantity items incl. taxes - * @return - */ - BigDecimal getTotalGross(); + } diff --git a/mustang/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDExporter.java b/mustang/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDExporter.java index 8e33b89f..06f861cb 100644 --- a/mustang/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDExporter.java +++ b/mustang/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDExporter.java @@ -64,6 +64,37 @@ public class ZUGFeRDExporter { */ + + private class LineCalc { + private IZUGFeRDExportableItem currentItem=null; + private BigDecimal priceGross; + private BigDecimal totalGross; + private BigDecimal itemTotalNetAmount; + private BigDecimal itemTotalVATAmount; + + public LineCalc(IZUGFeRDExportableItem currentItem) { + this.currentItem=currentItem; + BigDecimal multiplicator=currentItem.getProduct().getVATPercent().divide(new BigDecimal(100)).add(new BigDecimal(1)); + priceGross=currentItem.getPrice().multiply(multiplicator); + totalGross=currentItem.getPrice().multiply(multiplicator).multiply(currentItem.getQuantity()); + itemTotalNetAmount=currentItem.getQuantity().multiply(currentItem.getPrice()).setScale(2,BigDecimal.ROUND_HALF_UP); + itemTotalVATAmount=totalGross.subtract(itemTotalNetAmount); + } + public BigDecimal getPriceGross() { + return priceGross; + } + public BigDecimal getTotalGross() { + return totalGross; + } + public BigDecimal getItemTotalNetAmount() { + return itemTotalNetAmount; + } + + public BigDecimal getItemTotalVATAmount() { + return itemTotalVATAmount; + } + + } @@ -415,6 +446,8 @@ public class ZUGFeRDExporter { int lineID=0; for (IZUGFeRDExportableItem currentItem : trans.getZFItems()) { lineID++; + + LineCalc lc=new LineCalc(currentItem); xml=xml+ " \n"+ //$NON-NLS-1$ " \n" //$NON-NLS-1$ + " "+lineID+"\n" //$NON-NLS-1$ //$NON-NLS-2$ @@ -422,7 +455,7 @@ public class ZUGFeRDExporter { + " \n" //$NON-NLS-1$ + " \n" //$NON-NLS-1$ - + " "+priceFormat(currentItem.getPriceGross())+"\n" //$NON-NLS-1$ //$NON-NLS-2$ + + " "+priceFormat(lc.getPriceGross())+"\n" //$NON-NLS-1$ //$NON-NLS-2$ + " 1.0000\n" //$NON-NLS-1$ //$NON-NLS-2$ // + " \n" // + " false\n" @@ -431,7 +464,7 @@ public class ZUGFeRDExporter { // + " \n" + " \n" //$NON-NLS-1$ + " \n" //$NON-NLS-1$ - + " "+priceFormat(currentItem.getPrice())+"\n" //$NON-NLS-1$ //$NON-NLS-2$ + + " "+priceFormat(lc.getPriceGross())+"\n" //$NON-NLS-1$ //$NON-NLS-2$ + " 1.0000\n" //$NON-NLS-1$ //$NON-NLS-2$ + " \n" //$NON-NLS-1$ + " \n" //$NON-NLS-1$ @@ -446,7 +479,7 @@ public class ZUGFeRDExporter { + " "+vatFormat(currentItem.getProduct().getVATPercent())+"\n" //$NON-NLS-1$ //$NON-NLS-2$ + " \n" //$NON-NLS-1$ + " \n" //$NON-NLS-1$ - + " "+currencyFormat(currentItem.getTotalGross())+"\n" //$NON-NLS-1$ //$NON-NLS-2$ + + " "+currencyFormat(lc.getTotalGross())+"\n" //$NON-NLS-1$ //$NON-NLS-2$ + " \n" //$NON-NLS-1$ + " \n" //$NON-NLS-1$ + " \n" //$NON-NLS-1$ @@ -482,8 +515,8 @@ public class ZUGFeRDExporter { for (IZUGFeRDExportableItem currentItem : trans.getZFItems()) { BigDecimal percent=currentItem.getProduct().getVATPercent(); - BigDecimal currentBasis=currentItem.getQuantity().multiply(currentItem.getPrice()).setScale(2,BigDecimal.ROUND_HALF_UP );// item total net amount - VATAmount itemVATAmount=new VATAmount(currentBasis, currentItem.getTotalGross().subtract(currentBasis)) ; + LineCalc lc=new LineCalc(currentItem); + VATAmount itemVATAmount=new VATAmount(lc.getItemTotalNetAmount(), lc.getItemTotalVATAmount() ) ; VATAmount current=hm.get(percent); if (current==null) { hm.put(percent, itemVATAmount);