Enhance Charges/Allowances with reasonCode.

This commit is contained in:
langfr
2024-07-30 15:37:57 +01:00
parent 5da63fe80f
commit 77ddc7627d
5 changed files with 178 additions and 69 deletions

View File

@@ -26,6 +26,10 @@ public class Charge implements IZUGFeRDAllowanceCharge {
* a simple human readable description * a simple human readable description
*/ */
protected String reason; protected String reason;
/**
* Code from list UNTDID 5189
*/
protected String reasonCode;
/** /**
* the category ID why this charge has been applied * the category ID why this charge has been applied
*/ */
@@ -94,6 +98,22 @@ public class Charge implements IZUGFeRDAllowanceCharge {
} }
@Override
public String getReasonCode() {
return reasonCode;
}
/***
* Reason code for the charge
* @param reasonCode from list UNTDID 5189
* @return fluid setter
*/
public Charge setReasonCode(String reasonCode) {
this.reasonCode = reasonCode;
return this;
}
@Override @Override
public BigDecimal getTotalAmount(IAbsoluteValueProvider currentItem) { public BigDecimal getTotalAmount(IAbsoluteValueProvider currentItem) {
if (totalAmount!=null) { if (totalAmount!=null) {
@@ -137,7 +157,7 @@ public class Charge implements IZUGFeRDAllowanceCharge {
/*** /***
* machine readable reason for this allowance/charge * the category ID why this has been applied
* @param categoryCode usually S * @param categoryCode usually S
* @return fluid setter * @return fluid setter
*/ */

View File

@@ -44,6 +44,12 @@ public interface IZUGFeRDAllowanceCharge {
*/ */
String getReason(); String getReason();
/***
* get the code for the allowance/charge
* @return the code
*/
String getReasonCode();
/*** /***
* get the applicable tax percentage for the allowance/charge * get the applicable tax percentage for the allowance/charge
* @return the percentage * @return the percentage

View File

@@ -244,10 +244,16 @@ public class ZUGFeRD2PullProvider implements IXMLProvider {
// only in extended profile // only in extended profile
reason = "<ram:Reason>" + XMLTools.encodeXML(allowance.getReason()) + "</ram:Reason>"; reason = "<ram:Reason>" + XMLTools.encodeXML(allowance.getReason()) + "</ram:Reason>";
} }
String reasonCode = "";
if ((allowance.getReasonCode() != null) && (profile == Profiles.getByName("XRechnung"))) {
// only in XRechnung profile
reasonCode = "<ram:ReasonCode>" + allowance.getReasonCode() + "</ram:ReasonCode>";
}
final String allowanceChargeStr = "<ram:AppliedTradeAllowanceCharge><ram:ChargeIndicator><udt:Indicator>" + final String allowanceChargeStr = "<ram:AppliedTradeAllowanceCharge><ram:ChargeIndicator><udt:Indicator>" +
chargeIndicator + "</udt:Indicator></ram:ChargeIndicator>" + percentage + chargeIndicator + "</udt:Indicator></ram:ChargeIndicator>" + percentage +
"<ram:ActualAmount>" + priceFormat(allowance.getTotalAmount(item)) + "</ram:ActualAmount>" + "<ram:ActualAmount>" + priceFormat(allowance.getTotalAmount(item)) + "</ram:ActualAmount>" +
reason + reason +
reasonCode +
"</ram:AppliedTradeAllowanceCharge>"; "</ram:AppliedTradeAllowanceCharge>";
return allowanceChargeStr; return allowanceChargeStr;
} }
@@ -269,10 +275,21 @@ public class ZUGFeRD2PullProvider implements IXMLProvider {
chargeIndicator = "true"; chargeIndicator = "true";
} }
String reason = "";
if ((allowance.getReason() != null) && (profile == Profiles.getByName("Extended"))) {
// only in extended profile
reason = "<ram:Reason>" + XMLTools.encodeXML(allowance.getReason()) + "</ram:Reason>";
}
String reasonCode = "";
if ((allowance.getReasonCode() != null) && (profile == Profiles.getByName("XRechnung"))) {
// only in XRechnung profile
reasonCode = "<ram:ReasonCode>" + allowance.getReasonCode() + "</ram:ReasonCode>";
}
final String itemTotalAllowanceChargeStr = "<ram:SpecifiedTradeAllowanceCharge><ram:ChargeIndicator><udt:Indicator>" + final String itemTotalAllowanceChargeStr = "<ram:SpecifiedTradeAllowanceCharge><ram:ChargeIndicator><udt:Indicator>" +
chargeIndicator + "</udt:Indicator></ram:ChargeIndicator>" + percentage + chargeIndicator + "</udt:Indicator></ram:ChargeIndicator>" + percentage +
"<ram:ActualAmount>" + currencyFormat(allowance.getTotalAmount(item)) + "</ram:ActualAmount>" + "<ram:ActualAmount>" + currencyFormat(allowance.getTotalAmount(item)) + "</ram:ActualAmount>" +
"<ram:Reason>" + XMLTools.encodeXML(allowance.getReason()) + "</ram:Reason>" + reason +
reasonCode +
"</ram:SpecifiedTradeAllowanceCharge>"; "</ram:SpecifiedTradeAllowanceCharge>";
return itemTotalAllowanceChargeStr; return itemTotalAllowanceChargeStr;
} }
@@ -645,7 +662,29 @@ public class ZUGFeRD2PullProvider implements IXMLProvider {
} }
if ((trans.getZFCharges() != null) && (trans.getZFCharges().length > 0)) { if ((trans.getZFCharges() != null) && (trans.getZFCharges().length > 0)) {
if (profile == Profiles.getByName("XRechnung")) {
for(IZUGFeRDAllowanceCharge charge : trans.getZFCharges()) {
xml += "<ram:SpecifiedTradeAllowanceCharge>" +
"<ram:ChargeIndicator>" +
"<udt:Indicator>true</udt:Indicator>" +
"</ram:ChargeIndicator>" +
"<ram:ActualAmount>" + currencyFormat(charge.getTotalAmount(calc)) + "</ram:ActualAmount>";
if (charge.getReason() != null) {
xml += "<ram:Reason>" + XMLTools.encodeXML(charge.getReason()) + "</ram:Reason>";
}
if (charge.getReasonCode() != null) {
xml += "<ram:ReasonCode>" + charge.getReasonCode() + "</ram:ReasonCode>";
}
xml += "<ram:CategoryTradeTax>" +
"<ram:TypeCode>VAT</ram:TypeCode>" +
"<ram:CategoryCode>" + charge.getCategoryCode() + "</ram:CategoryCode>";
if (charge.getTaxPercent() != null) {
xml += "<ram:RateApplicablePercent>" + vatFormat(charge.getTaxPercent()) + "</ram:RateApplicablePercent>";
}
xml += "</ram:CategoryTradeTax>" +
"</ram:SpecifiedTradeAllowanceCharge>";
}
} else {
for (final BigDecimal currentTaxPercent : VATPercentAmountMap.keySet()) { for (final BigDecimal currentTaxPercent : VATPercentAmountMap.keySet()) {
if (calc.getChargesForPercent(currentTaxPercent).compareTo(BigDecimal.ZERO) != 0) { if (calc.getChargesForPercent(currentTaxPercent).compareTo(BigDecimal.ZERO) != 0) {
xml += "<ram:SpecifiedTradeAllowanceCharge>" + xml += "<ram:SpecifiedTradeAllowanceCharge>" +
@@ -663,8 +702,32 @@ public class ZUGFeRD2PullProvider implements IXMLProvider {
} }
} }
} }
}
if ((trans.getZFAllowances() != null) && (trans.getZFAllowances().length > 0)) { if ((trans.getZFAllowances() != null) && (trans.getZFAllowances().length > 0)) {
if (profile == Profiles.getByName("XRechnung")) {
for(IZUGFeRDAllowanceCharge allowance : trans.getZFAllowances()) {
xml += "<ram:SpecifiedTradeAllowanceCharge>" +
"<ram:ChargeIndicator>" +
"<udt:Indicator>false</udt:Indicator>" +
"</ram:ChargeIndicator>" +
"<ram:ActualAmount>" + currencyFormat(allowance.getTotalAmount(calc)) + "</ram:ActualAmount>";
if (allowance.getReason() != null) {
xml += "<ram:Reason>" + XMLTools.encodeXML(allowance.getReason()) + "</ram:Reason>";
}
if (allowance.getReasonCode() != null) {
xml += "<ram:ReasonCode>" + allowance.getReasonCode() + "</ram:ReasonCode>";
}
xml += "<ram:CategoryTradeTax>" +
"<ram:TypeCode>VAT</ram:TypeCode>" +
"<ram:CategoryCode>" + allowance.getCategoryCode() + "</ram:CategoryCode>";
if (allowance.getTaxPercent() != null) {
xml += "<ram:RateApplicablePercent>" + vatFormat(allowance.getTaxPercent()) + "</ram:RateApplicablePercent>";
}
xml += "</ram:CategoryTradeTax>" +
"</ram:SpecifiedTradeAllowanceCharge>";
}
} else {
for (final BigDecimal currentTaxPercent : VATPercentAmountMap.keySet()) { for (final BigDecimal currentTaxPercent : VATPercentAmountMap.keySet()) {
if (calc.getAllowancesForPercent(currentTaxPercent).compareTo(BigDecimal.ZERO) != 0) { if (calc.getAllowancesForPercent(currentTaxPercent).compareTo(BigDecimal.ZERO) != 0) {
xml += "<ram:SpecifiedTradeAllowanceCharge>" + xml += "<ram:SpecifiedTradeAllowanceCharge>" +
@@ -682,6 +745,7 @@ public class ZUGFeRD2PullProvider implements IXMLProvider {
} }
} }
} }
}
if ((trans.getPaymentTerms() == null) && (getProfile() != Profiles.getByName("Minimum")) && ((paymentTermsDescription != null) || (trans.getTradeSettlement() != null) || (hasDueDate))) { if ((trans.getPaymentTerms() == null) && (getProfile() != Profiles.getByName("Minimum")) && ((paymentTermsDescription != null) || (trans.getTradeSettlement() != null) || (hasDueDate))) {

View File

@@ -357,6 +357,7 @@ public class ZUGFeRDInvoiceImporter extends ZUGFeRDImporter {
boolean isCharge = true; boolean isCharge = true;
String chargeAmount = null; String chargeAmount = null;
String reason = null; String reason = null;
String reasonCode = null;
String taxPercent = null; String taxPercent = null;
for (int chargeChildIndex = 0; chargeChildIndex < chargeNodeChilds.getLength(); chargeChildIndex++) { for (int chargeChildIndex = 0; chargeChildIndex < chargeNodeChilds.getLength(); chargeChildIndex++) {
String chargeChildName = chargeNodeChilds.item(chargeChildIndex).getLocalName(); String chargeChildName = chargeNodeChilds.item(chargeChildIndex).getLocalName();
@@ -377,6 +378,8 @@ public class ZUGFeRDInvoiceImporter extends ZUGFeRDImporter {
chargeAmount = chargeNodeChilds.item(chargeChildIndex).getTextContent(); chargeAmount = chargeNodeChilds.item(chargeChildIndex).getTextContent();
} else if (chargeChildName.equals("Reason")) { } else if (chargeChildName.equals("Reason")) {
reason = chargeNodeChilds.item(chargeChildIndex).getTextContent(); reason = chargeNodeChilds.item(chargeChildIndex).getTextContent();
} else if (chargeChildName.equals("ReasonCode")) {
reasonCode = chargeNodeChilds.item(chargeChildIndex).getTextContent();
} else if (chargeChildName.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++) {
@@ -395,16 +398,21 @@ public class ZUGFeRDInvoiceImporter extends ZUGFeRDImporter {
if (reason != null) { if (reason != null) {
c.setReason(reason); c.setReason(reason);
} }
if (reasonCode != null) {
c.setReasonCode(reasonCode);
}
if (taxPercent != null) { if (taxPercent != null) {
c.setTaxPercent(new BigDecimal(taxPercent)); c.setTaxPercent(new BigDecimal(taxPercent));
} }
zpp.addCharge(c); zpp.addCharge(c);
} else { } else {
Allowance a = new Allowance(new BigDecimal(chargeAmount)); Allowance a = new Allowance(new BigDecimal(chargeAmount));
if (reason != null) { if (reason != null) {
a.setReason(reason); a.setReason(reason);
} }
if (reasonCode != null) {
a.setReasonCode(reasonCode);
}
if (taxPercent != null) { if (taxPercent != null) {
a.setTaxPercent(new BigDecimal(taxPercent)); a.setTaxPercent(new BigDecimal(taxPercent));
} }

View File

@@ -23,6 +23,7 @@ import java.math.BigDecimal;
public class IZUGFeRDAllowanceChargeImpl implements IZUGFeRDAllowanceCharge { public class IZUGFeRDAllowanceChargeImpl implements IZUGFeRDAllowanceCharge {
private BigDecimal totalAmount; private BigDecimal totalAmount;
private String reason; private String reason;
private String reasonCode;
private BigDecimal taxPercent; private BigDecimal taxPercent;
boolean isCharge=true; boolean isCharge=true;
@@ -36,6 +37,11 @@ public class IZUGFeRDAllowanceChargeImpl implements IZUGFeRDAllowanceCharge {
return reason; return reason;
} }
@Override
public String getReasonCode() {
return reasonCode;
}
@Override @Override
public BigDecimal getTaxPercent() { public BigDecimal getTaxPercent() {
return taxPercent; return taxPercent;
@@ -61,6 +67,11 @@ public class IZUGFeRDAllowanceChargeImpl implements IZUGFeRDAllowanceCharge {
return this; return this;
} }
public IZUGFeRDAllowanceChargeImpl setReasonCode(String reasonCode) {
this.reasonCode = reasonCode;
return this;
}
public IZUGFeRDAllowanceChargeImpl setTaxPercent(BigDecimal taxPercent) { public IZUGFeRDAllowanceChargeImpl setTaxPercent(BigDecimal taxPercent) {
this.taxPercent = taxPercent; this.taxPercent = taxPercent;
return this; return this;