QMT-1461: Rechnungseingang - ZUGFeRD-Rechnungen importieren
This commit is contained in:
@@ -20,15 +20,21 @@
|
||||
*/
|
||||
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.util.ArrayList;
|
||||
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
|
||||
* @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 Date issueDate = null, dueDate = null, deliveryDate = null;
|
||||
protected BigDecimal totalPrepaidAmount = null;
|
||||
protected BigDecimal grandTotalAmount = null;
|
||||
protected BigDecimal duePayableAmount = null;
|
||||
protected TradeParty sender = null, recipient = null, deliveryAddress = null;
|
||||
@JsonDeserialize(contentAs=Item.class)
|
||||
protected ArrayList<IZUGFeRDExportableItem> ZFItems = null;
|
||||
@@ -433,6 +441,24 @@ public class Invoice implements IExportableTransaction {
|
||||
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
|
||||
public IZUGFeRDExportableTradeParty getSender() {
|
||||
return sender;
|
||||
@@ -445,6 +471,7 @@ public class Invoice implements IExportableTransaction {
|
||||
* @param ownContact the sender contact
|
||||
* @return fluent setter
|
||||
*/
|
||||
@Deprecated
|
||||
public Invoice setOwnContact(Contact ownContact) {
|
||||
this.sender.setContact(ownContact);
|
||||
return this;
|
||||
@@ -689,4 +716,5 @@ public class Invoice implements IExportableTransaction {
|
||||
this.specifiedProcuringProjectName = specifiedProcuringProjectName;
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
*
|
||||
*********************************************************************** */
|
||||
package org.mustangproject.ZUGFeRD;
|
||||
|
||||
/**
|
||||
* Mustangproject's ZUGFeRD implementation
|
||||
* Neccessary interface for ZUGFeRD exporter
|
||||
@@ -26,7 +27,6 @@ package org.mustangproject.ZUGFeRD;
|
||||
* @author jstaerk
|
||||
* */
|
||||
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
|
||||
@@ -34,11 +34,12 @@ import org.mustangproject.FileAttachment;
|
||||
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)
|
||||
* for
|
||||
* the interface of an transaction, e.g. an invoice, you want to create xml
|
||||
* (potentially to be added to a PDF) for
|
||||
*
|
||||
* @see org.mustangproject.Invoice
|
||||
*/
|
||||
public interface IExportableTransaction {
|
||||
public interface IExportableTransaction {
|
||||
|
||||
/**
|
||||
* appears in /rsm:CrossIndustryDocument/rsm:HeaderExchangedDocument/ram:Name
|
||||
@@ -49,7 +50,6 @@ public interface IExportableTransaction {
|
||||
return "RECHNUNG";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
@@ -59,7 +59,6 @@ public interface IExportableTransaction {
|
||||
return DocumentCodeTypeConstants.INVOICE;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Number, typically invoice number of the invoice
|
||||
*
|
||||
@@ -69,7 +68,6 @@ public interface IExportableTransaction {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* the date when the invoice was created
|
||||
*
|
||||
@@ -79,19 +77,20 @@ public interface IExportableTransaction {
|
||||
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>
|
||||
* 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() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* when the invoice is to be paid
|
||||
*
|
||||
@@ -105,7 +104,6 @@ public interface IExportableTransaction {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* the sender of the invoice
|
||||
*
|
||||
@@ -115,10 +113,8 @@ public interface IExportableTransaction {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* subject of the document e.g. invoice and order
|
||||
* number as human readable text
|
||||
* subject of the document e.g. invoice and order number as human readable text
|
||||
*
|
||||
* @return string with document subject
|
||||
*/
|
||||
@@ -130,20 +126,16 @@ public interface IExportableTransaction {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
default IZUGFeRDAllowanceCharge[] getZFCharges() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
default IZUGFeRDAllowanceCharge[] getZFLogisticsServiceCharges() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
IZUGFeRDExportableItem[] getZFItems();
|
||||
|
||||
|
||||
/**
|
||||
* the recipient
|
||||
*
|
||||
@@ -151,9 +143,9 @@ public interface IExportableTransaction {
|
||||
*/
|
||||
IZUGFeRDExportableTradeParty getRecipient();
|
||||
|
||||
|
||||
/**
|
||||
* the creditors payment informations
|
||||
*
|
||||
* @deprecated use getTradeSettlement
|
||||
* @return an array of IZUGFeRDTradeSettlementPayment
|
||||
*/
|
||||
@@ -161,6 +153,7 @@ public interface IExportableTransaction {
|
||||
default IZUGFeRDTradeSettlementPayment[] getTradeSettlementPayment() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* the payment information for any payment means
|
||||
*
|
||||
@@ -170,35 +163,32 @@ public interface IExportableTransaction {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Tax ID (not VAT ID) of the sender
|
||||
*
|
||||
* @return Tax ID (not VAT ID) of the sender
|
||||
*/
|
||||
default String getOwnTaxID() {
|
||||
if (getSender()!=null) {
|
||||
if (getSender() != null) {
|
||||
return getSender().getTaxID();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* VAT ID (Umsatzsteueridentifikationsnummer) of the sender
|
||||
*
|
||||
* @return VAT ID (Umsatzsteueridentifikationsnummer) of the sender
|
||||
*/
|
||||
default String getOwnVATID() {
|
||||
if (getSender()!=null) {
|
||||
if (getSender() != null) {
|
||||
return getSender().getVATID();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* supplier identification assigned by the costumer
|
||||
*
|
||||
@@ -208,42 +198,39 @@ public interface IExportableTransaction {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* own name
|
||||
*
|
||||
* @return the sender's organisation name
|
||||
*/
|
||||
default String getOwnOrganisationName() {
|
||||
if (getSender()!=null) {
|
||||
if (getSender() != null) {
|
||||
return getSender().getName();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* own street address
|
||||
*
|
||||
* @return sender street address
|
||||
*/
|
||||
default String getOwnStreet() {
|
||||
if (getSender()!=null) {
|
||||
if (getSender() != null) {
|
||||
return getSender().getStreet();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* own street postal code
|
||||
*
|
||||
* @return sender postal code
|
||||
*/
|
||||
default String getOwnZIP() {
|
||||
if (getSender()!=null) {
|
||||
if (getSender() != null) {
|
||||
return getSender().getZIP();
|
||||
} else {
|
||||
return null;
|
||||
@@ -251,14 +238,13 @@ public interface IExportableTransaction {
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* own city
|
||||
*
|
||||
* @return the invoice sender's city
|
||||
*/
|
||||
default String getOwnLocation() {
|
||||
if (getSender()!=null) {
|
||||
if (getSender() != null) {
|
||||
return getSender().getLocation();
|
||||
} else {
|
||||
return null;
|
||||
@@ -266,14 +252,13 @@ public interface IExportableTransaction {
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* own two digit country code
|
||||
*
|
||||
* @return the invoice senders two character country iso code
|
||||
*/
|
||||
default String getOwnCountry() {
|
||||
if (getSender()!=null) {
|
||||
if (getSender() != null) {
|
||||
return getSender().getCountry();
|
||||
} else {
|
||||
return null;
|
||||
@@ -281,7 +266,6 @@ public interface IExportableTransaction {
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get delivery date
|
||||
*
|
||||
@@ -289,7 +273,6 @@ public interface IExportableTransaction {
|
||||
*/
|
||||
Date getDeliveryDate();
|
||||
|
||||
|
||||
/**
|
||||
* get main invoice currency used on the invoice
|
||||
*
|
||||
@@ -299,7 +282,6 @@ public interface IExportableTransaction {
|
||||
return "EUR";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
@@ -337,9 +320,9 @@ public interface IExportableTransaction {
|
||||
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
|
||||
*/
|
||||
@@ -347,7 +330,6 @@ public interface IExportableTransaction {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* consignee name (name of the organisation the goods are shipped to)
|
||||
*
|
||||
@@ -357,9 +339,9 @@ public interface IExportableTransaction {
|
||||
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
|
||||
*/
|
||||
@@ -367,9 +349,9 @@ public interface IExportableTransaction {
|
||||
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
|
||||
*/
|
||||
@@ -377,7 +359,6 @@ public interface IExportableTransaction {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* consignee city (city of the organisation the goods are shipped to)
|
||||
*
|
||||
@@ -387,9 +368,9 @@ public interface IExportableTransaction {
|
||||
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
|
||||
*/
|
||||
@@ -397,17 +378,19 @@ public interface IExportableTransaction {
|
||||
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
|
||||
*/
|
||||
default String getSellerOrderReferencedDocumentID() {
|
||||
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
|
||||
*/
|
||||
@@ -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
|
||||
*/
|
||||
@@ -424,9 +408,13 @@ public interface IExportableTransaction {
|
||||
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
|
||||
*/
|
||||
@@ -434,19 +422,21 @@ public interface IExportableTransaction {
|
||||
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() {
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
|
||||
|
||||
/***
|
||||
* delivery address, i.e. ram:ShipToTradeParty (only supported for zf2)
|
||||
*
|
||||
* @return the IZUGFeRDExportableTradeParty delivery address
|
||||
*/
|
||||
|
||||
@@ -454,9 +444,10 @@ public interface IExportableTransaction {
|
||||
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
|
||||
*/
|
||||
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
|
||||
*/
|
||||
default Date getDetailedDeliveryPeriodTo() {
|
||||
@@ -472,8 +465,9 @@ public interface IExportableTransaction {
|
||||
}
|
||||
|
||||
/**
|
||||
* get additional referenced documents acccording to BG-24 XRechnung (Rechnungsbegruendende Unterlagen),
|
||||
* i.e. ram:ApplicableHeaderTradeAgreement/ram:AdditionalReferencedDocument
|
||||
* get additional referenced documents acccording to BG-24 XRechnung
|
||||
* (Rechnungsbegruendende Unterlagen), i.e.
|
||||
* ram:ApplicableHeaderTradeAgreement/ram:AdditionalReferencedDocument
|
||||
*
|
||||
* @return a array of objects from class FileAttachment
|
||||
*/
|
||||
@@ -484,19 +478,23 @@ public interface IExportableTransaction {
|
||||
default String getDespatchAdviceReferencedDocumentID() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/***
|
||||
* 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() {
|
||||
return null;
|
||||
}
|
||||
|
||||
default String getSpecifiedProcuringProjectName(){
|
||||
default String getSpecifiedProcuringProjectName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
default String getSpecifiedProcuringProjectID(){
|
||||
default String getSpecifiedProcuringProjectID() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -76,6 +76,7 @@ public class ZUGFeRDImporter {
|
||||
* parsed Document
|
||||
*/
|
||||
private Document document;
|
||||
private Integer version;
|
||||
|
||||
|
||||
protected ZUGFeRDImporter() {
|
||||
@@ -193,6 +194,7 @@ public class ZUGFeRDImporter {
|
||||
|
||||
public void setRawXML(byte[] rawXML) throws IOException {
|
||||
this.rawXML = rawXML;
|
||||
this.version = null;
|
||||
try {
|
||||
setDocument();
|
||||
} catch (ParserConfigurationException | SAXException e) {
|
||||
@@ -656,15 +658,16 @@ public class ZUGFeRDImporter {
|
||||
if (!containsMeta) {
|
||||
throw new Exception("Not yet parsed");
|
||||
}
|
||||
if (getUTF8().contains("<rsm:CrossIndustryDocument")) {
|
||||
String head = getUTF8();
|
||||
if (head.contains("<rsm:CrossIndustryDocument")) {
|
||||
return EStandard.zugferd;
|
||||
} else if (getUTF8().contains("<CrossIndustryDocument")) {
|
||||
} else if (head.contains("<CrossIndustryDocument")) {
|
||||
return EStandard.zugferd;
|
||||
} else if (getUTF8().contains("<urn:rsm:CrossIndustryInvoice")) {
|
||||
} else if (head.contains("<urn:rsm:CrossIndustryInvoice") || head.contains("<rsm:CrossIndustryInvoice")) {
|
||||
return EStandard.facturx;
|
||||
} else if (getUTF8().contains("<SCRDMCCBDACIDAMessageStructure")) {
|
||||
} else if (head.contains("<SCRDMCCBDACIDAMessageStructure")) {
|
||||
return EStandard.despatchadvice;
|
||||
} else if (getUTF8().contains("<rsm:SCRDMCCBDACIOMessageStructure")) {
|
||||
} else if (head.contains("<rsm:SCRDMCCBDACIOMessageStructure")) {
|
||||
return EStandard.orderx;
|
||||
}
|
||||
|
||||
@@ -675,16 +678,21 @@ public class ZUGFeRDImporter {
|
||||
if (!containsMeta) {
|
||||
throw new Exception("Not yet parsed");
|
||||
}
|
||||
if (version != null)
|
||||
return version;
|
||||
|
||||
String head = getUTF8();
|
||||
if (head.contains("<rsm:CrossIndustryDocument") //
|
||||
|| head.contains("<CrossIndustryDocument") //
|
||||
|| head.contains("<SCRDMCCBDACIDAMessageStructure") //
|
||||
|| head.contains("<rsm:SCRDMCCBDACIOMessageStructure")) { //
|
||||
return 1;
|
||||
version = 1;
|
||||
} else if (head.contains("<rsm:CrossIndustryInvoice")) {
|
||||
return 2;
|
||||
version = 2;
|
||||
}
|
||||
throw new Exception("ZUGFeRD version could not be determined");
|
||||
else
|
||||
throw new Exception("ZUGFeRD version could not be determined");
|
||||
return version;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,13 +1,5 @@
|
||||
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.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
@@ -17,6 +9,27 @@ import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
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 {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(ZUGFeRDInvoiceImporter.class.getCanonicalName()); // log
|
||||
private boolean recalcPrice = false;
|
||||
@@ -81,11 +94,12 @@ public class ZUGFeRDInvoiceImporter extends ZUGFeRDImporter {
|
||||
Node exchangedDocumentNode = ExchangedDocumentNodes.item(i);
|
||||
NodeList exchangedDocumentChilds = exchangedDocumentNode.getChildNodes();
|
||||
for (int documentChildIndex = 0; documentChildIndex < exchangedDocumentChilds.getLength(); documentChildIndex++) {
|
||||
if ((exchangedDocumentChilds.item(documentChildIndex).getLocalName() != null) && (exchangedDocumentChilds.item(documentChildIndex).getLocalName().equals("ID"))) {
|
||||
number = exchangedDocumentChilds.item(documentChildIndex).getTextContent();
|
||||
Node item = exchangedDocumentChilds.item(documentChildIndex);
|
||||
if ((item.getLocalName() != null) && (item.getLocalName().equals("ID"))) {
|
||||
number = item.getTextContent();
|
||||
}
|
||||
if ((exchangedDocumentChilds.item(documentChildIndex).getLocalName() != null) && (exchangedDocumentChilds.item(documentChildIndex).getLocalName().equals("IssueDateTime"))) {
|
||||
NodeList issueDateTimeChilds = exchangedDocumentChilds.item(documentChildIndex).getChildNodes();
|
||||
if ((item.getLocalName() != null) && (item.getLocalName().equals("IssueDateTime"))) {
|
||||
NodeList issueDateTimeChilds = item.getChildNodes();
|
||||
for (int issueDateChildIndex = 0; issueDateChildIndex < issueDateTimeChilds.getLength(); issueDateChildIndex++) {
|
||||
if ((issueDateTimeChilds.item(issueDateChildIndex).getLocalName() != null) && (issueDateTimeChilds.item(issueDateChildIndex).getLocalName().equals("DateTimeString"))) {
|
||||
issueDate = new SimpleDateFormat("yyyyMMdd").parse(issueDateTimeChilds.item(issueDateChildIndex).getTextContent());
|
||||
@@ -173,7 +187,9 @@ public class ZUGFeRDInvoiceImporter extends ZUGFeRDImporter {
|
||||
Node currentItemNode = nodes.item(i);
|
||||
NodeList itemChilds = currentItemNode.getChildNodes();
|
||||
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();
|
||||
for (int tradeLineChildIndex = 0; tradeLineChildIndex < tradeLineChilds.getLength(); tradeLineChildIndex++) {
|
||||
|
||||
@@ -184,13 +200,14 @@ public class ZUGFeRDInvoiceImporter extends ZUGFeRDImporter {
|
||||
|
||||
NodeList refDocChilds = tradeLineChilds.item(tradeLineChildIndex).getChildNodes();
|
||||
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();
|
||||
}
|
||||
if ((refDocChilds.item(refDocIndex).getLocalName() != null) && (refDocChilds.item(refDocIndex).getLocalName().equals("TypeCode"))) {
|
||||
if ((localName != null) && (localName.equals("TypeCode"))) {
|
||||
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();
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
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
|
||||
quantity = tradeLineChilds.item(tradeLineChildIndex).getTextContent();
|
||||
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();
|
||||
for (int tradeProductChildIndex = 0; tradeProductChildIndex < tradeProductChilds.getLength(); tradeProductChildIndex++) {
|
||||
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();
|
||||
for (int tradeSettlementChildIndex = 0; tradeSettlementChildIndex < tradeSettlementChilds.getLength(); tradeSettlementChildIndex++) {
|
||||
|
||||
if (tradeSettlementChilds.item(tradeSettlementChildIndex).getLocalName() != null) {
|
||||
if (tradeSettlementChilds.item(tradeSettlementChildIndex).getLocalName().equals("ApplicableTradeTax")) {
|
||||
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++) {
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (tradeSettlementChilds.item(tradeSettlementChildIndex).getLocalName().equals("SpecifiedTradeSettlementLineMonetarySummation")) {
|
||||
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"))) {
|
||||
@@ -297,20 +323,21 @@ public class ZUGFeRDInvoiceImporter extends ZUGFeRDImporter {
|
||||
String reason = null;
|
||||
String taxPercent = null;
|
||||
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();
|
||||
for (int indicatorChildIndex = 0; indicatorChildIndex < indicatorChilds.getLength(); indicatorChildIndex++) {
|
||||
if ((indicatorChilds.item(indicatorChildIndex).getLocalName() != null) && (indicatorChilds.item(indicatorChildIndex).getLocalName().equals("Indicator"))) {
|
||||
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();
|
||||
} else if (chargeNodeChilds.item(chargeChildIndex).getLocalName().equals("Reason")) {
|
||||
} else if (chargeChildName.equals("Reason")) {
|
||||
reason = chargeNodeChilds.item(chargeChildIndex).getTextContent();
|
||||
} else if (chargeNodeChilds.item(chargeChildIndex).getLocalName().equals("CategoryTradeTax")) {
|
||||
} else if (chargeChildName.equals("CategoryTradeTax")) {
|
||||
NodeList taxChilds = chargeNodeChilds.item(chargeChildIndex).getChildNodes();
|
||||
for (int taxChildIndex = 0; taxChildIndex < taxChilds.getLength(); taxChildIndex++) {
|
||||
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);
|
||||
String expectedStringTotalGross = tc.getGrandTotal().toPlainString();
|
||||
zpp.setGrandTotalAmount(tc.getGrandTotal());
|
||||
zpp.setTotalPrepaidAmount(tc.getTotalPrepaid());
|
||||
zpp.setDuePayableAmount(tc.getGrandTotal().add(tc.getTotalPrepaid().negate()));
|
||||
EStandard whichType;
|
||||
try {
|
||||
whichType = getStandard();
|
||||
|
||||
Reference in New Issue
Block a user