From a79a48095e57621304d3081fe877ee2c7cfc6566 Mon Sep 17 00:00:00 2001 From: jstaerk Date: Sat, 21 Nov 2020 20:46:05 +0100 Subject: [PATCH] support account holders, new sample invoice --- History.md | 2 + .../java/org/mustangproject/BankDetails.java | 24 ++++++- .../IZUGFeRDTradeSettlementPayment.java | 18 ++++- .../mustangproject/ZUGFeRD/ZF2PushTest.java | 66 +++++++++++-------- .../mustangproject/validator/LibraryTest.java | 2 +- 5 files changed, 79 insertions(+), 33 deletions(-) diff --git a/History.md b/History.md index a281e817..1f969a08 100644 --- a/History.md +++ b/History.md @@ -14,6 +14,8 @@ - new sample invoice - delivery period also on item level - corrected more than 100 javadoc entries +- support specification of account (holder) names +- new sample invoice (20201121_508) 2.0.0 ===== diff --git a/library/src/main/java/org/mustangproject/BankDetails.java b/library/src/main/java/org/mustangproject/BankDetails.java index 0b4298cb..69645d3f 100644 --- a/library/src/main/java/org/mustangproject/BankDetails.java +++ b/library/src/main/java/org/mustangproject/BankDetails.java @@ -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; @@ -23,7 +23,7 @@ public class BankDetails implements IZUGFeRDTradeSettlementPayment { * if you deduct from a customer's account you may e.g. leave out the first or last * digits so that nobody spying on the invoice gets to know the complete number * @param IBAN the "IBAN ID", i.e. the IBAN or parts of it - * @return fluent setter + * @return fluent setter< */ public BankDetails setIBAN(String IBAN) { 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; + } + } diff --git a/library/src/main/java/org/mustangproject/ZUGFeRD/IZUGFeRDTradeSettlementPayment.java b/library/src/main/java/org/mustangproject/ZUGFeRD/IZUGFeRDTradeSettlementPayment.java index bfb1cc66..65561315 100644 --- a/library/src/main/java/org/mustangproject/ZUGFeRD/IZUGFeRDTradeSettlementPayment.java +++ b/library/src/main/java/org/mustangproject/ZUGFeRD/IZUGFeRDTradeSettlementPayment.java @@ -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="" + XMLTools.encodeXML(getAccountName()) + "\n"; //$NON-NLS-2$ + + } + String xml = " \n" + " 42\n" - + " Überweisung\n" + + " Bank transfer\n" + " \n" + " " + XMLTools.encodeXML(getOwnIBAN()) + "\n"; //$NON-NLS-2$ - xml+= " \n" + xml+= accountNameStr; + xml+= " \n" + " \n" + " " + XMLTools.encodeXML(getOwnBIC()) + "\n" //$NON-NLS-2$ // + " "+trans.getOwnBankName()+"\n" diff --git a/library/src/test/java/org/mustangproject/ZUGFeRD/ZF2PushTest.java b/library/src/test/java/org/mustangproject/ZUGFeRD/ZF2PushTest.java index 3821e6d8..89e96242 100644 --- a/library/src/test/java/org/mustangproject/ZUGFeRD/ZF2PushTest.java +++ b/library/src/test/java/org/mustangproject/ZUGFeRD/ZF2PushTest.java @@ -37,7 +37,7 @@ import junit.framework.TestCase; @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class ZF2PushTest extends TestCase { - final String TARGET_PDF = "./target/testout-ZF2Push.pdf"; + final String TARGET_PDF = "./target/testout-MustangGnuaccountingBeispielRE-20201121_508.pdf"; final String TARGET_ALLOWANCESPDF = "./target/testout-ZF2PushAllowances.pdf"; final String TARGET_CORRECTIONPDF = "./target/testout-ZF2PushCorrection.pdf"; final String TARGET_ITEMCHARGESALLOWANCESPDF = "./target/testout-ZF2PushItemChargesAllowances.pdf"; @@ -50,46 +50,48 @@ public class ZF2PushTest extends TestCase { // the writing part - String orgname = "Test company"; - String number = "RE-20170509/505"; - String priceStr = "1.00"; + String orgname = "Bei Spiel GmbH"; + String number = "RE-20201121/508"; + String priceStr = "160.00"; + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + BigDecimal price = new BigDecimal(priceStr); - String occurenceFrom = "20201001"; - String occurenceTo = "20201005"; - String contractID = "376zreurzu0983"; try (InputStream SOURCE_PDF = this.getClass() - .getResourceAsStream("/MustangGnuaccountingBeispielRE-20170509_505blanko.pdf"); + .getResourceAsStream("/MustangGnuaccountingBeispielRE-20201121_508blanko.pdf"); ZUGFeRDExporterFromA1 ze = new ZUGFeRDExporterFromA1().setProducer("My Application") .setCreator(System.getProperty("user.name")).setZUGFeRDVersion(2).ignorePDFAErrors() .load(SOURCE_PDF)) { - try { - ze.setTransaction(new Invoice().setDueDate(new Date()).setIssueDate(new Date()).setDeliveryDate(new Date()).setContractReferencedDocument(contractID).setDetailedDeliveryPeriod(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").setAdditionalAddress("Hinterhaus 3").setContact(new Contact("nameRep", "phoneRep", "emailRep@test.com"))).setNumber(number).addItem(new Item(new Product("Testprodukt", "", "C62", new BigDecimal(19)), price, new BigDecimal(1.0)))); - } catch (ParseException ex) { - throw new RuntimeException("Parse exception"); - } + + ze.setTransaction(new Invoice().setDueDate(sdf.parse("2020-12-12")).setIssueDate(sdf.parse("2020-11-21")).setDeliveryDate(sdf.parse("2020-11-10")) + .setSender(new TradeParty(orgname, "Ecke 12", "12345", "Stadthausen", "DE").addBankDetails(new BankDetails("DE88200800000970375700", "COBADEFFXXX").setAccountName("Max Mustermann")).addVATID("DE136695976")) + .setRecipient(new TradeParty("Theodor Est", "Bahnstr. 42", "88802", "Spielkreis", "DE") + .setContact(new Contact("Ingmar N. Fo", "(555) 23 78-23", "info@localhost.local")).setID("2")) + .setNumber(number) + .setReferenceNumber("AB321") + .addItem(new Item(new Product("Design (hours)", "Of a sample invoice", "HUR", new BigDecimal(7)), price, new BigDecimal(1.0))) + .addItem(new Item(new Product("Ballons", "various colors, ~2000ml", "H87", new BigDecimal(19)), new BigDecimal("0.79"), new BigDecimal(400.0))) + .addItem(new Item(new Product("Hot air „heiße Luft“ (litres)", "", "LTR", new BigDecimal(19)), new BigDecimal("0.025"), new BigDecimal(800.0))) + ); ze.export(TARGET_PDF); - } catch (IOException e) { - fail("IOException should not be raised in testEdgeExport"); + } catch (IOException | ParseException e) { + fail("Exception should not be raised in testPushExport"); } // now check the contents (like MustangReaderTest) ZUGFeRDImporter zi = new ZUGFeRDImporter(TARGET_PDF); - assertTrue(zi.getUTF8().contains("777666555")); //the iban + assertTrue(zi.getUTF8().contains("DE88200800000970375700")); //the iban + assertTrue(zi.getUTF8().contains("Max Mustermann")); //account holder assertTrue(zi.getUTF8().contains("