Skip to content

Commit

Permalink
addressing #159 gross price. removing jaxb from zf1.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jochen Stärk authored and Jochen Stärk committed Jun 14, 2020
1 parent 5dbb3a7 commit b9efc21
Show file tree
Hide file tree
Showing 6 changed files with 191 additions and 234 deletions.
26 changes: 26 additions & 0 deletions library/src/main/java/org/mustangproject/XMLTools.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,32 @@
package org.mustangproject;

import java.math.BigDecimal;
import java.math.RoundingMode;

public class XMLTools {


public static String nDigitFormat(BigDecimal value, int scale) {
/*
* I needed 123,45, locale independent.I tried
* NumberFormat.getCurrencyInstance().format( 12345.6789 ); but that is locale
* specific.I also tried DecimalFormat df = new DecimalFormat( "0,00" );
* df.setDecimalSeparatorAlwaysShown(true); df.setGroupingUsed(false);
* DecimalFormatSymbols symbols = new DecimalFormatSymbols();
* symbols.setDecimalSeparator(','); symbols.setGroupingSeparator(' ');
* df.setDecimalFormatSymbols(symbols);
*
* but that would not switch off grouping. Although I liked very much the
* (incomplete) "BNF diagram" in
* http://docs.oracle.com/javase/tutorial/i18n/format/decimalFormat.html in the
* end I decided to calculate myself and take eur+sparator+cents
*
*/
return value.setScale(scale, RoundingMode.HALF_UP).toPlainString();

}


public static String encodeXML(CharSequence s) {
StringBuilder sb = new StringBuilder();
int len = s.length();
Expand Down
39 changes: 39 additions & 0 deletions library/src/main/java/org/mustangproject/ZUGFeRD/LineCalc.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.mustangproject.ZUGFeRD;

import java.math.BigDecimal;

public class LineCalc {
private BigDecimal totalGross;
private BigDecimal priceGross;
private BigDecimal itemTotalNetAmount;
private BigDecimal itemTotalVATAmount;

public LineCalc(IZUGFeRDExportableItem currentItem) {
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())
.multiply(multiplicator);
itemTotalNetAmount = currentItem.getQuantity().multiply(currentItem.getPrice()).divide(currentItem.getBasisQuantity())
.setScale(2, BigDecimal.ROUND_HALF_UP);
itemTotalVATAmount = totalGross.subtract(itemTotalNetAmount);
}

public BigDecimal getItemTotalNetAmount() {
return itemTotalNetAmount;
}

public BigDecimal getItemTotalVATAmount() {
return itemTotalVATAmount;
}

public BigDecimal getItemTotalGrossAmount() {
return itemTotalVATAmount;
}

public BigDecimal getPriceGross() {
return priceGross;
}


}
Loading

0 comments on commit b9efc21

Please sign in to comment.