QMT-1461: Rechnungseingang - ZUGFeRD-Rechnungen importieren

This commit is contained in:
Stefan Schmaltz
2022-10-11 14:57:08 +02:00
parent 5c0a3134ac
commit 524165b1ba
4 changed files with 174 additions and 110 deletions

View File

@@ -20,15 +20,21 @@
*/ */
package org.mustangproject; package org.mustangproject;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import org.mustangproject.ZUGFeRD.*;
import org.mustangproject.ZUGFeRD.model.DocumentCodeTypeConstants;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import org.mustangproject.ZUGFeRD.IExportableTransaction;
import org.mustangproject.ZUGFeRD.IZUGFeRDAllowanceCharge;
import org.mustangproject.ZUGFeRD.IZUGFeRDExportableItem;
import org.mustangproject.ZUGFeRD.IZUGFeRDExportableTradeParty;
import org.mustangproject.ZUGFeRD.IZUGFeRDPaymentTerms;
import org.mustangproject.ZUGFeRD.IZUGFeRDTradeSettlement;
import org.mustangproject.ZUGFeRD.model.DocumentCodeTypeConstants;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
/*** /***
* An invoice, with fluent setters * An invoice, with fluent setters
* @see IExportableTransaction if you want to implement an interface instead * @see IExportableTransaction if you want to implement an interface instead
@@ -39,6 +45,8 @@ public class Invoice implements IExportableTransaction {
protected String documentName = null, documentCode = null, number = null, ownOrganisationFullPlaintextInfo = null, referenceNumber = null, shipToOrganisationID = null, shipToOrganisationName = null, shipToStreet = null, shipToZIP = null, shipToLocation = null, shipToCountry = null, buyerOrderReferencedDocumentID = null, invoiceReferencedDocumentID = null, buyerOrderReferencedDocumentIssueDateTime = null, ownForeignOrganisationID = null, ownOrganisationName = null, currency = null, paymentTermDescription = null; protected String documentName = null, documentCode = null, number = null, ownOrganisationFullPlaintextInfo = null, referenceNumber = null, shipToOrganisationID = null, shipToOrganisationName = null, shipToStreet = null, shipToZIP = null, shipToLocation = null, shipToCountry = null, buyerOrderReferencedDocumentID = null, invoiceReferencedDocumentID = null, buyerOrderReferencedDocumentIssueDateTime = null, ownForeignOrganisationID = null, ownOrganisationName = null, currency = null, paymentTermDescription = null;
protected Date issueDate = null, dueDate = null, deliveryDate = null; protected Date issueDate = null, dueDate = null, deliveryDate = null;
protected BigDecimal totalPrepaidAmount = null; protected BigDecimal totalPrepaidAmount = null;
protected BigDecimal grandTotalAmount = null;
protected BigDecimal duePayableAmount = null;
protected TradeParty sender = null, recipient = null, deliveryAddress = null; protected TradeParty sender = null, recipient = null, deliveryAddress = null;
@JsonDeserialize(contentAs=Item.class) @JsonDeserialize(contentAs=Item.class)
protected ArrayList<IZUGFeRDExportableItem> ZFItems = null; protected ArrayList<IZUGFeRDExportableItem> ZFItems = null;
@@ -433,6 +441,24 @@ public class Invoice implements IExportableTransaction {
return this; return this;
} }
public BigDecimal getGrandTotalAmount() {
return grandTotalAmount;
}
public Invoice setGrandTotalAmount(BigDecimal grandTotalAmount) {
this.grandTotalAmount = grandTotalAmount;
return this;
}
public BigDecimal getDuePayableAmount() {
return duePayableAmount;
}
public Invoice setDuePayableAmount(BigDecimal duePayableAmount) {
this.duePayableAmount = duePayableAmount;
return this;
}
@Override @Override
public IZUGFeRDExportableTradeParty getSender() { public IZUGFeRDExportableTradeParty getSender() {
return sender; return sender;
@@ -445,6 +471,7 @@ public class Invoice implements IExportableTransaction {
* @param ownContact the sender contact * @param ownContact the sender contact
* @return fluent setter * @return fluent setter
*/ */
@Deprecated
public Invoice setOwnContact(Contact ownContact) { public Invoice setOwnContact(Contact ownContact) {
this.sender.setContact(ownContact); this.sender.setContact(ownContact);
return this; return this;
@@ -689,4 +716,5 @@ public class Invoice implements IExportableTransaction {
this.specifiedProcuringProjectName = specifiedProcuringProjectName; this.specifiedProcuringProjectName = specifiedProcuringProjectName;
return this; return this;
} }
} }

View File

@@ -17,6 +17,7 @@
* *
*********************************************************************** */ *********************************************************************** */
package org.mustangproject.ZUGFeRD; package org.mustangproject.ZUGFeRD;
/** /**
* Mustangproject's ZUGFeRD implementation * Mustangproject's ZUGFeRD implementation
* Neccessary interface for ZUGFeRD exporter * Neccessary interface for ZUGFeRD exporter
@@ -26,7 +27,6 @@ package org.mustangproject.ZUGFeRD;
* @author jstaerk * @author jstaerk
* */ * */
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.Date; import java.util.Date;
@@ -34,8 +34,9 @@ import org.mustangproject.FileAttachment;
import org.mustangproject.ZUGFeRD.model.DocumentCodeTypeConstants; import org.mustangproject.ZUGFeRD.model.DocumentCodeTypeConstants;
/*** /***
* the interface of an transaction, e.g. an invoice, you want to create xml (potentially to be added to a PDF) * the interface of an transaction, e.g. an invoice, you want to create xml
* for * (potentially to be added to a PDF) for
*
* @see org.mustangproject.Invoice * @see org.mustangproject.Invoice
*/ */
public interface IExportableTransaction { public interface IExportableTransaction {
@@ -49,7 +50,6 @@ public interface IExportableTransaction {
return "RECHNUNG"; return "RECHNUNG";
} }
/** /**
* *
* *
@@ -59,7 +59,6 @@ public interface IExportableTransaction {
return DocumentCodeTypeConstants.INVOICE; return DocumentCodeTypeConstants.INVOICE;
} }
/** /**
* Number, typically invoice number of the invoice * Number, typically invoice number of the invoice
* *
@@ -69,7 +68,6 @@ public interface IExportableTransaction {
return null; return null;
} }
/** /**
* the date when the invoice was created * the date when the invoice was created
* *
@@ -79,19 +77,20 @@ public interface IExportableTransaction {
return null; return null;
} }
/** /**
* this should be the full sender institution name, details, manager and tax registration. It is one of the few functions which may return null. e.g. * this should be the full sender institution name, details, manager and tax
* registration. It is one of the few functions which may return null. e.g.
* <p> * <p>
* Lieferant GmbH Lieferantenstraße 20 80333 München Deutschland Geschäftsführer: Hans Muster Handelsregisternummer: H A 123 * Lieferant GmbH Lieferantenstraße 20 80333 München Deutschland
* Geschäftsführer: Hans Muster Handelsregisternummer: H A 123
* *
* @return null or full sender institution name, details, manager and tax registration * @return null or full sender institution name, details, manager and tax
* registration
*/ */
default String getOwnOrganisationFullPlaintextInfo() { default String getOwnOrganisationFullPlaintextInfo() {
return null; return null;
} }
/** /**
* when the invoice is to be paid * when the invoice is to be paid
* *
@@ -105,7 +104,6 @@ public interface IExportableTransaction {
return null; return null;
} }
/** /**
* the sender of the invoice * the sender of the invoice
* *
@@ -115,10 +113,8 @@ public interface IExportableTransaction {
return null; return null;
} }
/** /**
* subject of the document e.g. invoice and order * subject of the document e.g. invoice and order number as human readable text
* number as human readable text
* *
* @return string with document subject * @return string with document subject
*/ */
@@ -130,20 +126,16 @@ public interface IExportableTransaction {
return null; return null;
} }
default IZUGFeRDAllowanceCharge[] getZFCharges() { default IZUGFeRDAllowanceCharge[] getZFCharges() {
return null; return null;
} }
default IZUGFeRDAllowanceCharge[] getZFLogisticsServiceCharges() { default IZUGFeRDAllowanceCharge[] getZFLogisticsServiceCharges() {
return null; return null;
} }
IZUGFeRDExportableItem[] getZFItems(); IZUGFeRDExportableItem[] getZFItems();
/** /**
* the recipient * the recipient
* *
@@ -151,9 +143,9 @@ public interface IExportableTransaction {
*/ */
IZUGFeRDExportableTradeParty getRecipient(); IZUGFeRDExportableTradeParty getRecipient();
/** /**
* the creditors payment informations * the creditors payment informations
*
* @deprecated use getTradeSettlement * @deprecated use getTradeSettlement
* @return an array of IZUGFeRDTradeSettlementPayment * @return an array of IZUGFeRDTradeSettlementPayment
*/ */
@@ -161,6 +153,7 @@ public interface IExportableTransaction {
default IZUGFeRDTradeSettlementPayment[] getTradeSettlementPayment() { default IZUGFeRDTradeSettlementPayment[] getTradeSettlementPayment() {
return null; return null;
} }
/** /**
* the payment information for any payment means * the payment information for any payment means
* *
@@ -170,7 +163,6 @@ public interface IExportableTransaction {
return null; return null;
} }
/** /**
* Tax ID (not VAT ID) of the sender * Tax ID (not VAT ID) of the sender
* *
@@ -184,7 +176,6 @@ public interface IExportableTransaction {
} }
} }
/** /**
* VAT ID (Umsatzsteueridentifikationsnummer) of the sender * VAT ID (Umsatzsteueridentifikationsnummer) of the sender
* *
@@ -198,7 +189,6 @@ public interface IExportableTransaction {
} }
} }
/** /**
* supplier identification assigned by the costumer * supplier identification assigned by the costumer
* *
@@ -208,7 +198,6 @@ public interface IExportableTransaction {
return null; return null;
} }
/** /**
* own name * own name
* *
@@ -222,7 +211,6 @@ public interface IExportableTransaction {
} }
} }
/** /**
* own street address * own street address
* *
@@ -236,7 +224,6 @@ public interface IExportableTransaction {
} }
} }
/** /**
* own street postal code * own street postal code
* *
@@ -251,7 +238,6 @@ public interface IExportableTransaction {
} }
/** /**
* own city * own city
* *
@@ -266,7 +252,6 @@ public interface IExportableTransaction {
} }
/** /**
* own two digit country code * own two digit country code
* *
@@ -281,7 +266,6 @@ public interface IExportableTransaction {
} }
/** /**
* get delivery date * get delivery date
* *
@@ -289,7 +273,6 @@ public interface IExportableTransaction {
*/ */
Date getDeliveryDate(); Date getDeliveryDate();
/** /**
* get main invoice currency used on the invoice * get main invoice currency used on the invoice
* *
@@ -299,7 +282,6 @@ public interface IExportableTransaction {
return "EUR"; return "EUR";
} }
/** /**
* get payment term descriptional text e.g. Bis zum 22.10.2015 ohne Abzug * get payment term descriptional text e.g. Bis zum 22.10.2015 ohne Abzug
* *
@@ -329,7 +311,8 @@ public interface IExportableTransaction {
} }
/** /**
* get reference document number typically used for Invoice Corrections Will be added as IncludedNote in comfort profile * get reference document number typically used for Invoice Corrections Will be
* added as IncludedNote in comfort profile
* *
* @return the ID of the document this document refers to * @return the ID of the document this document refers to
*/ */
@@ -337,9 +320,9 @@ public interface IExportableTransaction {
return null; return null;
} }
/** /**
* consignee identification (identification of the organisation the goods are shipped to [assigned by the costumer]) * consignee identification (identification of the organisation the goods are
* shipped to [assigned by the costumer])
* *
* @return the sender's identification * @return the sender's identification
*/ */
@@ -347,7 +330,6 @@ public interface IExportableTransaction {
return null; return null;
} }
/** /**
* consignee name (name of the organisation the goods are shipped to) * consignee name (name of the organisation the goods are shipped to)
* *
@@ -357,9 +339,9 @@ public interface IExportableTransaction {
return null; return null;
} }
/** /**
* consignee street address (street of the organisation the goods are shipped to) * consignee street address (street of the organisation the goods are shipped
* to)
* *
* @return consignee street address * @return consignee street address
*/ */
@@ -367,9 +349,9 @@ public interface IExportableTransaction {
return null; return null;
} }
/** /**
* consignee street postal code (postal code of the organisation the goods are shipped to) * consignee street postal code (postal code of the organisation the goods are
* shipped to)
* *
* @return consignee postal code * @return consignee postal code
*/ */
@@ -377,7 +359,6 @@ public interface IExportableTransaction {
return null; return null;
} }
/** /**
* consignee city (city of the organisation the goods are shipped to) * consignee city (city of the organisation the goods are shipped to)
* *
@@ -387,9 +368,9 @@ public interface IExportableTransaction {
return null; return null;
} }
/** /**
* consignee two digit country code (country code of the organisation the goods are shipped to) * consignee two digit country code (country code of the organisation the goods
* are shipped to)
* *
* @return the consignee's two character country iso code * @return the consignee's two character country iso code
*/ */
@@ -397,17 +378,19 @@ public interface IExportableTransaction {
return null; return null;
} }
/** /**
* get the ID of the SellerOrderReferencedDocument, which sits in the ApplicableSupplyChainTradeAgreement/ApplicableHeaderTradeAgreement * get the ID of the SellerOrderReferencedDocument, which sits in the
* ApplicableSupplyChainTradeAgreement/ApplicableHeaderTradeAgreement
* *
* @return the ID of the document * @return the ID of the document
*/ */
default String getSellerOrderReferencedDocumentID() { default String getSellerOrderReferencedDocumentID() {
return null; return null;
} }
/** /**
* get the ID of the BuyerOrderReferencedDocument, which sits in the ApplicableSupplyChainTradeAgreement * get the ID of the BuyerOrderReferencedDocument, which sits in the
* ApplicableSupplyChainTradeAgreement
* *
* @return the ID of the document * @return the ID of the document
*/ */
@@ -416,7 +399,8 @@ public interface IExportableTransaction {
} }
/** /**
* get the ID of the preceding invoice, which is e.g. to be corrected if this is a correction * get the ID of the preceding invoice, which is e.g. to be corrected if this is
* a correction
* *
* @return the ID of the document * @return the ID of the document
*/ */
@@ -424,9 +408,13 @@ public interface IExportableTransaction {
return null; return null;
} }
default Date getInvoiceReferencedIssueDate(){return null;} default Date getInvoiceReferencedIssueDate() {
return null;
}
/** /**
* get the issue timestamp of the BuyerOrderReferencedDocument, which sits in the ApplicableSupplyChainTradeAgreement * get the issue timestamp of the BuyerOrderReferencedDocument, which sits in
* the ApplicableSupplyChainTradeAgreement
* *
* @return the IssueDateTime in format CCYY-MM-DDTHH:MM:SS * @return the IssueDateTime in format CCYY-MM-DDTHH:MM:SS
*/ */
@@ -434,19 +422,21 @@ public interface IExportableTransaction {
return null; return null;
} }
/** /**
* get the TotalPrepaidAmount located in SpecifiedTradeSettlementMonetarySummation (v1) or SpecifiedTradeSettlementHeaderMonetarySummation (v2) * get the TotalPrepaidAmount located in
* SpecifiedTradeSettlementMonetarySummation (v1) or
* SpecifiedTradeSettlementHeaderMonetarySummation (v2)
* *
* @return the total sum (incl. VAT) of prepayments, i.e. the difference between GrandTotalAmount and DuePayableAmount * @return the total sum (incl. VAT) of prepayments, i.e. the difference between
* GrandTotalAmount and DuePayableAmount
*/ */
default BigDecimal getTotalPrepaidAmount() { default BigDecimal getTotalPrepaidAmount() {
return BigDecimal.ZERO; return BigDecimal.ZERO;
} }
/*** /***
* delivery address, i.e. ram:ShipToTradeParty (only supported for zf2) * delivery address, i.e. ram:ShipToTradeParty (only supported for zf2)
*
* @return the IZUGFeRDExportableTradeParty delivery address * @return the IZUGFeRDExportableTradeParty delivery address
*/ */
@@ -454,9 +444,10 @@ public interface IExportableTransaction {
return null; return null;
} }
/*** /***
* specifies the document level delivery period, will be included in a BillingSpecifiedPeriod element * specifies the document level delivery period, will be included in a
* BillingSpecifiedPeriod element
*
* @return the beginning of the delivery period * @return the beginning of the delivery period
*/ */
default Date getDetailedDeliveryPeriodFrom() { default Date getDetailedDeliveryPeriodFrom() {
@@ -464,7 +455,9 @@ public interface IExportableTransaction {
} }
/*** /***
* specifies the document level delivery period, will be included in a BillingSpecifiedPeriod element * specifies the document level delivery period, will be included in a
* BillingSpecifiedPeriod element
*
* @return the end of the delivery period * @return the end of the delivery period
*/ */
default Date getDetailedDeliveryPeriodTo() { default Date getDetailedDeliveryPeriodTo() {
@@ -472,8 +465,9 @@ public interface IExportableTransaction {
} }
/** /**
* get additional referenced documents acccording to BG-24 XRechnung (Rechnungsbegruendende Unterlagen), * get additional referenced documents acccording to BG-24 XRechnung
* i.e. ram:ApplicableHeaderTradeAgreement/ram:AdditionalReferencedDocument * (Rechnungsbegruendende Unterlagen), i.e.
* ram:ApplicableHeaderTradeAgreement/ram:AdditionalReferencedDocument
* *
* @return a array of objects from class FileAttachment * @return a array of objects from class FileAttachment
*/ */
@@ -484,9 +478,12 @@ public interface IExportableTransaction {
default String getDespatchAdviceReferencedDocumentID() { default String getDespatchAdviceReferencedDocumentID() {
return null; return null;
} }
/*** /***
* additional text description * additional text description
* @return an array of strings of document wide "includedNotes" (descriptive text values) *
* @return an array of strings of document wide "includedNotes" (descriptive
* text values)
*/ */
default String[] getNotes() { default String[] getNotes() {
return null; return null;
@@ -499,4 +496,5 @@ public interface IExportableTransaction {
default String getSpecifiedProcuringProjectID() { default String getSpecifiedProcuringProjectID() {
return null; return null;
} }
} }

View File

@@ -76,6 +76,7 @@ public class ZUGFeRDImporter {
* parsed Document * parsed Document
*/ */
private Document document; private Document document;
private Integer version;
protected ZUGFeRDImporter() { protected ZUGFeRDImporter() {
@@ -193,6 +194,7 @@ public class ZUGFeRDImporter {
public void setRawXML(byte[] rawXML) throws IOException { public void setRawXML(byte[] rawXML) throws IOException {
this.rawXML = rawXML; this.rawXML = rawXML;
this.version = null;
try { try {
setDocument(); setDocument();
} catch (ParserConfigurationException | SAXException e) { } catch (ParserConfigurationException | SAXException e) {
@@ -656,15 +658,16 @@ public class ZUGFeRDImporter {
if (!containsMeta) { if (!containsMeta) {
throw new Exception("Not yet parsed"); throw new Exception("Not yet parsed");
} }
if (getUTF8().contains("<rsm:CrossIndustryDocument")) { String head = getUTF8();
if (head.contains("<rsm:CrossIndustryDocument")) {
return EStandard.zugferd; return EStandard.zugferd;
} else if (getUTF8().contains("<CrossIndustryDocument")) { } else if (head.contains("<CrossIndustryDocument")) {
return EStandard.zugferd; return EStandard.zugferd;
} else if (getUTF8().contains("<urn:rsm:CrossIndustryInvoice")) { } else if (head.contains("<urn:rsm:CrossIndustryInvoice") || head.contains("<rsm:CrossIndustryInvoice")) {
return EStandard.facturx; return EStandard.facturx;
} else if (getUTF8().contains("<SCRDMCCBDACIDAMessageStructure")) { } else if (head.contains("<SCRDMCCBDACIDAMessageStructure")) {
return EStandard.despatchadvice; return EStandard.despatchadvice;
} else if (getUTF8().contains("<rsm:SCRDMCCBDACIOMessageStructure")) { } else if (head.contains("<rsm:SCRDMCCBDACIOMessageStructure")) {
return EStandard.orderx; return EStandard.orderx;
} }
@@ -675,16 +678,21 @@ public class ZUGFeRDImporter {
if (!containsMeta) { if (!containsMeta) {
throw new Exception("Not yet parsed"); throw new Exception("Not yet parsed");
} }
if (version != null)
return version;
String head = getUTF8(); String head = getUTF8();
if (head.contains("<rsm:CrossIndustryDocument") // if (head.contains("<rsm:CrossIndustryDocument") //
|| head.contains("<CrossIndustryDocument") // || head.contains("<CrossIndustryDocument") //
|| head.contains("<SCRDMCCBDACIDAMessageStructure") // || head.contains("<SCRDMCCBDACIDAMessageStructure") //
|| head.contains("<rsm:SCRDMCCBDACIOMessageStructure")) { // || head.contains("<rsm:SCRDMCCBDACIOMessageStructure")) { //
return 1; version = 1;
} else if (head.contains("<rsm:CrossIndustryInvoice")) { } else if (head.contains("<rsm:CrossIndustryInvoice")) {
return 2; version = 2;
} }
else
throw new Exception("ZUGFeRD version could not be determined"); throw new Exception("ZUGFeRD version could not be determined");
return version;
} }

View File

@@ -1,13 +1,5 @@
package org.mustangproject.ZUGFeRD; package org.mustangproject.ZUGFeRD;
import org.apache.pdfbox.pdmodel.common.filespecification.PDEmbeddedFile;
import org.mustangproject.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import javax.xml.xpath.*;
import java.io.IOException; import java.io.IOException;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.RoundingMode; import java.math.RoundingMode;
@@ -17,6 +9,27 @@ import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpression;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
import org.mustangproject.Allowance;
import org.mustangproject.Charge;
import org.mustangproject.EStandard;
import org.mustangproject.Invoice;
import org.mustangproject.Item;
import org.mustangproject.Product;
import org.mustangproject.ReferencedDocument;
import org.mustangproject.SchemedID;
import org.mustangproject.TradeParty;
import org.mustangproject.XMLTools;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
public class ZUGFeRDInvoiceImporter extends ZUGFeRDImporter { public class ZUGFeRDInvoiceImporter extends ZUGFeRDImporter {
private static final Logger LOGGER = LoggerFactory.getLogger(ZUGFeRDInvoiceImporter.class.getCanonicalName()); // log private static final Logger LOGGER = LoggerFactory.getLogger(ZUGFeRDInvoiceImporter.class.getCanonicalName()); // log
private boolean recalcPrice = false; private boolean recalcPrice = false;
@@ -81,11 +94,12 @@ public class ZUGFeRDInvoiceImporter extends ZUGFeRDImporter {
Node exchangedDocumentNode = ExchangedDocumentNodes.item(i); Node exchangedDocumentNode = ExchangedDocumentNodes.item(i);
NodeList exchangedDocumentChilds = exchangedDocumentNode.getChildNodes(); NodeList exchangedDocumentChilds = exchangedDocumentNode.getChildNodes();
for (int documentChildIndex = 0; documentChildIndex < exchangedDocumentChilds.getLength(); documentChildIndex++) { for (int documentChildIndex = 0; documentChildIndex < exchangedDocumentChilds.getLength(); documentChildIndex++) {
if ((exchangedDocumentChilds.item(documentChildIndex).getLocalName() != null) && (exchangedDocumentChilds.item(documentChildIndex).getLocalName().equals("ID"))) { Node item = exchangedDocumentChilds.item(documentChildIndex);
number = exchangedDocumentChilds.item(documentChildIndex).getTextContent(); if ((item.getLocalName() != null) && (item.getLocalName().equals("ID"))) {
number = item.getTextContent();
} }
if ((exchangedDocumentChilds.item(documentChildIndex).getLocalName() != null) && (exchangedDocumentChilds.item(documentChildIndex).getLocalName().equals("IssueDateTime"))) { if ((item.getLocalName() != null) && (item.getLocalName().equals("IssueDateTime"))) {
NodeList issueDateTimeChilds = exchangedDocumentChilds.item(documentChildIndex).getChildNodes(); NodeList issueDateTimeChilds = item.getChildNodes();
for (int issueDateChildIndex = 0; issueDateChildIndex < issueDateTimeChilds.getLength(); issueDateChildIndex++) { for (int issueDateChildIndex = 0; issueDateChildIndex < issueDateTimeChilds.getLength(); issueDateChildIndex++) {
if ((issueDateTimeChilds.item(issueDateChildIndex).getLocalName() != null) && (issueDateTimeChilds.item(issueDateChildIndex).getLocalName().equals("DateTimeString"))) { if ((issueDateTimeChilds.item(issueDateChildIndex).getLocalName() != null) && (issueDateTimeChilds.item(issueDateChildIndex).getLocalName().equals("DateTimeString"))) {
issueDate = new SimpleDateFormat("yyyyMMdd").parse(issueDateTimeChilds.item(issueDateChildIndex).getTextContent()); issueDate = new SimpleDateFormat("yyyyMMdd").parse(issueDateTimeChilds.item(issueDateChildIndex).getTextContent());
@@ -173,7 +187,9 @@ public class ZUGFeRDInvoiceImporter extends ZUGFeRDImporter {
Node currentItemNode = nodes.item(i); Node currentItemNode = nodes.item(i);
NodeList itemChilds = currentItemNode.getChildNodes(); NodeList itemChilds = currentItemNode.getChildNodes();
for (int itemChildIndex = 0; itemChildIndex < itemChilds.getLength(); itemChildIndex++) { for (int itemChildIndex = 0; itemChildIndex < itemChilds.getLength(); itemChildIndex++) {
if ((itemChilds.item(itemChildIndex).getLocalName() != null) && (itemChilds.item(itemChildIndex).getLocalName().equals("SpecifiedLineTradeAgreement"))) { String lineTrade = itemChilds.item(itemChildIndex).getLocalName();
if ((lineTrade != null) && (lineTrade.equals("SpecifiedLineTradeAgreement")
|| lineTrade.equals("SpecifiedSupplyChainTradeAgreement"))) {
NodeList tradeLineChilds = itemChilds.item(itemChildIndex).getChildNodes(); NodeList tradeLineChilds = itemChilds.item(itemChildIndex).getChildNodes();
for (int tradeLineChildIndex = 0; tradeLineChildIndex < tradeLineChilds.getLength(); tradeLineChildIndex++) { for (int tradeLineChildIndex = 0; tradeLineChildIndex < tradeLineChilds.getLength(); tradeLineChildIndex++) {
@@ -184,13 +200,14 @@ public class ZUGFeRDInvoiceImporter extends ZUGFeRDImporter {
NodeList refDocChilds = tradeLineChilds.item(tradeLineChildIndex).getChildNodes(); NodeList refDocChilds = tradeLineChilds.item(tradeLineChildIndex).getChildNodes();
for (int refDocIndex = 0; refDocIndex < refDocChilds.getLength(); refDocIndex++) { for (int refDocIndex = 0; refDocIndex < refDocChilds.getLength(); refDocIndex++) {
if ((refDocChilds.item(refDocIndex).getLocalName() != null) && (refDocChilds.item(refDocIndex).getLocalName().equals("IssuerAssignedID"))) { String localName = refDocChilds.item(refDocIndex).getLocalName();
if ((localName != null) && (localName.equals("IssuerAssignedID"))) {
IssuerAssignedID = refDocChilds.item(refDocIndex).getTextContent(); IssuerAssignedID = refDocChilds.item(refDocIndex).getTextContent();
} }
if ((refDocChilds.item(refDocIndex).getLocalName() != null) && (refDocChilds.item(refDocIndex).getLocalName().equals("TypeCode"))) { if ((localName != null) && (localName.equals("TypeCode"))) {
TypeCode = refDocChilds.item(refDocIndex).getTextContent(); TypeCode = refDocChilds.item(refDocIndex).getTextContent();
} }
if ((refDocChilds.item(refDocIndex).getLocalName() != null) && (refDocChilds.item(refDocIndex).getLocalName().equals("ReferenceTypeCode"))) { if ((localName != null) && (localName.equals("ReferenceTypeCode"))) {
ReferenceTypeCode = refDocChilds.item(refDocIndex).getTextContent(); ReferenceTypeCode = refDocChilds.item(refDocIndex).getTextContent();
} }
} }
@@ -214,17 +231,21 @@ public class ZUGFeRDInvoiceImporter extends ZUGFeRDImporter {
} }
} }
} }
if ((itemChilds.item(itemChildIndex).getLocalName() != null) && (itemChilds.item(itemChildIndex).getLocalName().equals("SpecifiedLineTradeDelivery"))) { if ((lineTrade != null) && (lineTrade.equals("SpecifiedLineTradeDelivery")
|| lineTrade.equals("SpecifiedSupplyChainTradeDelivery"))) {
NodeList tradeLineChilds = itemChilds.item(itemChildIndex).getChildNodes(); NodeList tradeLineChilds = itemChilds.item(itemChildIndex).getChildNodes();
for (int tradeLineChildIndex = 0; tradeLineChildIndex < tradeLineChilds.getLength(); tradeLineChildIndex++) { for (int tradeLineChildIndex = 0; tradeLineChildIndex < tradeLineChilds.getLength(); tradeLineChildIndex++) {
if ((tradeLineChilds.item(tradeLineChildIndex).getLocalName() != null) && (tradeLineChilds.item(tradeLineChildIndex).getLocalName().equals("BilledQuantity") || tradeLineChilds.item(tradeLineChildIndex).getLocalName().equals("RequestedQuantity") || tradeLineChilds.item(tradeLineChildIndex).getLocalName().equals("DespatchedQuantity"))) { 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 //RequestedQuantity is for Order-X, BilledQuantity for FX and ZF
quantity = tradeLineChilds.item(tradeLineChildIndex).getTextContent(); quantity = tradeLineChilds.item(tradeLineChildIndex).getTextContent();
unitCode = tradeLineChilds.item(tradeLineChildIndex).getAttributes().getNamedItem("unitCode").getNodeValue(); unitCode = tradeLineChilds.item(tradeLineChildIndex).getAttributes().getNamedItem("unitCode").getNodeValue();
} }
} }
} }
if ((itemChilds.item(itemChildIndex).getLocalName() != null) && (itemChilds.item(itemChildIndex).getLocalName().equals("SpecifiedTradeProduct"))) { if ((lineTrade != null) && (lineTrade.equals("SpecifiedTradeProduct"))) {
NodeList tradeProductChilds = itemChilds.item(itemChildIndex).getChildNodes(); NodeList tradeProductChilds = itemChilds.item(itemChildIndex).getChildNodes();
for (int tradeProductChildIndex = 0; tradeProductChildIndex < tradeProductChilds.getLength(); tradeProductChildIndex++) { for (int tradeProductChildIndex = 0; tradeProductChildIndex < tradeProductChilds.getLength(); tradeProductChildIndex++) {
if ((tradeProductChilds.item(tradeProductChildIndex).getLocalName() != null) && (tradeProductChilds.item(tradeProductChildIndex).getLocalName().equals("Name"))) { if ((tradeProductChilds.item(tradeProductChildIndex).getLocalName() != null) && (tradeProductChilds.item(tradeProductChildIndex).getLocalName().equals("Name"))) {
@@ -238,21 +259,26 @@ public class ZUGFeRDInvoiceImporter extends ZUGFeRDImporter {
} }
} }
} }
if ((itemChilds.item(itemChildIndex).getLocalName() != null) && (itemChilds.item(itemChildIndex).getLocalName().equals("SpecifiedLineTradeSettlement"))) { if ((lineTrade != null) && (lineTrade.equals("SpecifiedLineTradeSettlement")
|| lineTrade.equals("SpecifiedSupplyChainTradeSettlement"))) {
NodeList tradeSettlementChilds = itemChilds.item(itemChildIndex).getChildNodes(); NodeList tradeSettlementChilds = itemChilds.item(itemChildIndex).getChildNodes();
for (int tradeSettlementChildIndex = 0; tradeSettlementChildIndex < tradeSettlementChilds.getLength(); tradeSettlementChildIndex++) { for (int tradeSettlementChildIndex = 0; tradeSettlementChildIndex < tradeSettlementChilds.getLength(); tradeSettlementChildIndex++) {
if (tradeSettlementChilds.item(tradeSettlementChildIndex).getLocalName() != null) { String tradeSettlementName = tradeSettlementChilds.item(tradeSettlementChildIndex)
if (tradeSettlementChilds.item(tradeSettlementChildIndex).getLocalName().equals("ApplicableTradeTax")) { .getLocalName();
if (tradeSettlementName != null) {
if (tradeSettlementName.equals("ApplicableTradeTax")) {
NodeList taxChilds = tradeSettlementChilds.item(tradeSettlementChildIndex).getChildNodes(); NodeList taxChilds = tradeSettlementChilds.item(tradeSettlementChildIndex).getChildNodes();
for (int taxChildIndex = 0; taxChildIndex < taxChilds.getLength(); taxChildIndex++) { for (int taxChildIndex = 0; taxChildIndex < taxChilds.getLength(); taxChildIndex++) {
if ((taxChilds.item(taxChildIndex).getLocalName() != null) && (taxChilds.item(taxChildIndex).getLocalName().equals("RateApplicablePercent"))) { String taxChildName = taxChilds.item(taxChildIndex).getLocalName();
if ((taxChildName != null) && (taxChildName.equals("RateApplicablePercent")
|| taxChildName.equals("ApplicablePercent"))) {
vatPercent = taxChilds.item(taxChildIndex).getTextContent(); vatPercent = taxChilds.item(taxChildIndex).getTextContent();
} }
} }
} }
if (tradeSettlementChilds.item(tradeSettlementChildIndex).getLocalName().equals("SpecifiedTradeSettlementLineMonetarySummation")) { if (tradeSettlementName.equals("SpecifiedTradeSettlementLineMonetarySummation")) {
NodeList totalChilds = tradeSettlementChilds.item(tradeSettlementChildIndex).getChildNodes(); NodeList totalChilds = tradeSettlementChilds.item(tradeSettlementChildIndex).getChildNodes();
for (int totalChildIndex = 0; totalChildIndex < totalChilds.getLength(); totalChildIndex++) { for (int totalChildIndex = 0; totalChildIndex < totalChilds.getLength(); totalChildIndex++) {
if ((totalChilds.item(totalChildIndex).getLocalName() != null) && (totalChilds.item(totalChildIndex).getLocalName().equals("LineTotalAmount"))) { if ((totalChilds.item(totalChildIndex).getLocalName() != null) && (totalChilds.item(totalChildIndex).getLocalName().equals("LineTotalAmount"))) {
@@ -297,20 +323,21 @@ public class ZUGFeRDInvoiceImporter extends ZUGFeRDImporter {
String reason = null; String reason = null;
String taxPercent = null; String taxPercent = null;
for (int chargeChildIndex = 0; chargeChildIndex < chargeNodeChilds.getLength(); chargeChildIndex++) { for (int chargeChildIndex = 0; chargeChildIndex < chargeNodeChilds.getLength(); chargeChildIndex++) {
if (chargeNodeChilds.item(chargeChildIndex).getLocalName() != null) { String chargeChildName = chargeNodeChilds.item(chargeChildIndex).getLocalName();
if (chargeChildName != null) {
if (chargeNodeChilds.item(chargeChildIndex).getLocalName().equals("ChargeIndicator")) { if (chargeChildName.equals("ChargeIndicator")) {
NodeList indicatorChilds = chargeNodeChilds.item(chargeChildIndex).getChildNodes(); NodeList indicatorChilds = chargeNodeChilds.item(chargeChildIndex).getChildNodes();
for (int indicatorChildIndex = 0; indicatorChildIndex < indicatorChilds.getLength(); indicatorChildIndex++) { for (int indicatorChildIndex = 0; indicatorChildIndex < indicatorChilds.getLength(); indicatorChildIndex++) {
if ((indicatorChilds.item(indicatorChildIndex).getLocalName() != null) && (indicatorChilds.item(indicatorChildIndex).getLocalName().equals("Indicator"))) { if ((indicatorChilds.item(indicatorChildIndex).getLocalName() != null) && (indicatorChilds.item(indicatorChildIndex).getLocalName().equals("Indicator"))) {
isCharge = indicatorChilds.item(indicatorChildIndex).getTextContent().equalsIgnoreCase("true"); isCharge = indicatorChilds.item(indicatorChildIndex).getTextContent().equalsIgnoreCase("true");
} }
} }
} else if (chargeNodeChilds.item(chargeChildIndex).getLocalName().equals("ActualAmount")) { } else if (chargeChildName.equals("ActualAmount")) {
chargeAmount = chargeNodeChilds.item(chargeChildIndex).getTextContent(); chargeAmount = chargeNodeChilds.item(chargeChildIndex).getTextContent();
} else if (chargeNodeChilds.item(chargeChildIndex).getLocalName().equals("Reason")) { } else if (chargeChildName.equals("Reason")) {
reason = chargeNodeChilds.item(chargeChildIndex).getTextContent(); reason = chargeNodeChilds.item(chargeChildIndex).getTextContent();
} else if (chargeNodeChilds.item(chargeChildIndex).getLocalName().equals("CategoryTradeTax")) { } else if (chargeChildName.equals("CategoryTradeTax")) {
NodeList taxChilds = chargeNodeChilds.item(chargeChildIndex).getChildNodes(); NodeList taxChilds = chargeNodeChilds.item(chargeChildIndex).getChildNodes();
for (int taxChildIndex = 0; taxChildIndex < taxChilds.getLength(); taxChildIndex++) { for (int taxChildIndex = 0; taxChildIndex < taxChilds.getLength(); taxChildIndex++) {
if ((taxChilds.item(taxChildIndex).getLocalName() != null) && (taxChilds.item(taxChildIndex).getLocalName().equals("RateApplicablePercent"))) { if ((taxChilds.item(taxChildIndex).getLocalName() != null) && (taxChilds.item(taxChildIndex).getLocalName().equals("RateApplicablePercent"))) {
@@ -347,6 +374,9 @@ public class ZUGFeRDInvoiceImporter extends ZUGFeRDImporter {
TransactionCalculator tc = new TransactionCalculator(zpp); TransactionCalculator tc = new TransactionCalculator(zpp);
String expectedStringTotalGross = tc.getGrandTotal().toPlainString(); String expectedStringTotalGross = tc.getGrandTotal().toPlainString();
zpp.setGrandTotalAmount(tc.getGrandTotal());
zpp.setTotalPrepaidAmount(tc.getTotalPrepaid());
zpp.setDuePayableAmount(tc.getGrandTotal().add(tc.getTotalPrepaid().negate()));
EStandard whichType; EStandard whichType;
try { try {
whichType = getStandard(); whichType = getStandard();