From d4b1bd0e3dd8ddf7733f4d1c2f5a29cbf92cb748 Mon Sep 17 00:00:00 2001 From: Pierre Barke Date: Mon, 12 Aug 2019 10:10:01 +0200 Subject: [PATCH] switched IZUGFeRDExportableContact to default-Methods; added ShipToTradeParty: if the merchandies is not shipped to the same address as stated in the invoide; added BuyerOrderReferencedDocument: the ID of the purchase order the invoice ist based on --- .../ZUGFeRD/IZUGFeRDExportableContact.java | 24 +++-- .../IZUGFeRDExportableTransaction.java | 75 +++++++++++++++- .../ZUGFeRDTransactionModelConverter.java | 87 +++++++++++++++++-- 3 files changed, 171 insertions(+), 15 deletions(-) diff --git a/src/main/java/org/mustangproject/ZUGFeRD/IZUGFeRDExportableContact.java b/src/main/java/org/mustangproject/ZUGFeRD/IZUGFeRDExportableContact.java index 125852c8..a1de8dd2 100644 --- a/src/main/java/org/mustangproject/ZUGFeRD/IZUGFeRDExportableContact.java +++ b/src/main/java/org/mustangproject/ZUGFeRD/IZUGFeRDExportableContact.java @@ -44,7 +44,9 @@ public interface IZUGFeRDExportableContact { * * @return First and last name of the recipient */ - String getName(); + default String getName() { + return null; + } /** @@ -52,7 +54,9 @@ public interface IZUGFeRDExportableContact { * * @return Postal code of the recipient */ - String getZIP(); + default String getZIP() { + return null; + } /** @@ -60,7 +64,9 @@ public interface IZUGFeRDExportableContact { * * @return VAT ID (Umsatzsteueridentifikationsnummer) of the contact */ - String getVATID(); + default String getVATID() { + return null; + } /** @@ -68,7 +74,9 @@ public interface IZUGFeRDExportableContact { * * @return two-letter iso country code of the contact */ - String getCountry(); + default String getCountry() { + return null; + } /** @@ -76,7 +84,9 @@ public interface IZUGFeRDExportableContact { * * @return Returns the city of the recipient */ - String getLocation(); + default String getLocation() { + return null; + } /** @@ -84,6 +94,8 @@ public interface IZUGFeRDExportableContact { * * @return street address (street+number) of the contact */ - String getStreet(); + default String getStreet() { + return null; + } } diff --git a/src/main/java/org/mustangproject/ZUGFeRD/IZUGFeRDExportableTransaction.java b/src/main/java/org/mustangproject/ZUGFeRD/IZUGFeRDExportableTransaction.java index 21b55190..fd1308ef 100644 --- a/src/main/java/org/mustangproject/ZUGFeRD/IZUGFeRDExportableTransaction.java +++ b/src/main/java/org/mustangproject/ZUGFeRD/IZUGFeRDExportableTransaction.java @@ -27,10 +27,10 @@ package org.mustangproject.ZUGFeRD; * */ -import org.mustangproject.ZUGFeRD.model.DocumentCodeTypeConstants; - import java.util.Date; +import org.mustangproject.ZUGFeRD.model.DocumentCodeTypeConstants; + public interface IZUGFeRDExportableTransaction { /** @@ -42,6 +42,7 @@ public interface IZUGFeRDExportableTransaction { return DocumentCodeTypeConstants.INVOICE; } + /** * Number, typically invoice number of the invoice * @@ -281,4 +282,74 @@ public interface IZUGFeRDExportableTransaction { return null; } + + /** + * get reference number of the purchase order this invoice is based on + * + * @return the ID of the purchase order this document refers to + */ + default String getOrderReferenceNumber() { + return null; + } + + + /** + * consignee identification (identification of the organisation the goods are shipped to [assigned by the costumer]) + * + * @return the sender's identification + */ + default String getShipToOrganisationID() { + return null; + } + + + /** + * consignee name (name of the organisation the goods are shipped to) + * + * @return the consignee's organisation name + */ + default String getShipToOrganisationName() { + return null; + } + + + /** + * consignee street address (street of the organisation the goods are shipped to) + * + * @return consignee street address + */ + default String getShipToStreet() { + return null; + } + + + /** + * consignee street postal code (postal code of the organisation the goods are shipped to) + * + * @return consignee postal code + */ + default String getShipToZIP() { + return null; + } + + + /** + * consignee city (city of the organisation the goods are shipped to) + * + * @return the consignee's city + */ + default String getShipToLocation() { + return null; + } + + + /** + * consignee two digit country code (country code of the organisation the goods are shipped to) + * + * @return the consignee's two character country iso code + */ + default String getShipToCountry() { + return null; + } + } diff --git a/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDTransactionModelConverter.java b/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDTransactionModelConverter.java index d7434eee..c9343a8e 100644 --- a/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDTransactionModelConverter.java +++ b/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDTransactionModelConverter.java @@ -39,7 +39,6 @@ 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; @@ -55,6 +54,7 @@ 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.ReferencedDocumentType; import org.mustangproject.ZUGFeRD.model.SupplyChainEventType; import org.mustangproject.ZUGFeRD.model.SupplyChainTradeAgreementType; import org.mustangproject.ZUGFeRD.model.SupplyChainTradeDeliveryType; @@ -62,7 +62,6 @@ 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; @@ -201,10 +200,29 @@ class ZUGFeRDTransactionModelConverter { tradeAgreement.setBuyerTradeParty(getBuyer()); tradeAgreement.setSellerTradeParty(getSeller()); + if (getBuyerOrderReferencedDocument() != null) { + tradeAgreement.getBuyerOrderReferencedDocument().add(getBuyerOrderReferencedDocument()); + } + return tradeAgreement; } + private ReferencedDocumentType getBuyerOrderReferencedDocument() { + if (trans.getOrderReferenceNumber() == null) { + return null; + } + + ReferencedDocumentType buyerOrderReferencedDocument = xmlFactory.createReferencedDocumentType(); + + IDType orderID = xmlFactory.createIDType(); + orderID.setValue(trans.getOrderReferenceNumber()); + buyerOrderReferencedDocument.getID().add(orderID); + + return buyerOrderReferencedDocument; + } + + private TradePartyType getBuyer() { TradePartyType buyerTradeParty = xmlFactory.createTradePartyType(); @@ -308,10 +326,62 @@ class ZUGFeRDTransactionModelConverter { } + /** + * If the ship-to party (e.g. in the case of international transactions) or, in the case of virtual goods, the recipient has to be shown separately on an + * invoice, then this is done by adding the ShipToTradeParty + */ + private TradePartyType getShipToParty() { + if (trans.getShipToOrganisationName() == null) { + return null; + } + + TradePartyType shipToParty = xmlFactory.createTradePartyType(); + + if (trans.getShipToOrganisationID() != null) { + IDType sellerID = xmlFactory.createIDType(); + sellerID.setValue(trans.getShipToOrganisationID()); + shipToParty.getID().add(sellerID); + } + + TextType shipToName = xmlFactory.createTextType(); + shipToName.setValue(trans.getShipToOrganisationName()); + shipToParty.setName(shipToName); + + if (trans.getShipToLocation() != null) { + TradeAddressType shipToAddressType = xmlFactory + .createTradeAddressType(); + TextType shipToCityName = xmlFactory.createTextType(); + shipToCityName.setValue(trans.getShipToLocation()); + shipToAddressType.setCityName(shipToCityName); + + CountryIDType shipToCountryId = xmlFactory.createCountryIDType(); + shipToCountryId.setValue(trans.getShipToCountry()); + shipToAddressType.setCountryID(shipToCountryId); + + TextType shipToAddress = xmlFactory.createTextType(); + shipToAddress.setValue(trans.getShipToStreet()); + shipToAddressType.setLineOne(shipToAddress); + + CodeType shipToPostcode = xmlFactory.createCodeType(); + shipToPostcode.setValue(trans.getShipToZIP()); + shipToAddressType.getPostcodeCode().add(shipToPostcode); + + shipToParty.setPostalTradeAddress(shipToAddressType); + } + + return shipToParty; + } + + private SupplyChainTradeDeliveryType getTradeDelivery() { SupplyChainTradeDeliveryType tradeDelivery = xmlFactory .createSupplyChainTradeDeliveryType(); + + if (getShipToParty() != null) { + tradeDelivery.setShipToTradeParty(getShipToParty()); + } + SupplyChainEventType deliveryEvent = xmlFactory .createSupplyChainEventType(); DateTimeType deliveryDate = xmlFactory.createDateTimeType(); @@ -916,7 +986,7 @@ class ZUGFeRDTransactionModelConverter { } - private HashMap getVATPercentAmountMap(Boolean itemOnly) { + private HashMap getVATPercentAmountMap(Boolean itemOnly) { HashMap hm = new HashMap<>(); for (IZUGFeRDExportableItem currentItem : trans.getZFItems()) { @@ -938,8 +1008,9 @@ class ZUGFeRDTransactionModelConverter { BigDecimal percent = headerAllowance.getTaxPercent(); VATAmount itemVATAmount = new VATAmount( headerAllowance.getTotalAmount(), headerAllowance - .getTotalAmount().multiply(percent) - .divide(new BigDecimal(100)), trans.getDocumentCode()); + .getTotalAmount().multiply(percent) + .divide(new BigDecimal(100)), + trans.getDocumentCode()); VATAmount current = hm.get(percent); if (current == null) { hm.put(percent, itemVATAmount); @@ -956,7 +1027,8 @@ class ZUGFeRDTransactionModelConverter { VATAmount itemVATAmount = new VATAmount( logisticsServiceCharge.getTotalAmount(), logisticsServiceCharge.getTotalAmount() - .multiply(percent).divide(new BigDecimal(100)), trans.getDocumentCode()); + .multiply(percent).divide(new BigDecimal(100)), + trans.getDocumentCode()); VATAmount current = hm.get(percent); if (current == null) { hm.put(percent, itemVATAmount); @@ -971,7 +1043,8 @@ class ZUGFeRDTransactionModelConverter { BigDecimal percent = charge.getTaxPercent(); VATAmount itemVATAmount = new VATAmount( charge.getTotalAmount(), charge.getTotalAmount() - .multiply(percent).divide(new BigDecimal(100)), trans.getDocumentCode()); + .multiply(percent).divide(new BigDecimal(100)), + trans.getDocumentCode()); VATAmount current = hm.get(percent); if (current == null) { hm.put(percent, itemVATAmount);