Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions library/src/main/java/org/mustangproject/Invoice.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ public class Invoice implements IExportableTransaction {
protected String specifiedProcuringProjectID = null;
protected String specifiedProcuringProjectName = null;
protected String despatchAdviceReferencedDocumentID = null;
protected String deliveryNoteReferencedDocumentID = null;
protected Date deliveryNoteReferencedDocumentDate = null;
protected String vatDueDateTypeCode = null;
protected String creditorReferenceID; // required when direct debit is used.
private BigDecimal roundingAmount=null;
Expand Down Expand Up @@ -1073,6 +1075,28 @@ public Invoice setDespatchAdviceReferencedDocumentID(String despatchAdviceRefere
return this;
}

@Override
public String getDeliveryNoteReferencedDocumentID() {
return deliveryNoteReferencedDocumentID;
}


public Invoice setDeliveryNoteReferencedDocumentID(String deliveryNoteReferencedDocumentID) {
this.deliveryNoteReferencedDocumentID = deliveryNoteReferencedDocumentID;
return this;
}

@Override
public Date getDeliveryNoteReferencedDocumentDate() {
return deliveryNoteReferencedDocumentDate;
}


public Invoice setDeliveryNoteReferencedDocumentDate(Date deliveryNoteReferencedDocumentDate) {
this.deliveryNoteReferencedDocumentDate = deliveryNoteReferencedDocumentDate;
return this;
}


@Override
public String getSpecifiedProcuringProjectName() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,26 @@ default String getDespatchAdviceReferencedDocumentID() {
return null;
}

/**
* get delivery note document ID
* ram:ApplicableHeaderTradeDelivery/ram:DeliveryNoteReferencedDocument/IssuerAssignedID
*
* @return the ID of the delivery note document
*/
default String getDeliveryNoteReferencedDocumentID() {
return null;
}

/**
* get delivery note document date
* ram:ApplicableHeaderTradeDelivery/ram:DeliveryNoteReferencedDocument/FormattedIssueDateTime
*
* @return the date of the delivery note document
*/
default Date getDeliveryNoteReferencedDocumentDate() {
return null;
}

/***
* additional text description
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -676,12 +676,18 @@ public void generateXML(IExportableTransaction trans) {
+ "<ram:OccurrenceDateTime>" + DATE.udtFormat(trans.getDeliveryDate()) + "</ram:OccurrenceDateTime>"
+ "</ram:ActualDeliverySupplyChainEvent>";
}
/*
* + "<DeliveryNoteReferencedDocument>" +
* "<IssueDateTime format=\"102\">20130603</IssueDateTime>" +
* "<ID>2013-51112</ID>" +
* "</DeliveryNoteReferencedDocument>"
*/

if (trans.getDeliveryNoteReferencedDocumentID() != null && !trans.getDeliveryNoteReferencedDocumentID().trim().isEmpty()) {
xml += "<ram:DeliveryNoteReferencedDocument>";
xml += "<ram:IssuerAssignedID>" + XMLTools.encodeXML(trans.getDeliveryNoteReferencedDocumentID()) + "</ram:IssuerAssignedID>";
if (trans.getDeliveryNoteReferencedDocumentDate() != null) {
final SimpleDateFormat dateFormat102 = new SimpleDateFormat("yyyyMMdd");
xml += "<ram:FormattedIssueDateTime><qdt:DateTimeString format=\"102\">"+XMLTools.encodeXML(dateFormat102.format(trans.getDeliveryNoteReferencedDocumentDate()))+"</qdt:DateTimeString></ram:FormattedIssueDateTime>";
}
xml += "</ram:DeliveryNoteReferencedDocument>";

}

if (trans.getDespatchAdviceReferencedDocumentID() != null && !trans.getDespatchAdviceReferencedDocumentID().trim().isEmpty()) {
xml += "<ram:DespatchAdviceReferencedDocument>";
xml += "<ram:IssuerAssignedID>" + XMLTools.encodeXML(trans.getDespatchAdviceReferencedDocumentID()) + "</ram:IssuerAssignedID>";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,8 @@ public Invoice extractInto(Invoice zpp) throws XPathExpressionException, ParseEx
Date dueDate = null;
Date deliveryDate = null;
String despatchAdviceReferencedDocument = null;
String deliveryNoteReferencedDocumentID = null;
Date deliveryNoteReferencedDocumentDate = null;

for (int i = 0; i < ExchangedDocumentNodes.getLength(); i++) {
Node exchangedDocumentNode = ExchangedDocumentNodes.item(i);
Expand Down Expand Up @@ -681,6 +683,28 @@ public Invoice extractInto(Invoice zpp) throws XPathExpressionException, ParseEx
}
}
}

if (headerTradeDeliveryChilds.item(deliveryChildIndex).getLocalName().equals("DeliveryNoteReferencedDocument")) {
NodeList deliveryNoteReferencedDocumentChilds = headerTradeDeliveryChilds.item(deliveryChildIndex).getChildNodes();
for (int deliveryNoteReferencedDocumentIndex = 0; deliveryNoteReferencedDocumentIndex < deliveryNoteReferencedDocumentChilds.getLength(); deliveryNoteReferencedDocumentIndex++) {
if (deliveryNoteReferencedDocumentChilds.item(deliveryNoteReferencedDocumentIndex).getLocalName() != null
&& deliveryNoteReferencedDocumentChilds.item(deliveryNoteReferencedDocumentIndex).getLocalName().equals("IssuerAssignedID")) {
deliveryNoteReferencedDocumentID = XMLTools.trimOrNull(deliveryNoteReferencedDocumentChilds.item(deliveryNoteReferencedDocumentIndex));
}

if ((deliveryNoteReferencedDocumentChilds.item(deliveryNoteReferencedDocumentIndex).getLocalName() != null)
&& (deliveryNoteReferencedDocumentChilds.item(deliveryNoteReferencedDocumentIndex).getLocalName().equals("FormattedIssueDateTime"))) {

NodeList FormattedIssueDateTimeChilds = deliveryNoteReferencedDocumentChilds.item(deliveryNoteReferencedDocumentIndex).getChildNodes();
for (int dateChildIndex = 0; dateChildIndex < FormattedIssueDateTimeChilds.getLength(); dateChildIndex++) {
if ((FormattedIssueDateTimeChilds.item(dateChildIndex).getLocalName() != null)
&& (FormattedIssueDateTimeChilds.item(dateChildIndex).getLocalName().equals("DateTimeString"))) {
deliveryNoteReferencedDocumentDate = XMLTools.tryDate(FormattedIssueDateTimeChilds.item(dateChildIndex));
}
}
}
}
}
}
}
}
Expand Down Expand Up @@ -1009,6 +1033,14 @@ public Invoice extractInto(Invoice zpp) throws XPathExpressionException, ParseEx
}
}

if (deliveryNoteReferencedDocumentID != null) {
zpp.setDeliveryNoteReferencedDocumentID(deliveryNoteReferencedDocumentID);
}

if (deliveryNoteReferencedDocumentDate != null) {
zpp.setDeliveryNoteReferencedDocumentDate(deliveryNoteReferencedDocumentDate);
}

String invoiceReferencedDocumentID = extractString("//*[local-name()=\"InvoiceReferencedDocument\"]/*[local-name()=\"IssuerAssignedID\"]|//*[local-name()=\"BillingReference\"]/*[local-name()=\"InvoiceDocumentReference\"]/*[local-name()=\"ID\"]");
if (!invoiceReferencedDocumentID.isEmpty()) {
zpp.setInvoiceReferencedDocumentID(invoiceReferencedDocumentID);
Expand Down
10 changes: 10 additions & 0 deletions library/src/test/java/org/mustangproject/ZUGFeRD/ZF2EdgeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,16 @@ public String getDespatchAdviceReferencedDocumentID() {
return "123";
}

@Override
public String getDeliveryNoteReferencedDocumentID() {
return "0815";
}

@Override
public Date getDeliveryNoteReferencedDocumentDate() {
return new GregorianCalendar(2016, Calendar.APRIL, 1).getTime();
}

/**
* Create the test case
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -851,6 +851,8 @@ public void testCreditNoteExport() {
.setSender(new TradeParty(orgname, "teststr", "55232", "teststadt", "DE").addTaxID("4711").addVATID("DE0815").addBankDetails(new BankDetails("DE88200800000970375700", "COBADEFFXXX")))
.setRecipient(new TradeParty("Franz Müller", "teststr.12", "55232", "Entenhausen", "DE").addVATID("DE0815"))
.setNumber(number).setDespatchAdviceReferencedDocumentID(despatchAdviceReferencedDocumentID)
.setDeliveryNoteReferencedDocumentID("0815")
.setDeliveryNoteReferencedDocumentDate(new SimpleDateFormat("dd.MM.yyyy").parse("01.04.2016"))
.addItem(new Item(new Product("Testprodukt", "", "H87", new BigDecimal(19)), price, qty))
.addItem(new Item(new Product("Testprodukt", "", "H87", new BigDecimal(19)), price, qty))
.addItem(new Item(new Product("Testprodukt", "", "H87", new BigDecimal(19)), price, qty)).setCreditNote();
Expand All @@ -860,6 +862,8 @@ public void testCreditNoteExport() {
ze.export(TARGET_CREDITNOTEPDF);
} catch (IOException e) {
fail("IOException should not be raised");
} catch (ParseException e) {
fail("ParseException should not be raised");
}

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

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

} catch (XPathExpressionException e) {
fail("XPathExpressionException should not be raised");
Expand Down Expand Up @@ -912,6 +918,7 @@ public void testEmptyDocumentReference() {
.setBuyerOrderReferencedDocumentID("")
.setContractReferencedDocument("")
.setDespatchAdviceReferencedDocumentID("")
.setDeliveryNoteReferencedDocumentID("")
.setInvoiceReferencedDocumentID("");

zf2p.generateXML(i);
Expand All @@ -928,6 +935,7 @@ public void testEmptyDocumentReference() {
.setBuyerOrderReferencedDocumentID(" ")
.setContractReferencedDocument(" ")
.setDespatchAdviceReferencedDocumentID(" ")
.setDeliveryNoteReferencedDocumentID(" ")
.setInvoiceReferencedDocumentID(" ");

zf2p.generateXML(i);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -894,6 +894,8 @@ public void testImportExport() throws FileNotFoundException, XPathExpressionExce
assertNull(invoice.getSellerOrderReferencedDocumentID());
assertNull(invoice.getDespatchAdviceReferencedDocumentID());
assertNull(invoice.getInvoiceReferencedDocumentID());
assertNull(invoice.getDeliveryNoteReferencedDocumentID());
assertNull(invoice.getDeliveryNoteReferencedDocumentDate());
}

@Test
Expand Down