continued parsing UBL
This commit is contained in:
@@ -1,13 +1,18 @@
|
||||
package org.mustangproject;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import org.apache.fop.util.XMLUtil;
|
||||
import org.mustangproject.ZUGFeRD.IReferencedDocument;
|
||||
import org.mustangproject.ZUGFeRD.IZUGFeRDAllowanceCharge;
|
||||
import org.mustangproject.ZUGFeRD.IZUGFeRDExportableItem;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/***
|
||||
* describes any invoice line
|
||||
@@ -16,15 +21,15 @@ import java.util.Date;
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class Item implements IZUGFeRDExportableItem {
|
||||
protected BigDecimal price, quantity, tax, grossPrice, lineTotalAmount;
|
||||
protected BigDecimal basisQuantity=BigDecimal.ONE;
|
||||
protected Date detailedDeliveryPeriodFrom=null, detailedDeliveryPeriodTo=null;
|
||||
protected BigDecimal basisQuantity = BigDecimal.ONE;
|
||||
protected Date detailedDeliveryPeriodFrom = null, detailedDeliveryPeriodTo = null;
|
||||
protected String id;
|
||||
protected String referencedLineID=null;
|
||||
protected String referencedLineID = null;
|
||||
protected Product product;
|
||||
protected ArrayList<String> notes = null;
|
||||
protected ArrayList<ReferencedDocument> referencedDocuments = null;
|
||||
protected ArrayList<IZUGFeRDAllowanceCharge> Allowances = new ArrayList<IZUGFeRDAllowanceCharge>(),
|
||||
Charges = new ArrayList<IZUGFeRDAllowanceCharge>();
|
||||
Charges = new ArrayList<IZUGFeRDAllowanceCharge>();
|
||||
|
||||
/***
|
||||
* default constructor
|
||||
@@ -46,8 +51,225 @@ public class Item implements IZUGFeRDExportableItem {
|
||||
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) {
|
||||
referencedLineID=s;
|
||||
referencedLineID = s;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -66,6 +288,7 @@ public class Item implements IZUGFeRDExportableItem {
|
||||
|
||||
/**
|
||||
* should only be set by calculator classes or maybe when reading from XML
|
||||
*
|
||||
* @param lineTotalAmount price*quantity of this line
|
||||
* @return fluent setter
|
||||
*/
|
||||
@@ -130,7 +353,6 @@ public class Item implements IZUGFeRDExportableItem {
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public BigDecimal getQuantity() {
|
||||
return quantity;
|
||||
@@ -163,10 +385,9 @@ public class Item implements IZUGFeRDExportableItem {
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public String[] getNotes() {
|
||||
if (notes==null) {
|
||||
if (notes == null) {
|
||||
return null;
|
||||
}
|
||||
return notes.toArray(new String[0]);
|
||||
@@ -206,8 +427,8 @@ public class Item implements IZUGFeRDExportableItem {
|
||||
* @return fluent setter
|
||||
*/
|
||||
public Item addNote(String text) {
|
||||
if (notes==null) {
|
||||
notes=new ArrayList<String>();
|
||||
if (notes == null) {
|
||||
notes = new ArrayList<String>();
|
||||
}
|
||||
notes.add(text);
|
||||
return this;
|
||||
@@ -219,8 +440,8 @@ public class Item implements IZUGFeRDExportableItem {
|
||||
* @return fluent setter
|
||||
*/
|
||||
public Item addReferencedDocument(ReferencedDocument doc) {
|
||||
if (referencedDocuments==null) {
|
||||
referencedDocuments=new ArrayList<ReferencedDocument>();
|
||||
if (referencedDocuments == null) {
|
||||
referencedDocuments = new ArrayList<ReferencedDocument>();
|
||||
}
|
||||
referencedDocuments.add(doc);
|
||||
return this;
|
||||
@@ -228,11 +449,12 @@ public class Item implements IZUGFeRDExportableItem {
|
||||
|
||||
@Override
|
||||
public IReferencedDocument[] getReferencedDocuments() {
|
||||
if (referencedDocuments==null) {
|
||||
if (referencedDocuments == null) {
|
||||
return null;
|
||||
}
|
||||
return referencedDocuments.toArray(new IReferencedDocument[0]);
|
||||
}
|
||||
|
||||
/***
|
||||
* specify a item level delivery period
|
||||
* (apart from the document level delivery period, and the document level
|
||||
@@ -243,8 +465,8 @@ public class Item implements IZUGFeRDExportableItem {
|
||||
* @return fluent setter
|
||||
*/
|
||||
public Item setDetailedDeliveryPeriod(Date from, Date to) {
|
||||
detailedDeliveryPeriodFrom=from;
|
||||
detailedDeliveryPeriodTo=to;
|
||||
detailedDeliveryPeriodFrom = from;
|
||||
detailedDeliveryPeriodTo = to;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,8 +3,14 @@ package org.mustangproject;
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
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.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
public class XMLTools extends XMLWriter {
|
||||
@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) {
|
||||
/*
|
||||
* I needed 123,45, locale independent.I tried
|
||||
|
||||
@@ -91,7 +91,7 @@ public class ZUGFeRDInvoiceImporter extends ZUGFeRDImporter {
|
||||
Node exchangedDocumentNode = ExchangedDocumentNodes.item(i);
|
||||
NodeList exchangedDocumentChilds = exchangedDocumentNode.getChildNodes();
|
||||
for (int documentChildIndex = 0; documentChildIndex < exchangedDocumentChilds
|
||||
.getLength(); documentChildIndex++) {
|
||||
.getLength(); documentChildIndex++) {
|
||||
Node item = exchangedDocumentChilds.item(documentChildIndex);
|
||||
if ((item.getLocalName() != null) && (item.getLocalName().equals("ID"))) {
|
||||
number = item.getTextContent();
|
||||
@@ -99,18 +99,29 @@ public class ZUGFeRDInvoiceImporter extends ZUGFeRDImporter {
|
||||
if ((item.getLocalName() != null) && (item.getLocalName().equals("IssueDateTime"))) {
|
||||
NodeList issueDateTimeChilds = item.getChildNodes();
|
||||
for (int issueDateChildIndex = 0; issueDateChildIndex < issueDateTimeChilds
|
||||
.getLength(); issueDateChildIndex++) {
|
||||
.getLength(); issueDateChildIndex++) {
|
||||
if ((issueDateTimeChilds.item(issueDateChildIndex).getLocalName() != null)
|
||||
&& (issueDateTimeChilds.item(issueDateChildIndex).getLocalName()
|
||||
.equals("DateTimeString"))) {
|
||||
&& (issueDateTimeChilds.item(issueDateChildIndex).getLocalName()
|
||||
.equals("DateTimeString"))) {
|
||||
issueDate = new SimpleDateFormat("yyyyMMdd")
|
||||
.parse(issueDateTimeChilds.item(issueDateChildIndex).getTextContent());
|
||||
.parse(issueDateTimeChilds.item(issueDateChildIndex).getTextContent());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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\"]");
|
||||
NodeList headerTradeDeliveryNodes = (NodeList) xpr.evaluate(getDocument(), XPathConstants.NODESET);
|
||||
|
||||
@@ -119,25 +130,25 @@ public class ZUGFeRDInvoiceImporter extends ZUGFeRDImporter {
|
||||
Node headerTradeDeliveryNode = headerTradeDeliveryNodes.item(i);
|
||||
NodeList headerTradeDeliveryChilds = headerTradeDeliveryNode.getChildNodes();
|
||||
for (int deliveryChildIndex = 0; deliveryChildIndex < headerTradeDeliveryChilds
|
||||
.getLength(); deliveryChildIndex++) {
|
||||
.getLength(); deliveryChildIndex++) {
|
||||
if ((headerTradeDeliveryChilds.item(deliveryChildIndex).getLocalName() != null)
|
||||
&& (headerTradeDeliveryChilds.item(deliveryChildIndex).getLocalName()
|
||||
.equals("ActualDeliverySupplyChainEvent"))) {
|
||||
&& (headerTradeDeliveryChilds.item(deliveryChildIndex).getLocalName()
|
||||
.equals("ActualDeliverySupplyChainEvent"))) {
|
||||
NodeList actualDeliveryChilds = headerTradeDeliveryChilds.item(deliveryChildIndex).getChildNodes();
|
||||
for (int actualDeliveryChildIndex = 0; actualDeliveryChildIndex < actualDeliveryChilds
|
||||
.getLength(); actualDeliveryChildIndex++) {
|
||||
.getLength(); actualDeliveryChildIndex++) {
|
||||
if ((actualDeliveryChilds.item(actualDeliveryChildIndex).getLocalName() != null)
|
||||
&& (actualDeliveryChilds.item(actualDeliveryChildIndex).getLocalName()
|
||||
.equals("OccurrenceDateTime"))) {
|
||||
&& (actualDeliveryChilds.item(actualDeliveryChildIndex).getLocalName()
|
||||
.equals("OccurrenceDateTime"))) {
|
||||
NodeList occurenceChilds = actualDeliveryChilds.item(actualDeliveryChildIndex)
|
||||
.getChildNodes();
|
||||
.getChildNodes();
|
||||
for (int occurenceChildIndex = 0; occurenceChildIndex < occurenceChilds
|
||||
.getLength(); occurenceChildIndex++) {
|
||||
.getLength(); occurenceChildIndex++) {
|
||||
if ((occurenceChilds.item(occurenceChildIndex).getLocalName() != null)
|
||||
&& (occurenceChilds.item(occurenceChildIndex).getLocalName()
|
||||
.equals("DateTimeString"))) {
|
||||
&& (occurenceChilds.item(occurenceChildIndex).getLocalName()
|
||||
.equals("DateTimeString"))) {
|
||||
deliveryDate = new SimpleDateFormat("yyyyMMdd")
|
||||
.parse(occurenceChilds.item(occurenceChildIndex).getTextContent());
|
||||
.parse(occurenceChilds.item(occurenceChildIndex).getTextContent());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -155,29 +166,29 @@ public class ZUGFeRDInvoiceImporter extends ZUGFeRDImporter {
|
||||
Node headerTradeAgreementNode = headerTradeAgreementNodes.item(i);
|
||||
NodeList headerTradeAgreementChilds = headerTradeAgreementNode.getChildNodes();
|
||||
for (int agreementChildIndex = 0; agreementChildIndex < headerTradeAgreementChilds
|
||||
.getLength(); agreementChildIndex++) {
|
||||
.getLength(); agreementChildIndex++) {
|
||||
if ((headerTradeAgreementChilds.item(agreementChildIndex).getLocalName() != null)
|
||||
&& (headerTradeAgreementChilds.item(agreementChildIndex).getLocalName()
|
||||
.equals("BuyerOrderReferencedDocument"))) {
|
||||
&& (headerTradeAgreementChilds.item(agreementChildIndex).getLocalName()
|
||||
.equals("BuyerOrderReferencedDocument"))) {
|
||||
NodeList buyerOrderChilds = headerTradeAgreementChilds.item(agreementChildIndex).getChildNodes();
|
||||
for (int buyerOrderChildIndex = 0; buyerOrderChildIndex < buyerOrderChilds
|
||||
.getLength(); buyerOrderChildIndex++) {
|
||||
.getLength(); buyerOrderChildIndex++) {
|
||||
if ((buyerOrderChilds.item(buyerOrderChildIndex).getLocalName() != null)
|
||||
&& (buyerOrderChilds.item(buyerOrderChildIndex).getLocalName()
|
||||
.equals("IssuerAssignedID"))) {
|
||||
&& (buyerOrderChilds.item(buyerOrderChildIndex).getLocalName()
|
||||
.equals("IssuerAssignedID"))) {
|
||||
buyerOrderIssuerAssignedID = buyerOrderChilds.item(buyerOrderChildIndex).getTextContent();
|
||||
}
|
||||
}
|
||||
}
|
||||
if ((headerTradeAgreementChilds.item(agreementChildIndex).getLocalName() != null)
|
||||
&& (headerTradeAgreementChilds.item(agreementChildIndex).getLocalName()
|
||||
.equals("SellerOrderReferencedDocument"))) {
|
||||
&& (headerTradeAgreementChilds.item(agreementChildIndex).getLocalName()
|
||||
.equals("SellerOrderReferencedDocument"))) {
|
||||
NodeList sellerOrderChilds = headerTradeAgreementChilds.item(agreementChildIndex).getChildNodes();
|
||||
for (int sellerOrderChildIndex = 0; sellerOrderChildIndex < sellerOrderChilds
|
||||
.getLength(); sellerOrderChildIndex++) {
|
||||
.getLength(); sellerOrderChildIndex++) {
|
||||
if ((sellerOrderChilds.item(sellerOrderChildIndex).getLocalName() != null)
|
||||
&& (sellerOrderChilds.item(sellerOrderChildIndex).getLocalName()
|
||||
.equals("IssuerAssignedID"))) {
|
||||
&& (sellerOrderChilds.item(sellerOrderChildIndex).getLocalName()
|
||||
.equals("IssuerAssignedID"))) {
|
||||
sellerOrderIssuerAssignedID = sellerOrderChilds.item(sellerOrderChildIndex).getTextContent();
|
||||
}
|
||||
}
|
||||
@@ -195,22 +206,22 @@ public class ZUGFeRDInvoiceImporter extends ZUGFeRDImporter {
|
||||
Node headerTradeSettlementNode = headerTradeSettlementNodes.item(i);
|
||||
NodeList headerTradeSettlementChilds = headerTradeSettlementNode.getChildNodes();
|
||||
for (int settlementChildIndex = 0; settlementChildIndex < headerTradeSettlementChilds
|
||||
.getLength(); settlementChildIndex++) {
|
||||
.getLength(); settlementChildIndex++) {
|
||||
if ((headerTradeSettlementChilds.item(settlementChildIndex).getLocalName() != null)
|
||||
&& (headerTradeSettlementChilds.item(settlementChildIndex).getLocalName()
|
||||
.equals("SpecifiedTradePaymentTerms"))) {
|
||||
&& (headerTradeSettlementChilds.item(settlementChildIndex).getLocalName()
|
||||
.equals("SpecifiedTradePaymentTerms"))) {
|
||||
NodeList paymentTermChilds = headerTradeSettlementChilds.item(settlementChildIndex).getChildNodes();
|
||||
for (int paymentTermChildIndex = 0; paymentTermChildIndex < paymentTermChilds
|
||||
.getLength(); paymentTermChildIndex++) {
|
||||
.getLength(); paymentTermChildIndex++) {
|
||||
if ((paymentTermChilds.item(paymentTermChildIndex).getLocalName() != null) && (paymentTermChilds
|
||||
.item(paymentTermChildIndex).getLocalName().equals("DueDateDateTime"))) {
|
||||
.item(paymentTermChildIndex).getLocalName().equals("DueDateDateTime"))) {
|
||||
NodeList dueDateChilds = paymentTermChilds.item(paymentTermChildIndex).getChildNodes();
|
||||
for (int dueDateChildIndex = 0; dueDateChildIndex < dueDateChilds
|
||||
.getLength(); dueDateChildIndex++) {
|
||||
.getLength(); dueDateChildIndex++) {
|
||||
if ((dueDateChilds.item(dueDateChildIndex).getLocalName() != null) && (dueDateChilds
|
||||
.item(dueDateChildIndex).getLocalName().equals("DateTimeString"))) {
|
||||
.item(dueDateChildIndex).getLocalName().equals("DateTimeString"))) {
|
||||
dueDate = new SimpleDateFormat("yyyyMMdd")
|
||||
.parse(dueDateChilds.item(dueDateChildIndex).getTextContent());
|
||||
.parse(dueDateChilds.item(dueDateChildIndex).getTextContent());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -220,7 +231,7 @@ public class ZUGFeRDInvoiceImporter extends ZUGFeRDImporter {
|
||||
}
|
||||
|
||||
zpp.setDueDate(dueDate).setDeliveryDate(deliveryDate).setIssueDate(issueDate)
|
||||
.setSender(new TradeParty(SellerNodes)).setRecipient(new TradeParty(BuyerNodes)).setNumber(number);
|
||||
.setSender(new TradeParty(SellerNodes)).setRecipient(new TradeParty(BuyerNodes)).setNumber(number);
|
||||
if (buyerOrderIssuerAssignedID != null) {
|
||||
zpp.setBuyerOrderReferencedDocumentID(buyerOrderIssuerAssignedID);
|
||||
}
|
||||
@@ -248,178 +259,8 @@ public class ZUGFeRDInvoiceImporter extends ZUGFeRDImporter {
|
||||
} else {
|
||||
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);
|
||||
NodeList itemChilds = currentItemNode.getChildNodes();
|
||||
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);
|
||||
}
|
||||
}
|
||||
Item it = new Item(currentItemNode.getChildNodes(), recalcPrice);
|
||||
zpp.addItem(it);
|
||||
|
||||
}
|
||||
@@ -443,12 +284,12 @@ public class ZUGFeRDInvoiceImporter extends ZUGFeRDImporter {
|
||||
if (chargeChildName.equals("ChargeIndicator")) {
|
||||
NodeList indicatorChilds = chargeNodeChilds.item(chargeChildIndex).getChildNodes();
|
||||
for (int indicatorChildIndex = 0; indicatorChildIndex < indicatorChilds
|
||||
.getLength(); indicatorChildIndex++) {
|
||||
.getLength(); indicatorChildIndex++) {
|
||||
if ((indicatorChilds.item(indicatorChildIndex).getLocalName() != null)
|
||||
&& (indicatorChilds.item(indicatorChildIndex).getLocalName()
|
||||
.equals("Indicator"))) {
|
||||
&& (indicatorChilds.item(indicatorChildIndex).getLocalName()
|
||||
.equals("Indicator"))) {
|
||||
isCharge = indicatorChilds.item(indicatorChildIndex).getTextContent()
|
||||
.equalsIgnoreCase("true");
|
||||
.equalsIgnoreCase("true");
|
||||
}
|
||||
}
|
||||
} else if (chargeChildName.equals("ActualAmount")) {
|
||||
@@ -460,7 +301,7 @@ public class ZUGFeRDInvoiceImporter extends ZUGFeRDImporter {
|
||||
for (int taxChildIndex = 0; taxChildIndex < taxChilds.getLength(); taxChildIndex++) {
|
||||
String taxItemName = taxChilds.item(taxChildIndex).getLocalName();
|
||||
if ((taxItemName != null) && (taxItemName.equals("RateApplicablePercent")
|
||||
|| taxItemName.equals("ApplicablePercent"))) {
|
||||
|| taxItemName.equals("ApplicablePercent"))) {
|
||||
taxPercent = taxChilds.item(taxChildIndex).getTextContent();
|
||||
}
|
||||
}
|
||||
@@ -502,10 +343,10 @@ public class ZUGFeRDInvoiceImporter extends ZUGFeRDImporter {
|
||||
}
|
||||
|
||||
if ((whichType != EStandard.despatchadvice)
|
||||
&& ((!expectedStringTotalGross.equals(XMLTools.nDigitFormat(expectedGrandTotal, 2)))
|
||||
&& (!ignoreCalculationErrors))) {
|
||||
&& ((!expectedStringTotalGross.equals(XMLTools.nDigitFormat(expectedGrandTotal, 2)))
|
||||
&& (!ignoreCalculationErrors))) {
|
||||
throw new ParseException(
|
||||
"Could not reproduce the invoice, this could mean that it could not be read properly", 0);
|
||||
"Could not reproduce the invoice, this could mean that it could not be read properly", 0);
|
||||
}
|
||||
}
|
||||
return zpp;
|
||||
|
||||
@@ -104,11 +104,11 @@ public class ZF2ZInvoiceImporterTest extends ResourceCase {
|
||||
boolean hasExceptions = false;
|
||||
|
||||
ZUGFeRDInvoiceImporter zii = new ZUGFeRDInvoiceImporter();
|
||||
File expectedResult=getResourceAsFile("testout-ZF2new.ubl.xml");
|
||||
File expectedResult = getResourceAsFile("testout-ZF2new.ubl.xml");
|
||||
|
||||
Invoice invoice = null;
|
||||
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);
|
||||
|
||||
@@ -120,13 +120,13 @@ public class ZF2ZInvoiceImporterTest extends ResourceCase {
|
||||
// Reading ZUGFeRD
|
||||
assertEquals("Bei Spiel GmbH", invoice.getOwnOrganisationName());
|
||||
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("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("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());
|
||||
|
||||
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
|
||||
|
||||
}
|
||||
|
||||
public void testEdgeInvoiceImport() {
|
||||
|
||||
ZUGFeRDInvoiceImporter zii = new ZUGFeRDInvoiceImporter("./target/testout-ZF2PushEdge.pdf");
|
||||
|
||||
Reference in New Issue
Block a user