diff --git a/src/main/java/org/mustangproject/ZUGFeRD/IZUGFeRDExportableContact.java b/src/main/java/org/mustangproject/ZUGFeRD/IZUGFeRDExportableContact.java index f03d7e5a..125852c8 100644 --- a/src/main/java/org/mustangproject/ZUGFeRD/IZUGFeRDExportableContact.java +++ b/src/main/java/org/mustangproject/ZUGFeRD/IZUGFeRDExportableContact.java @@ -19,9 +19,7 @@ package org.mustangproject.ZUGFeRD; /** - * Mustangproject's ZUGFeRD implementation - * Neccessary interface for ZUGFeRD exporter - * Licensed under the APLv2 + * Mustangproject's ZUGFeRD implementation Neccessary interface for ZUGFeRD exporter Licensed under the APLv2 * * @author jstaerk * @version 1.2.0 @@ -31,6 +29,16 @@ package org.mustangproject.ZUGFeRD; public interface IZUGFeRDExportableContact { + /** + * customer identification assigned by the seller + * + * @return customer identification + */ + default String getID() { + return null; + } + + /** * First and last name of the recipient * @@ -38,6 +46,7 @@ public interface IZUGFeRDExportableContact { */ String getName(); + /** * Postal code of the recipient * @@ -45,6 +54,7 @@ public interface IZUGFeRDExportableContact { */ String getZIP(); + /** * VAT ID (Umsatzsteueridentifikationsnummer) of the contact * @@ -52,6 +62,7 @@ public interface IZUGFeRDExportableContact { */ String getVATID(); + /** * two-letter country code of the contact * @@ -59,6 +70,7 @@ public interface IZUGFeRDExportableContact { */ String getCountry(); + /** * Returns the city of the contact * @@ -66,6 +78,7 @@ public interface IZUGFeRDExportableContact { */ String getLocation(); + /** * Returns the street address (street+number) of the contact * diff --git a/src/main/java/org/mustangproject/ZUGFeRD/IZUGFeRDExportableTransaction.java b/src/main/java/org/mustangproject/ZUGFeRD/IZUGFeRDExportableTransaction.java index 1c4c4dbc..21b55190 100644 --- a/src/main/java/org/mustangproject/ZUGFeRD/IZUGFeRDExportableTransaction.java +++ b/src/main/java/org/mustangproject/ZUGFeRD/IZUGFeRDExportableTransaction.java @@ -47,46 +47,55 @@ public interface IZUGFeRDExportableTransaction { * * @return invoice number */ - String getNumber(); + default String getNumber() { + return null; + } + /** * the date when the invoice was created * * @return when the invoice was created */ - Date getIssueDate(); + default Date getIssueDate() { + 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. *
- * 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 */ - String getOwnOrganisationFullPlaintextInfo(); + default String getOwnOrganisationFullPlaintextInfo() { + return null; + } + /** * when the invoice is to be paid * * @return when the invoice is to be paid */ - Date getDueDate(); + default Date getDueDate() { + return null; + } + IZUGFeRDAllowanceCharge[] getZFAllowances(); + IZUGFeRDAllowanceCharge[] getZFCharges(); + IZUGFeRDAllowanceCharge[] getZFLogisticsServiceCharges(); + IZUGFeRDExportableItem[] getZFItems(); + /** * the recipient * @@ -94,89 +103,136 @@ public interface IZUGFeRDExportableTransaction { */ IZUGFeRDExportableContact getRecipient(); + /** * BIC of the sender * * @return the BIC code of the recipient sender's bank */ - String getOwnBIC(); + default String getOwnBIC() { + return null; + } + /** * BLZ of the sender * * @return the BLZ code of the recipient sender's bank */ - String getOwnBLZ(); + default String getOwnBLZ() { + return null; + } + /** * Bank name of the sender * * @return the name of the sender's bank */ - String getOwnBankName(); + default String getOwnBankName() { + return null; + } + /** * IBAN of the sender * * @return the IBAN of the invoice sender's bank account */ - String getOwnIBAN(); + default String getOwnIBAN() { + return null; + } + /** * IBAN of the sender * * @return the Account Number of the invoice sender's bank account */ - String getOwnKto(); + default String getOwnKto() { + return null; + } + /** * Tax ID (not VAT ID) of the sender * * @return Tax ID (not VAT ID) of the sender */ - String getOwnTaxID(); + default String getOwnTaxID() { + return null; + } + /** * VAT ID (Umsatzsteueridentifikationsnummer) of the sender * * @return VAT ID (Umsatzsteueridentifikationsnummer) of the sender */ - String getOwnVATID(); + default String getOwnVATID() { + return null; + } + + + /** + * supplier identification assigned by the costumer + * + * @return the sender's identification + */ + default String getOwnForeignOrganisationID() { + return null; + } + /** * own name * * @return the sender's organisation name */ - String getOwnOrganisationName(); + default String getOwnOrganisationName() { + return null; + } + /** * own street address * * @return sender street address */ - String getOwnStreet(); + default String getOwnStreet() { + return null; + } + /** * own street postal code * * @return sender postal code */ - String getOwnZIP(); + default String getOwnZIP() { + return null; + } + /** * own city * * @return the invoice sender's city */ - String getOwnLocation(); + default String getOwnLocation() { + return null; + } + /** * own two digit country code * * @return the invoice senders two character country iso code */ - String getOwnCountry(); + default String getOwnCountry() { + return null; + } + /** * get delivery date @@ -185,35 +241,44 @@ public interface IZUGFeRDExportableTransaction { */ Date getDeliveryDate(); + /** * get main invoice currency used on the invoice * * @return three character currency of this invoice */ - String getCurrency(); + default String getCurrency() { + return null; + } + /** * get payment information text. e.g. Bank transfer * * @return payment information text */ - String getOwnPaymentInfoText(); + default String getOwnPaymentInfoText() { + return null; + } + /** - * 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 * * @return get payment terms */ - String getPaymentTermDescription(); + default String getPaymentTermDescription() { + return null; + } + /** - * 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 */ - String getReferenceNumber(); + default String getReferenceNumber() { + return null; + } } diff --git a/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDTransactionModelConverter.java b/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDTransactionModelConverter.java index 8d087e8a..d7434eee 100644 --- a/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDTransactionModelConverter.java +++ b/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDTransactionModelConverter.java @@ -18,14 +18,65 @@ *********************************************************************** */ package org.mustangproject.ZUGFeRD; -import org.mustangproject.ZUGFeRD.model.*; - -import javax.xml.bind.JAXBElement; import java.math.BigDecimal; import java.text.DecimalFormat; import java.text.DecimalFormatSymbols; import java.text.SimpleDateFormat; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; + +import javax.xml.bind.JAXBElement; + +import org.mustangproject.ZUGFeRD.model.AmountType; +import org.mustangproject.ZUGFeRD.model.CodeType; +import org.mustangproject.ZUGFeRD.model.CountryIDType; +import org.mustangproject.ZUGFeRD.model.CreditorFinancialAccountType; +import org.mustangproject.ZUGFeRD.model.CreditorFinancialInstitutionType; +import org.mustangproject.ZUGFeRD.model.CrossIndustryDocumentType; +import org.mustangproject.ZUGFeRD.model.DateTimeType; +import org.mustangproject.ZUGFeRD.model.DateTimeTypeConstants; +import org.mustangproject.ZUGFeRD.model.DocumentCodeType; +import org.mustangproject.ZUGFeRD.model.DocumentCodeTypeConstants; +import org.mustangproject.ZUGFeRD.model.DocumentContextParameterType; +import org.mustangproject.ZUGFeRD.model.DocumentContextParameterTypeConstants; +import org.mustangproject.ZUGFeRD.model.DocumentLineDocumentType; +import org.mustangproject.ZUGFeRD.model.ExchangedDocumentContextType; +import org.mustangproject.ZUGFeRD.model.ExchangedDocumentType; +import org.mustangproject.ZUGFeRD.model.IDType; +import org.mustangproject.ZUGFeRD.model.IndicatorType; +import org.mustangproject.ZUGFeRD.model.LogisticsServiceChargeType; +import org.mustangproject.ZUGFeRD.model.NoteType; +import org.mustangproject.ZUGFeRD.model.NoteTypeConstants; +import org.mustangproject.ZUGFeRD.model.ObjectFactory; +import org.mustangproject.ZUGFeRD.model.PaymentMeansCodeType; +import org.mustangproject.ZUGFeRD.model.PaymentMeansCodeTypeConstants; +import org.mustangproject.ZUGFeRD.model.PercentType; +import org.mustangproject.ZUGFeRD.model.QuantityType; +import org.mustangproject.ZUGFeRD.model.SupplyChainEventType; +import org.mustangproject.ZUGFeRD.model.SupplyChainTradeAgreementType; +import org.mustangproject.ZUGFeRD.model.SupplyChainTradeDeliveryType; +import org.mustangproject.ZUGFeRD.model.SupplyChainTradeLineItemType; +import org.mustangproject.ZUGFeRD.model.SupplyChainTradeSettlementType; +import org.mustangproject.ZUGFeRD.model.SupplyChainTradeTransactionType; +import org.mustangproject.ZUGFeRD.model.TaxCategoryCodeType; +import org.mustangproject.ZUGFeRD.model.TaxCategoryCodeTypeConstants; +import org.mustangproject.ZUGFeRD.model.TaxRegistrationType; +import org.mustangproject.ZUGFeRD.model.TaxRegistrationTypeConstants; +import org.mustangproject.ZUGFeRD.model.TaxTypeCodeType; +import org.mustangproject.ZUGFeRD.model.TaxTypeCodeTypeConstants; +import org.mustangproject.ZUGFeRD.model.TextType; +import org.mustangproject.ZUGFeRD.model.TradeAddressType; +import org.mustangproject.ZUGFeRD.model.TradeAllowanceChargeType; +import org.mustangproject.ZUGFeRD.model.TradePartyType; +import org.mustangproject.ZUGFeRD.model.TradePaymentTermsType; +import org.mustangproject.ZUGFeRD.model.TradePriceType; +import org.mustangproject.ZUGFeRD.model.TradeProductType; +import org.mustangproject.ZUGFeRD.model.TradeSettlementMonetarySummationType; +import org.mustangproject.ZUGFeRD.model.TradeSettlementPaymentMeansType; +import org.mustangproject.ZUGFeRD.model.TradeTaxType; class ZUGFeRDTransactionModelConverter { private static final SimpleDateFormat zugferdDateFormat = new SimpleDateFormat("yyyyMMdd"); @@ -36,10 +87,11 @@ class ZUGFeRDTransactionModelConverter { private boolean isTest; private String currency = "EUR"; + ZUGFeRDTransactionModelConverter(IZUGFeRDExportableTransaction trans) { this.trans = trans; totals = new Totals(); - this.currency = trans.getCurrency() != null ? trans.getCurrency() : currency; + currency = trans.getCurrency() != null ? trans.getCurrency() : currency; } @@ -47,15 +99,15 @@ class ZUGFeRDTransactionModelConverter { CrossIndustryDocumentType invoice = xmlFactory .createCrossIndustryDocumentType(); - invoice.setSpecifiedExchangedDocumentContext(this.getDocumentContext()); - invoice.setHeaderExchangedDocument(this.getDocument()); - invoice.setSpecifiedSupplyChainTradeTransaction(this - .getTradeTransaction()); + invoice.setSpecifiedExchangedDocumentContext(getDocumentContext()); + invoice.setHeaderExchangedDocument(getDocument()); + invoice.setSpecifiedSupplyChainTradeTransaction(getTradeTransaction()); return xmlFactory .createCrossIndustryDocument(invoice); } + private ExchangedDocumentContextType getDocumentContext() { ExchangedDocumentContextType context = xmlFactory @@ -75,6 +127,7 @@ class ZUGFeRDTransactionModelConverter { return context; } + private ExchangedDocumentType getDocument() { ExchangedDocumentType document = xmlFactory @@ -124,36 +177,44 @@ class ZUGFeRDTransactionModelConverter { return document; } + private SupplyChainTradeTransactionType getTradeTransaction() { SupplyChainTradeTransactionType transaction = xmlFactory .createSupplyChainTradeTransactionType(); transaction.getApplicableSupplyChainTradeAgreement().add( - this.getTradeAgreement()); - transaction.setApplicableSupplyChainTradeDelivery(this - .getTradeDelivery()); - transaction.setApplicableSupplyChainTradeSettlement(this - .getTradeSettlement()); + getTradeAgreement()); + transaction.setApplicableSupplyChainTradeDelivery(getTradeDelivery()); + transaction.setApplicableSupplyChainTradeSettlement(getTradeSettlement()); transaction.getIncludedSupplyChainTradeLineItem().addAll( - this.getLineItems()); + getLineItems()); return transaction; } + private SupplyChainTradeAgreementType getTradeAgreement() { SupplyChainTradeAgreementType tradeAgreement = xmlFactory .createSupplyChainTradeAgreementType(); - tradeAgreement.setBuyerTradeParty(this.getBuyer()); - tradeAgreement.setSellerTradeParty(this.getSeller()); + tradeAgreement.setBuyerTradeParty(getBuyer()); + tradeAgreement.setSellerTradeParty(getSeller()); return tradeAgreement; } + private TradePartyType getBuyer() { TradePartyType buyerTradeParty = xmlFactory.createTradePartyType(); + + if (trans.getRecipient().getID() != null) { + IDType buyerID = xmlFactory.createIDType(); + buyerID.setValue(trans.getRecipient().getID()); + buyerTradeParty.getID().add(buyerID); + } + TextType buyerName = xmlFactory.createTextType(); buyerName.setValue(trans.getRecipient().getName()); buyerTradeParty.setName(buyerName); @@ -189,9 +250,17 @@ class ZUGFeRDTransactionModelConverter { return buyerTradeParty; } + private TradePartyType getSeller() { TradePartyType sellerTradeParty = xmlFactory.createTradePartyType(); + + if (trans.getOwnForeignOrganisationID() != null) { + IDType sellerID = xmlFactory.createIDType(); + sellerID.setValue(trans.getOwnForeignOrganisationID()); + sellerTradeParty.getID().add(sellerID); + } + TextType sellerName = xmlFactory.createTextType(); sellerName.setValue(trans.getOwnOrganisationName()); sellerTradeParty.setName(sellerName); @@ -238,6 +307,7 @@ class ZUGFeRDTransactionModelConverter { return sellerTradeParty; } + private SupplyChainTradeDeliveryType getTradeDelivery() { SupplyChainTradeDeliveryType tradeDelivery = xmlFactory @@ -257,6 +327,7 @@ class ZUGFeRDTransactionModelConverter { return tradeDelivery; } + private SupplyChainTradeSettlementType getTradeSettlement() { SupplyChainTradeSettlementType tradeSettlement = xmlFactory .createSupplyChainTradeSettlementType(); @@ -270,29 +341,29 @@ class ZUGFeRDTransactionModelConverter { tradeSettlement.setInvoiceCurrencyCode(currencyCode); tradeSettlement.getSpecifiedTradeSettlementPaymentMeans().add( - this.getPaymentData()); - tradeSettlement.getApplicableTradeTax().addAll(this.getTradeTax()); + getPaymentData()); + tradeSettlement.getApplicableTradeTax().addAll(getTradeTax()); tradeSettlement.getSpecifiedTradePaymentTerms().addAll( - this.getPaymentTerms()); + getPaymentTerms()); if (trans.getZFAllowances() != null) { tradeSettlement.getSpecifiedTradeAllowanceCharge().addAll( - this.getHeaderAllowances()); + getHeaderAllowances()); } if (trans.getZFLogisticsServiceCharges() != null) { tradeSettlement.getSpecifiedLogisticsServiceCharge().addAll( - this.getHeaderLogisticsServiceCharges()); + getHeaderLogisticsServiceCharges()); } if (trans.getZFCharges() != null) { tradeSettlement.getSpecifiedTradeAllowanceCharge().addAll( - this.getHeaderCharges()); + getHeaderCharges()); } - tradeSettlement.setSpecifiedTradeSettlementMonetarySummation(this - .getMonetarySummation()); + tradeSettlement.setSpecifiedTradeSettlementMonetarySummation(getMonetarySummation()); return tradeSettlement; } + private TradeSettlementPaymentMeansType getPaymentData() { TradeSettlementPaymentMeansType paymentData = xmlFactory .createTradeSettlementPaymentMeansType(); @@ -335,6 +406,7 @@ class ZUGFeRDTransactionModelConverter { return paymentData; } + private Collection