Format cash discount details correctly in the payment text

Error BR-DE-18 XRechnung

Discount lines in <name/> must match this regular expression: <value-of select="$XR-SKONTO-REGEX"/>. The information on granting a discount shall be transmitted in the element "Payment terms" (BT-20) as follows: The first segment shall be "SKONTO", the second "TAGE=n", the third "PROZENT=n". Percentages shall be stated without a sign and with a dot as the decimal separator and two decimal places. If the amount to be calculated is based not on BT-115, "Amount due for payment", but only on part of the invoice amount due, the base amount for calculating the discount shall be stated as the fourth segment "BASISBETRAG=n" in accordance with the semantic data type Amount. Each entry begins with a #, the segments are separated by a # and a line ends with a #. An XML-compliant line break shall follow at the end of a complete discount specification. All information on granting a discount shall be in uppercase. Additional whitespace (spaces, tabs or line breaks) is not permitted. Characters or text other than those specified above are not permitted.

Mandatory rule: As long as it is violated, the invoice is invalid and will be rejected by validators.
What is wrong

A cash discount entry in ram:Description does not match the required format. The segments must begin with and be separated by #; SKONTO, TAGE=n and PROZENT=n are required. If the calculation basis is not BT-115, BASISBETRAG=n must also be provided. Values must be uppercase, and the percentage must have no sign and use a decimal point followed by two digits. Disallowed whitespace, other content, or a missing XML-compliant line break at the end also causes the test to fail.

What the rule means

The payment terms convey cash discount details in a defined text format. The basis amount is required when the discount is calculated on part of the amount rather than the due payable amount BT-115.

Affected fields BT-20 BT-115
Please format the cash discount details in the payment terms correctly

The cash discount details in the payment text do not follow the required structure. Adjust the segments, the percentage, and the final line break.

What to do
  1. Check the first ram:Description under ram:SpecifiedTradePaymentTerms.
  2. Provide the segments in the order SKONTO, TAGE=n and PROZENT=n, separated by #.
  3. If the calculation basis is not BT-115, add BASISBETRAG=n; end the entry with # and an XML-compliant line break.
  4. Check the cash discount details using AddTradePaymentTerms(...) or PaymentTerms.
  5. Generate the invoice again and validate it once more.
What it looks like
✗ Triggers the message
<ram:SpecifiedTradePaymentTerms>
  <ram:Description>#SKONTO#TAGE=14#PROZENT=2#</ram:Description>
</ram:SpecifiedTradePaymentTerms>
✓ Correct
<ram:SpecifiedTradePaymentTerms>
  <ram:Description>#SKONTO#TAGE=14#PROZENT=2.00#</ram:Description>
</ram:SpecifiedTradePaymentTerms>
Check in FactoorSharp
  • FacturXInvoice.AddTradePaymentTerms(description, dueDate, paymentTermsType, dueDays, percentage, baseAmount, actualAmount, maturityDate) (BT-20)
  • FacturXInvoice.ClearTradePaymentTerms() (BT-20)
  • FacturXInvoice.DuePayableAmount (BT-115)
  • FacturXInvoice.GetTradePaymentTerms() (BT-20)
  • FacturXInvoice.PaymentTerms (BT-20)
Technical details

The test matches each line beginning with # in the first ram:Description against $XR-SKONTO-REGEX. It also requires the text after the last complete cash discount entry to begin with a line break.

Where the rule applies

The rule checks the first description under ram:SpecifiedTradePaymentTerms in the invoice header payment information.

Original message from the Schematron
Skonto Zeilen in <name/> muessen diesem regulärem Ausdruck entsprechen: <value-of select="$XR-SKONTO-REGEX"/>. Die Informationen zur Gewährung von Skonto müssen wie folgt im Element "Payment terms" (BT-20) übermittelt werden: Anzugeben ist im ersten Segment "SKONTO", im zweiten "TAGE=n", im dritten "PROZENT=n". Prozentzahlen sind ohne Vorzeichen sowie mit Punkt getrennt von zwei Nachkommastellen anzugeben. Liegt dem zu berechnenden Betrag nicht BT-115, "fälliger Betrag" zugrunde, sondern nur ein Teil des fälligen Betrags der Rechnung, ist der Grundwert zur Berechnung von Skonto als viertes Segment "BASISBETRAG=n" gemäß dem semantischen Datentypen Amount anzugeben. Jeder Eintrag beginnt mit einer #, die Segmente sind mit einer # getrennt und eine Zeile schließt mit einer # ab. Am Ende einer vollständigen Skontoangabe muss ein XML-konformer Zeilenumbruch folgen. Alle Angaben zur Gewährung von Skonto müssen in Großbuchstaben gemacht werden. Zusätzliches Whitespace (Leerzeichen, Tabulatoren oder Zeilenumbrüche) ist nicht zulässig. Andere Zeichen oder Texte als in den oberen Vorgaben genannt sind nicht zulässig.
Context (rule/@context)
/rsm:CrossIndustryInvoice
Test expression (assert/@test)
every $line in rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeSettlement/ ram:SpecifiedTradePaymentTerms/ram:Description[1]/tokenize(. , '(\r?\n)')[starts-with( normalize-space(.) , '#')] satisfies matches ( normalize-space ($line), $XR-SKONTO-REGEX ) and matches( rsm:SupplyChainTradeTransaction/ram:ApplicableHeaderTradeSettlement/ ram:SpecifiedTradePaymentTerms/ram:Description[1]/tokenize(. , '#.+#')[last()], '^\s*\n' )