Merge remote-tracking branch 'remotes/origin/master' into master

This commit is contained in:
Sebastian Sieber
2020-11-23 08:17:17 +01:00
17 changed files with 234 additions and 96 deletions

View File

@@ -6,7 +6,7 @@ import org.mustangproject.ZUGFeRD.IZUGFeRDTradeSettlementPayment;
* provides e.g. the IBAN to transfer money to :-)
*/
public class BankDetails implements IZUGFeRDTradeSettlementPayment {
protected String IBAN, BIC;
protected String IBAN, BIC, accountName=null;
public BankDetails(String IBAN, String BIC) {
this.IBAN = IBAN;
@@ -34,6 +34,11 @@ public class BankDetails implements IZUGFeRDTradeSettlementPayment {
return BIC;
}
/***
* The bank identifier. Bank name is no longer neccessary in SEPA.
* @param BIC the bic code
* @return fluent setter
*/
public BankDetails setBIC(String BIC) {
this.BIC = BIC;
return this;
@@ -55,6 +60,21 @@ public class BankDetails implements IZUGFeRDTradeSettlementPayment {
}
/**
* set Holder
* @param name account name (usually account holder if != sender)
* @return fluent setter
*/
public BankDetails setAccountName(String name) {
accountName=name;
return this;
}
@Override
public String getAccountName() {
return accountName;
}
}

View File

@@ -5,12 +5,14 @@ import org.mustangproject.ZUGFeRD.IZUGFeRDExportableItem;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
/***
* describes any invoice line
*/
public class Item implements IZUGFeRDExportableItem {
protected BigDecimal price, quantity, tax, grossPrice, lineTotalAmount;
protected Date detailedDeliveryPeriodFrom=null, detailedDeliveryPeriodTo=null;
protected String id;
protected Product product;
protected ArrayList<String> notes = null;
@@ -58,6 +60,7 @@ public class Item implements IZUGFeRDExportableItem {
return this;
}
public BigDecimal getTax() {
return tax;
}
@@ -135,11 +138,23 @@ public class Item implements IZUGFeRDExportableItem {
}
/***
* Adds a item level addition to the price (will be multiplied by quantity)
* @see org.mustangproject.Charge
* @param izac a relative or absolute charge
* @return fluent setter
*/
public Item addCharge(IZUGFeRDAllowanceCharge izac) {
Charges.add(izac);
return this;
}
/***
* Adds a item level reduction the price (will be multiplied by quantity)
* @see org.mustangproject.Allowance
* @param izac a relative or absolute allowance
* @return fluent setter
*/
public Item addAllowance(IZUGFeRDAllowanceCharge izac) {
Allowances.add(izac);
return this;
@@ -158,5 +173,37 @@ public class Item implements IZUGFeRDExportableItem {
return this;
}
/***
* specify a item level delivery period
* (apart from the document level delivery period, and the document level
* delivery day, which is probably anyway required)
*
* @param from start date
* @param to end date
* @return fluent setter
*/
public Item setDetailedDeliveryPeriod(Date from, Date to) {
detailedDeliveryPeriodFrom=from;
detailedDeliveryPeriodTo=to;
return this;
}
/***
* specifies the item level delivery period (there is also one on document level),
* this will be included in a BillingSpecifiedPeriod element
* @return the beginning of the delivery period
*/
public Date getDetailedDeliveryPeriodFrom() {
return detailedDeliveryPeriodFrom;
}
/***
* specifies the item level delivery period (there is also one on document level),
* this will be included in a BillingSpecifiedPeriod element
* @return the end of the delivery period
*/
public Date getDetailedDeliveryPeriodTo() {
return detailedDeliveryPeriodTo;
}
}

View File

@@ -27,6 +27,7 @@ package org.mustangproject.ZUGFeRD;
* */
import java.math.BigDecimal;
import java.util.Date;
public interface IZUGFeRDExportableItem extends IAbsoluteValueProvider{
@@ -88,4 +89,24 @@ public interface IZUGFeRDExportableItem extends IAbsoluteValueProvider{
return null;
}
/***
* specifies the item level delivery period (there is also one on document level),
* this will be included in a BillingSpecifiedPeriod element
* @return the beginning of the delivery period
*/
default Date getDetailedDeliveryPeriodFrom() {
return null;
}
/***
* specifies the item level delivery period (there is also one on document level),
* this will be included in a BillingSpecifiedPeriod element
* @return the end of the delivery period
*/
default Date getDetailedDeliveryPeriodTo() {
return null;
}
}

View File

@@ -1,21 +1,23 @@
/** **********************************************************************
*
/**
* *********************************************************************
* <p>
* Copyright 2018 Jochen Staerk
*
* <p>
* Use is subject to license terms.
*
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0.
*
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
* <p>
* See the License for the specific language governing permissions and
* limitations under the License.
*
*********************************************************************** */
* <p>
* **********************************************************************
*/
package org.mustangproject.ZUGFeRD;
import java.math.BigDecimal;
@@ -78,7 +80,7 @@ public interface IZUGFeRDExportableProduct {
/**
* Get the ID that had been assigned by the seller to
* identify the product
*
*
* @return seller assigned product ID
*/
default String getSellerAssignedID() {
@@ -88,33 +90,34 @@ public interface IZUGFeRDExportableProduct {
/**
* Get the ID that had been assigned by the buyer to
* identify the product
*
*
* @return buyer assigned product ID
*/
default String getBuyerAssignedID() {
return null;
}
/**
* VAT percent of the product (e.g. 19, or 5.1 if you like)
*
* @return VAT percent of the product
*/
BigDecimal getVATPercent();
default boolean isIntraCommunitySupply() {
return false;
}
default String getTaxCategoryCode() {
if (getVATPercent().equals(new BigDecimal(0))) {
if (isIntraCommunitySupply()) {
return "K";
} else if (getVATPercent().equals(new BigDecimal(0))) {
return "Z"; // zero rated goods
} else if (isIntraCommunitySupply()) {
return "K";
} else {
return "S"; // one of the "standard" rates (not neccessarily a default rate, even a deducted VAT is standard calculation)
}
}
} else {
return "S"; // one of the "standard" rates (not neccessarily a default rate, even a deducted VAT is standard calculation)
}
}
default String getTaxExemptionReason() {
if (isIntraCommunitySupply())
return "Intra-community supply";

View File

@@ -52,14 +52,28 @@ public interface IZUGFeRDTradeSettlementPayment extends IZUGFeRDTradeSettlement
return null;
}
/***
* Account name
*
* @return the name of the account holder (if not identical to sender)
*/
default String getAccountName() { return null; }
default String getSettlementXML() {
String accountNameStr="";
if (getAccountName()!=null) {
accountNameStr="<ram:AccountName>" + XMLTools.encodeXML(getAccountName()) + "</ram:AccountName>\n"; //$NON-NLS-2$
}
String xml = " <ram:SpecifiedTradeSettlementPaymentMeans>\n"
+ " <ram:TypeCode>42</ram:TypeCode>\n"
+ " <ram:Information>Überweisung</ram:Information>\n"
+ " <ram:Information>Bank transfer</ram:Information>\n"
+ " <ram:PayeePartyCreditorFinancialAccount>\n"
+ " <ram:IBANID>" + XMLTools.encodeXML(getOwnIBAN()) + "</ram:IBANID>\n"; //$NON-NLS-2$
xml+= " </ram:PayeePartyCreditorFinancialAccount>\n"
xml+= accountNameStr;
xml+= " </ram:PayeePartyCreditorFinancialAccount>\n"
+ " <ram:PayeeSpecifiedCreditorFinancialInstitution>\n"
+ " <ram:BICID>" + XMLTools.encodeXML(getOwnBIC()) + "</ram:BICID>\n" //$NON-NLS-2$
// + " <ram:Name>"+trans.getOwnBankName()+"</ram:Name>\n"

View File

@@ -33,7 +33,7 @@ public class Profiles {
{"BASIC", new Profile("BASIC", "urn:cen.eu:en16931:2017#compliant#urn:factur-x.eu:1p0:basic")},
{"EN16931", new Profile("EN16931", "urn:cen.eu:en16931:2017")},
{"EXTENDED", new Profile("EXTENDED", "urn:cen.eu:en16931:2017#conformant#urn:factur-x.eu:1p0:extended")},
{"XRECHNUNG", new Profile("XRECHNUNG", "urn:cen.eu:en16931:2017#compliant#urn:xoev-de:kosit:standard:xrechnung_2.0")}
{"XRECHNUNG", new Profile("XRECHNUNG", "urn:cen.eu:en16931:2017#compliant#urn:xoev-de:kosit:standard:xrechnung_1.2")}
}).collect(Collectors.toMap(data -> (String) data[0], data -> (Profile) data[1]));
static Map<String, Profile> zf1Map = Stream.of(new Object[][]{

View File

@@ -107,6 +107,7 @@ public class ZUGFeRD2PullProvider implements IXMLProvider {
}
// @todo check if the two boolean args can be refactored
/***
* returns the UN/CEFACT CII XML for companies(tradeparties), which is actually
* the same for ZF1 (v 2013b) and ZF2 (v 2016b)
@@ -127,7 +128,7 @@ public class ZUGFeRD2PullProvider implements IXMLProvider {
}
xml += " <ram:Name>" + XMLTools.encodeXML(party.getName()) + "</ram:Name>\n"; //$NON-NLS-2$
if ((party.getContact() != null)&&(isSender||profile==Profiles.getByName("Extended"))) {
if ((party.getContact() != null) && (isSender || profile == Profiles.getByName("Extended"))) {
xml = xml + "<ram:DefinedTradeContact>\n" + " <ram:PersonName>" + XMLTools.encodeXML(party.getContact().getName())
+ "</ram:PersonName>\n";
if (party.getContact().getPhone() != null) {
@@ -137,8 +138,7 @@ public class ZUGFeRD2PullProvider implements IXMLProvider {
+ " </ram:TelephoneUniversalCommunication>\n";
}
if (party.getContact().getFax() != null) {
if ((party.getContact().getFax() != null) && (profile == Profiles.getByName("Extended"))) {
xml = xml + " <ram:FaxUniversalCommunication>\n" + " <ram:CompleteNumber>"
+ XMLTools.encodeXML(party.getContact().getFax()) + "</ram:CompleteNumber>\n"
+ " </ram:FaxUniversalCommunication>\n";
@@ -167,13 +167,13 @@ public class ZUGFeRD2PullProvider implements IXMLProvider {
+ " <ram:CountryID>" + XMLTools.encodeXML(party.getCountry())
+ "</ram:CountryID>\n"
+ " </ram:PostalTradeAddress>\n";
if ((party.getVATID() != null)&&(!isShipToTradeParty)) {
if ((party.getVATID() != null) && (!isShipToTradeParty)) {
xml += " <ram:SpecifiedTaxRegistration>\n"
+ " <ram:ID schemeID=\"VA\">" + XMLTools.encodeXML(party.getVATID())
+ "</ram:ID>\n"
+ " </ram:SpecifiedTaxRegistration>\n";
}
if ((party.getTaxID() != null)&&(!isShipToTradeParty)) {
if ((party.getTaxID() != null) && (!isShipToTradeParty)) {
xml += " <ram:SpecifiedTaxRegistration>\n"
+ " <ram:ID schemeID=\"FC\">" + XMLTools.encodeXML(party.getTaxID())
+ "</ram:ID>\n"
@@ -194,7 +194,7 @@ public class ZUGFeRD2PullProvider implements IXMLProvider {
protected String getAllowanceChargeStr(IZUGFeRDAllowanceCharge allowance, IAbsoluteValueProvider item) {
String percentage = "";
String chargeIndicator = "false";
if ((allowance.getPercent() != null)&&(profile==Profiles.getByName("Extended"))) {
if ((allowance.getPercent() != null) && (profile == Profiles.getByName("Extended"))) {
percentage = "<ram:CalculationPercent>" + vatFormat(allowance.getPercent()) + "</ram:CalculationPercent>";
percentage += "<ram:BasisAmount>" + item.getValue() + "</ram:BasisAmount>";
}
@@ -202,15 +202,15 @@ public class ZUGFeRD2PullProvider implements IXMLProvider {
chargeIndicator = "true";
}
String reason="";
if ((allowance.getReason()!=null)&&(profile==Profiles.getByName("Extended"))) {
String reason = "";
if ((allowance.getReason() != null) && (profile == Profiles.getByName("Extended"))) {
// only in extended profile
reason="<ram:Reason>"+XMLTools.encodeXML(allowance.getReason())+"</ram:Reason>";
reason = "<ram:Reason>" + XMLTools.encodeXML(allowance.getReason()) + "</ram:Reason>";
}
String allowanceChargeStr = "<ram:AppliedTradeAllowanceCharge><ram:ChargeIndicator><udt:Indicator>" +
chargeIndicator + "</udt:Indicator></ram:ChargeIndicator>" + percentage +
"<ram:ActualAmount>" + priceFormat(allowance.getTotalAmount(item)) + "</ram:ActualAmount>" +
reason+
reason +
"</ram:AppliedTradeAllowanceCharge>";
return allowanceChargeStr;
}
@@ -229,7 +229,7 @@ public class ZUGFeRD2PullProvider implements IXMLProvider {
paymentTermsDescription = trans.getPaymentTermDescription();
}
if ((paymentTermsDescription == null)&&(trans.getDocumentCode()!= org.mustangproject.ZUGFeRD.model.DocumentCodeTypeConstants.CORRECTEDINVOICE)) {
if ((paymentTermsDescription == null) && (trans.getDocumentCode() != org.mustangproject.ZUGFeRD.model.DocumentCodeTypeConstants.CORRECTEDINVOICE)) {
paymentTermsDescription = "Zahlbar ohne Abzug bis " + germanDateFormat.format(trans.getDueDate());
}
@@ -379,8 +379,20 @@ public class ZUGFeRD2PullProvider implements IXMLProvider {
+ " <ram:RateApplicablePercent>"
+ vatFormat(currentItem.getProduct().getVATPercent()) + "</ram:RateApplicablePercent>\n"
+ " </ram:ApplicableTradeTax>\n"
+ " <ram:SpecifiedTradeSettlementLineMonetarySummation>\n"
+ " </ram:ApplicableTradeTax>\n";
if ((currentItem.getDetailedDeliveryPeriodFrom() != null) || (currentItem.getDetailedDeliveryPeriodTo() != null)) {
xml = xml + "<ram:BillingSpecifiedPeriod>";
if (currentItem.getDetailedDeliveryPeriodFrom() != null) {
xml = xml + "<ram:StartDateTime><udt:DateTimeString format='102'>" + zugferdDateFormat.format(currentItem.getDetailedDeliveryPeriodFrom()) + "</udt:DateTimeString></ram:StartDateTime>";
}
if (currentItem.getDetailedDeliveryPeriodTo() != null) {
xml = xml + "<ram:EndDateTime><udt:DateTimeString format='102'>" + zugferdDateFormat.format(currentItem.getDetailedDeliveryPeriodTo()) + "</udt:DateTimeString></ram:EndDateTime>";
}
xml = xml + "</ram:BillingSpecifiedPeriod>";
}
xml = xml + " <ram:SpecifiedTradeSettlementLineMonetarySummation>\n"
+ " <ram:LineTotalAmount>" + currencyFormat(lc.getItemTotalNetAmount())
+ "</ram:LineTotalAmount>\n" // currencyID=\"EUR\"
+ " </ram:SpecifiedTradeSettlementLineMonetarySummation>\n";
@@ -430,7 +442,7 @@ public class ZUGFeRD2PullProvider implements IXMLProvider {
+ " <ram:TypeCode>916</ram:TypeCode>\n"
+ " <ram:Name>" + f.getDescription() + "</ram:Name>\n"
+ " <ram:AttachmentBinaryObject mimeCode=\"" + f.getMimetype() + "\"\n"
+ " filename=\"" + f.getFilename() + ">" + documentContent + "\n"
+ " filename=\"" + f.getFilename() + "\">" + documentContent + "\n"
+ " </ram:AdditionalReferencedDocument>\n";
}
}
@@ -482,8 +494,8 @@ public class ZUGFeRD2PullProvider implements IXMLProvider {
}
}
}
if (trans.getDocumentCode()== DocumentCodeTypeConstants.CORRECTEDINVOICE) {
hasDueDate=false;
if (trans.getDocumentCode() == DocumentCodeTypeConstants.CORRECTEDINVOICE) {
hasDueDate = false;
}
HashMap<BigDecimal, VATAmount> VATPercentAmountMap = calc.getVATPercentAmountMap();
@@ -518,7 +530,7 @@ public class ZUGFeRD2PullProvider implements IXMLProvider {
if ((trans.getZFCharges() != null) && (trans.getZFCharges().length > 0)) {
for (BigDecimal currentTaxPercent : VATPercentAmountMap.keySet()) {
if (calc.getChargesForPercent(currentTaxPercent).compareTo(BigDecimal.ZERO)!=0) {
if (calc.getChargesForPercent(currentTaxPercent).compareTo(BigDecimal.ZERO) != 0) {
xml = xml + " <ram:SpecifiedTradeAllowanceCharge>\n" +
@@ -526,7 +538,7 @@ public class ZUGFeRD2PullProvider implements IXMLProvider {
" <udt:Indicator>true</udt:Indicator>\n" +
" </ram:ChargeIndicator>\n" +
" <ram:ActualAmount>" + currencyFormat(calc.getChargesForPercent(currentTaxPercent)) + "</ram:ActualAmount>\n" +
" <ram:Reason>"+XMLTools.encodeXML(calc.getChargeReasonForPercent(currentTaxPercent))+"</ram:Reason>\n" +
" <ram:Reason>" + XMLTools.encodeXML(calc.getChargeReasonForPercent(currentTaxPercent)) + "</ram:Reason>\n" +
" <ram:CategoryTradeTax>\n" +
" <ram:TypeCode>VAT</ram:TypeCode>\n" +
" <ram:CategoryCode>" + VATPercentAmountMap.get(currentTaxPercent).getCategoryCode() + "</ram:CategoryCode>\n" +
@@ -541,13 +553,13 @@ public class ZUGFeRD2PullProvider implements IXMLProvider {
if ((trans.getZFAllowances() != null) && (trans.getZFAllowances().length > 0)) {
for (BigDecimal currentTaxPercent : VATPercentAmountMap.keySet()) {
if (calc.getAllowancesForPercent(currentTaxPercent).compareTo(BigDecimal.ZERO)!= 0) {
if (calc.getAllowancesForPercent(currentTaxPercent).compareTo(BigDecimal.ZERO) != 0) {
xml = xml + " <ram:SpecifiedTradeAllowanceCharge>\n" +
" <ram:ChargeIndicator>\n" +
" <udt:Indicator>false</udt:Indicator>\n" +
" </ram:ChargeIndicator>\n" +
" <ram:ActualAmount>" + currencyFormat(calc.getAllowancesForPercent(currentTaxPercent)) + "</ram:ActualAmount>\n" +
" <ram:Reason>"+XMLTools.encodeXML(calc.getAllowanceReasonForPercent(currentTaxPercent))+"</ram:Reason>\n" +
" <ram:Reason>" + XMLTools.encodeXML(calc.getAllowanceReasonForPercent(currentTaxPercent)) + "</ram:Reason>\n" +
" <ram:CategoryTradeTax>\n" +
" <ram:TypeCode>VAT</ram:TypeCode>\n" +
" <ram:CategoryCode>" + VATPercentAmountMap.get(currentTaxPercent).getCategoryCode() + "</ram:CategoryCode>\n" +
@@ -621,7 +633,7 @@ public class ZUGFeRD2PullProvider implements IXMLProvider {
try {
zugferdRaw = xml.getBytes("UTF-8");
zugferdData=XMLTools.removeBOM(zugferdRaw);
zugferdData = XMLTools.removeBOM(zugferdRaw);
} catch (UnsupportedEncodingException e) {
Logger.getLogger(ZUGFeRD2PullProvider.class.getName()).log(Level.SEVERE, null, e);
}