ValidateInvoiceBusinessRules

Invoices, Compliance

Requires the Small Business edition — in Delphi, C++Builder and Lazarus code create the library as TPDFlibSmallBusiness (unit PDFlibSmallBusiness) or TPDFlibEnterprise; this method is Pascal-only: it returns a record through an out parameter and takes a provider interface, so no DLL, ActiveX or Dylib build exports it; the Single edition keeps the method, which returns False and sets LastErrorCode to 901 (PDFLIB_ERROR_SMALLBUSINESS_REQUIRED)

Description

Validate the selected embedded invoice XML with a versioned provider

Syntax

Delphi

Function TPDFlib.ValidateInvoiceBusinessRules(Const EmbeddedFileName: WideString;
  Const Request: TPDFInvoiceValidationRequest;
  Const Provider: IPDFInvoiceValidationProvider;
  Out Report: TPDFInvoiceValidationReport): Boolean; Virtual;

Parameters

EmbeddedFileNameFile name of the embedded invoice XML attachment to validate
RequestValidation request carrying the rule set, the schema and Schematron requirements, the timeout and the output size limit
ProviderProvider interface that executes the requested validation stages
ReportReceives the stage-by-stage validation report

Return values

Returns True when the requested rule validation ran and the embedded invoice passed, with the stage details in Report. Returns False when the attachment cannot be found, a stage could not run or rule violations were found; in editions without invoice validation the function returns False and leaves Report empty

Remarks

Finds a document-level embedded attachment by its exact, case-sensitive filename (or auto-detects the Factur-X or single XML attachment when EmbeddedFileName is empty) and replaces Request.XMLBytes with the decoded attachment bytes; caller-supplied XML cannot substitute for the actual invoice

Returns true only when every requested stage completes successfully; Report.Complete=true with IsValid=false distinguishes a completed validation that found issues from unavailable engines, malformed inputs, or incomplete runs

Missing, ambiguous, unreadable, or oversized attachments return false with LastErrorCode=401 and an Invoice.Attachment* diagnostic; matching is bounded to 16384 attachments and decoding to 64 MB

Set Request.Rules.Standard and Version explicitly and supply trusted rule files for the exact syntax and profile, including any required profile-specific rules

PLDefaultInvoiceValidationRequest requires both schema and Schematron stages, sets a 30000 ms timeout and an 8 MB output limit; callers can disable a stage explicitly, which remains not_checked and makes no claim about those rules

IPDFInvoiceValidationProvider.ValidateStage receives the selected XML and rule package and must return a complete stage result, engine diagnostics, and structured issues; unavailable and exceptional providers cannot pass

Each stage reports its Coverage: subset for the built-in rules and rulePackage when an external engine ran the supplied schema or Schematron package, with the left-out rule areas in NotCovered. Report.FullConformance is true only when the report is valid, every requested stage ran the supplied rules with nothing left in NotCovered, and the rules came from a verified rule package; the JSON report adds coverage, fullConformance and package. Each issue carries a Category such as schema, calculation, codelist, profile or integrity

Set Rules.PackageFile to a rule package directory or its rulepackage.xml manifest instead of SchemaFile and SchematronStylesheetFile. The manifest names the standard, version, schema and Schematron stylesheet and lists every package file with its SHA-256; each file is checked before validation and again when an engine reads it, and a schema may import only listed files. Rules.PackageSHA256 pins the manifest itself. A missing file, a changed digest, a path outside the package directory or a version other than the requested one stops both stages with an integrity issue (RulePackage.Missing, RulePackage.Integrity, RulePackage.Digest, RulePackage.Path, RulePackage.Mismatch or RulePackage.Manifest), and Report.Package carries the verification result

Use PLValidateInvoiceXML directly for standalone invoice XML, PLCreateExternalInvoiceValidationProvider for the built-in tool adapter, and PLInvoiceValidationReportToJSON to serialize typed results

See also

ValidateFacturXInvoice, ValidateInvoiceBusinessRulesWithTools, ValidateInvoiceBusinessRulesWithPackage, ExtractFacturXXMLToString