Merge remote-tracking branch 'remotes/mustang-origin/master' into fork-master

# Conflicts:
#	validator/src/main/java/org/mustangproject/validator/PDFValidator.java
This commit is contained in:
Sebastian Sieber
2021-10-19 14:50:22 +02:00
193 changed files with 69013 additions and 8423 deletions

View File

@@ -3,13 +3,13 @@
<parent>
<groupId>org.mustangproject</groupId>
<artifactId>core</artifactId>
<version>2.1.2-SNAPSHOT</version>
<version>2.3.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>org.mustangproject</groupId>
<artifactId>library</artifactId>
<version>2.1.2-SNAPSHOT</version>
<version>2.3.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Library to write, read and validate e-invoices (Factur-X, ZUGFeRD and to a limited extend XRechnung/CII). </name>
<description>The Mustang project is a java library to read, write and validate Factur-X/ZUGFeRD meta data inside your invoice PDFs. To write files, a provided PDF/A will be combined with generated or provided XML.
@@ -67,12 +67,12 @@
<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>preflight</artifactId>
<version>[2.0.15,2.0.17]</version>
<version>2.0.24</version>
</dependency>
<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox</artifactId>
<version>[2.0.15,2.0.17]</version>
<version>2.0.24</version>
</dependency>
<dependency>
<groupId>org.dom4j</groupId>

View File

@@ -14,6 +14,7 @@ public class Item implements IZUGFeRDExportableItem {
protected BigDecimal price, quantity, tax, grossPrice, lineTotalAmount;
protected Date detailedDeliveryPeriodFrom=null, detailedDeliveryPeriodTo=null;
protected String id;
protected String referencedLineID=null;
protected Product product;
protected ArrayList<String> notes = null;
protected ArrayList<IZUGFeRDAllowanceCharge> Allowances = new ArrayList<IZUGFeRDAllowanceCharge>(),
@@ -31,6 +32,21 @@ public class Item implements IZUGFeRDExportableItem {
this.product = product;
}
public Item addReferencedLineID(String s) {
referencedLineID=s;
return this;
}
/***
* BT 132 (issue https://github.com/ZUGFeRD/mustangproject/issues/247)
* @return
*/
@Override
public String getBuyerOrderReferencedDocumentLineID() {
return referencedLineID;
}
public BigDecimal getLineTotalAmount() {
return lineTotalAmount;
}

View File

@@ -50,6 +50,15 @@ public interface IZUGFeRDExportableItem extends IAbsoluteValueProvider{
}
/***
* BT 132 (issue https://github.com/ZUGFeRD/mustangproject/issues/247)
* @return
*/
default String getBuyerOrderReferencedDocumentLineID() {
return null;
}
/**
* The price of one item excl. taxes
*

View File

@@ -68,8 +68,8 @@ public interface IZUGFeRDTradeSettlementPayment extends IZUGFeRDTradeSettlement
}
String xml = " <ram:SpecifiedTradeSettlementPaymentMeans>\n"
+ " <ram:TypeCode>42</ram:TypeCode>\n"
+ " <ram:Information>Bank transfer</ram:Information>\n"
+ " <ram:TypeCode>58</ram:TypeCode>\n"
+ " <ram:Information>SEPA credit transfer</ram:Information>\n"
+ " <ram:PayeePartyCreditorFinancialAccount>\n"
+ " <ram:IBANID>" + XMLTools.encodeXML(getOwnIBAN()) + "</ram:IBANID>\n";
xml+= accountNameStr;

View File

@@ -350,8 +350,14 @@ public class ZUGFeRD2PullProvider implements IXMLProvider {
+ "</ram:Description>\n"
+ " </ram:SpecifiedTradeProduct>\n"
+ " <ram:SpecifiedLineTradeAgreement>\n"
+ " <ram:GrossPriceProductTradePrice>\n"
+ " <ram:SpecifiedLineTradeAgreement>\n";
if (currentItem.getBuyerOrderReferencedDocumentLineID() != null) {
xml = xml + " <ram:BuyerOrderReferencedDocument> \n"
+ " <ram:LineID>"+XMLTools.encodeXML(currentItem.getBuyerOrderReferencedDocumentLineID())+"</ram:LineID>\n"
+ " </ram:BuyerOrderReferencedDocument>\n";
}
xml = xml + " <ram:GrossPriceProductTradePrice>\n"
+ " <ram:ChargeAmount>" + priceFormat(lc.getPriceGross())
+ "</ram:ChargeAmount>\n" //currencyID=\"EUR\"
+ "<ram:BasisQuantity unitCode=\"" + XMLTools.encodeXML(currentItem.getProduct().getUnit())
@@ -520,17 +526,17 @@ public class ZUGFeRD2PullProvider implements IXMLProvider {
for (final BigDecimal currentTaxPercent : VATPercentAmountMap.keySet()) {
final VATAmount amount = VATPercentAmountMap.get(currentTaxPercent);
if (amount != null) {
final String amountCategoryCode = amount.getCategoryCode();
final boolean displayExemptionReason = CATEGORY_CODES_WITH_EXEMPTION_REASON.contains(amountCategoryCode);
xml += " <ram:ApplicableTradeTax>\n"
+ " <ram:CalculatedAmount>" + currencyFormat(amount.getCalculated())
+ "</ram:CalculatedAmount>\n" //currencyID=\"EUR\"
+ " <ram:TypeCode>VAT</ram:TypeCode>\n"
+ (displayExemptionReason ? exemptionReason : "")
+ " <ram:BasisAmount>" + currencyFormat(amount.getBasis()) + "</ram:BasisAmount>\n" // currencyID=\"EUR\"
+ " <ram:CategoryCode>" + amountCategoryCode + "</ram:CategoryCode>\n"
+ " <ram:RateApplicablePercent>"
+ vatFormat(currentTaxPercent) + "</ram:RateApplicablePercent>\n" + " </ram:ApplicableTradeTax>\n" ;
final String amountCategoryCode = amount.getCategoryCode();
final boolean displayExemptionReason = CATEGORY_CODES_WITH_EXEMPTION_REASON.contains(amountCategoryCode);
xml += " <ram:ApplicableTradeTax>\n"
+ " <ram:CalculatedAmount>" + currencyFormat(amount.getCalculated())
+ "</ram:CalculatedAmount>\n" //currencyID=\"EUR\"
+ " <ram:TypeCode>VAT</ram:TypeCode>\n"
+ (displayExemptionReason ? exemptionReason : "")
+ " <ram:BasisAmount>" + currencyFormat(amount.getBasis()) + "</ram:BasisAmount>\n" // currencyID=\"EUR\"
+ " <ram:CategoryCode>" + amountCategoryCode + "</ram:CategoryCode>\n"
+ " <ram:RateApplicablePercent>"
+ vatFormat(currentTaxPercent) + "</ram:RateApplicablePercent>\n" + " </ram:ApplicableTradeTax>\n";
}
}
if ((trans.getDetailedDeliveryPeriodFrom() != null) || (trans.getDetailedDeliveryPeriodTo() != null)) {

View File

@@ -28,6 +28,10 @@ import org.apache.pdfbox.pdmodel.common.filespecification.PDComplexFileSpecifica
import org.apache.pdfbox.pdmodel.common.filespecification.PDEmbeddedFile;
import org.apache.pdfbox.pdmodel.documentinterchange.logicalstructure.PDMarkInfo;
import org.apache.pdfbox.pdmodel.documentinterchange.logicalstructure.PDStructureTreeRoot;
import org.apache.pdfbox.pdmodel.font.PDCIDFontType2;
import org.apache.pdfbox.pdmodel.font.PDFont;
import org.apache.pdfbox.pdmodel.font.PDFontDescriptor;
import org.apache.pdfbox.pdmodel.font.PDType0Font;
import org.apache.pdfbox.pdmodel.graphics.color.PDOutputIntent;
import org.apache.pdfbox.preflight.utils.ByteArrayDataSource;
import org.apache.xmpbox.XMPMetadata;
@@ -46,11 +50,7 @@ import javax.activation.DataSource;
import javax.activation.FileDataSource;
import javax.xml.transform.TransformerException;
import java.io.*;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.Map;
import java.util.*;
public class ZUGFeRDExporterFromA3 extends XRExporter implements IZUGFeRDExporter, IExporter, Closeable {
private boolean isFacturX = true;
@@ -92,13 +92,19 @@ public class ZUGFeRDExporterFromA3 extends XRExporter implements IZUGFeRDExporte
*/
protected String creatorTool = "mustangproject";
/** @deprecated author is never set yet */
/**
* @deprecated author is never set yet
*/
@Deprecated
protected String author;
/** @deprecated title is never set yet */
/**
* @deprecated title is never set yet
*/
@Deprecated
protected String title;
/** @deprecated subject is never set yet */
/**
* @deprecated subject is never set yet
*/
@Deprecated
protected String subject;
@@ -129,17 +135,17 @@ public class ZUGFeRDExporterFromA3 extends XRExporter implements IZUGFeRDExporte
}
public ZUGFeRDExporterFromA3 setProfile(Profile p) {
this.profile=p;
if (xmlProvider!=null) {
this.profile = p;
if (xmlProvider != null) {
xmlProvider.setProfile(p);
}
return this;
}
public ZUGFeRDExporterFromA3 setProfile(String profilename) {
this.profile=Profiles.getByName(profilename);
this.profile = Profiles.getByName(profilename);
if (xmlProvider!=null) {
if (xmlProvider != null) {
xmlProvider.setProfile(this.profile);
}
return this;
@@ -208,8 +214,8 @@ public class ZUGFeRDExporterFromA3 extends XRExporter implements IZUGFeRDExporte
* Factur-X is now set by default since ZF 2.1, you have to disable it if you dont wont it
* Generate ZF2.1 files with filename factur-x.xml
*
* @deprecated
* @return this (fluent setter)
* @deprecated
*/
public ZUGFeRDExporterFromA3 setFacturX() {
isFacturX = true;
@@ -244,8 +250,9 @@ public class ZUGFeRDExporterFromA3 extends XRExporter implements IZUGFeRDExporte
public void attachFile(FileAttachment file) {
fileAttachments.add(file);
}
public void attachFile(String filename, byte[] data, String mimetype, String relation) {
FileAttachment fa=new FileAttachment(filename, mimetype, relation, data);
FileAttachment fa = new FileAttachment(filename, mimetype, relation, data);
fileAttachments.add(fa);
}
@@ -474,12 +481,48 @@ public class ZUGFeRDExporterFromA3 extends XRExporter implements IZUGFeRDExporte
metadata.addSchema(pdfaex);
}
private void removeCidSet(PDDocumentCatalog catalog, PDDocument doc) {
// https://github.com/ZUGFeRD/mustangproject/issues/249
COSName cidSet = COSName.getPDFName("CIDSet");
// iterate over all pdf pages
for (Object object : doc.getPages()) {
if (object instanceof PDPage) {
PDPage page = (PDPage) object;
PDResources res = page.getResources();
for (COSName fontName : res.getFontNames()) {
try {
PDFont pdFont = res.getFont(fontName);
if (pdFont instanceof PDType0Font) {
PDType0Font typedFont = (PDType0Font) pdFont;
if (typedFont.getDescendantFont() instanceof PDCIDFontType2) {
PDCIDFontType2 f = (PDCIDFontType2) typedFont.getDescendantFont();
PDFontDescriptor fontDescriptor = pdFont.getFontDescriptor();
fontDescriptor.getCOSObject().removeItem(cidSet);
}
}
} catch (IOException e) {
e.printStackTrace();
}
// do stuff with the font
}
}
}
}
protected void prepareDocument() throws IOException {
PDDocumentCatalog cat = doc.getDocumentCatalog();
metadata = new PDMetadata(doc);
cat.setMetadata(metadata);
removeCidSet(cat, doc);
xmp = getXmpMetadata();
writeAdobePDFSchema(xmp);
writePDFAIdentificationSchema(xmp);
@@ -521,7 +564,7 @@ public class ZUGFeRDExporterFromA3 extends XRExporter implements IZUGFeRDExporte
return prepare();
}
public IExporter prepare() throws IOException{
public IExporter prepare() throws IOException {
prepareDocument();
xmlProvider.generateXML(trans);
String filename = getFilenameForVersion(ZFVersion, xmlProvider.getProfile());
@@ -529,7 +572,7 @@ public class ZUGFeRDExporterFromA3 extends XRExporter implements IZUGFeRDExporte
"Invoice metadata conforming to ZUGFeRD standard (http://www.ferd-net.de/front_content.php?idcat=231&lang=4)",
"text/xml", xmlProvider.getXML());
for (FileAttachment attachment: fileAttachments) {
for (FileAttachment attachment : fileAttachments) {
PDFAttachGenericFile(doc, attachment.getFilename(), attachment.getRelation(), attachment.getDescription(), attachment.getMimetype(), attachment.getData());
}
@@ -739,10 +782,11 @@ public class ZUGFeRDExporterFromA3 extends XRExporter implements IZUGFeRDExporte
protected void setXMLProvider(IXMLProvider p) {
this.xmlProvider = p;
if (profile!=null) {
if (profile != null) {
xmlProvider.setProfile(profile);
}
}
@Override
public ZUGFeRDExporterFromA3 setZUGFeRDVersion(int version) {
this.ZFVersion = version;

View File

@@ -272,7 +272,8 @@ public class ZUGFeRDImporter {
return extractString("//ApplicableHeaderTradeSettlement//InvoiceCurrencyCode");
}
} catch (final Exception e) {
e.printStackTrace();
Logger.getLogger(ZUGFeRDImporter.class.getName()).log(Level.SEVERE, null, e);
return "";
}
}
@@ -306,7 +307,7 @@ public class ZUGFeRDImporter {
return extractString("//BuyerOrderReferencedDocument//IssuerAssignedID");
}
} catch (final Exception e) {
e.printStackTrace();
Logger.getLogger(ZUGFeRDImporter.class.getName()).log(Level.SEVERE, null, e);
return "";
}
}
@@ -329,7 +330,7 @@ public class ZUGFeRDImporter {
return extractString("//ExchangedDocument//IssueDateTime//DateTimeString");
}
} catch (final Exception e) {
e.printStackTrace();
Logger.getLogger(ZUGFeRDImporter.class.getName()).log(Level.SEVERE, null, e);
return "";
}
}
@@ -345,7 +346,7 @@ public class ZUGFeRDImporter {
return extractString("//SpecifiedTradeSettlementHeaderMonetarySummation//TaxBasisTotalAmount");
}
} catch (final Exception e) {
e.printStackTrace();
Logger.getLogger(ZUGFeRDImporter.class.getName()).log(Level.SEVERE, null, e);
return "";
}
}
@@ -361,7 +362,7 @@ public class ZUGFeRDImporter {
return extractString("//SpecifiedTradeSettlementHeaderMonetarySummation//TaxTotalAmount");
}
} catch (final Exception e) {
e.printStackTrace();
Logger.getLogger(ZUGFeRDImporter.class.getName()).log(Level.SEVERE, null, e);
return "";
}
}
@@ -377,7 +378,7 @@ public class ZUGFeRDImporter {
return extractString("//SpecifiedTradeSettlementHeaderMonetarySummation//RoundingAmount");
}
} catch (final Exception e) {
e.printStackTrace();
Logger.getLogger(ZUGFeRDImporter.class.getName()).log(Level.SEVERE, null, e);
return "";
}
}
@@ -393,7 +394,7 @@ public class ZUGFeRDImporter {
return extractString("//SpecifiedTradeSettlementHeaderMonetarySummation//TotalPrepaidAmount");
}
} catch (final Exception e) {
e.printStackTrace();
Logger.getLogger(ZUGFeRDImporter.class.getName()).log(Level.SEVERE, null, e);
return "";
}
}
@@ -431,7 +432,7 @@ public class ZUGFeRDImporter {
return extractString("//ExchangedDocument//IncludedNote");
}
} catch (final Exception e) {
e.printStackTrace();
Logger.getLogger(ZUGFeRDImporter.class.getName()).log(Level.SEVERE, null, e);
return "";
}
}
@@ -456,7 +457,7 @@ public class ZUGFeRDImporter {
return extractString("//SpecifiedTradeSettlementHeaderMonetarySummation//LineTotalAmount");
}
} catch (final Exception e) {
e.printStackTrace();
Logger.getLogger(ZUGFeRDImporter.class.getName()).log(Level.SEVERE, null, e);
return "";
}
}
@@ -479,7 +480,7 @@ public class ZUGFeRDImporter {
return extractString("//ActualDeliverySupplyChainEvent//OccurrenceDateTime//DateTimeString");
}
} catch (final Exception e) {
e.printStackTrace();
Logger.getLogger(ZUGFeRDImporter.class.getName()).log(Level.SEVERE, null, e);
return "";
}
}
@@ -495,7 +496,7 @@ public class ZUGFeRDImporter {
return extractString("//ExchangedDocument//ID");
}
} catch (final Exception e) {
e.printStackTrace();
Logger.getLogger(ZUGFeRDImporter.class.getName()).log(Level.SEVERE, null, e);
return "";
}
}
@@ -513,7 +514,7 @@ public class ZUGFeRDImporter {
return extractString("//ExchangedDocument/TypeCode");
}
} catch (final Exception e) {
e.printStackTrace();
Logger.getLogger(ZUGFeRDImporter.class.getName()).log(Level.SEVERE, null, e);
return "";
}
}
@@ -530,7 +531,7 @@ public class ZUGFeRDImporter {
return extractString("//ApplicableHeaderTradeAgreement/BuyerReference");
}
} catch (final Exception e) {
e.printStackTrace();
Logger.getLogger(ZUGFeRDImporter.class.getName()).log(Level.SEVERE, null, e);
return "";
}
}
@@ -718,7 +719,7 @@ public class ZUGFeRDImporter {
nl = getNodeListByPath("//CrossIndustryInvoice//SupplyChainTradeTransaction//ApplicableHeaderTradeAgreement//BuyerTradeParty//PostalTradeAddress");
}
} catch (final Exception e) {
e.printStackTrace();
Logger.getLogger(ZUGFeRDImporter.class.getName()).log(Level.SEVERE, null, e);
return null;
}
@@ -741,7 +742,7 @@ public class ZUGFeRDImporter {
nl = getNodeListByPath("//CrossIndustryInvoice//SupplyChainTradeTransaction//ApplicableHeaderTradeAgreement//SellerTradeParty//PostalTradeAddress");
}
} catch (final Exception e) {
e.printStackTrace();
Logger.getLogger(ZUGFeRDImporter.class.getName()).log(Level.SEVERE, null, e);
return null;
}
@@ -940,7 +941,7 @@ public class ZUGFeRDImporter {
nl = getNodeListByPath("//CrossIndustryInvoice//SupplyChainTradeTransaction//IncludedSupplyChainTradeLineItem");
}
} catch (final Exception e) {
e.printStackTrace();
Logger.getLogger(ZUGFeRDImporter.class.getName()).log(Level.SEVERE, null, e);
}
for (int i = 0; i < nl.getLength(); i++) {
@@ -985,7 +986,7 @@ public class ZUGFeRDImporter {
final XPathExpression xpr = xPath.compile(s);
return (NodeList) xpr.evaluate(getDocument(), XPathConstants.NODESET);
} catch (final Exception e) {
e.printStackTrace();
Logger.getLogger(ZUGFeRDImporter.class.getName()).log(Level.SEVERE, null, e);
return null;
}
}

View File

@@ -377,7 +377,7 @@ public class ZF2PushTest extends TestCase {
.setDeliveryAddress(new TradeParty("just the other side of the street", "teststr.12a", "55232", "Entenhausen", "DE").addVATID("DE47110"))
.setContractReferencedDocument(contractID)
.setRecipient(new TradeParty("Franz Müller", "teststr.12", "55232", "Entenhausen", "DE").setID("0008734").addVATID("DE4711").setContact(new Contact("Franz Müller", "01779999999", "franz@mueller.de", "teststr. 12", "55232", "Entenhausen", "DE").setFax("++49555123456")).setAdditionalAddress("Hinterhaus 3"))
.addItem(new Item(new Product("Testprodukt", "", "C62", new BigDecimal(16)), price, new BigDecimal(1.0)).addNote("item level 1/1").addAllowance(new Allowance(new BigDecimal(0.02)).setReason("item discount").setTaxPercent(new BigDecimal(16))).setDetailedDeliveryPeriod(sdf.parse("2020-01-13"), sdf.parse("2020-01-15")))
.addItem(new Item(new Product("Testprodukt", "", "C62", new BigDecimal(16)), price, new BigDecimal(1.0)).addReferencedLineID("xxx").addNote("item level 1/1").addAllowance(new Allowance(new BigDecimal(0.02)).setReason("item discount").setTaxPercent(new BigDecimal(16))).setDetailedDeliveryPeriod(sdf.parse("2020-01-13"), sdf.parse("2020-01-15")))
.addCharge(new Charge(new BigDecimal(0.5)).setReason("quick delivery charge").setTaxPercent(new BigDecimal(16)))
.addAllowance(new Allowance(new BigDecimal(0.2)).setReason("discount").setTaxPercent(new BigDecimal(16)))
.setDeliveryDate(sdf.parse("2020-11-02")).setOwnVATID("DE0815").setNumber(number)
@@ -399,6 +399,7 @@ public class ZF2PushTest extends TestCase {
assertTrue(zi.getUTF8().contains("Hinterhaus"));
assertTrue(zi.getUTF8().contains("0009845"));
assertTrue(zi.getUTF8().contains("0008734"));
assertTrue(zi.getUTF8().contains("ram:BuyerOrderReferencedDocument"));
assertTrue(zi.getUTF8().contains(occurrenceFrom));
assertTrue(zi.getUTF8().contains(occurrenceTo));
assertTrue(zi.getUTF8().contains(contractID));