Merge branch 'master' into master

This commit is contained in:
Jochen Staerk
2024-11-17 19:49:49 +01:00
committed by GitHub
14 changed files with 482 additions and 521 deletions

View File

@@ -0,0 +1,13 @@
package org.mustangproject.Exceptions;
import java.text.ParseException;
/***
* will be thrown if a invoice cant be reproduced numerically
*/
public class ArithmetricException extends ParseException {
public ArithmetricException() {
super(
"Could not reproduce the invoice, this could mean that it could not be read properly", 0);
}
}

View File

@@ -0,0 +1,12 @@
package org.mustangproject.Exceptions;
import java.text.ParseException;
/***
* will be thrown if a invoice cant be read
*/
public class StructureException extends ParseException {
public StructureException(String message, int line) {
super(message, line);
}
}

View File

@@ -23,7 +23,7 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public class TradeParty implements IZUGFeRDExportableTradeParty {
protected String name, zip, street, location, country;
protected String name, zip, street, location, country, taxScheme;
protected String taxID = null, vatID = null;
protected String ID = null;
protected String description = null;
@@ -91,8 +91,46 @@ public class TradeParty implements IZUGFeRDExportableTradeParty {
}
}
// UBL only: formally it can have a name as well but BT27 party name *should* be stored in
// so overwrite if one exists
if (currentTopElementName.equals("PartyTaxScheme")) {
NodeList partyTaxScheme = party.item(partyIndex).getChildNodes();
for (int partyTaxSchemeIndex = 0; partyTaxSchemeIndex < partyTaxScheme.getLength(); partyTaxSchemeIndex++) {
if (partyTaxScheme.item(partyTaxSchemeIndex).getLocalName() != null) {
if (partyTaxScheme.item(partyTaxSchemeIndex).getLocalName().equals("CompanyID")) {
setTaxID(partyTaxScheme.item(partyTaxSchemeIndex).getTextContent());
}
}
}
}
// if (currentTopElementName.equals("PartyTaxScheme")) {
// NodeList partyTaxScheme = party.item(partyIndex).getChildNodes();
// for (int partyTaxSchemeIndex = 0; partyTaxSchemeIndex < partyTaxScheme.getLength(); partyTaxSchemeIndex++) {
// if (partyTaxScheme.item(partyTaxSchemeIndex).getLocalName() != null) {
// if (partyTaxScheme.item(partyTaxSchemeIndex).getLocalName().equals("TaxScheme")) {
// NodeList taxScheme = partyTaxScheme.item(partyTaxSchemeIndex).getChildNodes();
// for (int taxSchemeIndex = 0 ; taxSchemeIndex < taxScheme.getLength(); taxSchemeIndex++) {
// if (taxScheme.item(taxSchemeIndex).getLocalName() != null) {
// if(taxScheme.item(taxSchemeIndex).getLocalName().equals("ID")){
// if (partyTaxScheme.item(partyTaxSchemeIndex).getLocalName().equals("CompanyID")) {
// setTaxID(partyTaxScheme.item(partyTaxSchemeIndex).getTextContent());
// } else {
// setVATID(partyTaxScheme.item(partyTaxSchemeIndex).getTextContent());
// }
// }
// }
// }
// }
//
// }
// }
// }
/*
UBL only: formally it can have a name as well but BT27 party name *should* be stored in
so overwrite if one exists
*/
if (currentTopElementName.equals("PartyLegalEntity")) {
NodeList legal = party.item(partyIndex).getChildNodes();
for (int legalChildIndex = 0; legalChildIndex < legal.getLength(); legalChildIndex++) {
@@ -100,6 +138,9 @@ public class TradeParty implements IZUGFeRDExportableTradeParty {
if (legal.item(legalChildIndex).getLocalName().equals("RegistrationName")) {
setName(legal.item(legalChildIndex).getTextContent());
}
if (legal.item(legalChildIndex).getLocalName().equals("CompanyLegalForm")) {
setDescription(legal.item(legalChildIndex).getTextContent());
}
}
}
}
@@ -212,26 +253,27 @@ public class TradeParty implements IZUGFeRDExportableTradeParty {
}
if (currentUBLChild.equals("SpecifiedTaxRegistration")) {
if (currentUBLChild.equals("PartyTaxScheme")) {
NodeList taxChilds = nodes.item(nodeIndex).getChildNodes();
for (int taxChildIndex = 0; taxChildIndex < taxChilds.getLength(); taxChildIndex++) {
if (taxChilds.item(taxChildIndex).getLocalName() != null) {
if ((taxChilds.item(taxChildIndex).getLocalName().equals("ID"))) {
if (taxChilds.item(taxChildIndex).getAttributes().getNamedItem("schemeID") != null) {
Node firstChild = taxChilds.item(taxChildIndex).getFirstChild();
if (firstChild != null) {
if (taxChilds.item(taxChildIndex).getAttributes().getNamedItem("schemeID").getNodeValue().equals("VA")) {
setVATID(firstChild.getNodeValue());
if ((taxChilds.item(taxChildIndex).getLocalName().equals("TaxScheme"))) {
if (taxChilds.item(taxChildIndex).getLocalName().equals("CompanyID")) {
if (taxChilds.item(taxChildIndex).getLocalName().equals("ID")) {
if (taxChilds.item(taxChildIndex).getLocalName().equals("CompanyID")) {
setVATID(taxChilds.item(taxChildIndex).getTextContent());
}
if (taxChilds.item(taxChildIndex).getAttributes().getNamedItem("schemeID").getNodeValue().equals("FC")) {
setTaxID(firstChild.getNodeValue());
// setTaxID(partyTaxScheme.item(partyTaxSchemeIndex).getTextContent());
if (taxChilds.item(taxChildIndex).getAttributes().getNamedItem("ID").getNodeValue().equals("FC")) {
if (taxChilds.item(taxChildIndex).getLocalName().equals("CompanyID")) {
setTaxID(taxChilds.item(taxChildIndex).getTextContent());
}
}
}
}
}
}
}
}
}
}

View File

@@ -54,15 +54,6 @@ public class ZUGFeRDImporter extends ZUGFeRDInvoiceImporter {
}
/***
* Wrapper for protected method extractString
* @param xpathStr the xpath expression to be evaluated
* @return the extracted String for the specific path in the document
*/
public String wExtractString(String xpathStr) {
return extractString(xpathStr);
}
////////////////////////////////////

View File

@@ -9,6 +9,8 @@ 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.*;
import org.mustangproject.Exceptions.ArithmetricException;
import org.mustangproject.Exceptions.StructureException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
@@ -352,6 +354,34 @@ public class ZUGFeRDInvoiceImporter {
}
}
}
List<IncludedNote> includedNotes = new ArrayList<>();
if ((item.getLocalName() != null) && (item.getLocalName().equals("IncludedNote"))) {
String subjectCode = "";
String content = null;
NodeList includedNodeChilds = item.getChildNodes();
for (int issueDateChildIndex = 0; issueDateChildIndex < includedNodeChilds.getLength(); issueDateChildIndex++) {
if ((includedNodeChilds.item(issueDateChildIndex).getLocalName() != null)
&& (includedNodeChilds.item(issueDateChildIndex).getLocalName().equals("Content"))) {
content = XMLTools.trimOrNull(includedNodeChilds.item(issueDateChildIndex));
}
if ((includedNodeChilds.item(issueDateChildIndex).getLocalName() != null)
&& (includedNodeChilds.item(issueDateChildIndex).getLocalName().equals("SubjectCode"))) {
subjectCode = XMLTools.trimOrNull(includedNodeChilds.item(issueDateChildIndex));
}
}
switch (subjectCode){
case "AAI": includedNotes.add(IncludedNote.generalNote(content)); break;
case "REG": includedNotes.add(IncludedNote.regulatoryNote(content)); break;
case "ABL": includedNotes.add(IncludedNote.legalNote(content)); break;
case "CUS": includedNotes.add(IncludedNote.customsNote(content)); break;
case "SUR": includedNotes.add(IncludedNote.sellerNote(content)); break;
case "TXD": includedNotes.add(IncludedNote.taxNote(content)); break;
case "ACY": includedNotes.add(IncludedNote.introductionNote(content)); break;
case "AAK": includedNotes.add(IncludedNote.discountBonusNote(content)); break;
default: includedNotes.add(IncludedNote.unspecifiedNote(content)); break;
}
}
zpp.addNotes(includedNotes);
}
}
String rootNode = extractString("local-name(/*)");
@@ -440,7 +470,8 @@ public class ZUGFeRDInvoiceImporter {
}
String currency = extractString("//*[local-name()=\"ApplicableHeaderTradeSettlement\"]/*[local-name()=\"InvoiceCurrencyCode\"]|*[local-name()=\"DocumentCurrencyCode\"]");
String currency = extractString("//*[local-name()=\"ApplicableHeaderTradeSettlement\"]/*[local-name()=\"InvoiceCurrencyCode\"]|//*[local-name()=\"DocumentCurrencyCode\"]") ;
zpp.setCurrency(currency);
xpr = xpath.compile("//*[local-name()=\"ApplicableHeaderTradeSettlement\"]|//*[local-name()=\"ApplicableSupplyChainTradeSettlement\"]");
@@ -578,6 +609,9 @@ public class ZUGFeRDInvoiceImporter {
if (buyerOrderIssuerAssignedID != null) {
zpp.setBuyerOrderReferencedDocumentID(buyerOrderIssuerAssignedID);
}
else {
zpp.setBuyerOrderReferencedDocumentID(extractString("//*[local-name()=\"OrderReference\"]/*[local-name()=\"ID\"]"));
}
if (sellerOrderIssuerAssignedID != null) {
zpp.setSellerOrderReferencedDocumentID(sellerOrderIssuerAssignedID);
}
@@ -697,15 +731,13 @@ public class ZUGFeRDInvoiceImporter {
try {
whichType = getStandard();
} catch (Exception e) {
throw new ParseException("Could not find out if it's an invoice, order, or delivery advice", 0);
throw new StructureException("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);
throw new ArithmetricException();
}
}
return zpp;

View File

@@ -249,6 +249,12 @@ public class ZUGFeRDVisualizer {
EStandard theStandard = findOutStandardFromRootNode(fis);
fis = new FileInputStream(xmlFilename);//rewind :-(
return toFOP(fis, theStandard);
}
protected String toFOP(InputStream is, EStandard theStandard)
throws FileNotFoundException, TransformerException {
try {
if (mXsltPDFTemplate == null) {
mXsltPDFTemplate = mFactory.newTemplates(
@@ -263,11 +269,11 @@ public class ZUGFeRDVisualizer {
//zf2 or fx
if (theStandard == EStandard.facturx) {
applyZF2XSLT(fis, iaos);
applyZF2XSLT(is, iaos);
} else if (theStandard == EStandard.ubl) {
applyUBL2XSLT(fis, iaos);
applyUBL2XSLT(is, iaos);
} else if (theStandard == EStandard.ubl_creditnote) {
applyUBLCreditNote2XSLT(fis, iaos);
applyUBLCreditNote2XSLT(is, iaos);
}