invoiceimporter to read global IDs

This commit is contained in:
jstaerk
2022-08-11 13:18:29 +02:00
parent 797c9c5880
commit 9670124e66
3 changed files with 54 additions and 16 deletions

View File

@@ -93,6 +93,13 @@ public class TradeParty implements IZUGFeRDExportableTradeParty {
if (itemChilds.item(itemChildIndex).getLocalName().equals("Name")) {
setName(itemChilds.item(itemChildIndex).getTextContent());
}
if (itemChilds.item(itemChildIndex).getLocalName().equals("GlobalID")) {
if (itemChilds.item(itemChildIndex).getAttributes().getNamedItem("schemeID") != null) {
SchemedID gid=new SchemedID().setScheme(itemChilds.item(itemChildIndex).getAttributes().getNamedItem("schemeID").getNodeValue()).setId(itemChilds.item(itemChildIndex).getTextContent());
addGlobalID(gid);
}
}
if (itemChilds.item(itemChildIndex).getLocalName().equals("DefinedTradeContact")) {
NodeList contact = itemChilds.item(itemChildIndex).getChildNodes();
setContact(new Contact(contact));

View File

@@ -161,6 +161,7 @@ public class ZUGFeRDInvoiceImporter extends ZUGFeRDImporter {
String price = "0";
String name = "";
String description = "";
SchemedID gid = null;
String quantity = "0";
String vatPercent = "0";
String lineTotal = "0";
@@ -229,6 +230,12 @@ public class ZUGFeRDInvoiceImporter extends ZUGFeRDImporter {
if ((tradeProductChilds.item(tradeProductChildIndex).getLocalName() != null) && (tradeProductChilds.item(tradeProductChildIndex).getLocalName().equals("Name"))) {
name = tradeProductChilds.item(tradeProductChildIndex).getTextContent();
}
if ((tradeProductChilds.item(tradeProductChildIndex).getLocalName() != null) && (tradeProductChilds.item(tradeProductChildIndex).getLocalName().equals("GlobalID"))) {
if (tradeProductChilds.item(tradeProductChildIndex).getAttributes().getNamedItem("schemeID") != null) {
gid = new SchemedID().setScheme(tradeProductChilds.item(tradeProductChildIndex).getAttributes().getNamedItem("schemeID").getNodeValue()).setId(tradeProductChilds.item(tradeProductChildIndex).getTextContent());
}
}
}
}
if ((itemChilds.item(itemChildIndex).getLocalName() != null) && (itemChilds.item(itemChildIndex).getLocalName().equals("SpecifiedLineTradeSettlement"))) {
@@ -262,7 +269,11 @@ public class ZUGFeRDInvoiceImporter extends ZUGFeRDImporter {
if ((recalcPrice) && (!qty.equals(BigDecimal.ZERO))) {
prc = new BigDecimal(lineTotal.trim()).divide(qty, 4, RoundingMode.HALF_UP);
}
Item it=new Item(new Product(name, description, unitCode, new BigDecimal(vatPercent.trim())), prc, qty);
Product p = new Product(name, description, unitCode, new BigDecimal(vatPercent.trim()));
if (gid != null) {
p.addGlobalID(gid);
}
Item it = new Item(p, prc, qty);
if (rdocs != null) {
for (ReferencedDocument rdoc : rdocs) {
it.addReferencedDocument(rdoc);

View File

@@ -37,6 +37,8 @@ import org.xmlunit.builder.Input;
import org.xmlunit.xpath.JAXPXPathEngine;
import org.xmlunit.xpath.XPathEngine;
import javax.xml.xpath.XPathExpressionException;
import static org.xmlunit.assertj.XmlAssert.assertThat;
@@ -428,6 +430,24 @@ public class ZF2PushTest extends TestCase {
assertTrue(zi.getUTF8().contains("document level 2/2"));
assertFalse(zi.getUTF8().contains("++49555123456")); // in profile EN16931 contact fax number is not allowed
ZUGFeRDInvoiceImporter zii = new ZUGFeRDInvoiceImporter(TARGET_PUSHEDGE);
try {
Invoice i = zii.extractInvoice();
assertEquals("4304171000002", i.getRecipient().getGlobalID());
assertEquals("2001015001325", i.getZFItems()[0].getProduct().getGlobalID());
} catch (XPathExpressionException e) {
fail("XPathExpressionException should not be raised in testEdgeExport");
} catch (ParseException e) {
fail("ParseException should not be raised in testEdgeExport");
/* a parseException would also be fired if the calculated grand total does not
match the read grand total */
}
}
public void testAllowancesExport() {