be able to refer to contract id

This commit is contained in:
Jochen Stärk
2020-10-06 12:43:35 +02:00
parent cd3a5b75ef
commit 66fd7b4316
2 changed files with 98 additions and 85 deletions

View File

@@ -45,7 +45,7 @@ public class ZUGFeRD2PullProvider implements IXMLProvider {
protected byte[] zugferdData; protected byte[] zugferdData;
private IExportableTransaction trans; private IExportableTransaction trans;
private String paymentTermsDescription; private String paymentTermsDescription;
protected Profile profile=Profiles.getByName("EN16931"); protected Profile profile = Profiles.getByName("EN16931");
/** /**
@@ -118,24 +118,26 @@ public class ZUGFeRD2PullProvider implements IXMLProvider {
private BigDecimal getCharges() { private BigDecimal getCharges() {
BigDecimal res = new BigDecimal(0); BigDecimal res = new BigDecimal(0);
IZUGFeRDAllowanceCharge[] charges= trans.getZFCharges(); IZUGFeRDAllowanceCharge[] charges = trans.getZFCharges();
if ((charges!=null) && (charges.length>0)) { if ((charges != null) && (charges.length > 0)) {
for (IZUGFeRDAllowanceCharge currentCharge:charges) { for (IZUGFeRDAllowanceCharge currentCharge : charges) {
res=res.add(currentCharge.getTotalAmount(trans)); res = res.add(currentCharge.getTotalAmount(trans));
} }
} }
return res; return res;
} }
private BigDecimal getAllowances() { private BigDecimal getAllowances() {
BigDecimal res = new BigDecimal(0); BigDecimal res = new BigDecimal(0);
IZUGFeRDAllowanceCharge[] allowances= trans.getZFAllowances(); IZUGFeRDAllowanceCharge[] allowances = trans.getZFAllowances();
if ((allowances!=null) && (allowances.length>0)) { if ((allowances != null) && (allowances.length > 0)) {
for (IZUGFeRDAllowanceCharge currentAllowance:allowances) { for (IZUGFeRDAllowanceCharge currentAllowance : allowances) {
res=res.add(currentAllowance.getTotalAmount(trans)); res = res.add(currentAllowance.getTotalAmount(trans));
} }
} }
return res; return res;
} }
private BigDecimal getTotal() { private BigDecimal getTotal() {
BigDecimal res = new BigDecimal(0); BigDecimal res = new BigDecimal(0);
for (IZUGFeRDExportableItem currentItem : trans.getZFItems()) { for (IZUGFeRDExportableItem currentItem : trans.getZFItems()) {
@@ -174,28 +176,28 @@ public class ZUGFeRD2PullProvider implements IXMLProvider {
} }
IZUGFeRDAllowanceCharge[] charges= trans.getZFCharges(); IZUGFeRDAllowanceCharge[] charges = trans.getZFCharges();
if ((charges!=null) && (charges.length>0)) { if ((charges != null) && (charges.length > 0)) {
for (IZUGFeRDAllowanceCharge currentCharge:charges) { for (IZUGFeRDAllowanceCharge currentCharge : charges) {
VATAmount theAmount=hm.get(currentCharge.getTaxPercent()); VATAmount theAmount = hm.get(currentCharge.getTaxPercent());
if (theAmount==null) { if (theAmount == null) {
theAmount=new VATAmount(new BigDecimal(0),new BigDecimal(0),"S"); theAmount = new VATAmount(new BigDecimal(0), new BigDecimal(0), "S");
} }
theAmount.setBasis(theAmount.getBasis().add(currentCharge.getTotalAmount(trans))); theAmount.setBasis(theAmount.getBasis().add(currentCharge.getTotalAmount(trans)));
BigDecimal factor=currentCharge.getTaxPercent().divide(new BigDecimal(100)); BigDecimal factor = currentCharge.getTaxPercent().divide(new BigDecimal(100));
theAmount.setCalculated(theAmount.getBasis().multiply(factor)); theAmount.setCalculated(theAmount.getBasis().multiply(factor));
hm.put(currentCharge.getTaxPercent(), theAmount); hm.put(currentCharge.getTaxPercent(), theAmount);
} }
} }
IZUGFeRDAllowanceCharge[] allowances= trans.getZFAllowances(); IZUGFeRDAllowanceCharge[] allowances = trans.getZFAllowances();
if ((allowances!=null) && (allowances.length>0)) { if ((allowances != null) && (allowances.length > 0)) {
for (IZUGFeRDAllowanceCharge currentAllowance:allowances) { for (IZUGFeRDAllowanceCharge currentAllowance : allowances) {
VATAmount theAmount=hm.get(currentAllowance.getTaxPercent()); VATAmount theAmount = hm.get(currentAllowance.getTaxPercent());
if (theAmount==null) { if (theAmount == null) {
theAmount=new VATAmount(new BigDecimal(0),new BigDecimal(0),"S"); theAmount = new VATAmount(new BigDecimal(0), new BigDecimal(0), "S");
} }
theAmount.setBasis(theAmount.getBasis().subtract(currentAllowance.getTotalAmount(trans))); theAmount.setBasis(theAmount.getBasis().subtract(currentAllowance.getTotalAmount(trans)));
BigDecimal factor=currentAllowance.getTaxPercent().divide(new BigDecimal(100)); BigDecimal factor = currentAllowance.getTaxPercent().divide(new BigDecimal(100));
theAmount.setCalculated(theAmount.getBasis().multiply(factor)); theAmount.setCalculated(theAmount.getBasis().multiply(factor));
hm.put(currentAllowance.getTaxPercent(), theAmount); hm.put(currentAllowance.getTaxPercent(), theAmount);
@@ -203,7 +205,6 @@ public class ZUGFeRD2PullProvider implements IXMLProvider {
} }
return hm; return hm;
} }
@@ -216,10 +217,9 @@ public class ZUGFeRD2PullProvider implements IXMLProvider {
String xml = ""; String xml = "";
// According EN16931 either GlobalID or seller assigned ID might be present for BuyerTradeParty // According EN16931 either GlobalID or seller assigned ID might be present for BuyerTradeParty
// and ShipToTradeParty, but not both. Prefer seller assigned ID for now. // and ShipToTradeParty, but not both. Prefer seller assigned ID for now.
if (party.getID()!=null) { if (party.getID() != null) {
xml += " <ram:ID>" + XMLTools.encodeXML(party.getID()) + "</ram:ID>\n"; xml += " <ram:ID>" + XMLTools.encodeXML(party.getID()) + "</ram:ID>\n";
} } else if ((party.getGlobalIDScheme() != null) && (party.getGlobalID() != null)) {
else if ((party.getGlobalIDScheme()!=null)&&(party.getGlobalID()!=null)) {
xml = xml + " <ram:GlobalID schemeID=\"" + XMLTools.encodeXML(party.getGlobalIDScheme()) + "\">" xml = xml + " <ram:GlobalID schemeID=\"" + XMLTools.encodeXML(party.getGlobalIDScheme()) + "\">"
+ XMLTools.encodeXML(party.getGlobalID()) + "</ram:GlobalID>\n"; + XMLTools.encodeXML(party.getGlobalID()) + "</ram:GlobalID>\n";
} }
@@ -273,6 +273,7 @@ public class ZUGFeRD2PullProvider implements IXMLProvider {
return xml; return xml;
} }
@Override @Override
public void generateXML(IExportableTransaction trans) { public void generateXML(IExportableTransaction trans) {
this.trans = trans; this.trans = trans;
@@ -386,7 +387,6 @@ public class ZUGFeRD2PullProvider implements IXMLProvider {
} }
xml = xml + " <ram:Name>" + XMLTools.encodeXML(currentItem.getProduct().getName()) + "</ram:Name>\n" //$NON-NLS-2$ xml = xml + " <ram:Name>" + XMLTools.encodeXML(currentItem.getProduct().getName()) + "</ram:Name>\n" //$NON-NLS-2$
+ " <ram:Description>" + XMLTools.encodeXML(currentItem.getProduct().getDescription()) + " <ram:Description>" + XMLTools.encodeXML(currentItem.getProduct().getDescription())
+ "</ram:Description>\n" + "</ram:Description>\n"
@@ -404,7 +404,7 @@ public class ZUGFeRD2PullProvider implements IXMLProvider {
// + " <ActualAmount currencyID=\"EUR\">0.6667</ActualAmount>\n" // + " <ActualAmount currencyID=\"EUR\">0.6667</ActualAmount>\n"
// + " <Reason>Rabatt</Reason>\n" // + " <Reason>Rabatt</Reason>\n"
// + " </AppliedTradeAllowanceCharge>\n" // + " </AppliedTradeAllowanceCharge>\n"
+" </ram:GrossPriceProductTradePrice>\n" + " </ram:GrossPriceProductTradePrice>\n"
+ " <ram:NetPriceProductTradePrice>\n" + " <ram:NetPriceProductTradePrice>\n"
+ " <ram:ChargeAmount>" + priceFormat(lc.getPrice()) + " <ram:ChargeAmount>" + priceFormat(lc.getPrice())
+ "</ram:ChargeAmount>\n" // currencyID=\"EUR\" + "</ram:ChargeAmount>\n" // currencyID=\"EUR\"
@@ -451,7 +451,7 @@ public class ZUGFeRD2PullProvider implements IXMLProvider {
// + " <ID>GE2020211</ID>\n" // + " <ID>GE2020211</ID>\n"
// + " <GlobalID schemeID=\"0088\">4000001987658</GlobalID>\n" // + " <GlobalID schemeID=\"0088\">4000001987658</GlobalID>\n"
xml+=getTradePartyAsXML(trans.getRecipient()); xml += getTradePartyAsXML(trans.getRecipient());
xml += " </ram:BuyerTradeParty>\n"; xml += " </ram:BuyerTradeParty>\n";
if (trans.getBuyerOrderReferencedDocumentID() != null) { if (trans.getBuyerOrderReferencedDocumentID() != null) {
@@ -460,6 +460,14 @@ public class ZUGFeRD2PullProvider implements IXMLProvider {
+ XMLTools.encodeXML(trans.getBuyerOrderReferencedDocumentID()) + "</ram:IssuerAssignedID>\n" + XMLTools.encodeXML(trans.getBuyerOrderReferencedDocumentID()) + "</ram:IssuerAssignedID>\n"
+ " </ram:BuyerOrderReferencedDocument>\n"; + " </ram:BuyerOrderReferencedDocument>\n";
} }
if (trans.getContractReferencedDocument() != null) {
xml = xml + " <ram:ContractReferencedDocument>\n"
+ " <ram:IssuerAssignedID>"
+ XMLTools.encodeXML(trans.getContractReferencedDocument()) + "</ram:IssuerAssignedID>\n"
+ " </ram:ContractReferencedDocument>\n";
}
xml = xml + " </ram:ApplicableHeaderTradeAgreement>\n" xml = xml + " </ram:ApplicableHeaderTradeAgreement>\n"
+ " <ram:ApplicableHeaderTradeDelivery>\n"; + " <ram:ApplicableHeaderTradeDelivery>\n";
if (this.trans.getDeliveryAddress() != null) { if (this.trans.getDeliveryAddress() != null) {
@@ -524,25 +532,25 @@ public class ZUGFeRD2PullProvider implements IXMLProvider {
} }
} }
if ((trans.getOccurrencePeriodFrom()!=null) || (trans.getOccurrencePeriodTo()!=null)) { if ((trans.getOccurrencePeriodFrom() != null) || (trans.getOccurrencePeriodTo() != null)) {
xml=xml+"<ram:BillingSpecifiedPeriod>"; xml = xml + "<ram:BillingSpecifiedPeriod>";
if (trans.getOccurrencePeriodFrom()!=null) { if (trans.getOccurrencePeriodFrom() != null) {
xml=xml+"<ram:StartDateTime><udt:DateTimeString format='102'>"+zugferdDateFormat.format(trans.getOccurrencePeriodFrom())+"</udt:DateTimeString></ram:StartDateTime>"; xml = xml + "<ram:StartDateTime><udt:DateTimeString format='102'>" + zugferdDateFormat.format(trans.getOccurrencePeriodFrom()) + "</udt:DateTimeString></ram:StartDateTime>";
} }
if (trans.getOccurrencePeriodTo()!=null) { if (trans.getOccurrencePeriodTo() != null) {
xml=xml+"<ram:EndDateTime><udt:DateTimeString format='102'>"+zugferdDateFormat.format(trans.getOccurrencePeriodTo())+"</udt:DateTimeString></ram:EndDateTime>"; xml = xml + "<ram:EndDateTime><udt:DateTimeString format='102'>" + zugferdDateFormat.format(trans.getOccurrencePeriodTo()) + "</udt:DateTimeString></ram:EndDateTime>";
} }
xml=xml+"</ram:BillingSpecifiedPeriod>"; xml = xml + "</ram:BillingSpecifiedPeriod>";
} }
if ((trans.getZFCharges()!=null)&&(trans.getZFCharges().length>0)) { if ((trans.getZFCharges() != null) && (trans.getZFCharges().length > 0)) {
xml = xml + " <ram:SpecifiedTradeAllowanceCharge>\n" + xml = xml + " <ram:SpecifiedTradeAllowanceCharge>\n" +
" <ram:ChargeIndicator>\n" + " <ram:ChargeIndicator>\n" +
" <udt:Indicator>true</udt:Indicator>\n" + " <udt:Indicator>true</udt:Indicator>\n" +
" </ram:ChargeIndicator>\n" + " </ram:ChargeIndicator>\n" +
" <ram:ActualAmount>"+currencyFormat(getCharges())+"</ram:ActualAmount>\n" + " <ram:ActualAmount>" + currencyFormat(getCharges()) + "</ram:ActualAmount>\n" +
" <ram:Reason>Charge</ram:Reason>\n" + " <ram:Reason>Charge</ram:Reason>\n" +
" <ram:CategoryTradeTax>\n" + " <ram:CategoryTradeTax>\n" +
" <ram:TypeCode>VAT</ram:TypeCode>\n" + " <ram:TypeCode>VAT</ram:TypeCode>\n" +
@@ -554,12 +562,12 @@ public class ZUGFeRD2PullProvider implements IXMLProvider {
} }
if ((trans.getZFAllowances()!=null)&&(trans.getZFAllowances().length>0)) { if ((trans.getZFAllowances() != null) && (trans.getZFAllowances().length > 0)) {
xml = xml + " <ram:SpecifiedTradeAllowanceCharge>\n" + xml = xml + " <ram:SpecifiedTradeAllowanceCharge>\n" +
" <ram:ChargeIndicator>\n" + " <ram:ChargeIndicator>\n" +
" <udt:Indicator>false</udt:Indicator>\n" + " <udt:Indicator>false</udt:Indicator>\n" +
" </ram:ChargeIndicator>\n" + " </ram:ChargeIndicator>\n" +
" <ram:ActualAmount>"+currencyFormat(getAllowances())+"</ram:ActualAmount>\n" + " <ram:ActualAmount>" + currencyFormat(getAllowances()) + "</ram:ActualAmount>\n" +
" <ram:Reason>Allowance</ram:Reason>\n" + " <ram:Reason>Allowance</ram:Reason>\n" +
" <ram:CategoryTradeTax>\n" + " <ram:CategoryTradeTax>\n" +
" <ram:TypeCode>VAT</ram:TypeCode>\n" + " <ram:TypeCode>VAT</ram:TypeCode>\n" +
@@ -595,10 +603,9 @@ public class ZUGFeRD2PullProvider implements IXMLProvider {
} }
String allowanceTotalLine = "<ram:AllowanceTotalAmount>" + currencyFormat(getAllowances()) + "</ram:AllowanceTotalAmount>";
String allowanceTotalLine="<ram:AllowanceTotalAmount>"+currencyFormat(getAllowances())+"</ram:AllowanceTotalAmount>"; String chargesTotalLine = "<ram:ChargeTotalAmount>" + currencyFormat(getCharges()) + "</ram:ChargeTotalAmount>";
String chargesTotalLine="<ram:ChargeTotalAmount>"+currencyFormat(getCharges())+"</ram:ChargeTotalAmount>";
xml = xml + " <ram:SpecifiedTradeSettlementHeaderMonetarySummation>\n" xml = xml + " <ram:SpecifiedTradeSettlementHeaderMonetarySummation>\n"
+ " <ram:LineTotalAmount>" + currencyFormat(getTotal()) + "</ram:LineTotalAmount>\n" //$NON-NLS-2$ + " <ram:LineTotalAmount>" + currencyFormat(getTotal()) + "</ram:LineTotalAmount>\n" //$NON-NLS-2$
@@ -648,7 +655,7 @@ public class ZUGFeRD2PullProvider implements IXMLProvider {
@Override @Override
public void setProfile(Profile p) { public void setProfile(Profile p) {
profile=p; profile = p;
} }
private String buildPaymentTermsXml() { private String buildPaymentTermsXml() {

View File

@@ -49,6 +49,9 @@ public class ZF2PushTest extends TestCase {
String number = "123"; String number = "123";
String amountStr = "1.00"; String amountStr = "1.00";
BigDecimal amount = new BigDecimal(amountStr); BigDecimal amount = new BigDecimal(amountStr);
String occurenceFrom="20201001";
String occurenceTo="20201005";
String contractID="376zreurzu0983";
try (InputStream SOURCE_PDF = this.getClass() try (InputStream SOURCE_PDF = this.getClass()
.getResourceAsStream("/MustangGnuaccountingBeispielRE-20170509_505blanko.pdf"); .getResourceAsStream("/MustangGnuaccountingBeispielRE-20170509_505blanko.pdf");
@@ -57,7 +60,7 @@ public class ZF2PushTest extends TestCase {
.load(SOURCE_PDF)) { .load(SOURCE_PDF)) {
try { try {
ze.setTransaction(new Invoice().setDueDate(new Date()).setIssueDate(new Date()).setDeliveryDate(new Date()).setOccurrencePeriod(new SimpleDateFormat("yyyy-MM-dd").parse("2020-10-01"), new SimpleDateFormat("yyyy-MM-dd").parse("2020-10-05")).setContractReferencedDocument("0815").setSender(new TradeParty(orgname, "teststr", "55232", "teststadt", "DE").addBankDetails(new BankDetails("777666555", "DE4321"))).setOwnTaxID("4711").setOwnVATID("DE19990815").setRecipient(new TradeParty("Franz Müller", "teststr.12", "55232", "Entenhausen", "DE").setContact(new Contact("nameRep", "phoneRep", "emailRep@test.com"))).setNumber(number).addItem(new Item(new Product("Testprodukt", "", "C62", new BigDecimal(19)), amount, new BigDecimal(1.0)))); ze.setTransaction(new Invoice().setDueDate(new Date()).setIssueDate(new Date()).setDeliveryDate(new Date()).setContractReferencedDocument(contractID).setOccurrencePeriod(new SimpleDateFormat("yyyyMMdd").parse(occurenceFrom), new SimpleDateFormat("yyyyMMdd").parse(occurenceTo)).setSender(new TradeParty(orgname, "teststr", "55232", "teststadt", "DE").addBankDetails(new BankDetails("777666555", "DE4321"))).setOwnTaxID("4711").setOwnVATID("DE19990815").setRecipient(new TradeParty("Franz Müller", "teststr.12", "55232", "Entenhausen", "DE").setContact(new Contact("nameRep", "phoneRep", "emailRep@test.com"))).setNumber(number).addItem(new Item(new Product("Testprodukt", "", "C62", new BigDecimal(19)), amount, new BigDecimal(1.0))));
} catch (ParseException ex) { } catch (ParseException ex) {
throw new RuntimeException("Parse exception"); throw new RuntimeException("Parse exception");
} }
@@ -74,6 +77,9 @@ public class ZF2PushTest extends TestCase {
ZUGFeRDImporter zi = new ZUGFeRDImporter(TARGET_PDF); ZUGFeRDImporter zi = new ZUGFeRDImporter(TARGET_PDF);
assertTrue(zi.getUTF8().contains("EUR")); assertTrue(zi.getUTF8().contains("EUR"));
assertTrue(zi.getUTF8().contains(occurenceFrom));
assertTrue(zi.getUTF8().contains(occurenceTo));
assertTrue(zi.getUTF8().contains(contractID));
assertTrue(zi.getUTF8().contains("0815")); assertTrue(zi.getUTF8().contains("0815"));
// Reading ZUGFeRD // Reading ZUGFeRD