continued parsing UBL

This commit is contained in:
jstaerk
2023-09-11 11:32:17 +02:00
parent fcb52431ba
commit 5bc13c01eb
4 changed files with 323 additions and 237 deletions

View File

@@ -1,13 +1,18 @@
package org.mustangproject; package org.mustangproject;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import org.apache.fop.util.XMLUtil;
import org.mustangproject.ZUGFeRD.IReferencedDocument; import org.mustangproject.ZUGFeRD.IReferencedDocument;
import org.mustangproject.ZUGFeRD.IZUGFeRDAllowanceCharge; import org.mustangproject.ZUGFeRD.IZUGFeRDAllowanceCharge;
import org.mustangproject.ZUGFeRD.IZUGFeRDExportableItem; import org.mustangproject.ZUGFeRD.IZUGFeRDExportableItem;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List;
/*** /***
* describes any invoice line * describes any invoice line
@@ -16,10 +21,10 @@ import java.util.Date;
@JsonIgnoreProperties(ignoreUnknown = true) @JsonIgnoreProperties(ignoreUnknown = true)
public class Item implements IZUGFeRDExportableItem { public class Item implements IZUGFeRDExportableItem {
protected BigDecimal price, quantity, tax, grossPrice, lineTotalAmount; protected BigDecimal price, quantity, tax, grossPrice, lineTotalAmount;
protected BigDecimal basisQuantity=BigDecimal.ONE; protected BigDecimal basisQuantity = BigDecimal.ONE;
protected Date detailedDeliveryPeriodFrom=null, detailedDeliveryPeriodTo=null; protected Date detailedDeliveryPeriodFrom = null, detailedDeliveryPeriodTo = null;
protected String id; protected String id;
protected String referencedLineID=null; protected String referencedLineID = null;
protected Product product; protected Product product;
protected ArrayList<String> notes = null; protected ArrayList<String> notes = null;
protected ArrayList<ReferencedDocument> referencedDocuments = null; protected ArrayList<ReferencedDocument> referencedDocuments = null;
@@ -46,8 +51,225 @@ public class Item implements IZUGFeRDExportableItem {
public Item() { public Item() {
} }
public Item(NodeList itemChilds, boolean recalcPrice) {
String price = "0";
String basisQuantity = "1";
String name = "";
String sellerAssignedID = null;
String description = "";
SchemedID gid = null;
String quantity = "0";
String vatPercent = null;
String lineTotal = "0";
String unitCode = "0";
ArrayList<ReferencedDocument> rdocs = null;
// nodes.item(i).getTextContent())) {
for (int itemChildIndex = 0; itemChildIndex < itemChilds.getLength(); itemChildIndex++) {
String lineTrade = itemChilds.item(itemChildIndex).getLocalName();
if ((lineTrade != null) && (lineTrade.equals("Item"))) {
// ubl
//we need: name description unitcode
//and we additionally have vat%
NodeList UBLitemChilds = itemChilds.item(itemChildIndex).getChildNodes();
for (Node currentUBLItemChildNode : XMLTools.asList(UBLitemChilds)) {
if ((currentUBLItemChildNode.getLocalName() != null) && (currentUBLItemChildNode.getLocalName().equals("Name"))) {
name = currentUBLItemChildNode.getTextContent();
}
if ((currentUBLItemChildNode.getLocalName() != null) && (currentUBLItemChildNode.getLocalName().equals("ClassifiedTaxCategory"))) {
for (Node currentUBLTaxChildNode : XMLTools.asList(currentUBLItemChildNode.getChildNodes())) {
if ((currentUBLTaxChildNode.getLocalName() != null) && (currentUBLTaxChildNode.getLocalName().equals("Percent"))) {
vatPercent = currentUBLTaxChildNode.getTextContent();
}
}
}
}
}
if ((lineTrade != null) && (lineTrade.equals("Price"))) {
// ubl
// PriceAmount with currencyID and BaseQuantity with unitCode
NodeList UBLpriceChilds = itemChilds.item(itemChildIndex).getChildNodes();
for (Node currentUBLPriceChildNode : XMLTools.asList(UBLpriceChilds)) {
if ((currentUBLPriceChildNode.getLocalName() != null) && (currentUBLPriceChildNode.getLocalName().equals("PriceAmount"))) {
price = currentUBLPriceChildNode.getTextContent();
}
if ((currentUBLPriceChildNode.getLocalName() != null) && (currentUBLPriceChildNode.getLocalName().equals("BaseQuantity"))) {
basisQuantity = currentUBLPriceChildNode.getTextContent();
}
}
}
if ((lineTrade != null) && (lineTrade.equals("InvoicedQuantity"))) {
// ubl
quantity = itemChilds.item(itemChildIndex).getTextContent();
unitCode = itemChilds.item(itemChildIndex).getAttributes()
.getNamedItem("unitCode").getNodeValue();
}
if ((lineTrade != null) && (lineTrade.equals("SpecifiedLineTradeAgreement")
|| lineTrade.equals("SpecifiedSupplyChainTradeAgreement"))) {
NodeList tradeLineChilds = itemChilds.item(itemChildIndex).getChildNodes();
for (int tradeLineChildIndex = 0; tradeLineChildIndex < tradeLineChilds
.getLength(); tradeLineChildIndex++) {
if ((tradeLineChilds.item(tradeLineChildIndex).getLocalName() != null) && tradeLineChilds
.item(tradeLineChildIndex).getLocalName().equals("AdditionalReferencedDocument")) {
String IssuerAssignedID = "";
String TypeCode = "";
String ReferenceTypeCode = "";
NodeList refDocChilds = tradeLineChilds.item(tradeLineChildIndex).getChildNodes();
for (int refDocIndex = 0; refDocIndex < refDocChilds.getLength(); refDocIndex++) {
String localName = refDocChilds.item(refDocIndex).getLocalName();
if ((localName != null) && (localName.equals("IssuerAssignedID"))) {
IssuerAssignedID = refDocChilds.item(refDocIndex).getTextContent();
}
if ((localName != null) && (localName.equals("TypeCode"))) {
TypeCode = refDocChilds.item(refDocIndex).getTextContent();
}
if ((localName != null) && (localName.equals("ReferenceTypeCode"))) {
ReferenceTypeCode = refDocChilds.item(refDocIndex).getTextContent();
}
}
ReferencedDocument rd = new ReferencedDocument(IssuerAssignedID, TypeCode,
ReferenceTypeCode);
if (rdocs == null) {
rdocs = new ArrayList<ReferencedDocument>();
}
rdocs.add(rd);
}
if ((tradeLineChilds.item(tradeLineChildIndex).getLocalName() != null) && tradeLineChilds
.item(tradeLineChildIndex).getLocalName().equals("NetPriceProductTradePrice")) {
NodeList netChilds = tradeLineChilds.item(tradeLineChildIndex).getChildNodes();
for (int netIndex = 0; netIndex < netChilds.getLength(); netIndex++) {
if ((netChilds.item(netIndex).getLocalName() != null)
&& (netChilds.item(netIndex).getLocalName().equals("ChargeAmount"))) {
price = netChilds.item(netIndex).getTextContent();// ChargeAmount
}
if ((netChilds.item(netIndex).getLocalName() != null)
&& ((netChilds.item(netIndex).getLocalName().equals("BasisQuantity")) || (netChilds.item(netIndex).getLocalName().equals("InvoicedQuantity")))) {
basisQuantity = netChilds.item(netIndex).getTextContent();// ChargeAmount
}
}
}
}
}
if ((lineTrade != null) && (lineTrade.equals("SpecifiedLineTradeDelivery")
|| lineTrade.equals("SpecifiedSupplyChainTradeDelivery"))) {
NodeList tradeLineChilds = itemChilds.item(itemChildIndex).getChildNodes();
for (int tradeLineChildIndex = 0; tradeLineChildIndex < tradeLineChilds
.getLength(); tradeLineChildIndex++) {
String tradeName = tradeLineChilds.item(tradeLineChildIndex).getLocalName();
if ((tradeName != null)
&& (tradeName.equals("BilledQuantity") || tradeName.equals("RequestedQuantity")
|| tradeName.equals("DespatchedQuantity"))) {
// RequestedQuantity is for Order-X, BilledQuantity for FX and ZF
quantity = tradeLineChilds.item(tradeLineChildIndex).getTextContent();
unitCode = tradeLineChilds.item(tradeLineChildIndex).getAttributes()
.getNamedItem("unitCode").getNodeValue();
}
}
}
if ((lineTrade != null) && (lineTrade.equals("SpecifiedTradeProduct"))) {
NodeList tradeProductChilds = itemChilds.item(itemChildIndex).getChildNodes();
for (int tradeProductChildIndex = 0; tradeProductChildIndex < tradeProductChilds
.getLength(); tradeProductChildIndex++) {
if ((tradeProductChilds.item(tradeProductChildIndex).getLocalName() != null)
&& (tradeProductChilds.item(tradeProductChildIndex).getLocalName()
.equals("Name"))) {
name = tradeProductChilds.item(tradeProductChildIndex).getTextContent();
}
if ((tradeProductChilds.item(tradeProductChildIndex).getLocalName() != null)
&& (tradeProductChilds.item(tradeProductChildIndex).getLocalName()
.equals("SellerAssignedID"))) {
sellerAssignedID = tradeProductChilds.item(tradeProductChildIndex).getTextContent();
}
if ((tradeProductChilds.item(tradeProductChildIndex).getLocalName() != null)
&& (tradeProductChilds.item(tradeProductChildIndex).getLocalName()
.equals("GlobalID"))) {
if (tradeProductChilds.item(tradeProductChildIndex).getAttributes()
.getNamedItem("schemeID") != null) {
gid = new SchemedID()
.setScheme(tradeProductChilds.item(tradeProductChildIndex).getAttributes()
.getNamedItem("schemeID").getNodeValue())
.setId(tradeProductChilds.item(tradeProductChildIndex).getTextContent());
}
}
}
}
if ((lineTrade != null) && (lineTrade.equals("SpecifiedLineTradeSettlement")
|| lineTrade.equals("SpecifiedSupplyChainTradeSettlement"))) {
NodeList tradeSettlementChilds = itemChilds.item(itemChildIndex).getChildNodes();
for (int tradeSettlementChildIndex = 0; tradeSettlementChildIndex < tradeSettlementChilds
.getLength(); tradeSettlementChildIndex++) {
String tradeSettlementName = tradeSettlementChilds.item(tradeSettlementChildIndex)
.getLocalName();
if (tradeSettlementName != null) {
if (tradeSettlementName.equals("ApplicableTradeTax")) {
NodeList taxChilds = tradeSettlementChilds.item(tradeSettlementChildIndex)
.getChildNodes();
for (int taxChildIndex = 0; taxChildIndex < taxChilds
.getLength(); taxChildIndex++) {
String taxChildName = taxChilds.item(taxChildIndex).getLocalName();
if ((taxChildName != null) && (taxChildName.equals("RateApplicablePercent")
|| taxChildName.equals("ApplicablePercent"))) {
vatPercent = taxChilds.item(taxChildIndex).getTextContent();
}
}
}
if (tradeSettlementName.equals("SpecifiedTradeSettlementLineMonetarySummation")) {
NodeList totalChilds = tradeSettlementChilds.item(tradeSettlementChildIndex)
.getChildNodes();
for (int totalChildIndex = 0; totalChildIndex < totalChilds
.getLength(); totalChildIndex++) {
if ((totalChilds.item(totalChildIndex).getLocalName() != null) && (totalChilds
.item(totalChildIndex).getLocalName().equals("LineTotalAmount"))) {
lineTotal = totalChilds.item(totalChildIndex).getTextContent();
}
}
}
}
}
}
}
BigDecimal prc = new BigDecimal(price.trim());
BigDecimal qty = new BigDecimal(quantity.trim());
if ((recalcPrice) && (!qty.equals(BigDecimal.ZERO))) {
prc = new BigDecimal(lineTotal.trim()).divide(qty, 4, RoundingMode.HALF_UP);
}
Product p = new Product(name, description, unitCode,
vatPercent == null ? null : new BigDecimal(vatPercent.trim()));
if (gid != null) {
p.addGlobalID(gid);
}
if (sellerAssignedID != null) {
p.setSellerAssignedID(sellerAssignedID);
}
setProduct(p);
setPrice(prc);
setQuantity(qty);
setBasisQuantity(new BigDecimal(basisQuantity));
if (rdocs != null) {
for (ReferencedDocument rdoc : rdocs) {
addReferencedDocument(rdoc);
}
}
}
public Item addReferencedLineID(String s) { public Item addReferencedLineID(String s) {
referencedLineID=s; referencedLineID = s;
return this; return this;
} }
@@ -66,6 +288,7 @@ public class Item implements IZUGFeRDExportableItem {
/** /**
* should only be set by calculator classes or maybe when reading from XML * should only be set by calculator classes or maybe when reading from XML
*
* @param lineTotalAmount price*quantity of this line * @param lineTotalAmount price*quantity of this line
* @return fluent setter * @return fluent setter
*/ */
@@ -130,7 +353,6 @@ public class Item implements IZUGFeRDExportableItem {
} }
@Override @Override
public BigDecimal getQuantity() { public BigDecimal getQuantity() {
return quantity; return quantity;
@@ -163,10 +385,9 @@ public class Item implements IZUGFeRDExportableItem {
} }
@Override @Override
public String[] getNotes() { public String[] getNotes() {
if (notes==null) { if (notes == null) {
return null; return null;
} }
return notes.toArray(new String[0]); return notes.toArray(new String[0]);
@@ -206,8 +427,8 @@ public class Item implements IZUGFeRDExportableItem {
* @return fluent setter * @return fluent setter
*/ */
public Item addNote(String text) { public Item addNote(String text) {
if (notes==null) { if (notes == null) {
notes=new ArrayList<String>(); notes = new ArrayList<String>();
} }
notes.add(text); notes.add(text);
return this; return this;
@@ -219,8 +440,8 @@ public class Item implements IZUGFeRDExportableItem {
* @return fluent setter * @return fluent setter
*/ */
public Item addReferencedDocument(ReferencedDocument doc) { public Item addReferencedDocument(ReferencedDocument doc) {
if (referencedDocuments==null) { if (referencedDocuments == null) {
referencedDocuments=new ArrayList<ReferencedDocument>(); referencedDocuments = new ArrayList<ReferencedDocument>();
} }
referencedDocuments.add(doc); referencedDocuments.add(doc);
return this; return this;
@@ -228,11 +449,12 @@ public class Item implements IZUGFeRDExportableItem {
@Override @Override
public IReferencedDocument[] getReferencedDocuments() { public IReferencedDocument[] getReferencedDocuments() {
if (referencedDocuments==null) { if (referencedDocuments == null) {
return null; return null;
} }
return referencedDocuments.toArray(new IReferencedDocument[0]); return referencedDocuments.toArray(new IReferencedDocument[0]);
} }
/*** /***
* specify a item level delivery period * specify a item level delivery period
* (apart from the document level delivery period, and the document level * (apart from the document level delivery period, and the document level
@@ -243,8 +465,8 @@ public class Item implements IZUGFeRDExportableItem {
* @return fluent setter * @return fluent setter
*/ */
public Item setDetailedDeliveryPeriod(Date from, Date to) { public Item setDetailedDeliveryPeriod(Date from, Date to) {
detailedDeliveryPeriodFrom=from; detailedDeliveryPeriodFrom = from;
detailedDeliveryPeriodTo=to; detailedDeliveryPeriodTo = to;
return this; return this;
} }

View File

@@ -3,8 +3,14 @@ package org.mustangproject;
import java.io.IOException; import java.io.IOException;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.RoundingMode; import java.math.RoundingMode;
import java.util.AbstractList;
import java.util.Collections;
import java.util.List;
import java.util.RandomAccess;
import org.dom4j.io.XMLWriter; import org.dom4j.io.XMLWriter;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
public class XMLTools extends XMLWriter { public class XMLTools extends XMLWriter {
@Override @Override
@@ -18,7 +24,23 @@ public class XMLTools extends XMLWriter {
} }
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;
}
public Node get(int index) {
return list.item(index);
}
public int size() {
return list.getLength();
}
}
public static String nDigitFormat(BigDecimal value, int scale) { public static String nDigitFormat(BigDecimal value, int scale) {
/* /*
* I needed 123,45, locale independent.I tried * I needed 123,45, locale independent.I tried

View File

@@ -110,7 +110,18 @@ public class ZUGFeRDInvoiceImporter extends ZUGFeRDImporter {
} }
} }
} }
String rootNode=extractString("local-name(/*)");
if (rootNode.equals("Invoice"))
{
// UBL...
number = extractString("//*[local-name()=\"Invoice\"]/*[local-name()=\"ID\"]").trim();
issueDate=new SimpleDateFormat("yyyy-MM-dd")
.parse(extractString("//*[local-name()=\"Invoice\"]/*[local-name()=\"IssueDate\"]").trim());
dueDate=new SimpleDateFormat("yyyy-MM-dd")
.parse(extractString("//*[local-name()=\"Invoice\"]/*[local-name()=\"DueDate\"]").trim());
deliveryDate=new SimpleDateFormat("yyyy-MM-dd")
.parse(extractString("//*[local-name()=\"Delivery\"]/*[local-name()=\"ActualDeliveryDate\"]").trim());
}
xpr = xpath.compile("//*[local-name()=\"ApplicableHeaderTradeDelivery\"]"); xpr = xpath.compile("//*[local-name()=\"ApplicableHeaderTradeDelivery\"]");
NodeList headerTradeDeliveryNodes = (NodeList) xpr.evaluate(getDocument(), XPathConstants.NODESET); NodeList headerTradeDeliveryNodes = (NodeList) xpr.evaluate(getDocument(), XPathConstants.NODESET);
@@ -248,178 +259,8 @@ public class ZUGFeRDInvoiceImporter extends ZUGFeRDImporter {
} else { } else {
for (int i = 0; i < nodes.getLength(); i++) { for (int i = 0; i < nodes.getLength(); i++) {
String price = "0";
String basisQuantity = "1";
String name = "";
String sellerAssignedID = null;
String description = "";
SchemedID gid = null;
String quantity = "0";
String vatPercent = null;
String lineTotal = "0";
String unitCode = "0";
ArrayList<ReferencedDocument> rdocs = null;
// nodes.item(i).getTextContent())) {
Node currentItemNode = nodes.item(i); Node currentItemNode = nodes.item(i);
NodeList itemChilds = currentItemNode.getChildNodes(); Item it = new Item(currentItemNode.getChildNodes(), recalcPrice);
for (int itemChildIndex = 0; itemChildIndex < itemChilds.getLength(); itemChildIndex++) {
String lineTrade = itemChilds.item(itemChildIndex).getLocalName();
if ((lineTrade != null) && (lineTrade.equals("SpecifiedLineTradeAgreement")
|| lineTrade.equals("SpecifiedSupplyChainTradeAgreement"))) {
NodeList tradeLineChilds = itemChilds.item(itemChildIndex).getChildNodes();
for (int tradeLineChildIndex = 0; tradeLineChildIndex < tradeLineChilds
.getLength(); tradeLineChildIndex++) {
if ((tradeLineChilds.item(tradeLineChildIndex).getLocalName() != null) && tradeLineChilds
.item(tradeLineChildIndex).getLocalName().equals("AdditionalReferencedDocument")) {
String IssuerAssignedID = "";
String TypeCode = "";
String ReferenceTypeCode = "";
NodeList refDocChilds = tradeLineChilds.item(tradeLineChildIndex).getChildNodes();
for (int refDocIndex = 0; refDocIndex < refDocChilds.getLength(); refDocIndex++) {
String localName = refDocChilds.item(refDocIndex).getLocalName();
if ((localName != null) && (localName.equals("IssuerAssignedID"))) {
IssuerAssignedID = refDocChilds.item(refDocIndex).getTextContent();
}
if ((localName != null) && (localName.equals("TypeCode"))) {
TypeCode = refDocChilds.item(refDocIndex).getTextContent();
}
if ((localName != null) && (localName.equals("ReferenceTypeCode"))) {
ReferenceTypeCode = refDocChilds.item(refDocIndex).getTextContent();
}
}
ReferencedDocument rd = new ReferencedDocument(IssuerAssignedID, TypeCode,
ReferenceTypeCode);
if (rdocs == null) {
rdocs = new ArrayList<ReferencedDocument>();
}
rdocs.add(rd);
}
if ((tradeLineChilds.item(tradeLineChildIndex).getLocalName() != null) && tradeLineChilds
.item(tradeLineChildIndex).getLocalName().equals("NetPriceProductTradePrice")) {
NodeList netChilds = tradeLineChilds.item(tradeLineChildIndex).getChildNodes();
for (int netIndex = 0; netIndex < netChilds.getLength(); netIndex++) {
if ((netChilds.item(netIndex).getLocalName() != null)
&& (netChilds.item(netIndex).getLocalName().equals("ChargeAmount"))) {
price = netChilds.item(netIndex).getTextContent();// ChargeAmount
}
if ((netChilds.item(netIndex).getLocalName() != null)
&& ((netChilds.item(netIndex).getLocalName().equals("BasisQuantity"))||(netChilds.item(netIndex).getLocalName().equals("InvoicedQuantity")))) {
basisQuantity = netChilds.item(netIndex).getTextContent();// ChargeAmount
}
}
}
}
}
if ((lineTrade != null) && (lineTrade.equals("SpecifiedLineTradeDelivery")
|| lineTrade.equals("SpecifiedSupplyChainTradeDelivery"))) {
NodeList tradeLineChilds = itemChilds.item(itemChildIndex).getChildNodes();
for (int tradeLineChildIndex = 0; tradeLineChildIndex < tradeLineChilds
.getLength(); tradeLineChildIndex++) {
String tradeName = tradeLineChilds.item(tradeLineChildIndex).getLocalName();
if ((tradeName != null)
&& (tradeName.equals("BilledQuantity") || tradeName.equals("RequestedQuantity")
|| tradeName.equals("DespatchedQuantity"))) {
// RequestedQuantity is for Order-X, BilledQuantity for FX and ZF
quantity = tradeLineChilds.item(tradeLineChildIndex).getTextContent();
unitCode = tradeLineChilds.item(tradeLineChildIndex).getAttributes()
.getNamedItem("unitCode").getNodeValue();
}
}
}
if ((lineTrade != null) && (lineTrade.equals("SpecifiedTradeProduct"))) {
NodeList tradeProductChilds = itemChilds.item(itemChildIndex).getChildNodes();
for (int tradeProductChildIndex = 0; tradeProductChildIndex < tradeProductChilds
.getLength(); tradeProductChildIndex++) {
if ((tradeProductChilds.item(tradeProductChildIndex).getLocalName() != null)
&& (tradeProductChilds.item(tradeProductChildIndex).getLocalName()
.equals("Name"))) {
name = tradeProductChilds.item(tradeProductChildIndex).getTextContent();
}
if ((tradeProductChilds.item(tradeProductChildIndex).getLocalName() != null)
&& (tradeProductChilds.item(tradeProductChildIndex).getLocalName()
.equals("SellerAssignedID"))) {
sellerAssignedID = tradeProductChilds.item(tradeProductChildIndex).getTextContent();
}
if ((tradeProductChilds.item(tradeProductChildIndex).getLocalName() != null)
&& (tradeProductChilds.item(tradeProductChildIndex).getLocalName()
.equals("GlobalID"))) {
if (tradeProductChilds.item(tradeProductChildIndex).getAttributes()
.getNamedItem("schemeID") != null) {
gid = new SchemedID()
.setScheme(tradeProductChilds.item(tradeProductChildIndex).getAttributes()
.getNamedItem("schemeID").getNodeValue())
.setId(tradeProductChilds.item(tradeProductChildIndex).getTextContent());
}
}
}
}
if ((lineTrade != null) && (lineTrade.equals("SpecifiedLineTradeSettlement")
|| lineTrade.equals("SpecifiedSupplyChainTradeSettlement"))) {
NodeList tradeSettlementChilds = itemChilds.item(itemChildIndex).getChildNodes();
for (int tradeSettlementChildIndex = 0; tradeSettlementChildIndex < tradeSettlementChilds
.getLength(); tradeSettlementChildIndex++) {
String tradeSettlementName = tradeSettlementChilds.item(tradeSettlementChildIndex)
.getLocalName();
if (tradeSettlementName != null) {
if (tradeSettlementName.equals("ApplicableTradeTax")) {
NodeList taxChilds = tradeSettlementChilds.item(tradeSettlementChildIndex)
.getChildNodes();
for (int taxChildIndex = 0; taxChildIndex < taxChilds
.getLength(); taxChildIndex++) {
String taxChildName = taxChilds.item(taxChildIndex).getLocalName();
if ((taxChildName != null) && (taxChildName.equals("RateApplicablePercent")
|| taxChildName.equals("ApplicablePercent"))) {
vatPercent = taxChilds.item(taxChildIndex).getTextContent();
}
}
}
if (tradeSettlementName.equals("SpecifiedTradeSettlementLineMonetarySummation")) {
NodeList totalChilds = tradeSettlementChilds.item(tradeSettlementChildIndex)
.getChildNodes();
for (int totalChildIndex = 0; totalChildIndex < totalChilds
.getLength(); totalChildIndex++) {
if ((totalChilds.item(totalChildIndex).getLocalName() != null) && (totalChilds
.item(totalChildIndex).getLocalName().equals("LineTotalAmount"))) {
lineTotal = totalChilds.item(totalChildIndex).getTextContent();
}
}
}
}
}
}
}
BigDecimal prc = new BigDecimal(price.trim());
BigDecimal qty = new BigDecimal(quantity.trim());
if ((recalcPrice) && (!qty.equals(BigDecimal.ZERO))) {
prc = new BigDecimal(lineTotal.trim()).divide(qty, 4, RoundingMode.HALF_UP);
}
Product p = new Product(name, description, unitCode,
vatPercent == null ? null : new BigDecimal(vatPercent.trim()));
if (gid != null) {
p.addGlobalID(gid);
}
if (sellerAssignedID != null) {
p.setSellerAssignedID(sellerAssignedID);
}
Item it = new Item(p, prc, qty);
it.setBasisQuantity(new BigDecimal(basisQuantity));
if (rdocs != null) {
for (ReferencedDocument rdoc : rdocs) {
it.addReferencedDocument(rdoc);
}
}
zpp.addItem(it); zpp.addItem(it);
} }

View File

@@ -104,11 +104,11 @@ public class ZF2ZInvoiceImporterTest extends ResourceCase {
boolean hasExceptions = false; boolean hasExceptions = false;
ZUGFeRDInvoiceImporter zii = new ZUGFeRDInvoiceImporter(); ZUGFeRDInvoiceImporter zii = new ZUGFeRDInvoiceImporter();
File expectedResult=getResourceAsFile("testout-ZF2new.ubl.xml"); File expectedResult = getResourceAsFile("testout-ZF2new.ubl.xml");
Invoice invoice = null; Invoice invoice = null;
try { try {
String xml = new String(Files.readAllBytes(expectedResult.toPath()), StandardCharsets.UTF_8).replace("\r","").replace("\n",""); String xml = new String(Files.readAllBytes(expectedResult.toPath()), StandardCharsets.UTF_8).replace("\r", "").replace("\n", "");
zii.fromXML(xml); zii.fromXML(xml);
@@ -120,13 +120,13 @@ public class ZF2ZInvoiceImporterTest extends ResourceCase {
// Reading ZUGFeRD // Reading ZUGFeRD
assertEquals("Bei Spiel GmbH", invoice.getOwnOrganisationName()); assertEquals("Bei Spiel GmbH", invoice.getOwnOrganisationName());
assertEquals(3, invoice.getZFItems().length); assertEquals(3, invoice.getZFItems().length);
assertEquals("400.0000", invoice.getZFItems()[1].getQuantity().toString()); assertEquals("400", invoice.getZFItems()[1].getQuantity().toString());
assertEquals("AB321", invoice.getReferenceNumber()); assertEquals("AB321", invoice.getReferenceNumber());
assertEquals("160.0000", invoice.getZFItems()[0].getPrice().toString()); assertEquals("160", invoice.getZFItems()[0].getPrice().toString());
assertEquals("Heiße Luft pro Liter", invoice.getZFItems()[2].getProduct().getName()); assertEquals("Heiße Luft pro Liter", invoice.getZFItems()[2].getProduct().getName());
assertEquals("LTR", invoice.getZFItems()[2].getProduct().getUnit()); assertEquals("LTR", invoice.getZFItems()[2].getProduct().getUnit());
assertEquals("7.00", invoice.getZFItems()[0].getProduct().getVATPercent().toString()); assertEquals("7", invoice.getZFItems()[0].getProduct().getVATPercent().toString());
assertEquals("RE-20170509/505", invoice.getNumber()); assertEquals("RE-20170509/505", invoice.getNumber());
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
@@ -153,6 +153,7 @@ public class ZF2ZInvoiceImporterTest extends ResourceCase {
// name street location zip country, contact name phone email, total amount // name street location zip country, contact name phone email, total amount
} }
public void testEdgeInvoiceImport() { public void testEdgeInvoiceImport() {
ZUGFeRDInvoiceImporter zii = new ZUGFeRDInvoiceImporter("./target/testout-ZF2PushEdge.pdf"); ZUGFeRDInvoiceImporter zii = new ZUGFeRDInvoiceImporter("./target/testout-ZF2PushEdge.pdf");