@@ -64,15 +64,15 @@ public class Item implements IZUGFeRDExportableItem {
|
||||
//and we additionally have vat%
|
||||
setProduct(new Product());
|
||||
icnm.getAsString("Name").ifPresent(product::setName);
|
||||
icnm.getAsNodeMap("ClassifiedTaxCategory").flatMap(m -> m.getAsString("Percent"))
|
||||
.ifPresent(vatPercent -> product.setVATPercent(new BigDecimal(vatPercent.trim())));
|
||||
icnm.getAsNodeMap("ClassifiedTaxCategory").flatMap(m -> m.getAsBigDecimal("Percent"))
|
||||
.ifPresent(product::setVATPercent);
|
||||
});
|
||||
|
||||
itemMap.getAsNodeMap("Price").ifPresent(icnm -> {
|
||||
// ubl
|
||||
// PriceAmount with currencyID and BaseQuantity with unitCode
|
||||
icnm.getAsString("PriceAmount").ifPresent(amount -> setPrice(new BigDecimal(amount.trim())));
|
||||
icnm.getAsString("BaseQuantity").ifPresent(baseQuantity -> setQuantity(new BigDecimal(baseQuantity.trim())));
|
||||
icnm.getAsBigDecimal("PriceAmount").ifPresent(this::setPrice);
|
||||
icnm.getAsBigDecimal("BaseQuantity").ifPresent(this::setBasisQuantity);
|
||||
});
|
||||
|
||||
itemMap.getNode("InvoicedQuantity").ifPresent(icn -> {
|
||||
@@ -82,19 +82,17 @@ public class Item implements IZUGFeRDExportableItem {
|
||||
});
|
||||
|
||||
itemMap.getAsNodeMap("SpecifiedLineTradeAgreement", "SpecifiedSupplyChainTradeAgreement").ifPresent(icnm -> {
|
||||
icnm.getAllNodes("AdditionalReferencedDocument").map(ReferencedDocument::fromNode)
|
||||
.forEach(this::addReferencedDocument);
|
||||
|
||||
icnm.getAsNodeMap("BuyerOrderReferencedDocument")
|
||||
.flatMap(bordNodes -> bordNodes.getAsString("LineID"))
|
||||
.ifPresent(this::addReferencedLineID);
|
||||
|
||||
icnm.getAsNodeMap("NetPriceProductTradePrice").ifPresent(npptpNodes -> {
|
||||
npptpNodes.getAsString("ChargeAmount")
|
||||
.ifPresent(amount -> setPrice(new BigDecimal(amount.trim())));
|
||||
npptpNodes.getAsString("BasisQuantity")
|
||||
.ifPresent(bq -> setBasisQuantity(new BigDecimal(bq.trim())));
|
||||
npptpNodes.getAsBigDecimal("ChargeAmount").ifPresent(this::setPrice);
|
||||
npptpNodes.getAsBigDecimal("BasisQuantity").ifPresent(this::setBasisQuantity);
|
||||
});
|
||||
|
||||
icnm.getAllNodes("AdditionalReferencedDocument").map(ReferencedDocument::fromNode)
|
||||
.forEach(this::addReferencedDocument);
|
||||
});
|
||||
|
||||
itemMap.getNode("SpecifiedTradeProduct").map(Product::new).ifPresent(this::setProduct);
|
||||
@@ -114,13 +112,13 @@ public class Item implements IZUGFeRDExportableItem {
|
||||
|
||||
itemMap.getAsNodeMap("SpecifiedLineTradeSettlement", "SpecifiedSupplyChainTradeSettlement").ifPresent(icnm -> {
|
||||
icnm.getAsNodeMap("ApplicableTradeTax")
|
||||
.map(cnm -> cnm.getAsStringOrNull("RateApplicablePercent", "ApplicablePercent"))
|
||||
.ifPresent(vatPercent -> product.setVATPercent(new BigDecimal(vatPercent.trim())));
|
||||
.flatMap(cnm -> cnm.getAsBigDecimal("RateApplicablePercent", "ApplicablePercent"))
|
||||
.ifPresent(product::setVATPercent);
|
||||
|
||||
if (recalcPrice && !BigDecimal.ZERO.equals(quantity)) {
|
||||
icnm.getAsNodeMap("SpecifiedTradeSettlementLineMonetarySummation")
|
||||
.map(cnm -> cnm.getAsStringOrNull("LineTotalAmount"))
|
||||
.ifPresent(lineTotal -> setPrice(new BigDecimal(lineTotal.trim()).divide(quantity, 4, RoundingMode.HALF_UP)));
|
||||
.flatMap(cnm -> cnm.getAsBigDecimal("LineTotalAmount"))
|
||||
.ifPresent(lineTotal -> setPrice(lineTotal.divide(quantity, 4, RoundingMode.HALF_UP)));
|
||||
}
|
||||
|
||||
icnm.getAllNodes("AdditionalReferencedDocument").map(ReferencedDocument::fromNode).forEach(this::addAdditionalReference);
|
||||
|
||||
@@ -4,21 +4,9 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.AbstractList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.RandomAccess;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.dom4j.io.XMLWriter;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
public class XMLTools extends XMLWriter {
|
||||
@Override
|
||||
@@ -31,30 +19,6 @@ public class XMLTools extends XMLWriter {
|
||||
return super.escapeElementEntities(s);
|
||||
}
|
||||
|
||||
public static List<Node> asList(NodeList n) {
|
||||
return n.getLength() == 0 ?
|
||||
Collections.<Node>emptyList() : new NodeListWrapper(n);
|
||||
}
|
||||
|
||||
static final class NodeListWrapper extends AbstractList<Node>
|
||||
implements RandomAccess {
|
||||
private final NodeList list;
|
||||
|
||||
NodeListWrapper(NodeList l) {
|
||||
list = l;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Node get(int index) {
|
||||
return list.item(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return list.getLength();
|
||||
}
|
||||
}
|
||||
|
||||
public static String nDigitFormat(BigDecimal value, int scale) {
|
||||
/*
|
||||
* I needed 123,45, locale independent.I tried
|
||||
@@ -75,7 +39,6 @@ public class XMLTools extends XMLWriter {
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static String encodeXML(CharSequence s) {
|
||||
if (s == null) {
|
||||
return "";
|
||||
|
||||
@@ -23,6 +23,7 @@ package org.mustangproject.util;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -102,6 +103,18 @@ public class NodeMap {
|
||||
return getNode(localNames).map(Node::getTextContent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the text content of a matching node
|
||||
* <p>
|
||||
* In case more than one node matches, it is not guaranteed that the first match is selected
|
||||
*
|
||||
* @param localNames one or more {@code LocalName}s
|
||||
* @return the text content of the matching node, converted to BigDecimal
|
||||
*/
|
||||
public Optional<BigDecimal> getAsBigDecimal(String... localNames) {
|
||||
return getNode(localNames).map(Node::getTextContent).map(s->new BigDecimal(s.trim()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the text content of a matching node
|
||||
* <p>
|
||||
|
||||
Reference in New Issue
Block a user