Class AbstractInvoice

java.lang.Object
com.fourjs.report.facturx.AbstractInvoice
Direct Known Subclasses:
Invoice, Invoice, Invoice, Invoice, Invoice

public abstract class AbstractInvoice extends Object
BG-0 Invoice — the root of a Factur-X (ZUGFeRD) Cross Industry Invoice (/rsm:CrossIndustryInvoice), and the abstract base class of the five profile-specific Invoice classes (MINIMUM, BASIC WL, BASIC, EN 16931 and EXTENDED). The concrete subclass carries the business-term accessors for its profile; this base class provides the behaviour they share:

main(String[]) is a command-line front end over these operations. It reads an invoice from -xmlInput, -pdfInput or -input and performs the action named by -action: xmlOutput and dataUrlOutput re-serialize the invoice, rawXmlOutput copies the embedded XML verbatim, metadataOutput prints the PDF metadata, JUnitJavaOutput emits a unit test, and validate (or the narrower validateAgainstXSD / validateAgainstSchematronXSLT) validates the document against the XML Schema and the Schematron rules. Validation needs the specification files, whose location is given by the specification.directory system property; the specification.version system property selects the release to validate against (1.09.2 by default, 1.0.07 and 1.0.06 are also known). Schematron warnings are reported but do not make a document invalid or change the exit status.

  • Field Details

    • debug

      public static final boolean debug
      Whether the API emits debug tracing while it builds and serializes an invoice. When true, diagnostic lines prefixed with "FACTUR-X DEBUG" are written to standard output; when false (the default), no such output is produced.

      The value is read once, at class initialization, from the facturx.debug system property: it is true only when that property is set to "true" (for example -Dfacturx.debug=true on the command line) and false otherwise.

    • computeBT131

      public static final boolean computeBT131
      Whether the invoiced line net amount BT-131 is computed by the API. When true (the default), each line's BT-131 is derived from its item net price and quantity and a value set through the corresponding setter is ignored unless recomputation is disabled; when false, BT-131 is not computed and the value you set is used as given.

      The value is read once, at class initialization, from the facturx.computeBT131 system property: it is false only when that property is set to "false" (for example -Dfacturx.computeBT131=false on the command line) and true otherwise.

  • Method Details

    • toXML

      public void toXML(PrintStream out) throws IOException, FacturXException
      Serializes to a Factur-X XML document that matches the profile specific XML Schema.
      Parameters:
      out - the print stream to write to
      Throws:
      IOException
      FacturXException
    • toXML

      public abstract void toXML(PrintWriter out) throws IOException, FacturXException
      Serializes to a Factur-X XML document that matches the profile specific XML Schema.
      Parameters:
      out - the print stream to write to
      Throws:
      IOException
      FacturXException
    • getProfile

      public abstract AbstractInvoice.Profile getProfile()
    • getXMLAsDataURL

      public String getXMLAsDataURL() throws IOException, FacturXException
      Throws:
      IOException
      FacturXException
    • toJUnitJavaSourceCode

      public abstract void toJUnitJavaSourceCode(PrintStream out, String packageName, String className, String referenceFilesDirectory) throws FacturXException
      Creates JUnit Java source code that will construct an Invoice instance identical with this Invoice from API calls and compare the produced XML against a reference file.
      Parameters:
      out - the print stream to write to
      packageName - the package name to use in the package declaration
      className - the name to use as class name for the test class
      referenceFilesDirectory - the directory in which the test expects the reference output xml file that is named className+".xml"
      Throws:
      FacturXException
    • main

      public static void main(String[] args) throws Exception
      Command-line entry point. It reads Factur-X documents and performs actions on them: one or more groups of the form -input <file>... -action <action>, processed left to right. Run it with -help for the usage text.

      The input is given by:

      -input <file>... (alias -inputFileName)
      one or more files, up to the next option, for the following -action; a .xml name is read as XML and a .pdf name as a hybrid PDF. A name containing * or ? in its last segment is expanded to the matching files, sorted by name (for shells that do not expand wildcards, such as the Windows command prompt); a pattern without a match is an error.
      -xmlInput <file>, -pdfInput <file>
      older options: read one invoice at once, for a following -xmlOutput or -JUnitJavaOutput (also older) or an output action without -input

      The action is selected by -action <action> and performed on every input file:

      xmlOutput
      re-serialize the invoice to Factur-X XML
      dataUrlOutput
      write the invoice as a base64 data: URL
      rawXmlOutput
      copy the embedded XML verbatim, without re-serializing
      metadataOutput
      print the PDF metadata (PDF input only)
      JUnitJavaOutput
      emit JUnit source that rebuilds the invoice through API calls (see toJUnitJavaSourceCode(PrintStream,String,String,String))
      validate, validateAgainstXSD, validateAgainstSchematronXSLT
      validate the document against the XML Schema, the Schematron rules, or both (validate); the specification files used are those bundled with the product, or those below the directory given by the specification.directory system property if it is set. Schematron warnings are reported but do not make the document invalid or change the exit status. With more than one input file, a summary line follows.

      The remaining options tune the output: -outputFileName <file> writes to a file instead of standard output (output actions, one input file only), and -packageName <name>, -className <name> and -referenceFilesDirectory <dir> supply the package, class name and reference-file directory used by JUnitJavaOutput.

      The order of the options matters, because they are processed left to right and -action acts immediately, on the state accumulated by the options that precede it: the input and every output option must therefore appear before the -action that uses them.

      A document that cannot be read or processed is reported and the remaining documents are still processed. The process exits with status 0 if every action succeeded and every validated document is valid, 1 if a document is not valid or could not be processed, and 2 if the command line is wrong (unknown option or action, missing value, missing input); nothing is silently ignored.

      Parameters:
      args - the command-line arguments described above
      Throws:
      Exception - never in practice; errors are reported and turned into the exit status
    • setRecompute

      public void setRecompute(boolean value)
      Controls the computation of computed fields like Invoice.getInvoiceTotalAmountWithoutVAT() By default the values are always computed but in the case that the values were explicitly set (e.g. after creating and instance via fromXMLFile(String,boolean)), it might be desirable to obtain the explicitly set values instead.
      Parameters:
      value - whether or not to ignore explicitly set values of computed fields and work with computed values instead
    • fromXMLFile

      public static AbstractInvoice fromXMLFile(String fileName, boolean recompute) throws IOException
      Creates an Invoice instance from a Factur-X XML document.
      Parameters:
      fileName - the Factur-X XML file to read from
      recompute - specifies whether or not computed fields are computed or the values from the file are used instead
      Throws:
      IOException
    • fromPDFFile

      public static AbstractInvoice fromPDFFile(String fileName, boolean recompute) throws IOException
      Creates an Invoice instance from a Factur-X hybrid PDF document.
      Parameters:
      fileName - the Factur-X hybrid PDF file to read from
      recompute - specifies whether or not computed fields are computed or the values from the file are used instead
      Returns:
      an Invoice instance or null if the PDF does not contain a file attachment named "factur-x.xml".
      Throws:
      IOException
    • parseDate

      public static LocalDate parseDate(String s) throws DateTimeParseException
      Deprecated.
      Use Util.parseDate(String) instead.
      parses dates in the Factur-x format YYYYMMDD
      Throws:
      DateTimeParseException
    • joinVeryLongString

      public static String joinVeryLongString(String[] chunks)
      Deprecated.
      Use Util.joinVeryLongString(String[]) instead.
      to be used for strings exceeding the compiler limit of 2^16 bytes for a string constant