Skip to content

Commit 17403c3

Browse files
authored
Merge pull request #994 from ThomasChr/addDeliveryNoteReference
add DeliveryNoteReferencedDocument for import and export
2 parents eae7d95 + f1f81cf commit 17403c3

File tree

7 files changed

+108
-6
lines changed

7 files changed

+108
-6
lines changed

library/src/main/java/org/mustangproject/Invoice.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ public class Invoice implements IExportableTransaction {
6868
protected String specifiedProcuringProjectID = null;
6969
protected String specifiedProcuringProjectName = null;
7070
protected String despatchAdviceReferencedDocumentID = null;
71+
protected String deliveryNoteReferencedDocumentID = null;
72+
protected Date deliveryNoteReferencedDocumentDate = null;
7173
protected String vatDueDateTypeCode = null;
7274
protected String creditorReferenceID; // required when direct debit is used.
7375
private BigDecimal roundingAmount=null;
@@ -1073,6 +1075,28 @@ public Invoice setDespatchAdviceReferencedDocumentID(String despatchAdviceRefere
10731075
return this;
10741076
}
10751077

1078+
@Override
1079+
public String getDeliveryNoteReferencedDocumentID() {
1080+
return deliveryNoteReferencedDocumentID;
1081+
}
1082+
1083+
1084+
public Invoice setDeliveryNoteReferencedDocumentID(String deliveryNoteReferencedDocumentID) {
1085+
this.deliveryNoteReferencedDocumentID = deliveryNoteReferencedDocumentID;
1086+
return this;
1087+
}
1088+
1089+
@Override
1090+
public Date getDeliveryNoteReferencedDocumentDate() {
1091+
return deliveryNoteReferencedDocumentDate;
1092+
}
1093+
1094+
1095+
public Invoice setDeliveryNoteReferencedDocumentDate(Date deliveryNoteReferencedDocumentDate) {
1096+
this.deliveryNoteReferencedDocumentDate = deliveryNoteReferencedDocumentDate;
1097+
return this;
1098+
}
1099+
10761100

10771101
@Override
10781102
public String getSpecifiedProcuringProjectName() {

library/src/main/java/org/mustangproject/ZUGFeRD/IExportableTransaction.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,26 @@ default String getDespatchAdviceReferencedDocumentID() {
562562
return null;
563563
}
564564

565+
/**
566+
* get delivery note document ID
567+
* ram:ApplicableHeaderTradeDelivery/ram:DeliveryNoteReferencedDocument/IssuerAssignedID
568+
*
569+
* @return the ID of the delivery note document
570+
*/
571+
default String getDeliveryNoteReferencedDocumentID() {
572+
return null;
573+
}
574+
575+
/**
576+
* get delivery note document date
577+
* ram:ApplicableHeaderTradeDelivery/ram:DeliveryNoteReferencedDocument/FormattedIssueDateTime
578+
*
579+
* @return the date of the delivery note document
580+
*/
581+
default Date getDeliveryNoteReferencedDocumentDate() {
582+
return null;
583+
}
584+
565585
/***
566586
* additional text description
567587
*

library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRD2PullProvider.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -676,12 +676,18 @@ public void generateXML(IExportableTransaction trans) {
676676
+ "<ram:OccurrenceDateTime>" + DATE.udtFormat(trans.getDeliveryDate()) + "</ram:OccurrenceDateTime>"
677677
+ "</ram:ActualDeliverySupplyChainEvent>";
678678
}
679-
/*
680-
* + "<DeliveryNoteReferencedDocument>" +
681-
* "<IssueDateTime format=\"102\">20130603</IssueDateTime>" +
682-
* "<ID>2013-51112</ID>" +
683-
* "</DeliveryNoteReferencedDocument>"
684-
*/
679+
680+
if (trans.getDeliveryNoteReferencedDocumentID() != null && !trans.getDeliveryNoteReferencedDocumentID().trim().isEmpty()) {
681+
xml += "<ram:DeliveryNoteReferencedDocument>";
682+
xml += "<ram:IssuerAssignedID>" + XMLTools.encodeXML(trans.getDeliveryNoteReferencedDocumentID()) + "</ram:IssuerAssignedID>";
683+
if (trans.getDeliveryNoteReferencedDocumentDate() != null) {
684+
final SimpleDateFormat dateFormat102 = new SimpleDateFormat("yyyyMMdd");
685+
xml += "<ram:FormattedIssueDateTime><qdt:DateTimeString format=\"102\">"+XMLTools.encodeXML(dateFormat102.format(trans.getDeliveryNoteReferencedDocumentDate()))+"</qdt:DateTimeString></ram:FormattedIssueDateTime>";
686+
}
687+
xml += "</ram:DeliveryNoteReferencedDocument>";
688+
689+
}
690+
685691
if (trans.getDespatchAdviceReferencedDocumentID() != null && !trans.getDespatchAdviceReferencedDocumentID().trim().isEmpty()) {
686692
xml += "<ram:DespatchAdviceReferencedDocument>";
687693
xml += "<ram:IssuerAssignedID>" + XMLTools.encodeXML(trans.getDespatchAdviceReferencedDocumentID()) + "</ram:IssuerAssignedID>";

library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,8 @@ public Invoice extractInto(Invoice zpp) throws XPathExpressionException, ParseEx
528528
Date dueDate = null;
529529
Date deliveryDate = null;
530530
String despatchAdviceReferencedDocument = null;
531+
String deliveryNoteReferencedDocumentID = null;
532+
Date deliveryNoteReferencedDocumentDate = null;
531533

532534
for (int i = 0; i < ExchangedDocumentNodes.getLength(); i++) {
533535
Node exchangedDocumentNode = ExchangedDocumentNodes.item(i);
@@ -681,6 +683,28 @@ public Invoice extractInto(Invoice zpp) throws XPathExpressionException, ParseEx
681683
}
682684
}
683685
}
686+
687+
if (headerTradeDeliveryChilds.item(deliveryChildIndex).getLocalName().equals("DeliveryNoteReferencedDocument")) {
688+
NodeList deliveryNoteReferencedDocumentChilds = headerTradeDeliveryChilds.item(deliveryChildIndex).getChildNodes();
689+
for (int deliveryNoteReferencedDocumentIndex = 0; deliveryNoteReferencedDocumentIndex < deliveryNoteReferencedDocumentChilds.getLength(); deliveryNoteReferencedDocumentIndex++) {
690+
if (deliveryNoteReferencedDocumentChilds.item(deliveryNoteReferencedDocumentIndex).getLocalName() != null
691+
&& deliveryNoteReferencedDocumentChilds.item(deliveryNoteReferencedDocumentIndex).getLocalName().equals("IssuerAssignedID")) {
692+
deliveryNoteReferencedDocumentID = XMLTools.trimOrNull(deliveryNoteReferencedDocumentChilds.item(deliveryNoteReferencedDocumentIndex));
693+
}
694+
695+
if ((deliveryNoteReferencedDocumentChilds.item(deliveryNoteReferencedDocumentIndex).getLocalName() != null)
696+
&& (deliveryNoteReferencedDocumentChilds.item(deliveryNoteReferencedDocumentIndex).getLocalName().equals("FormattedIssueDateTime"))) {
697+
698+
NodeList FormattedIssueDateTimeChilds = deliveryNoteReferencedDocumentChilds.item(deliveryNoteReferencedDocumentIndex).getChildNodes();
699+
for (int dateChildIndex = 0; dateChildIndex < FormattedIssueDateTimeChilds.getLength(); dateChildIndex++) {
700+
if ((FormattedIssueDateTimeChilds.item(dateChildIndex).getLocalName() != null)
701+
&& (FormattedIssueDateTimeChilds.item(dateChildIndex).getLocalName().equals("DateTimeString"))) {
702+
deliveryNoteReferencedDocumentDate = XMLTools.tryDate(FormattedIssueDateTimeChilds.item(dateChildIndex));
703+
}
704+
}
705+
}
706+
}
707+
}
684708
}
685709
}
686710
}
@@ -1009,6 +1033,14 @@ public Invoice extractInto(Invoice zpp) throws XPathExpressionException, ParseEx
10091033
}
10101034
}
10111035

1036+
if (deliveryNoteReferencedDocumentID != null) {
1037+
zpp.setDeliveryNoteReferencedDocumentID(deliveryNoteReferencedDocumentID);
1038+
}
1039+
1040+
if (deliveryNoteReferencedDocumentDate != null) {
1041+
zpp.setDeliveryNoteReferencedDocumentDate(deliveryNoteReferencedDocumentDate);
1042+
}
1043+
10121044
String invoiceReferencedDocumentID = extractString("//*[local-name()=\"InvoiceReferencedDocument\"]/*[local-name()=\"IssuerAssignedID\"]|//*[local-name()=\"BillingReference\"]/*[local-name()=\"InvoiceDocumentReference\"]/*[local-name()=\"ID\"]");
10131045
if (!invoiceReferencedDocumentID.isEmpty()) {
10141046
zpp.setInvoiceReferencedDocumentID(invoiceReferencedDocumentID);

library/src/test/java/org/mustangproject/ZUGFeRD/ZF2EdgeTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,16 @@ public String getDespatchAdviceReferencedDocumentID() {
304304
return "123";
305305
}
306306

307+
@Override
308+
public String getDeliveryNoteReferencedDocumentID() {
309+
return "0815";
310+
}
311+
312+
@Override
313+
public Date getDeliveryNoteReferencedDocumentDate() {
314+
return new GregorianCalendar(2016, Calendar.APRIL, 1).getTime();
315+
}
316+
307317
/**
308318
* Create the test case
309319
*

library/src/test/java/org/mustangproject/ZUGFeRD/ZF2PushTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -851,6 +851,8 @@ public void testCreditNoteExport() {
851851
.setSender(new TradeParty(orgname, "teststr", "55232", "teststadt", "DE").addTaxID("4711").addVATID("DE0815").addBankDetails(new BankDetails("DE88200800000970375700", "COBADEFFXXX")))
852852
.setRecipient(new TradeParty("Franz Müller", "teststr.12", "55232", "Entenhausen", "DE").addVATID("DE0815"))
853853
.setNumber(number).setDespatchAdviceReferencedDocumentID(despatchAdviceReferencedDocumentID)
854+
.setDeliveryNoteReferencedDocumentID("0815")
855+
.setDeliveryNoteReferencedDocumentDate(new SimpleDateFormat("dd.MM.yyyy").parse("01.04.2016"))
854856
.addItem(new Item(new Product("Testprodukt", "", "H87", new BigDecimal(19)), price, qty))
855857
.addItem(new Item(new Product("Testprodukt", "", "H87", new BigDecimal(19)), price, qty))
856858
.addItem(new Item(new Product("Testprodukt", "", "H87", new BigDecimal(19)), price, qty)).setCreditNote();
@@ -860,6 +862,8 @@ public void testCreditNoteExport() {
860862
ze.export(TARGET_CREDITNOTEPDF);
861863
} catch (IOException e) {
862864
fail("IOException should not be raised");
865+
} catch (ParseException e) {
866+
fail("ParseException should not be raised");
863867
}
864868

865869
// now check the contents (like MustangReaderTest)
@@ -882,6 +886,8 @@ public void testCreditNoteExport() {
882886
Invoice i = zii.extractInvoice();
883887

884888
assertEquals(despatchAdviceReferencedDocumentID, i.getDespatchAdviceReferencedDocumentID());
889+
assertEquals("0815", i.getDeliveryNoteReferencedDocumentID());
890+
assertEquals(new SimpleDateFormat("dd.MM.yyyy").parse("01.04.2016"), i.getDeliveryNoteReferencedDocumentDate());
885891

886892
} catch (XPathExpressionException e) {
887893
fail("XPathExpressionException should not be raised");
@@ -912,6 +918,7 @@ public void testEmptyDocumentReference() {
912918
.setBuyerOrderReferencedDocumentID("")
913919
.setContractReferencedDocument("")
914920
.setDespatchAdviceReferencedDocumentID("")
921+
.setDeliveryNoteReferencedDocumentID("")
915922
.setInvoiceReferencedDocumentID("");
916923

917924
zf2p.generateXML(i);
@@ -928,6 +935,7 @@ public void testEmptyDocumentReference() {
928935
.setBuyerOrderReferencedDocumentID(" ")
929936
.setContractReferencedDocument(" ")
930937
.setDespatchAdviceReferencedDocumentID(" ")
938+
.setDeliveryNoteReferencedDocumentID(" ")
931939
.setInvoiceReferencedDocumentID(" ");
932940

933941
zf2p.generateXML(i);

library/src/test/java/org/mustangproject/ZUGFeRD/ZF2ZInvoiceImporterTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -894,6 +894,8 @@ public void testImportExport() throws FileNotFoundException, XPathExpressionExce
894894
assertNull(invoice.getSellerOrderReferencedDocumentID());
895895
assertNull(invoice.getDespatchAdviceReferencedDocumentID());
896896
assertNull(invoice.getInvoiceReferencedDocumentID());
897+
assertNull(invoice.getDeliveryNoteReferencedDocumentID());
898+
assertNull(invoice.getDeliveryNoteReferencedDocumentDate());
897899
}
898900

899901
@Test

0 commit comments

Comments
 (0)