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,12 +161,13 @@ public class ZUGFeRDInvoiceImporter extends ZUGFeRDImporter {
String price = "0";
String name = "";
String description = "";
SchemedID gid = null;
String quantity = "0";
String vatPercent = "0";
String lineTotal = "0";
String unitCode = "0";
ArrayList<ReferencedDocument> rdocs=null;
ArrayList<ReferencedDocument> rdocs = null;
//nodes.item(i).getTextContent())) {
Node currentItemNode = nodes.item(i);
@@ -177,9 +178,9 @@ public class ZUGFeRDInvoiceImporter extends ZUGFeRDImporter {
for (int tradeLineChildIndex = 0; tradeLineChildIndex < tradeLineChilds.getLength(); tradeLineChildIndex++) {
if ((tradeLineChilds.item(tradeLineChildIndex).getLocalName() != null) && tradeLineChilds.item(tradeLineChildIndex).getLocalName().equals("AdditionalReferencedDocument")) {
String IssuerAssignedID="";
String TypeCode="";
String ReferenceTypeCode="";
String IssuerAssignedID = "";
String TypeCode = "";
String ReferenceTypeCode = "";
NodeList refDocChilds = tradeLineChilds.item(tradeLineChildIndex).getChildNodes();
for (int refDocIndex = 0; refDocIndex < refDocChilds.getLength(); refDocIndex++) {
@@ -194,9 +195,9 @@ public class ZUGFeRDInvoiceImporter extends ZUGFeRDImporter {
}
}
ReferencedDocument rd=new ReferencedDocument(IssuerAssignedID, TypeCode, ReferenceTypeCode);
if (rdocs==null) {
rdocs=new ArrayList<ReferencedDocument>();
ReferencedDocument rd = new ReferencedDocument(IssuerAssignedID, TypeCode, ReferenceTypeCode);
if (rdocs == null) {
rdocs = new ArrayList<ReferencedDocument>();
}
rdocs.add(rd);
@@ -216,7 +217,7 @@ public class ZUGFeRDInvoiceImporter extends ZUGFeRDImporter {
if ((itemChilds.item(itemChildIndex).getLocalName() != null) && (itemChilds.item(itemChildIndex).getLocalName().equals("SpecifiedLineTradeDelivery"))) {
NodeList tradeLineChilds = itemChilds.item(itemChildIndex).getChildNodes();
for (int tradeLineChildIndex = 0; tradeLineChildIndex < tradeLineChilds.getLength(); tradeLineChildIndex++) {
if ((tradeLineChilds.item(tradeLineChildIndex).getLocalName() != null) && (tradeLineChilds.item(tradeLineChildIndex).getLocalName().equals("BilledQuantity")||tradeLineChilds.item(tradeLineChildIndex).getLocalName().equals("RequestedQuantity")||tradeLineChilds.item(tradeLineChildIndex).getLocalName().equals("DespatchedQuantity"))) {
if ((tradeLineChilds.item(tradeLineChildIndex).getLocalName() != null) && (tradeLineChilds.item(tradeLineChildIndex).getLocalName().equals("BilledQuantity") || tradeLineChilds.item(tradeLineChildIndex).getLocalName().equals("RequestedQuantity") || tradeLineChilds.item(tradeLineChildIndex).getLocalName().equals("DespatchedQuantity"))) {
//RequestedQuantity is for Order-X, BilledQuantity for FX and ZF
quantity = tradeLineChilds.item(tradeLineChildIndex).getTextContent();
unitCode = tradeLineChilds.item(tradeLineChildIndex).getAttributes().getNamedItem("unitCode").getNodeValue();
@@ -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"))) {
@@ -260,11 +267,15 @@ public class ZUGFeRDInvoiceImporter extends ZUGFeRDImporter {
BigDecimal prc = new BigDecimal(price.trim());
BigDecimal qty = new BigDecimal(quantity.trim());
if ((recalcPrice) && (!qty.equals(BigDecimal.ZERO))) {
prc = new BigDecimal(lineTotal.trim()).divide(qty,4, RoundingMode.HALF_UP);
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);
if (rdocs!=null) {
for (ReferencedDocument rdoc: rdocs) {
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);
}
}
@@ -291,7 +302,7 @@ public class ZUGFeRDInvoiceImporter extends ZUGFeRDImporter {
if (chargeNodeChilds.item(chargeChildIndex).getLocalName().equals("ChargeIndicator")) {
NodeList indicatorChilds = chargeNodeChilds.item(chargeChildIndex).getChildNodes();
for (int indicatorChildIndex = 0; indicatorChildIndex < indicatorChilds.getLength(); indicatorChildIndex++) {
if ((indicatorChilds.item(indicatorChildIndex).getLocalName()!=null)&&(indicatorChilds.item(indicatorChildIndex).getLocalName().equals("Indicator"))) {
if ((indicatorChilds.item(indicatorChildIndex).getLocalName() != null) && (indicatorChilds.item(indicatorChildIndex).getLocalName().equals("Indicator"))) {
isCharge = indicatorChilds.item(indicatorChildIndex).getTextContent().equalsIgnoreCase("true");
}
}
@@ -338,13 +349,13 @@ public class ZUGFeRDInvoiceImporter extends ZUGFeRDImporter {
String expectedStringTotalGross = tc.getGrandTotal().toPlainString();
EStandard whichType;
try {
whichType=getStandard();
} catch(Exception e) {
whichType = getStandard();
} catch (Exception e) {
throw new ParseException("Could not find out if it's an invoice, order, or delivery advice", 0);
}
if ((whichType!=EStandard.despatchadvice) && ((!expectedStringTotalGross.equals(XMLTools.nDigitFormat(expectedGrandTotal, 2)))&&(!ignoreCalculationErrors))) {
if ((whichType != EStandard.despatchadvice) && ((!expectedStringTotalGross.equals(XMLTools.nDigitFormat(expectedGrandTotal, 2))) && (!ignoreCalculationErrors))) {
throw new ParseException("Could not reproduce the invoice, this could mean that it could not be read properly", 0);
}
}

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() {