corrected import of CIDA delivery advices
This commit is contained in:
@@ -44,6 +44,7 @@ import org.apache.pdfbox.pdmodel.PDEmbeddedFilesNameTreeNode;
|
||||
import org.apache.pdfbox.pdmodel.common.PDNameTreeNode;
|
||||
import org.apache.pdfbox.pdmodel.common.filespecification.PDComplexFileSpecification;
|
||||
import org.apache.pdfbox.pdmodel.common.filespecification.PDEmbeddedFile;
|
||||
import org.mustangproject.EStandard;
|
||||
import org.mustangproject.Item;
|
||||
import org.mustangproject.Product;
|
||||
import org.w3c.dom.Document;
|
||||
@@ -633,11 +634,28 @@ public class ZUGFeRDImporter {
|
||||
}
|
||||
|
||||
|
||||
public int getVersion() throws Exception {
|
||||
public EStandard getStandard() throws Exception {
|
||||
if (!containsMeta) {
|
||||
throw new Exception("Not yet parsed");
|
||||
}
|
||||
if (getUTF8().contains("<rsm:CrossIndustryDocument")) {
|
||||
return EStandard.zugferd;
|
||||
} else if (getUTF8().contains("<rsm:CrossIndustryInvoice")) {
|
||||
return EStandard.facturx;
|
||||
} else if (getUTF8().contains("<SCRDMCCBDACIDAMessageStructure")) {
|
||||
return EStandard.despatchadvice;
|
||||
} else if (getUTF8().contains("<rsm:SCRDMCCBDACIOMessageStructure")) {
|
||||
return EStandard.orderx;
|
||||
}
|
||||
|
||||
throw new Exception("ZUGFeRD version could not be determined");
|
||||
|
||||
}
|
||||
public int getVersion() throws Exception {
|
||||
if (!containsMeta) {
|
||||
throw new Exception("Not yet parsed");
|
||||
}
|
||||
if (getUTF8().contains("<rsm:CrossIndustryDocument")||getUTF8().contains("<SCRDMCCBDACIDAMessageStructure")||getUTF8().contains("<rsm:SCRDMCCBDACIOMessageStructure")) {
|
||||
return 1;
|
||||
} else if (getUTF8().contains("<rsm:CrossIndustryInvoice")) {
|
||||
return 2;
|
||||
@@ -939,11 +957,8 @@ public class ZUGFeRDImporter {
|
||||
final List<Node> lineItemNodes = new ArrayList<>();
|
||||
NodeList nl = null;
|
||||
try {
|
||||
if (getVersion() == 1) {
|
||||
nl = getNodeListByPath("//*[local-name() = 'CrossIndustryDocument']//*[local-name() = 'SpecifiedSupplyChainTradeTransaction']//*[local-name() = 'IncludedSupplyChainTradeLineItem']");
|
||||
} else {
|
||||
nl = getNodeListByPath("//*[local-name() = 'CrossIndustryInvoice']//*[local-name() = 'SupplyChainTradeTransaction']//*[local-name() = 'IncludedSupplyChainTradeLineItem']");
|
||||
}
|
||||
nl = getNodeListByPath("//*[local-name() = 'IncludedSupplyChainTradeLineItem']");
|
||||
|
||||
} catch (final Exception e) {
|
||||
Logger.getLogger(ZUGFeRDImporter.class.getName()).log(Level.SEVERE, null, e);
|
||||
}
|
||||
|
||||
@@ -216,7 +216,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"))) {
|
||||
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();
|
||||
@@ -336,7 +336,15 @@ public class ZUGFeRDInvoiceImporter extends ZUGFeRDImporter {
|
||||
|
||||
TransactionCalculator tc = new TransactionCalculator(zpp);
|
||||
String expectedStringTotalGross = tc.getGrandTotal().toPlainString();
|
||||
if ((!expectedStringTotalGross.equals(XMLTools.nDigitFormat(expectedGrandTotal, 2)))&&(!ignoreCalculationErrors)) {
|
||||
EStandard whichType;
|
||||
try {
|
||||
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))) {
|
||||
throw new ParseException("Could not reproduce the invoice, this could mean that it could not be read properly", 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -278,7 +278,7 @@ public class DXTest extends MustangReaderTestCase implements IExportableTransact
|
||||
.load(SOURCE_PDF)) {
|
||||
oe.setTransaction(this);
|
||||
String theXML = new String(oe.getProvider().getXML(), StandardCharsets.UTF_8);
|
||||
assertTrue(theXML.contains("<rsm:SCRDMCCBDACIOMessageStructure"));
|
||||
assertTrue(theXML.contains("<SCRDMCCBDACIDAMessageStructure"));
|
||||
Files.write(Paths.get(TARGET_XML), theXML.getBytes(StandardCharsets.UTF_8));
|
||||
oe.export(TARGET_PDF);
|
||||
} catch (IOException e) {
|
||||
@@ -291,10 +291,8 @@ public class DXTest extends MustangReaderTestCase implements IExportableTransact
|
||||
assertTrue(zi.getUTF8().contains("<ram:TypeCode>220</ram:TypeCode>"));
|
||||
assertTrue(zi.getUTF8().contains("<ram:ShipToTradeParty>"));
|
||||
assertFalse(zi.getUTF8().contains("EUR"));
|
||||
assertTrue(zi.getUTF8().contains("USD"));//currency should be USD, test for #150
|
||||
|
||||
// Now also check the "invoice"Importer
|
||||
assertEquals("496.00", zi.getAmount());
|
||||
assertEquals(zi.getLineItemList().size(),3);
|
||||
assertEquals(zi.getHolder(), getOwnOrganisationName());
|
||||
ZUGFeRDInvoiceImporter zii = new ZUGFeRDInvoiceImporter(TARGET_PDF);
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user