Debian Codegraph @

texmf-dist/source/latex/zugferd/zugferd.dtx

raw
1 % \iffalse meta-comment
2 %
3 % Copyright (C) 2021–2026 Marei Peischl <[email protected]>
4 % ---------------------------------------------------------
5 %
6 % This file may be distributed and/or modified under the
7 % conditions of the LaTeX Project Public License, either version 1.3c
8 % of this license or (at your option) any later version.
9 % The latest version of this license is in:
10 %
11 % http://www.latex-project.org/lppl.txt
12 %
13 % and version 1.3c or later is part of all distributions of LaTeX
14 % version 2008-05-04 or later.
15 %
16 % \fi
17 % \iffalse
18 %<*driver>
19 \ProvidesFile{zugferd.dtx}[2026-05-25 v0.11 ZUGFerd Invoice and Faktur-X]
20 %</driver>
21 %<package>\NeedsTeXFormat{LaTeX2e}[2023-11-01]
22 %<package>\ProvidesExplPackage{zugferd}{2026-05-25}{0.11}{Create ZUGFerd invoices using LaTeX}
23 %<*driver>
24 \RequirePackage{pdfmanagement}
25 \SetKeys[document/metadata]{
26 pdfstandard=a-3b,
27 pdfversion=1.7,
28 lang=en
29 }
30 \documentclass[english,lm-default=false,cs-break-nohyphen]{l3doc}
31 \usepackage{babel}
32 \usepackage{zugferd}[2026-05-25]
33 \EnableCrossrefs
34 %\CodelineIndex
35 \RecordChanges
36 \usepackage{biblatex}
37
38 \usepackage[highlightmode=immediate]{minted}
39 \newenvironment{examplecode}{%
40 \VerbatimEnvironment%
41 \fvset{gobble=0}%
42 \begin{VerbatimOut}[tabsize=3,gobble=1]{examplecode.out}%
43 }{%
44 \end{VerbatimOut}%
45 \inputminted[autogobble, escapeinside=||]{latex}{examplecode.out}%
46 }
47
48 \usepackage{accsupp}
49 \setminted{breaksymbol={\BeginAccSupp{method=escape,ActualText={}}\tiny\ensuremath{\hookrightarrow}\EndAccSupp{}},breaklines}
50
51 \ExplSyntaxOn
52 \makeatletter
53 \tl_new:N \l_ptxtools_doc_values_tl
54 \newcommand*{\codefamily}{\MacroFont}
55 \DeclareTextFontCommand{\codefont}{\codefamily}
56 \providecommand{\option}[1]{\codefont{#1}}
57 \providecommand{\value}[1]{\codefont{#1}}
58
59 \cs_new:Npn \_ptxtools_parse_key_option:w #1 #2 #3 #4 = #5 \q_stop {
60 \par
61 \begingroup
62 \def\PrintDescribeOption##1{
63 \parbox[b]{\marginparwidth}{\raggedleft\MacroFont ##1=}
64 \rlap{
65 \hskip\marginparsep\small
66 \IfBooleanTF{#3}
67 {\textsf{#5}}
68 {\textsf{(\codefont{#5})}}
69 }
70 }
71 \noindent\DescribeOption{#4}\hfill
72 \small
73 \tl_if_blank:nTF {#2} {\meta{\textrm{initially~unset}}} {
74 \IfBooleanTF{#1}
75 {#2}
76 {(default:~\codefont{#2})}
77 }\strut
78 \seq_if_empty:NF \l_ptxtools_BTkey_seq {
79 \rlap{\qquad\int_compare:nNnTF {\seq_count:N \l_ptxtools_BTkey_seq} = 1 {\seq_use:Nn \l_ptxtools_BTkey_seq {,}\seq_gclear:N \l_ptxtools_BTkey_seq} {BT-\meta{n}}}
80 }
81 \seq_if_empty:NF \l_ptxtools_BTkey_seq {
82 \par\strut\hfill
83 \seq_use:Nn \l_ptxtools_BTkey_seq {,~}
84 }
85 \par
86 \endgroup
87 }
88
89 \newcommand*{\PrintDescribeKeyOption}[1]{
90 {\MacroFont #1=}\rlap{\hskip\marginparsep \l_ptxtools_doc_values_tl}
91 }
92
93 \bool_new:N \l_ptxtools_last_was_describe_bool
94 \seq_new:N \l_ptxtools_BTkey_seq
95
96 \NewDocumentCommand{\DescribeKeyOption}{sO{}mms}{
97 \seq_set_from_clist:Nn \l_ptxtools_BTkey_seq {#2}
98 \bool_if:NTF \l_ptxtools_last_was_describe_bool {
99 \vskip -\lastskip
100 }{
101 \par
102 \dim_compare:nNnF {\parskip} > {\c_zero_dim} {\medskip}
103 }
104 \_ptxtools_parse_key_option:w #1 {#4} #5 #3 \q_stop
105 \bool_set_true:N \l_ptxtools_last_was_describe_bool
106 \AddToHookNext{para/begin}{
107 \bool_set_false:N \l_ptxtools_last_was_describe_bool
108 \OmitIndent
109 }
110 \smallskip
111 }
112
113 \newenvironment{valuelist}{
114 \list{}{
115 \labelwidth0pt
116 \itemindent0pt
117 \leftmargin0pt
118 \let\makelabel\valuelistlabel
119 \parskip\z@\itemsep\z@
120 }
121 }{
122 \endlist
123 }
124 \newcommand*\valuelistlabel[1]{
125 \makebox[\labelwidth][r]{
126 \normalfont\codefamily\color_select:n {black!60}
127 \begin{tabular}[t]{@{}r@{}}
128 \clist_use:nn {#1} {\\}
129 \end{tabular}
130 }
131 }
132
133 \newcommand*{\accessTaxExemptionReason}[1]{
134 \keys_set:nn {zugferd / tax } {category=#1}
135 Exemption~reason:~\tl_if_empty:NTF \l__zugferd_tax_exemption_reason_tl {\meta{empty}} {\l__zugferd_tax_exemption_reason_tl};~
136 Exemption~reason~code:~\tl_if_empty:NTF \l__zugferd_tax_exemption_code_tl {\meta{empty}} {\l__zugferd_tax_exemption_code_tl}
137 }
138 % to support small layout adjustments for the texdoc version
139 \newcommand*{\IfOnlyDocumentation}[1]{
140 \bool_if_exist:NT \g__codedoc_typeset_implementation_bool {
141 \bool_if:NF \g__codedoc_typeset_implementation_bool {#1}
142 }
143 }
144 % add a subtitle
145 \def\@maketitle{%
146 \newpage
147 \null
148 \vskip 2em%
149 \begin{center}%
150 \let \footnote \thanks
151 {\LARGE \@title \par}%
152 \vskip 1.5em%
153 {\large \@subtitle \par}%
154 \vskip 1em%
155 {\large
156 \lineskip .5em%
157 \begin{tabular}[t]{c}%
158 \@author
159 \end{tabular}\par}%
160 \vskip 1em%
161 {\large \@date}%
162 \end{center}%
163 \par
164 \vskip 1.5em}
165 \newcommand{\subtitle}[1]{\def\@subtitle{#1}}
166 \subtitle{}
167 \makeatother
168 \ExplSyntaxOff
169
170 \usepackage{underscore-ltx}
171
172 \begin{filecontents}{zugferd.bib}
173 @online{x-rechnung,
174 url={https://xeinkauf.de/dokumente/},
175 urldate={2024-08-20}
176 }
177 @online{spec-xrechnung,
178 url={https://xeinkauf.de/app/uploads/2024/07/302-XRechnung-2024-06-20.pdf},
179 author={{Koodinierungsstelle für IT-Standards}},
180 title={Spezifikation Standard XRechnung},
181 subtitle={CIUS und Extension},
182 edition={Version XRechnung 3.0.2},
183 date={2024-06-20},
184 urldate={2024-08-20},
185 langid={german}
186 }
187 @online{mustang-project,
188 title={Mustang Project},
189 url={https://github.com/ZUGFeRD/mustangproject},
190 urldate={2024-08-20}
191 }
192 @online{country-codes,
193 title={ECE/TRADE/201},
194 subtitle={ISO COUNTRY CODE for Representation of Names of Countries},
195 url={https://unece.org/trade/documents/iso-country-code-representation-names-countries},
196 urldate={2024-08-20},
197 }
198 @online{unit-codes,
199 title={Rec 20 – Codes for Units of Measure Used in International Trade},
200 url={https://unece.org/sites/default/files/2023-10/rec20_Rev17e-2021.xlsx},
201 urldate={2024-08-20},
202 note={Link directly to xlsx. \cite[see][for all revisions]{cl-recommendations}.}
203 }
204 @online{cl-recommendations,
205 author={United Nations Economic Commission for Europe (UNECE)},
206 title={Code List Recommendations},
207 url={https://unece.org/trade/uncefact/cl-recommendations},
208 urldate={2024-08-20}
209 }
210 @online{VAT-exemption-codes,
211 title={VAT exemption reason code list},
212 url={https://www.xrepository.de/details/urn:xoev-de:kosit:codeliste:vatex_1},
213 urldate={2024-08-20}
214 }
215 @online{zugferd-download,
216 title={ZUGFeRD 2.2},
217 subtitle={Download page},
218 url={https://ferd-net.de/standards/zugferd-2.2/zugferd-2.2.html},
219 urldate={2024-09-02},
220 }
221 @manual{scrletter,
222 title = {The scrletter package},
223 subtitle = {Letter extension to KOMA-Script classes},
224 author = {Kohm, Markus},
225 url = {https://komascript.de/},
226 urldate = {2024-09-03},
227 documentation = {ctan://macros/latex/contrib/koma-script/doc/scrguide-en.pdf},
228 date = {2023-07-07},
229 version = {3.41},
230 }
231 @online{leitweg-id,
232 title={Xeinkauf FAQ},
233 subtitle={Leitweg ID},
234 author={{Koordinierungsstelle für IT Standards (KoSIT)}},
235 url={https://xeinkauf.de/faq/xrechnung#leitweg-id},
236 urldate={2024-09-04}
237 }
238 @online{LaTeX-ZUGFeRD-GitHub,
239 title={ZUGFeRD - Create ZUGFeRD and other kinds of E-invoices using \LaTeX},
240 subtitle={GitHub Repository},
241 author={Peischl, Marei},
242 url={https://github.com/TeXhackse/LaTeX-ZUGFeRD}
243 }
244 @online{hyperref,
245 title = {CTAN: Package hyperref},
246 urldate = {2025-01-02},
247 language = {english},
248 author={Rahtz, Sebastian and Oberdiek, Heiko and {The \LaTeX{} Project}},
249 date={2024-11-05},
250 url = {https://ctan.org/pkg/hyperref},
251 documentation = {ctan://macros/latex/contrib/hyperref/doc/hyperref-doc.pdf}
252 }
253 \end{filecontents}
254 \addbibresource{zugferd.bib}
255 \nocite{cl-recommendations}
256
257 \usepackage{xspace}
258 \newcommand*{\XML}{XML\xspace}
259 \newcommand*{\XMLfile}{\XML file\xspace}
260
261 \DeclareRobustCommand{\issue}[1]{%
262 {\DeclareFieldFormat{citeurlpostfix}{\href{##1/issues/#1}{\##1}}\citefield{LaTeX-ZUGFeRD-GitHub}[citeurlpostfix]{url}}%
263 }
264 \newcommand*{\version}[1]{v#1}
265
266 \ExplSyntaxOn
267 \DoNotIndex{today,\bool_new:N,\bool_new:N,\str_gset:Nn,\newcommand,\newenvironment,\jobname,\def,\begin,\begingroup,
268 \let,\SetZugferdData,\today,\str_new:N,\keys,\tl_new:N,\str_gset:Nn,\bool_gset_false:N,\keys_set:nn,\tl_gset:Nn,
269 \char_set_catcode_parameter:N,\cs_if_exist:NTF,\iow_new:N,\pdfmeta_xmp_xmlns_new:nn,
270 \msg_new:nnnn,\msg_new:nnn,\keys_define:nn,\char_set_catcode_other:N,\bool_gset_true:N,\c_hash_str,\pdfmeta_xmp_property_new:nnnnn,\iow_newline:,\bool_if:NTF,\NewExpandableDocumentCommand,\NewDocumentEnvironment,\NewDocumentCommand,\IfPackageAtLeastTF,\IfNoValueTF,\IfNoValueT,\IfNoValueF,\IfNoValueTF,\iffalse,\fi,\ExplSyntaxOn,\ExplSyntaxOff}
271 \ExplSyntaxOff
272
273 \begin{document}
274 \EnableDocumentation\DisableImplementation
275 \DocInput{zugferd.dtx}
276
277 % don't typeset implementation for CTAN
278 \expandafter\ifx\csname DoNotTypesetImplementation\endcsname\relax
279 \DisableDocumentation\EnableImplementation
280 \DocInputAgain
281 \fi
282
283 \PrintChanges
284 \printbibliography
285 \PrintIndex
286 \end{document}
287 %</driver>
288 % \fi
289 %
290 % \changes{v0.8}{2024-09-11}{First CTAN version}
291 %
292 % \GetFileInfo{zugferd.dtx}
293 %
294 % \begin{documentation}
295 % \title{The \pkg{zugferd} package\thanks{This document
296 % corresponds to \textsf{zugferd}~\fileversion, dated \filedate.}}
297 % \subtitle{Creating electronic and hybrid invoices using \LaTeX}
298 % \author{Marei Peischl \\ \texttt{[email protected]}}
299 %
300 % \maketitle
301 %
302 % \begin{abstract}
303 % Invoicing is getting more and more automated.
304 % Starting with public sector, within Germany there already is a requirement to stick to the Faktur-X Standard.
305 % First invoices based on this implementation here have been created back in 2021.
306 % And this is now the trial to create a more universal and public package to support the current version of ZUGFeRD and therefore also X-Rechung and Faktur-X.
307 %
308 % \indent The fundamental idea of this package was to use the calculation within \LaTeX{} as well. So it also creates the \XMLfile for the attachment on the fly.
309 % To match typical setups there is a wrapper package which usually would also hold the personal invoicing layout configuration.
310 % \end{abstract}
311 %
312 % \IfOnlyDocumentation{\vfill}
313 % \section*{Sponsors \& Supporters}
314 % Most of this package has been created within my free time and for my personal use. At start, it was not a paid project at all.
315 % Since it is addressing business users it would be great if we could keep this actively maintained.
316 % If you are able to support this either financially for the maintenance effort, a custom extension, I'd love to hear from you.
317 %
318 % This project was financially supported by:
319 % \begin{itemize}
320 % \item Pengutronix e.K., \url{https://pengutronix.de}\newline
321 % Special thanks to them, as they also sponsored the minimal portable \TeX{} Live setup.
322 % \item Frederik Schwan (\href{https://schwan.it}{\nolinkurl{Schwan.IT}})
323 % \item byte physics e.K., \url{https://www.byte-physics.de}
324 % \end{itemize}
325 %
326 % \IfOnlyDocumentation{\clearpage}
327 %
328 % \tableofcontents
329 %
330 % \IfOnlyDocumentation{\clearpage}
331 %
332 % \section{Quick start}
333 % This package is still in development and does not provide any validation.
334 % To ensure your invoice is created correctly you should also validate the output files.
335 % There are tools like the \citetitle{mustang-project} \cite{mustang-project} providing an easy-to-use interface for the validation.
336 % In the appendix I will add some notes on my setup and how I use it within pipelines.
337 %
338 % The bundle provides an example file called \file{DEMO-rechnung-zugferd.tex}.
339 % This includes a basic setup for a valid X-Rechnung currently matching Version 3.0.2 of the standard.
340 % Details on the requirements can be found in the documentation at \cite{x-rechnung}.
341 %
342 % \subsection{Disclaimer concerning the \pkg{zugferd-invoice} Package}
343 % The included package \pkg{zugferd-invoice} is an example project which might match your own invoicing structure.
344 % It holds all the layout information which is static across all the invoices.
345 % This package is an example implementation and should not be used in production.
346 % It is published as a part of the documentation.
347 %
348 % The idea is to create your own version of this package to use your own layout and internally load the \pkg {zugferd} package that way.
349 % Of course, it's possible to use a copy of this package within your personal setup.
350 % But the syntax used in the DEMO file may change, so you have to ensure yourself to be compatible with updates.
351 %
352 % The interfaces for \pkg{zugferd} will hopefully stay the same.
353 % At least changes will be announced and build compatible during a deprecation period.
354 %
355 % \end{documentation}
356 % \iffalse
357 % \begin{macrocode}
358 %<*package>
359 %<@@=zugferd>
360 % \end{macrocode}
361 % Workaround to replace module name without having a visible <@@=zugferd> in the documentation
362 %</package>
363 % \fi
364 % \ExplSyntaxOn
365 % \tl_gset:Nn \g__codedoc_module_name_tl {zugferd}
366 % \ExplSyntaxOff
367 % \iffalse
368 %<*driver>
369 % \fi
370 % \begin{documentation}
371 \ExplSyntaxOn
372 \tl_gset:Nn \g__codedoc_module_name_tl {zugferd}
373 \ExplSyntaxOff
374 % \end{documentation}
375 % \iffalse
376 %</driver>
377 %<*package>
378 % \fi
379 % \begin{implementation}
380 % \section{Implementation}
381 % \changes{v0.11-dev}{2025-12-28}{Move definition of globa temporary tl}
382 % \begin{variable}{\l_@@_tmp_tl,\g_@@_tmp_tl,\g_@@_format_str,\g_@@_businessProcessId_str,\g_@@_writeTradeContact_bool,\g_@@_writePaymentMeans_bool,\g_@@_minimum_bool,\g_@@_conformance_level_str,\g_@@_xml_embedded_file_tl}
383 % \begin{macrocode}
384 \tl_new:N \l_@@_tmp_tl
385 \tl_new:N \g_@@_tmp_tl
386 \str_new:N \g_@@_format_str
387 \str_new:N \g_@@_businessProcessId_str
388 \bool_new:N \g_@@_writeTradeContact_bool
389 \bool_new:N \g_@@_writePaymentMeans_bool
390 \bool_new:N \g_@@_minimum_bool
391 \str_new:N \g_@@_conformance_level_str
392 \tl_new:N \g_@@_xml_embedded_file_tl
393 % \end{macrocode}
394 % \end{variable}
395 % \end{implementation}
396 % \begin{documentation}
397 % \section{Package Options}\label{sec:package-options}
398 % The package supports a few fundamental settings.
399 % These have to be set when the package is loaded as they are used internally to setup the scheme or activate the \XML mechanism.
400 %
401 % \DescribeKeyOption{format=xrechnung/xrechnung3.0/xrechnung2.3/basic/minimum}{xrechnung}
402 % \option{format} selects the scheme to be used for the zugferd invoice.
403 % Currently xrechnung3.0, xrechnung2.3, and the basic and minimum schemes are supported.
404 %
405 % The value \option{xrechnung} is set as an alias to |xrechnung3.0| and will always use the latest version supported by \pkg{zugferd}.
406 %
407 % This option also adjusts the file name which is used for embedding the \XML.
408 % It will be called |factur-x.xml| for all formats but the |xrechnung| ones.
409 % In that case it will be |xrechnung.xml|.
410 %
411 % \DescribeKeyOption{zugferd=\meta{boolean}}{true}*
412 % This option can be used to deactivate the \XML embedding.
413 % It would also disable the the \option{write-xml} option.
414 % This can be used to create a package which can use the same structure to also create invoices without \XML attachment.
415 % It can also be used with older \LaTeX{} releases than this package requires.
416 % There will be a warning, but the visible part should be okay.
417 %
418 % \DescribeKeyOption{write-xml=\meta{boolean}}{true}*
419 % Disable the \XML output.
420 % This can be used if you want to create the \XML attachment with different software than this package.
421 %
422 % In that case you can either rename your file to \meta{\cs[no-index]{jobname}\_zugferd.xml} or also adjust the \option{xml-file} option.
423 %
424 % \DescribeKeyOption{xml-file=\meta{filename}}{\cs[no-index]{jobname}_zugferd.xml}*
425 % Adjust the file name of the created or loaded \XMLfile.
426 %
427 % The option \option{xrechnung} is only used internally to set the global parameters for all |xrechnung| variants.
428 %
429 % \end{documentation}
430 % \begin{implementation}
431 % \begin{optionenv}{format,xrechnung,write-xml,zugferd,xml-file}
432 % \changes{v0.9a}{2024-11-07}{Add support for format=minimum}
433 % \changes{v0.11-dev}{2026-05-25}{change format and profile options to .usage=general}
434 % \begin{macrocode}
435 \char_set_catcode_other:N \#%
436 \keys_define:nn {zugferd} {
437 xrechnung .code:n = {
438 \bool_gset_true:N \g_@@_writeTradeContact_bool
439 \bool_gset_true:N \g_@@_writePaymentMeans_bool
440 \str_gset:Nn \g_@@_conformance_level_str {XRECHNUNG}
441 \tl_gset:Nn \g_@@_xml_embedded_file_tl {xrechnung.xml}
442 },
443 format .choice:,
444 format / xrechnung3.0 .code:n = {
445 \str_gset:Nx \g_@@_format_str {
446 urn:cen.eu:en16931:2017#compliant#urn:xeinkauf.de:kosit:xrechnung_3.0
447 }
448 \str_gset:Nx \g_@@_businessProcessId_str {
449 urn:fdc:peppol.eu:2017:poacc:billing:01:1.0
450 }
451 \keys_set:nn {zugferd}{xrechnung}
452 },
453 format / xrechnung2.3 .code:n = {
454 \str_gset:Nx \g_@@_format_str {
455 urn:cen.eu:en16931:2017#compliant#urn:xoev-de:kosit:standard:xrechnung_2.3
456 }
457 \keys_set:nn {zugferd}{xrechnung}
458 },
459 format / basic .code:n = {
460 \str_gset:Nx \g_@@_format_str {
461 urn:cen.eu:en16931:2017#compliant#urn:factur-x.eu:1p0:basic
462 }
463 \bool_gset_false:N \g_@@_writeTradeContact_bool
464 % \bool_gset_false:N \g_@@_writePaymentMeans_bool
465 \str_gset:Nn \g_@@_conformance_level_str {BASIC}
466 \tl_gset:Nn \g_@@_xml_embedded_file_tl {factur-x.xml}
467 },
468 format / minimum .code:n = {
469 \str_gset:Nx \g_@@_format_str {
470 urn:factur-x.eu:1p0:minimum
471 }
472 \bool_gset_true:N \g_@@_minimum_bool
473 \bool_gset_false:N \g_@@_writeTradeContact_bool
474 \bool_gset_false:N \g_@@_writePaymentMeans_bool
475 \str_gset:Nn \g_@@_conformance_level_str {MINIMUM}
476 \tl_gset:Nn \g_@@_xml_embedded_file_tl {factur-x.xml}
477 },
478 format / xrechnung .meta:n = { format = xrechnung3.0 },
479 format .initial:n = xrechnung,
480 format .usage:n = general,
481 write-xml .bool_gset:N = \g_@@_write_xml_bool,
482 write-xml .initial:n = true,
483 write-xml .usage:n = general,
484 zugferd .bool_gset:N = \g_@@_active_bool,
485 zugferd .initial:n = true,
486 zugferd .default:n = true,
487 zugferd .usage:n = general,
488 ZUGFerD .meta:n = {zugferd = #1},
489 xml-file .tl_gset:N = \g_@@_xml_file_tl,
490 xml-file .initial:n = \jobname _zugferd.xml,
491 xml-file .usage:n = general,
492 % \end{macrocode}
493 % Option to log variables for interface tests.
494 % \begin{macrocode}
495 testing .bool_gset:N = \g_@@_testing_bool,
496 testing .initial:n = false,
497 testing .usage:n = load,
498 % \end{macrocode}
499 % \end{optionenv}
500 % \end{implementation}
501 % \begin{documentation}
502 % \DescribeKeyOption{auto-exemption=\meta{boolean}}{true}
503 % \pkg{zugferd} tries to automatically add an exemption-reason for the most common VAT categories.
504 % In case a more specific reason is required this setting can be disabled and everything should be configured manually.
505 % See \autoref{sec:tax-category} for more explanation of this feature and the categories this applies to.
506 %
507 % \end{documentation}
508 % \begin{implementation}
509 % \changes{v0.7}{2024-09-10}{Added auto-exemption option}
510 % \begin{optionenv}{auto-exemption}
511 % \begin{macrocode}
512 auto-exemption .bool_gset:N = \g_@@_auto_exemption_bool,
513 auto-exemption .initial:n = true,
514 auto-exemption .default:n = true,
515 auto-exemption .usage:n = load,
516 % \end{macrocode}
517 % \end{optionenv}
518 % \end{implementation}
519 % \begin{documentation}
520 % \DescribeKeyOption{unknown-value-warning=\meta{boolean}}{true}
521 % There are predefined values for units, tax categories and payment-means.
522 % Since there are a lot of options \pkg{zugferd} does not define all of them.
523 % In case you want to use another one as the predefined options you there will a warning to make you aware of the fact, that the package does not know if that's a valid selection.
524 % This is to help you avoiding typos.
525 % In case you are sure about your selection and don't want to define an own value for this you can also disable the warning by setting \option{unknown-value-warning} to false.
526 %
527 % \end{documentation}
528 % \begin{implementation}
529 % \changes{v0.9d}{2025-01-02}{Added unknown-value-warning option}
530 % \begin{optionenv}{unknown-value-warning}
531 % \begin{macrocode}
532 unknown-value-warning .bool_gset:N = \g_@@_unknown_value_warning_bool,
533 unknown-value-warning .initial:n = true,
534 % \end{macrocode}
535 % \end{optionenv}
536 % \begin{macrocode}
537 }
538 \char_set_catcode_parameter:N \#%
539
540 \ProcessKeyOptions[zugferd]
541 % \end{macrocode}
542 % \subsection{Preparation to write the \file{.xml} file}
543 % \begin{variable}{\_@@_xml_writer_iow}
544 % \begin{macrocode}
545 \iow_new:N \_@@_xml_writer_iow
546 % \end{macrocode}
547 % \end{variable}
548 % To adjust the metadata it is necessary to use the \pkg{pdfmanagement-testphase} by Ulrike Fischer from the \LaTeX{} Project Team.
549 % She had prepared some experiment files for the PDF attachment in the experiments of the repository.
550 % We use these to embed the \XMLfile \issue{7}.
551 %
552 % This part prepares the XMP metadata according to the required scheme.
553 % \changes{v0.8a}{2024-09-17}{Use the new public interface for l3pdfmeta.}
554 % \changes{v0.11-dev}{2026-05-25}{Use command to check for pdfmanagement is compatible in case it is activated later.}
555 % \begin{macrocode}
556 \cs_new:Nn \_@@_check_for_pdfmanagement: {
557 \cs_if_exist:NF \pdfmeta_xmp_xmlns_new:nn {
558 \msg_new:nnnn {zugferd} {PDFmanagement-not-active} {
559 The~\LaTeX~PDF~management~is~not~active.\\
560 Activate~it~using~\string\DocumentMetadata.
561 } {
562 See~ZUGFeRD~or~PDFmanagement~documentation~for~more~information.
563 }
564 \msg_error:nn {zugferd} {PDFmanagement-not-active}
565 }
566 % \end{macrocode}
567 % \changes{v0.9a}{2024-11-07}{Add error message if pdfmanagement is outdated.}
568 % \changes{v0.9c}{2024-12-08}{Compatbility to show the error message in older formats versions.}
569 % \begin{macrocode}
570 \IfPackageAtLeastF{pdfmanagement}{2025-08-05}{
571 \IfPackageAtLeastF{pdfmanagement-testphase}{2024/09/13}{
572 \msg_new:nnnn {zugferd} {PDFmanagement-too-old} {
573 Your~version~of~\LaTeX's~PDF~management~is~too~old.
574 }{
575 You~need~to~update~your~LaTeX~distribution~to~be~able~
576 to~use~the~zugferd~package~correctly.
577 }
578 \msg_error:nn{zugferd} {PDFmanagement-too-old}
579 }
580 }
581 % \end{macrocode}
582 % Deactivate test, as this has to be done only once.
583 % \begin{macrocode}
584 \cs_gset_eq:NN \_@@_check_for_pdfmanagement: \prg_do_nothing:
585 }
586 \bool_if:NT \g_@@_active_bool {
587 \_@@_check_for_pdfmanagement:
588 }
589 % \end{macrocode}
590 % \changes{v0.11-dev}{2026-03-13}{Move metadata setup to enddocument}
591 % As the PDF metadata is written at the end of a document it's not necessary to select the type at beginning.
592 % \begin{macrocode}
593 \hook_gput_code:nnn {enddocument} {zugferd/set-metadata} {
594 \bool_if:NT \g_@@_active_bool {
595 \_@@_check_for_pdfmanagement:
596 %% based on experiments for l3pdfmeta by Ulrike Fischer
597 \pdfmeta_xmp_xmlns_new:nn {fx}{
598 urn:factur-x:pdfa:CrossIndustryDocument:invoice:1p0\c_hash_str
599 }
600
601 \pdfmeta_xmp_schema_new:nnn
602 {Factur-X~PDFA~Extension~Schema}
603 {fx}
604 {urn:factur-x:pdfa:CrossIndustryDocument:invoice:1p0\c_hash_str}
605
606 \pdfmeta_xmp_property_new:nnnnn
607 {fx}
608 {DocumentFileName}
609 {Text}
610 {external}
611 {name~of~the~embedded~XML~invoice~file}
612
613 \pdfmeta_xmp_property_new:nnnnn
614 {fx}
615 {DocumentType}
616 {Text}
617 {external}
618 {INVOICE}
619
620 \pdfmeta_xmp_property_new:nnnnn
621 {fx}
622 {Version}
623 {Text}
624 {external}
625 {The~actual~version~of~the~factur-x~schema}
626
627 \pdfmeta_xmp_property_new:nnnnn
628 {fx}
629 {ConformanceLevel}
630 {Text}
631 {external}
632 {The~conformance~level~of~the~factur-x~data}
633
634 \exp_args:Ne \pdfmeta_xmp_add:n {
635 % fix INVOICE
636 <fx:DocumentType>INVOICE</fx:DocumentType>
637 \iow_newline:
638 <fx:DocumentFileName>\g_@@_xml_embedded_file_tl</fx:DocumentFileName>
639 \iow_newline:
640 % fix schema version
641 <fx:Version>1.0</fx:Version>
642 \iow_newline:
643 % zulässige Werte MINIMUM, BASIC WL, BASIC, EN 16931, EXTENDED, XRECHNUNG
644 <fx:ConformanceLevel>\g_@@_conformance_level_str%
645 </fx:ConformanceLevel>%
646 \iow_newline:
647 %
648 }
649 }
650 }
651 % \end{macrocode}
652 % \end{implementation}
653 % \begin{documentation}
654 % \section{User Commands}
655 % The end user is only asked to set or access the data to be used by \pkg{zugferd}.
656 %
657 % \subsection{Setting Data}
658 % \begin{function}{\SetZUGFeRDData,\SetZugferdData}
659 % \begin{syntax}
660 % \cs[no-index]{SetZUGFeRDData}*\marg{key value list}
661 % \end{syntax}
662 %
663 % The two modes of \cs[no-index]{SetZUGFeRDData} control if the argument is expanded before the data is processed.
664 % Depending on the source of the data this might be necessary.
665 % In that case activate the expansion by using the star argument.
666 % Fields which are involved in the calculation will be expanded anyway, but the text fields will not, to support special characters.
667 % \end{function}
668 % \end{documentation}
669 % \begin{implementation}
670 % \begin{macro}{\SetZUGFeRDData}
671 % \begin{macrocode}
672 \NewDocumentCommand{\SetZUGFeRDData}{sm}{
673 \IfBooleanTF{#1}
674 {\keys_set:ne}
675 {\keys_set:nn}
676 {zugferd} {#2}
677 }
678 \let\SetZugferdData\SetZUGFeRDData
679 % \end{macrocode}
680 % \end{macro}
681 % \end{implementation}
682 % \begin{documentation}
683 % \subsection{Accessing Data for PDF output}
684 % \begin{function}{\InsertZUGFeRDData}
685 % \begin{syntax}
686 % \cs[no-index]{InsertZugferdData}\oarg{special mode option}\marg{data-selection}
687 % \end{syntax}
688 % ZUGFerd uses the same data as the \XMLfile inside the PDF.
689 % To simplify the reuse of data this command is designed to simplify the access to data fields, for example:
690 %
691 % \begin{examplecode}
692 % \InsertZUGFeRDData{id}
693 % \end{examplecode}
694 %
695 % By default \pkg{zugferd} tries to find the variable holding the data itself.
696 % First it looks for a token list, afterwards a string.
697 % Global variables are prefered over local ones.
698 %
699 % As the variable names may contain underscores and the option usually prefers dashes, dashes are converted to underscores for the detection.
700 %
701 % Some Variables have a more complex structure either with setting or saving them.
702 % To simplify accessing those \version{0.10-dev} also added a \pkg{l3keys} interface.
703 % The first variables using this by default are the |payment-means|.
704 % It's possible to use the same structure to access as to set the variable.
705 % Other variabels will follow.
706 % \begin{examplecode}
707 % \InsertZUGFeRDData{payment-means/iban}
708 % \end{examplecode}
709 %
710 % \subsubsection{Special data formats}
711 % For some data elements there already have been interfaces implemented to simplify the output.
712 % \begin{examplecode}
713 % {\InsertZUGFeRDData[set-today]{date}\today}
714 % \InsertZUGFeRDData[AddressData]{seller}
715 % \InsertZUGFeRDData[iso-date]{date}
716 % \end{examplecode}
717 % As special modes the command currently supports the options \option{AddressData}, \option{set-today} and \option{iso-date}.
718 % \end{function}
719 % \end{documentation}
720 %
721 % \begin{implementation}
722 % Auxiliary command to support unit testing on the output interfaces.
723 % \begin{macro}{\_@@_access_data:c}
724 % \begin{macrocode}
725 \bool_if:NTF \g_@@_testing_bool {
726 \cs_new:Nn \_@@_access_data:n {\tl_log:n {#1} #1}
727 \cs_new:Nn \_@@_access_data:N {\tl_log:N #1 #1}
728 \cs_generate_variant:Nn \_@@_access_data:N {c}
729 } {
730 \cs_set_eq:NN \_@@_access_data:c \use:c
731 \cs_set_eq:NN \_@@_access_data:n \use:n
732 }
733 \cs_generate_variant:Nn {\_@@_access_data:n} {e}
734 % \end{macrocode}
735 % \end{macro}
736 % \begin{macro}{\InsertZUGFeRDData,\InsertZugferdData}
737 % To simplify the usage in letters we also add fields to be able to use the zugferd data within \LaTeX{} output.
738 % \version{0.11} added more fleixble interfaces.
739 % \changes{v0.10}{2025-07-22}{Add Mechanism to provide explicit interface for data elements}
740 % \begin{macrocode}
741 \NewDocumentCommand{\InsertZUGFeRDData}{om}{
742 \IfNoValueTF{#1} {
743 % \end{macrocode}
744 % There are some mappings between the input and variable name.
745 % We can use those to define specific data keys to access the field content.
746 % \begin{macrocode}
747 \keys_if_exist:nnTF {zugferd/data} {#2} {
748 \keys_set:nn {zugferd/data} {#2}
749 } {
750 % \end{macrocode}
751 % If no specific interface is defined, we try to find the variable automatially.
752 % \begin{itemize}
753 % \item replace dashes by underscores
754 % \item try if a tokenlist or a string
755 % \item prefer global over local
756 % \item take the first existing variable and break the loop
757 % \end{itemize}
758 % \begin{macrocode}
759 \str_set:Ne \l_tmpa_str {#2}
760 \str_replace_all:Nnn \l_tmpa_str {-} {_}
761 \str_replace_all:Nnn \l_tmpa_str {/} {_}
762 \bool_set_true:N \g_tmpa_bool
763 \clist_map_inline:nn {tl, str} {
764 \clist_map_inline:nn {g, l} {
765 \use:c {##1 _if_exist:cT} {####1_@@_ \l_tmpa_str _##1}
766 {
767 \_@@_access_data:c {####1_@@_ \l_tmpa_str _##1}
768 \bool_gset_false:N \g_tmpa_bool
769 }
770 \bool_if:NF \g_tmpa_bool {\clist_map_break:}
771 }
772 \bool_if:NF \g_tmpa_bool {\clist_map_break:}
773 }
774 }
775 % \end{macrocode}
776 % Optional Argument was used.
777 % \begin{macrocode}
778 } {
779 \cs_if_exist_use:cTF {zugferd_print_#1:n} {
780 {#2}
781 } {
782 %TODO
783 }
784 }
785 }
786 \providecommand{\InsertZugferdData}{\InsertZUGFeRDData}
787 \providecommand{\insertZugferdData}{\InsertZUGFeRDData}
788 % \end{macrocode}
789 % \end{macro}
790 % \end{implementation}
791 % \begin{documentation}
792 % \DescribeOption{AddressData}
793 % Allows |seller|, |buyer| or |shipto| for the data selection.
794 % Will print the address, to be used in letters.
795 %
796 % \DescribeOption{set-today}
797 % For dates there also exists the variant which will not print the variable but parse the variable to be used as \cs{today}.
798 % Using this the date format can be controlled easier using the language setting of the document.
799 % Here you should take care to use it within a group to restore the real value of \cs[no-index]{today} afterwards as shown in the example above.
800 % \end{documentation}
801 % \begin{implementation}
802 % \begin{macrocode}
803 \cs_new:cn {zugferd_print_set-today:n} {
804 \_@@_set_today:v {g_@@_#1_tl}
805 }
806 % \end{macrocode}
807 % \end{implementation}
808 % \begin{documentation}
809 % \DescribeOption{iso-date}
810 % \changes{v0.10}{2025-07-28}{add iso-date Option for \InsertZUGFeRDData}
811 % This option enhances the \option{set-today} variant and will group the setting and convert the date to ISO format (YYYY-MM-DD).
812 % In contrast to set-today this is creating the date as output and keeps the change local.
813 % \end{documentation}
814 % \begin{implementation}
815 % \begin{macro}{\zugferd_print_iso-date:n}
816 % \begin{macrocode}
817 \cs_new:cn {zugferd_print_iso-date:n} {
818 {
819 \_@@_set_today:v {g_@@_#1_tl}
820 \the\year
821 -
822 \int_compare:nNnT {\month} < {10} {0} \the\month
823 -
824 \int_compare:nNnT {\day} < {10} {0}\the\day
825 }
826 }
827 % \end{macrocode}
828 % \end{macro}
829 % \begin{macro}{\_@@_set_today:c}
830 % Auxiliary function to use a date variable within the current group to be used as \cs[no-index]{today}.
831 % \begin{macrocode}
832 \cs_new:Nn \_@@_set_today:n {
833 \_@@_set_today_aux:w #1 \q_stop
834 }
835 \cs_generate_variant:Nn \_@@_set_today:n {v}
836 \cs_new:Npn \_@@_set_today_aux:w #1 #2 #3 #4 #5 #6 #7 #8 \q_stop{
837 \int_set:Nn \year {#1#2#3#4}
838 \int_set:Nn \month {#5#6}
839 \int_set:Nn \day {#7#8}
840 }
841 % \end{macrocode}
842 % \end{macro}
843 % \end{implementation}
844 %
845 % \begin{documentation}
846 %
847 % \changes{v0.10}{2025-07-01}{Add expandable interfaces to access data entries.}
848 % \begin{function}{\UseZUGFeRDElement}
849 % For all simple entries it's possible to use this expandable interface to data items.
850 % \begin{syntax}
851 % \cs[no-index]{UseZUGFeRDElement}\oarg{scope l/c/g}\marg{name}
852 % \end{syntax}
853 % This does not apply for the AddressData, see \cs[no-index]{UseZUGFeRDAddressItem} for an expandable way to access these.
854 % \end{function}
855 % \end{documentation}
856 % \begin{implementation}
857 % \begin{macro}{\UseZUGFeRDElement}
858 % \begin{macrocode}
859 \NewExpandableDocumentCommand{\UseZUGFeRDElement}{O{l}m}{
860 \use:c {#1_@@_#2_tl}
861 }
862 % \end{macrocode}
863 % \end{macro}
864 % \end{implementation}
865 % \begin{documentation}
866 % \begin{function}{\UseZUGFeRDAddressItem,\zugferd_use_AddressData_item:nn}
867 % Expandable command to access single items of a trade party address.
868 % \begin{syntax}
869 % \cs{UseZUGFeRDAddressItem}\marg{trade party (one of seller/buyer/shipto)}\marg{Item}
870 % \end{syntax}
871 % \end{function}
872 % \end{documentation}
873 % \begin{implementation}
874 % \begin{macro}{\UseZUGFeRDAddressItem,\zugferd_use_AddressData_item:nn}
875 % \begin{macrocode}
876 \NewExpandableDocumentCommand{\UseZUGFeRDAddressItem}{mm}{
877 \zugferd_use_AddressData_item:nn {#1} {#2}
878 }
879 \cs_new:Nn \zugferd_use_AddressData_item:nn {
880 \_@@_access_data:e
881 {\prop_item:cn {g_@@_#1_AddressData_prop } {#2}}
882 }
883 % \end{macrocode}
884 % \end{macro}
885 % \end{implementation}
886 %
887 % \begin{documentation}
888 % \section{Commands for template authors}
889 %
890 % \DescribeEnv{ZUGFeRD}
891 % To simplify the structure of the wrapper package, \pkg{zugferd} provides an environment for the \XML mechanism and does the attachment to the PDF file (of course only, if enabled, see \autoref{sec:package-options}).
892 % This provides the public interface bundling some steps together to reduce maintenance effort for any template maintainer using this package.
893 % It also avoids the use of internal commands.
894 %
895 % This environment opens the \XMLfile using \cs{startWritingZUGFeRDxml} and afterwards writes the \XML header including the File and Scheme information, the |ExchangedDocumentContext| and information of the |ExchangedDocument|.
896 % Notes will also be written within this step.
897 % Afterwards the environment should include all the mechanisms to write the invoice positions as well as summation.
898 %
899 % At the end of the environment the footer is inserted, before the output stream is closed using \cs{stopWritingZUGFeRDxml}. Which also attaches the \XMLfile to the PDF.
900 %
901 %
902 % \end{documentation}
903 % \begin{implementation}
904 % \begin{macrocode}
905 \NewDocumentEnvironment{ZUGFeRD}{o}{
906 \IfNoValueF{#1}{
907 \SetZUGFeRDData{#1}
908 }
909 \zugferd_enable_XML_interfaces:
910 \startWritingZUGFeRDxml
911 \zugferd_write_Header:
912 \ignorespaces
913 }{
914 \zugferd_enable_XML_interfaces:
915 \zugferd_write_Footer:
916 \stopWritingZUGFeRDxml
917 \zugferd_disable_XML_interfaces:
918 }
919 % \end{macrocode}
920 % \end{implementation}
921 %
922 % \begin{documentation}
923 % \begin{function}{\startWritingZUGFeRDxml}
924 % \cs[no-index]{startWritingZUGFeRDxml} is opening the output stream for the \XMLfile.
925 % It also adjusts the indentation.
926 % If \option{write-xml} is false, this option only opens a group to achieve the same structure in both modes.
927 % \end{function}
928 %
929 % \begin{function}{\stopWritingZUGFeRDxml}
930 % Here the output stream is closed and the \XMLfile is attached.
931 % In case \option{write-xml} is not active, the attachment will be made if that's not deactivated separately using \option{zugferd}.
932 % It also ends the group started by \cs[no-index]{startWritingZUGFeRDxml}.
933 % \end{function}
934 % \end{documentation}
935 %
936 % \begin{implementation}
937 % \begin{macro}{\startWritingZUGFeRDxml}
938 % \begin{macrocode}
939 \newcommand*{\startWritingZUGFeRDxml}{
940 \begingroup
941 \bool_if:NTF \g_@@_write_xml_bool {
942 \char_set_active_eq:nN {13} \_@@_xml_newline_indent:
943 \iow_open:Nn \_@@_xml_writer_iow {\g_@@_xml_file_tl}
944 }{
945 \msg_info:nn {zugferd} {no-xml-write}
946 }
947 }
948 \msg_new:nnn {zugferd} {no-xml-write} {
949 The~option~write-xml=false~was~set.\\
950 Writing~of~XML~file~is~deactivated.
951 }
952 % \end{macrocode}
953 % \end{macro}
954 % The PDF attachment is done after the writing stream is closed.
955 % \begin{macro}{\stopWritingZUGFeRDxml}
956 % \begin{macrocode}
957 %% The metadata elements are taken from Ulrike Fischer's faktur-x experiments
958 %% https://github.com/latex3/pdfresources/tree/main/experiments/factur-x-bills
959 \newcommand*{\stopWritingZUGFeRDxml}{%
960 \bool_if:NT \g_@@_write_xml_bool
961 {\iow_close:N \_@@_xml_writer_iow}%
962 \endgroup
963 \bool_if:NT \g_@@_active_bool {
964 \group_begin:
965 \pdfdict_put:nnn {l_pdffile/Filespec} {AFRelationship}{/Alternative}
966 %or /Source in some cases
967 \pdfdict_put:nnn {l_pdffile/Filespec} {Desc}{(Factur-X/ZUGFeRD-Rechnung)}
968 \exp_args:NnV \pdffile_embed_file:nnn {\g_@@_xml_file_tl}
969 \g_@@_xml_embedded_file_tl
970 {zugferd/rechnung}
971 \group_end:
972 % \end{macrocode}
973 % Since some tools require the Catalog entry to match the file name of the embedded file this this has to be set separately (\issue{26}).
974 % \changes{v0.9b}{2024-11-17}{Fix file name of embedded file for the zugferd profile.}
975 % \changes{v0.9c}{2024-12–08}{Remove second catalog entry linking to xml \issue{32}}
976 % \begin{macrocode}
977 \pdfmanagement_add:nee
978 {Catalog/Names/EmbeddedFiles}
979 {\g_@@_xml_embedded_file_tl}
980 {\pdf_object_ref:n{zugferd/rechnung}}
981 % steht in der doku ist aber pdf 2.0 ....
982 \pdfmanagement_add:nnx{Catalog}{AF}{\pdf_object_ref:n{zugferd/rechnung}}
983 }
984 }
985 % \end{macrocode}
986 % \end{macro}
987 % \end{implementation}
988 %
989 % \subsection{Formatting ZUGFeRD data for PDF output}
990 % \begin{documentation}
991 % \begin{function}{\zugferd_print_AddressDataSep:nnn}
992 % \begin{syntax}
993 % \cs[no-index]{zugferd_print_AddressDataSep:nnn}
994 % \marg{trade party (one of seller/buyer/shipto)}
995 % \marg{element}
996 % \marg{separator}
997 % \end{syntax}
998 % Dynamic interface to format address data fields.
999 % It would check if a specific command has been defined otherwhise the address item would be used after adding the separator.
1000 % The separator would not be added if a specific formatting macro was found, so be aware to add it to the definition if necessary.
1001 % Same applies to checks for empty items.
1002 % \end{function}
1003 %
1004 % \DescribeMacro{\zugferd_print_AddressData:nn}
1005 % There also is a variant without the separator argument.
1006 % This one would only access the formatted value.
1007 %
1008 % \DescribeMacro{\zugferd_print_address_country:n}
1009 % The commands which can be (re-)defined to adjust the output are called: \cs[no-index]{zugferd_print_address_\meta{field}:n}.
1010 % The argument will receive the value of the element.
1011 % So e.g. to enable to output the country code one can use:
1012 % \begin{examplecode}
1013 % \cs_set_nopar:Nn \zugferd_print_address_country:n {#1}
1014 % \end{examplecode}
1015 % \end{documentation}
1016 % \begin{implementation}
1017 % \begin{macro}{\zugferd_print_AddressDataSep:nnn}
1018 % \begin{macrocode}
1019 \cs_new:Nn \zugferd_print_AddressDataSep:nnn {
1020 \cs_if_exist:cTF {zugferd_print_address_#2:n} {
1021 \exp_args:Nne \use:c {zugferd_print_address_#2:n}
1022 {\zugferd_use_AddressData_item:nn {#1}{#2}}
1023 } {
1024 % \end{macrocode}
1025 % Add line break before item to avoid issues using the newline at the end of a paragraph.
1026 % \begin{macrocode}
1027 \prop_if_in:cnT { g_@@_#1_AddressData_prop } {#2} {
1028 #3
1029 \zugferd_use_AddressData_item:nn {#1}{#2}
1030 }
1031 }
1032 }
1033 % \end{macrocode}
1034 % \end{macro}
1035 % \begin{macro}{\zugferd_print_AddressData:nn}
1036 % \begin{macrocode}
1037 \cs_new:Nn \zugferd_print_AddressData:nn {
1038 \zugferd_print_AddressDataSep:nnn {#1} {#2} {}
1039 }
1040 % \end{macrocode}
1041 % \end{macro}
1042 % \end{implementation}
1043 % \begin{documentation}
1044 % \begin{function}{\zugferd_print_AddressData:n}
1045 % \begin{syntax}
1046 % \cs[no-index]{zugferd_print_AddressData:n}
1047 % \marg{type (one of seller/buyer/shipto)}
1048 % \end{syntax}
1049 % Used by the \option{AddressData} option of \cs[no-index]{InsertZUGFeRDData}.
1050 % It uses \cs[no-index]{zugferd_print_AddressData:nn} to print the name and would be followed by the
1051 % entries |lineone|, |linetwo|, |linethree|, |postcode|, |city| and |country|.
1052 % These entries would use \cs[no-index]{zugferd_print_AddressDataSep:nnn} using |\\| as a separator in case the following entry has been set.
1053 % |\\| is used instead of a more specific command to allow template developers to redefine it locally.
1054 %
1055 % This command also could be redefined to support different order of the entries.
1056 % \end{function}
1057 % \end{documentation}
1058 % \begin{implementation}
1059 % \begin{macro}{\zugferd_print_AddressData:n}
1060 % \begin{macrocode}
1061 \cs_new:Nn \zugferd_print_AddressData:n {
1062 \zugferd_print_AddressData:nn {#1} {name}
1063 \clist_map_inline:nn {
1064 lineone,
1065 linetwo,
1066 linethree,
1067 postcode,
1068 city,
1069 country
1070 } {
1071 \zugferd_print_AddressDataSep:nnn {#1} {##1} {\\}
1072 }
1073 }
1074 % \end{macrocode}
1075 % \end{macro}
1076 % \subsubsection{Pre-defined exceptions for AdressData}
1077 % For compatibility reasons by default |city| and |country| will be treated differently.
1078 % The default setting matches how national addresses are printed within Germany.
1079 % There is no new line added before the city which is printed after the postcode and the country will not be printed.
1080 % \begin{macro}{\zugferd_print_address_city:n}
1081 % \begin{macrocode}
1082 \cs_if_exist:NF \zugferd_print_address_city:n {
1083 \cs_new_nopar:Nn \zugferd_print_address_city:n {\space#1}
1084 }
1085 % \end{macrocode}
1086 % \end{macro}
1087 % \begin{macro}{\zugferd_print_address_country:n}
1088 % Default is empty, for compatbility reasons.
1089 % \begin{macrocode}
1090 \cs_if_exist:NF \zugferd_print_address_country:n {
1091 \cs_new_nopar:Nn \zugferd_print_address_country:n {}
1092 }
1093 % \end{macrocode}
1094 % \end{macro}
1095 % \end{implementation}
1096 %
1097 % \begin{documentation}
1098 % \subsection{Interfaces to write the \XML content}
1099 % \changes{v0.6}{2024-09-05}{Provide public interfaces and first version of the documentation.}
1100 % \label{sec:xml-interfaces}
1101 % In case you are using |write-xml=true| (which is the default) you need to ensure to call the \XML writing functions in the correct order.
1102 % For example after setting the global invoice data, like it's done in the example file.
1103 % The minimal example below would create a valid XML.
1104 % The interface commands are described afterwards.
1105 %
1106 % \begin{examplecode}
1107 % \begin{ZUGFeRD}
1108 % \zugferd_write_Item:nnnnnn {1} {} {Plushie~\TeX\ lion} {31.89} {2} {63.78}
1109 % \zugferd_startInvoiceSums:
1110 % \zugferd_write_TaxEntry:nnnn {S} {19} {63.78} {12.12}
1111 % \zugferd_write_Summation:nnnnnnnn {63.78} {0} {0} {63.78} {12.12} {75.90} {0} {75.90}
1112 % \zugferd_stopInvoiceSums:
1113 % \end{ZUGFeRD}
1114 % \end{examplecode}
1115 %
1116 % \begin{function}{\zugferd_write_Item:nnnnnn}
1117 % This command is the interface to write invoice items to the \XMLfile.
1118 % If the \XML interface is enabled this is a reference to the internal command \cs{_@@_insert_TradeLineItem:nnnnnn}.
1119 % \begin{syntax}
1120 % \cs[no-index]{zugferd_write_Item:nnnnn}
1121 % \marg{LineID}\marg{optional: item id (\enquote{SellerAssignedID})}\marg{item name}
1122 % \marg{NetPriceProductTradePrice}
1123 % \marg{BilledQuantity}
1124 % \marg{LineTotalAmount}
1125 % \end{syntax}
1126 % Within the product name macros are disabled using \cs[no-index]{zugferd_disable_macros:}, see \autoref{sec:disable_macros}.
1127 %
1128 % This command is using the local values of tax information as well as the unit code.
1129 % If you want to overwrite them, adjust them locally using the corresponding options, e.g.:
1130 % \begin{examplecode}
1131 % \group_begin:
1132 % \keys_set:nn {zugferd/item}{tax/rate=19, tax/category=S}
1133 % \zugferd_write_Item:nnnnnn {1} {} {Plushie \TeX\ lion} {31.89} {2} {63.78}
1134 % % Code using the data for visual representation
1135 % \group_end:
1136 % \end{examplecode}
1137 % This will set the tax rate to 19\,\% unregarding the global setting.
1138 %
1139 % This structure might look a bit overcomplicated as one might think the options could also be set as an additional argument.
1140 % This works as long as the Code for the visual part of the invoice is not referencing the internal data.
1141 % In case you don't do this it's also possible to use the following variant:
1142 % \end{function}
1143 %
1144 % \begin{function}{\zugferd_write_Item:nnnnnnn,\zugferd_write_Item:ennnnnn}
1145 % This is grouping the command and adding an argument in front to add additional options.
1146 % \begin{syntax}
1147 % \cs[no-index]{zugferd_write_Item:nnnnnnn}
1148 % \marg{additional local options}
1149 % \marg{LineID}\marg{optional: item id (\enquote{SellerAssignedID})}\marg{item name}
1150 % \marg{NetPriceProductTradePrice}
1151 % \marg{BilledQuantity}
1152 % \marg{LineTotalAmount}
1153 % \end{syntax}
1154 % The example above could then be replaced by
1155 % \begin{examplecode}
1156 % \zugferd_write_Item:nnnnnnn {tax/rate=19,tax/category=S} {1} {Plushie-01} {Plushie \TeX\ lion} {31.89} {2} {63.78}
1157 % % visual representation now may not refer to the data
1158 % \end{examplecode}
1159 % \end{function}
1160 %
1161 % \begin{function}{\zugferd_startInvoiceSums:, \zugferd_stopInvoiceSums:}
1162 % There is some global data which hast to be placed in the \XMLfile behind the invoice items.
1163 % As usually this this is where the summation block starts these commands have been named that way to enclose them.
1164 %
1165 % The starting includes the so called \enquote{ApplicableHeaderTradeAgreement} which contains the address data of both trade parties, see \autoref{sec:TradeParties}
1166 % And this will also print the \enquote{SpecifiedTradeSettlementPaymentMeans}, see \autoref{sec:PaymentMeans}.
1167 % \end{function}
1168 %
1169 % \begin{function}{\zugferd_write_TaxEntry:nnnn, \zugferd_write_TaxEntry:ennn}
1170 % \changes{v0.9c}{2024-12-08}{Added \cs{zugferd_write_TaxEntry:ennn} variant}
1171 % This command is writing the sum over a tax rate. This command has to be used once per rate applied to the items.
1172 % \begin{syntax}
1173 % \cs[no-index]{zugferd_write_TaxEntry:nnnn} \marg{tax category code} \marg{tax rate in \%} \marg{basis amount the tax applies to} \marg{tax amount}
1174 % \end{syntax}
1175 % The tax amount could of course be calculated internally.
1176 % In the example package this is done automatically, but the interface needs to support manual input as a lot of use cases for \LaTeX{} invoicing use it only to create the output file.
1177 % \end{function}
1178 %
1179 % \begin{function}{\zugferd_write_AllowanceCharge:, \zugferd_write_AllowanceCharge:n}
1180 % \changes{v0.10}{2025-09-08}{Add user interface for document level allowancaes and charges}
1181 % \begin{syntax}
1182 % \cs[no-index]{zugferd_write_AllowanceCharge:n} \marg{key-value settings to configure allowance/charge}
1183 % \end{syntax}
1184 % The command to write allowances or charges exists in two variants.
1185 % \cs[no-index]{zugferd_write_AllowanceCharge:n} takes an argument with the values, whereas \cs[no-index]{zugferd_write_AllowanceCharge:} iterates over the sequence configured by \option{add-allowance} and \option{add-charge}.
1186 % Examples can be found within the corresponding testfile \file{allowance-charge.lvt}.
1187 % \end{function}
1188 %
1189 % \begin{function}{\zugferd_write_Summation:nnnnnnnn}
1190 % \noindent The total values are all collected with a single macro.
1191 % \begin{syntax}
1192 % \cs[no-index]{zugferd_write_Summation:nnnnnnnn}
1193 % \marg{LineTotalAmount}\marg{ChargeTotalAmount}\marg{AllowanceTotalAmount}
1194 % \marg{TaxBasisTotalAmount}\marg{TaxTotalAmount}
1195 % \marg{GrandTotalAmount}\marg{TotalPrepaidAmount}\marg{DuePayableAmount}
1196 % \end{syntax}
1197 % This commnd is also writing the payment terms to the \XMLfile.
1198 % Please be aware that it's in general not possible to calculate the tax values in here, as there might be multiple tax rates applied.
1199 % This is only taking the sums over all tax entries.
1200 %
1201 % In case you are using some specials like category \enquote{E} the exemption reason will also be written at that point.
1202 % For that it is referencing the current value of the setting.
1203 % \end{function}
1204 %
1205 % \subsection{Commands to temporary disable/re-enable the \XML writing interfaces}
1206 % \begin{function}{\zugferd_enable_XML_interfaces:,\zugferd_disable_XML_interfaces:}
1207 % As there are a lot of use cases where code is processed multiple times, it's necessary to provide an interface to temporary disable the \XML writing mechanism.
1208 % A lot of these situations appear within table structures whereas a local adjustment would not be helpful.
1209 % Therefore these adjustments have to be done globally.
1210 %
1211 % The example package \pkg{zugferd-invoice} provides an example for this to ensure the \XML data is not written multiple times.
1212 % The \env{ZUGFeRD} environment has been constructed in a way, so it would automatically enable the interface when it begins and also when it ends, to write the data. So you should ensure this environment is only processed once or use the lower level interfaces directly.
1213 % \end{function}
1214 % \end{documentation}
1215 % \begin{implementation}
1216 % Provide public interfaces and the ZUGFeRD environment.
1217 % \begin{macro}{\zugferd_enable_XML_interfaces:,\zugferd_disable_XML_interfaces:}
1218 % \begin{macrocode}
1219 \cs_new:Nn \zugferd_enable_XML_interfaces: {
1220 \bool_if:NT \g_@@_write_xml_bool {
1221 \cs_gset:Nn \zugferd_write_Header: {
1222 \_@@_insert_Header:
1223 \_@@_insert_FrontMatter:
1224 }
1225 \cs_gset:Nn \zugferd_write_Footer: {
1226 \_@@_insert_Footer:
1227 }
1228 \bool_if:NTF \g_@@_minimum_bool {
1229 \cs_gset_eq:NN \zugferd_write_Item:nnnnnn \use_none:nnnnnn
1230 }{
1231 \cs_gset_eq:NN \zugferd_write_Item:nnnnnn
1232 \_@@_insert_TradeLineItem:nnnnnn
1233 }
1234 \cs_gset:Nn \zugferd_startInvoiceSums: {
1235 \_@@_ApplicableHeaderTradeAgreement:
1236 \_@@_ApplicableHeaderTradeSettlement_start:
1237 \_@@_SpecifiedTradeSettlementPaymentMeans:
1238 }
1239 \cs_gset:Nn \zugferd_stopInvoiceSums: {
1240 \_@@_ApplicableHeaderTradeSettlement_stop:
1241 }
1242 \bool_if:NTF \g_@@_minimum_bool {
1243 \cs_gset_eq:NN \zugferd_write_TaxEntry:nnnn \use_none:nnnn
1244 } {
1245 \cs_gset_eq:NN \zugferd_write_TaxEntry:nnnn
1246 \_@@_ApplicableTradeTax:nnnn
1247 }
1248 \cs_gset_eq:NN \zugferd_write_AllowanceCharge:n
1249 \_@@_SpecifiedTradeAllowanceCharge:n
1250 \cs_gset:Nn \zugferd_write_Summation:nnnnnnnn {
1251 \_@@_SpecifiedTradePaymentTerms:
1252
1253 \_@@_SpecifiedTradeSettlementHeaderMonetarySummation:nnnnnnnn
1254 {##1} {##2} {##3} {##4} {##5} {##6} {##7} {##8}
1255 }
1256 }
1257 }
1258 \cs_new:Nn \zugferd_disable_XML_interfaces: {
1259 \cs_gset_eq:NN \zugferd_write_Header: \prg_do_nothing:
1260 \cs_gset_eq:NN \zugferd_write_Footer: \prg_do_nothing:
1261 \cs_gset_eq:NN \zugferd_write_Item:nnnnnn \use_none:nnnnnn
1262 \cs_gset_eq:NN \zugferd_startInvoiceSums: \prg_do_nothing:
1263 \cs_gset_eq:NN \zugferd_stopInvoiceSums: \prg_do_nothing:
1264 \cs_gset_eq:NN \zugferd_write_TaxEntry:nnnn \use_none:nnnn
1265 \cs_gset_eq:NN \zugferd_write_AllowanceCharge:n \use_none:n
1266 \cs_gset_eq:NN \zugferd_write_Summation:nnnnnnnn \use_none:nnnnnnnn
1267 }
1268 \bool_if:NTF \g_@@_write_xml_bool {
1269 \zugferd_enable_XML_interfaces:
1270 }{
1271 \zugferd_disable_XML_interfaces:
1272 }
1273 % \end{macrocode}
1274 % \end{macro}
1275 % \changes{v0.9}{2024-10-23}{Add interface using an argument for the keyval options locally per item}
1276 % \begin{macro}{\zugferd_write_Item:nnnnnnn}
1277 % \begin{macrocode}
1278 \cs_new:Nn \zugferd_write_Item:nnnnnnn {
1279 \group_begin:
1280 \keys_set:nn {zugferd/item} {#1}
1281 \zugferd_write_Item:nnnnnn {#2} {#3} {#4} {#5} {#6} {#7}
1282 \group_end:
1283 }
1284 \cs_generate_variant:Nn \zugferd_write_Item:nnnnnnn {ennnnnn}
1285 % \end{macrocode}
1286 % \end{macro}
1287 % \begin{macro}{\zugferd_write_TaxEntry:ennn}
1288 % \begin{macrocode}
1289 \cs_generate_variant:Nn \zugferd_write_TaxEntry:nnnn {ennn}
1290 % \end{macrocode}
1291 % \end{macro}
1292 % \begin{macro}{\zugferd_write_AllowanceCharge:}
1293 % \begin{macrocode}
1294 \cs_new:Nn \zugferd_write_AllowanceCharge: {
1295 \_@@_SpecifiedTradeAllowanceCharge:
1296 }
1297 % \end{macrocode}
1298 % \end{macro}
1299 % \begin{macro}{\_@@_write_xml:n,\_@@_define_xml_writer:Nn,\_@@_define_xml_content:Nn}
1300 % These commands are used to toggle the writing of the \XMLfile. This corresponds to the option \option{write-xml}.
1301 % \begin{macrocode}
1302 \bool_if:NTF \g_@@_write_xml_bool {
1303 \cs_new:Nn \_@@_write_xml:n {
1304 \tl_if_blank:nF {#1} {
1305 \exp_last_unbraced:Nnf \tl_if_head_eq_charcode:nNTF {#1} \iow_newline: {
1306 \iow_now:Ne \_@@_xml_writer_iow {\use_none:n #1}
1307 } {
1308 \iow_now:Ne \_@@_xml_writer_iow {\_@@_xml_auto_indent: #1}
1309 }
1310 }
1311 }
1312 \cs_new_eq:NN \_@@_define_xml_writer:Nn \cs_new:Nn
1313 \cs_new_eq:NN \_@@_define_xml_content:Nn \cs_new:Nn
1314 } {
1315 \cs_set_eq:NN \_@@_write_xml:n \use_none:n
1316 \cs_set:Nn \_@@_define_xml_writer:Nn {\cs_new:Nn #1 {}}
1317 \cs_set:Nn \_@@_define_xml_content:Nn {\cs_new:Nn #1 {}}
1318 }
1319
1320 \cs_generate_variant:Nn \_@@_write_xml:n {e}
1321 % \end{macrocode}
1322 % \end{macro}
1323 % \subsection{Number rounding}
1324 % As \pkg{siunitx} is implementing this, \pkg{zugferd} uses it instead of building our own mechanism.
1325 % In version \version{0.9a} a public interface was added, as described in section \ref{sec:rounding-interface}.
1326 % \begin{macrocode}
1327 \RequirePackage{siunitx}
1328 % \end{macrocode}
1329 % \begin{macro}{\_@@_number_format:nNn,\_@@_number_format:nNe}
1330 % \changes{v0.11-dev}{2025-12-28}{Bugfix: Group the change of siunitx options to keep it local}
1331 % \cs{\_@@_gset_formatted_number:nNn} does only exist as a global variant.
1332 % To keep the change local one can use \variable{\g_@@_tmp_tl } and use that value for a local assignment.
1333 % \begin{macrocode}
1334 \cs_new:Nn \_@@_gset_formatted_number:nNn {
1335 \group_begin:
1336 \sisetup{
1337 parse-numbers=true,
1338 round-mode=places,
1339 round-precision=#1,
1340 round-pad = false,
1341 group-digits=none,
1342 minimum-decimal-digits=#1,
1343 output-decimal-marker=.
1344 }
1345 \siunitx_number_format:nN {#3} \l_@@_tmp_tl
1346 \tl_gset_eq:NN #2 \l_@@_tmp_tl
1347 \group_end:
1348 }
1349 \cs_generate_variant:Nn \_@@_gset_formatted_number:nNn {nNe}
1350 % \end{macrocode}
1351 % \end{macro}
1352 % \begin{macro}{\_@@_write_rounded:nnnn,\_@@_write_rounded:nnn}
1353 % \begin{macrocode}
1354 \cs_new:Nn \_@@_write_rounded:nnnn {
1355 \_@@_gset_formatted_number:nNn {#1} \g_@@_tmp_tl {#4}
1356 \_@@_write_xml:e {<ram:#2#3>\g_@@_tmp_tl</ram:#2>}
1357 }
1358 \cs_new:Nn \_@@_write_rounded:nnn {
1359 \_@@_write_rounded:nnnn {#1} {#2} {} {#3}
1360 }
1361 % \end{macrocode}
1362 % \end{macro}
1363 % \subsection{XML indentation}
1364 % The indentation of the \XML does not really matter.
1365 % For debugging, it's a lot simpler to have it included and this also helped to maintain the structure of the code during development, so I decided to keep it.
1366 % The indentation is created using a bunch of auxiliary commands and variables which are defined here.
1367 % \begin{variable}{\g_@@_indent_int}
1368 % \begin{macrocode}
1369 \int_new:N \g_@@_indent_int
1370 % \end{macrocode}
1371 % \end{variable}
1372 % \begin{function}{\_@@_indent:,\_@@_xml_auto_indent:,\_@@_xml_newline_indent: }
1373 % \begin{macrocode}
1374 \cs_new:Nn \_@@_indent: {
1375 \space\space
1376 }
1377 \cs_new:Nn \_@@_indent:n {
1378 \prg_replicate:nn {#1} {\_@@_indent:}
1379 }
1380 \cs_new:Nn \_@@_xml_auto_indent:n {
1381 \_@@_indent:n {\g_@@_indent_int #1}
1382 }
1383 \cs_new:Nn \_@@_xml_auto_indent: {
1384 \_@@_xml_auto_indent:n {}
1385 }
1386 % \end{macrocode}
1387 % \end{function}
1388 % The idea was to redefine the \cs[no-index]{newlinechar} to automatically indent the following line.
1389 % \begin{macrocode}
1390 \cs_new:Nn \_@@_xml_newline_indent:n {
1391 \iow_newline: \_@@_xml_auto_indent:n {#1}
1392 }
1393 \cs_new:Nn \_@@_xml_newline_indent: {
1394 \_@@_xml_newline_indent:n {}
1395 }
1396 % \end{macrocode}
1397 % \end{implementation}
1398 % Setting up the catcodes to simplify the \XML indentation.
1399 % \iffalse
1400 % \begin{macrocode}
1401 \cctab_new:N \g_@@_xml_cctab
1402 \begingroup%
1403 \endlinechar=13%
1404 \char_set_catcode:nn {13}{13}%
1405 \cctab_gsave_current:N \g_@@_xml_cctab%
1406 \endgroup
1407 % \end{macrocode}
1408 % \fi
1409 % \begin{documentation}
1410 % \subsection{Escaping macros inside \XML data}
1411 % \label{sec:disable_macros}
1412 % \begin{function}{\zugferd_disable_macros:}
1413 % Since we allow the use of \LaTeX{} code in some fields there has to be a mechanism to disable macros inside the \XML output.
1414 % The mechanism is created similar to the one by \pkg{hyperref}, and we also use some definitions from there to use those as a starting point.
1415 % To have a detailed list of all redefinitions, please have a look at the implementation of this command.
1416 %
1417 % There exists a hook to extend or overwrite these definitions |zugferd/disable-macros|.
1418 % You can add own redefinitions using this. For example if you want to overwrite the setting mapping a \cs[no-index]{newline} to a new line char instead of space, you could add the following to your setup:
1419 % \begin{examplecode}
1420 % \hook_gput_code:nnn {zugferd/disable-macros}
1421 % {newline-to-LF}
1422 % {\def\newline{\iow_newline:}}
1423 % \end{examplecode}
1424 % \end{function}
1425 % \end{documentation}
1426 % \begin{implementation}
1427 % \begin{macro}{\zugferd_disable_macros:}
1428 % The definition was mostly taken from \pkg{hyperref} \cite{hyperref}.
1429 % Most likely not all of these are required, but it's probably easier to take this as a reasonable choice instead of creating an own collection.
1430 % \iffalse
1431 % \begin{macrocode}
1432 %% modified list taken from hyperref.sty v7.01i
1433 %% Copyright
1434 %% 1995-2001 Sebastian Rahtz, with portions written by David Carlisle and Heiko Oberdiek
1435 %% 2001-2015 Heiko Oberdiek
1436 %% 2016-2019 Oberdiek Package Support Group
1437 %% 2019-2024 LaTeX Project
1438 %% modifications have been made to support the mechanism if hyperref is not loaded
1439 % \end{macrocode}
1440 % \fi
1441 % \begin{macrocode}
1442 \cs_new:Nn \zugferd_disable_macros: {
1443 \let\{\c_left_brace_str
1444 \let\textbraceleft\c_left_brace_str
1445 \let\}\c_right_brace_str
1446 \let\textbraceright\c_right_brace_str
1447 \let\#\c_hash_str
1448 % \end{macrocode}
1449 % This only is a part of the list.
1450 % There is no real use of printing the whole list, it's inside \file{zugferd.sty} anyway.
1451 % \comment
1452 % \begin{macrocode}
1453 \let\textnumbersign\c_hash_str
1454 \let\$\c_dollar_str
1455 \let\textdollar\c_dollar_str
1456 \let\%\c_percent_str
1457 \let\&\c_ampersand_str
1458 \let\_\c_underscore_str
1459 \def\P{§}
1460 \def\ldots{…}
1461 \def\dots{…}
1462 \def\\{\space}%
1463 \def\newline{\space}%
1464 \def\TeX{TeX}%
1465 \def\LaTeX{La\TeX}%
1466 \def\LaTeXe{\LaTeX2e}%
1467 \def\eTeX{e-\TeX}%
1468 \def\SliTeX{Sli\TeX}%
1469 \def\MF{Metafont}%
1470 \def\MP{Metapost}%
1471 \let\fontencoding\@gobble
1472 \let\fontfamily\@gobble
1473 \let\fontseries\@gobble
1474 \let\fontshape\@gobble
1475 \let\fontsize\@gobbletwo
1476 \let\selectfont\@empty
1477 \let\usefont\@gobblefour
1478 \let\emph\@firstofone
1479 \let\textnormal\@firstofone
1480 \let\textrm\@firstofone
1481 \let\textsf\@firstofone
1482 \let\texttt\@firstofone
1483 \let\textbf\@firstofone
1484 \let\textmd\@firstofone
1485 \let\textit\@firstofone
1486 \let\textsc\@firstofone
1487 \let\textsl\@firstofone
1488 \let\textup\@firstofone
1489 \let\normalfont\@empty
1490 \let\rmfamily\@empty
1491 \let\sffamily\@empty
1492 \let\ttfamily\@empty
1493 \let\bfseries\@empty
1494 \let\mdseries\@empty
1495 \let\itshape\@empty
1496 \let\scshape\@empty
1497 \let\slshape\@empty
1498 \let\upshape\@empty
1499 \let\em\@empty
1500 \let\rm\@empty
1501 \let\Huge\@empty
1502 \let\LARGE\@empty
1503 \let\Large\@empty
1504 \let\footnotesize\@empty
1505 \let\huge\@empty
1506 \let\large\@empty
1507 \let\normalsize\@empty
1508 \let\scriptsize\@empty
1509 \let\small\@empty
1510 \let\tiny\@empty
1511 \let\mathversion\@gobble
1512 \let\phantom\@gobble
1513 \let\vphantom\@gobble
1514 \let\hphantom\@gobble
1515 \let\ding\HyPsd@ding
1516 \let\Cube\HyPsd@DieFace
1517 % \end{macrocode}
1518 % \changes{v0.11-dev}{2026-03-11}{Fix Grouping of environments in xml data}
1519 % \begin{macrocode}
1520 \def\begin##1{\begingroup\csname##1\endcsname}%
1521 \def\end##1{\csname end##1\endcsname\endgroup}%
1522 \def\textcolor##1##{\@secondoftwo}%
1523 \def\TextOrMath{\ifmmode\expandafter\@secondoftwo\else\expandafter\@firstoftwo\fi}%
1524 \let\foreignlanguage\@secondoftwo
1525 \let\textlatin\@firstofone
1526 \let\cyr\relax
1527 \let\glqq\textglqq
1528 \let\grqq\textgrqq
1529 \let\glq\textglq
1530 \let\grq\textgrq
1531 \let\flqq\textflqq
1532 \let\frqq\textfrqq
1533 \let\flq\textflq
1534 \let\frq\textfrq
1535 \let\if@mid@expandable\@firstoftwo
1536 \let\hspace\@gobble
1537 \let\label\@gobble
1538 \let\index\@gobble
1539 \let\glossary\@gobble
1540 \let\@mkboth\@gobbletwo
1541 \let\leavevmode\@empty
1542 \let\mbox\@empty
1543 \def\halign{\@gobble}%
1544 \let\Hy@SectionAnchorHref\@gobble
1545 \let\ref\@gobble
1546 \let\href\@gobble
1547 \let\pageref\@gobble
1548 \let\nameref\@gobble
1549 \let\autoref\@gobble
1550 \let\ignorespaces\relax
1551 \let\ensuremath\@firstofone
1552 \def\ {\space\relax}% space
1553 \exp_args:NV \cs_set_nopar:cpn \c_space_tl {\space}
1554 \let\nobreakspace\space
1555 \hook_use:n {zugferd/disable-macros}
1556 % \end{macrocode}
1557 % \endcomment
1558 % \begin{macrocode}
1559 }
1560 % \end{macrocode}
1561 % To provide a possibility to extend or overwrite the macro list a hook is added.
1562 % \begin{macrocode}
1563 \hook_new:n {zugferd/disable-macros}
1564 % \end{macrocode}
1565 % \end{macro}
1566 % \end{implementation}
1567 % \begin{documentation}
1568 % \begin{function}{\zugferd_tl_set_escaped_xml:Nn, \zugferd_tl_gset_escaped_xml:Nn}
1569 % \changes{v0.9c}{2024-12-08}{Added mechanism to escape XML special characters.}
1570 % As described before and also in \issue{9} there are characters which are special in \XML but not within \LaTeX.
1571 % Additionally there are also characters which aren't special in \LaTeX{} but within \XML.
1572 % In version \version{0.9c} \pkg{zugferd} added some auxiliary commands to support users escaping those.
1573 % This mechanism involves turning the category codes of characters like |"<>'&| to active and might have side effects.
1574 % It is an experimental feature and should be handled with care!
1575 % \end{function}
1576 % \end{documentation}
1577 % \begin{implementation}
1578 % \begin{macrocode}
1579 \cs_new:Nn \zugferd_tl_gset_escaped_xml:Nn {
1580 \group_begin:
1581 \zugferd_disable_macros:
1582 \_@@_escape_xml_aux:
1583 \tl_gset_rescan:Nnn #1 {
1584 \cctab_select:N \c_str_cctab
1585 \_@@_escape_xml_activate:
1586 } {#2}
1587 \tl_gset:Ne #1 {#1}
1588 \group_end:
1589 }
1590 \cs_new:Nn \zugferd_tl_set_escaped_xml:Nn {
1591 \zugferd_tl_gset_escaped_xml:Nn \g_@@_tmp_tl {#2}
1592 \tl_set_eq:NN #1 \g_@@_tmp_tl
1593 }
1594 \cs_new:Nn \_@@_escape_xml_aux: {
1595 \edef\&{\tl_to_str:n {&amp;}}
1596 \edef\textgreater{\tl_to_str:n {&gt;}}
1597 \edef\textless{\tl_to_str:n {&lt;}}
1598 \edef\textquotedbl{\tl_to_str:n {&quot;}}
1599 \edef\textquotesingle{\tl_to_str:n {&apos;}}
1600 \char_set_active_eq:NN > \textgreater
1601 \char_set_active_eq:NN < \textless
1602 \char_set_active_eq:NN " \textquotedbl
1603 \char_set_active_eq:NN ' \textquotesingle
1604 \char_set_active_eq:NN & \&
1605 }
1606 \cs_new:Nn \_@@_escape_xml_activate: {
1607 \char_set_catcode_active:N >
1608 \char_set_catcode_active:N <
1609 \char_set_catcode_active:N "
1610 \char_set_catcode_active:N '
1611 \char_set_catcode_active:N &
1612 }
1613 % \end{macrocode}
1614 % \end{implementation}
1615 % \begin{documentation}
1616 % \subsection{Rounding Interface}
1617 % \label{sec:rounding-interface}
1618 % \changes{v0.9a}{2024-11-07}{Add public interface for the rounding mechanism.}
1619 % The demo package's implementation is also doing VAT calculations.
1620 % This rounding mechanism might have side effects if only the final values are rounded as reported in \issue{17} .
1621 % It is only an issue if fractions of units are used, but was fixed in \version{0.9a}.
1622 % To avoid this generally there now exists an interface to be used to do the rounding before the summation.
1623 %
1624 % \begin{function}{\zugferd_fp_set_rounded:Nn,zugferd_fp_gset_rounded:Nn}
1625 % This command can be used to access the \pkg{siunitx}'s rounding mechanism within \pkg{zugferd}.
1626 % The command is based on \cs[no-index]{fp_set:Nn} just is doing the rounding before the assignment.
1627 %
1628 % \begin{examplecode}
1629 % \zugferd_fp_gset_rounded:Nn \g_tmpa_fp {|\meta{amount}|* (|\meta{VAT rate}|/100) * |\meta{unit price}|}
1630 % \end{examplecode}
1631 % \end{function}
1632 % \end{documentation}
1633 % \begin{implementation}
1634 % \begin{macro}{\zugferd_fp_set_rounded:Nn, \zugferd_fp_gset_rounded:Nn}
1635 % \changes{v0.11-dev}{2025-12-28}{Bugfix: Group the change of siunitx options to keep it local}
1636 % \begin{macrocode}
1637 \cs_set:Nn \zugferd_fp_set_rounded:Nn {
1638 \_@@_gset_formatted_number:nNn {2} \g_@@_tmp_tl {\fp_eval:n {#2}}
1639 \fp_set:Nn #1 {\g_@@_tmp_tl}
1640 }
1641 \cs_set:Nn \zugferd_fp_gset_rounded:Nn {
1642 \_@@_gset_formatted_number:nNn {2} \g_@@_tmp_tl {\fp_eval:n {#2}}
1643 \fp_gset:Nn #1 {\g_@@_tmp_tl}
1644 }
1645 % \end{macrocode}
1646 % \end{macro}
1647 % \end{implementation}
1648 % \begin{documentation}
1649 % \section{Adding data to the XML}
1650 % All data which does not directly depend on amounts or specific items is provided using a key-value interface.
1651 % For some fields there is the option to define a global preset but locally overwrite it for a specific item.
1652 % This only applies to data fields used by the writing interfaces described in \autoref{sec:xml-interfaces}.
1653 %
1654 % This package is using the UN/CEFACT Cross Industry Invoice Syntax for the data.
1655 % Currently it is not planned to implement the UBL syntax as well, but generally this would be possible.
1656 %
1657 % Please be aware that the \pkg{zugferd} package does currently not handle any replacements concerning the content.
1658 % Therefore it might be necessary to escape special characters, like |&| to |&amp;|.
1659 % This also applies to |<|, |>|, |"| and |'|.
1660 % It's technically possible to do this either via active characters or string replacements.
1661 % But since it's adjusting the content this feature would never be enabled by default (Issue \issue{9}).
1662 %
1663 % In most cases this functionality will be used to change the tax setting or unit for a single item.
1664 % \autoref{sec:xml-interfaces} also provided an example for this.
1665 %
1666 % This section will now take all data which can be set using \cs{SetZUGFeRDData}.
1667 %
1668 % \end{documentation}
1669 % \begin{implementation}
1670 % \begin{variable}{\g_@@_notes_seq,\g_@@_id_tl,\g_@@_date_tl,\g_@@_subject_tl,\g_@@_fromaddress_tl,\g_@@_DocumentTypeCode_tl}
1671 % \begin{macrocode}
1672 \seq_new:N \g_@@_notes_seq
1673 \tl_new:N \g_@@_id_tl
1674 \tl_new:N \g_@@_date_tl
1675 \tl_new:N \g_@@_delivery_date_tl
1676 \tl_new:N \g_@@_subject_tl
1677 \tl_new:N \g_@@_fromaddress_tl
1678 \tl_new:N \g_@@_DocumentTypeCode_tl
1679 \tl_new:N \l_@@_currency_tl
1680 % \end{macrocode}
1681 % \end{variable}
1682 % \end{implementation}
1683 % \begin{documentation}
1684 % \subsection{General Invoicing Data}
1685 % Some of the general data currently supports only one value, which is already selected by default.
1686 % The interface already exists and may be extended later.
1687 %
1688 % \end{documentation}
1689 % \begin{implementation}
1690 % \begin{macrocode}
1691 \keys_define:nn { zugferd } {
1692 % TODO define others
1693 % \end{macrocode}
1694 % \end{implementation}
1695 % \begin{documentation}
1696 % \DescribeKeyOption[BT-3]{document-type=\meta{type}}{commercial-invoice}
1697 % Select the document type. Since \version{0.9c} \pkg{zugferd} supports the following types:
1698 % \changes{v0.9c}{2024-12-08}{Add support for other invoice types.}
1699 % \begin{valuelist}\setlength{\leftskip}{.5\linewidth}
1700 % \item[commercial-invoice] 380
1701 % \item[partial-invoice] 326
1702 % \item[corrected-invoice] 384
1703 % \item[self-billed-invoice] 389
1704 % \item[credit-note] 381
1705 % \item[partial-construction-invoice] 875
1706 % \item[partial-final-construction-invoice] 876
1707 % \item[final-construction-invoice] 877
1708 % \end{valuelist}
1709 % \end{documentation}
1710 % \begin{implementation}
1711 % \begin{optionenv}{id, document-type}
1712 % \begin{macrocode}
1713 document-type .choice:,
1714 document-type / commercial-invoice .code:n =
1715 \tl_gset:Nn \g_@@_DocumentTypeCode_tl {380},
1716 document-type / partial-invoice .code:n =
1717 \tl_gset:Nn \g_@@_DocumentTypeCode_tl {326},
1718 document-type / corrected-invoice .code:n =
1719 \tl_gset:Nn \g_@@_DocumentTypeCode_tl {384},
1720 document-type / self-billed-invoice .code:n =
1721 \tl_gset:Nn \g_@@_DocumentTypeCode_tl {389},
1722 document-type / credit-note .code:n =
1723 \tl_gset:Nn \g_@@_DocumentTypeCode_tl {381},
1724 document-type / partial-construction-invoice .code:n =
1725 \tl_gset:Nn \g_@@_DocumentTypeCode_tl {875},
1726 document-type / partial-final-construction-invoice .code:n =
1727 \tl_gset:Nn \g_@@_DocumentTypeCode_tl {876},
1728 document-type / final-construction-invoice .code:n =
1729 \tl_gset:Nn \g_@@_DocumentTypeCode_tl {877},
1730 document-type .initial:n = commercial-invoice,
1731 % \end{macrocode}
1732 % \end{optionenv}
1733 % \end{implementation}
1734 % \begin{documentation}
1735 % \subsubsection{Invoice number/document ID}
1736 % \DescribeKeyOption*[BT-1]{id=komavar/\meta{document ID/invoice number}}{}
1737 % This has to be set. Leaving it empty will lead to an invalid \XMLfile.
1738 %
1739 % The value |komavar| would reference the data provided the KOMA-Script letter variabe |invoice|. In case you don't use \pkg{scrletter} you should not use this setting.
1740 % More information can be found in the documentation \cite{scrletter}.
1741 % \end{documentation}
1742 % \begin{implementation}
1743 % \begin{macrocode}
1744 id .choice:,
1745 id / komavar .code:n = \tl_gset:Nf \g_@@_id_tl {\scr@invoice@var},
1746 id / unknown .code:n = \tl_gset:Nn \g_@@_id_tl {#1},
1747 % \end{macrocode}
1748 % \end{implementation}
1749 % \begin{documentation}
1750 % \subsubsection{Currency}
1751 % \DescribeKeyOption[BT-5]{currency=EUR/USD/CHF/€}{EUR}
1752 % Currently \pkg{zugferd} only supports one currency for an invoice. This might be extended later.
1753 % The currency is pre-configured to use Euro.
1754 % \end{documentation}
1755 % \begin{implementation}
1756 % \begin{macrocode}
1757 currency .choices:nn = {EUR, USD, CHF} {
1758 \tl_set_eq:NN \l_@@_currency_tl \l_keys_choice_tl
1759 },
1760 currency / € .meta:n = {currency = EUR},
1761 currency / unknown .code:n = {
1762 \exp_args:Nnnx \keys_if_choice_exist:nnnTF {zugferd} {unit} {
1763 \str_uppercase:f {#1}
1764 }
1765 {\keys_set:nx { zugferd } {unit= {\str_uppercase:f {#1}}}}
1766 {
1767 \bool_if:NT \g_@@_unknown_value_warning_bool {
1768 \msg_warning:nnn { zugferd } {unknown-value} {currency} {#1}
1769 }
1770 \tl_set:Ne \l_@@_currency_tl {\str_uppercase:f {#1}}
1771 }
1772 },
1773 currency .initial:n = EUR,
1774 % \end{macrocode}
1775 % \end{implementation}
1776 % \begin{documentation}
1777 % \subsubsection{Dates}
1778 % \label{sec:dates}
1779 % \DescribeKeyOption[BT-2]{date=auto/\meta{date formatted as YYYYMMDD}}{auto}
1780 % \DescribeKeyOption[BT-72]{delivery-date=auto/\meta{date formatted as YYYYMMDD}}{auto}
1781 % \DescribeKeyOption[BT-9]{due-date=\meta{date formatted as YYYYMMDD}}{}*
1782 % Currently there are three kinds of dates implemented.
1783 % The XML-Standard requires them to use the structure \meta{YYYYMMDD}.
1784 % For the day this document was compiled this would be: \enquote{\InsertZUGFeRDData{date}} (\today).
1785 %
1786 % Instead of providing a date value directly it's also possible to use \cs[no-index]{today}.
1787 % This is done using the value \value{auto} which is the default setting for \option{date} and \option{delivery-date}.
1788 % Please be aware, that this would change if you rebuild the document later. So you might want to use an actual value here.
1789 % \end{documentation}
1790 %
1791 % \begin{implementation}
1792 % \begin{optionenv}{date}
1793 % \begin{macrocode}
1794 date .choice:,
1795 date / auto .code:n = \tl_gset:Ne \g_@@_date_tl {
1796 \the\year
1797 \int_compare:nNnT {\month} < {10} {0} \the\month
1798 \int_compare:nNnT {\day} < {10} {0}\the\day
1799 },
1800 date / unknown .code:n = \tl_gset:Nn \g_@@_date_tl {#1},
1801 date .initial:n = auto,
1802 % \end{macrocode}
1803 % \end{optionenv}
1804 % \begin{optionenv}{delivery-date}
1805 % \begin{macrocode}
1806 delivery-date .choice:,
1807 delivery-date / auto .code:n = \tl_gset:Ne \g_@@_delivery_date_tl {
1808 \the\year
1809 \int_compare:nNnT {\month} < {10} {0} \the\month
1810 \int_compare:nNnT {\day} < {10} {0}\the\day
1811 },
1812 delivery-date / unknown .code:n = {
1813 \tl_gset:Nn \g_@@_delivery_date_tl {#1}
1814 },
1815 delivery-date .initial:n = auto,
1816 % \end{macrocode}
1817 % \end{optionenv}
1818 % \begin{optionenv}{due-date}
1819 % \begin{macrocode}
1820 due-date .tl_gset:N = \g_@@_due_date_tl,
1821 due-date .initial:n =,
1822 % \end{macrocode}
1823 % \end{optionenv}
1824 % \end{implementation}
1825 % \begin{documentation}
1826 % \DescribeKeyOption*[BT-73]{item/start-date=\meta{date formatted as YYYYMMDD}}{}*
1827 % \DescribeKeyOption*[BT-74]{item/end-date=\meta{date formatted as YYYYMMDD}}{}*
1828 % With version \version{0.10} support for a invoice wide |BillingSpecifiedPeriod| was added.
1829 % This supports setting |start-date| and |end-date| for the whole invoice in contrast to setting it for each item.
1830 % As this is optional, there is no default.
1831 % The element will be printed if both dates are set, as setting a single one will enforce the element to be invalid.
1832 % This element should be set as all the other dates (see \autoref{sec:dates}).
1833 % \end{documentation}
1834 % \begin{implementation}
1835 % \begin{optionenv}{start-date,end-date}
1836 % \begin{macrocode}
1837 start-date .tl_gset:N = \g_@@_start_date_tl,
1838 start-date .initial:n =,
1839 end-date .tl_gset:N = \g_@@_end_date_tl,
1840 end-date .initial:n =,
1841 % \end{macrocode}
1842 % \end{optionenv}
1843 % \end{implementation}
1844 % \begin{documentation}
1845 % \subsubsection{Payment terms}
1846 % \DescribeKeyOption[BT-20]{payment-terms=\meta{string}}{}
1847 % One option to set payment terms is the \option{due-date} mentioned before.
1848 % If this is not set or the setting is more complex one can use \option{payment-terms} to add more information.
1849 %
1850 % This setting is a string. In case there is expansion required this has to be done before.
1851 % \end{documentation}
1852 % \begin{implementation}
1853 % \begin{optionenv}{payment-terms}
1854 % \begin{macrocode}
1855 payment-terms .str_gset:N = \g_@@_payment_terms_str,
1856 payment-terms .initial:n =,
1857 % \end{macrocode}
1858 % \end{optionenv}
1859 % \end{implementation}
1860 % \begin{documentation}
1861 % \subsubsection{Allowances and Charges}
1862 % \changes{v0.10}{2025-09-08}{add the options add-charge and add-allowance.}
1863 % \DescribeKeyOption[BT-92,BT-93,BT-94,BT-97,BT-98]{add-allowance=\marg{keyval-list}}{}
1864 % \DescribeKeyOption[BT-99,BT-100,BT-101,BT-104,BT-105]{add-charge=\marg{keyval-list}}{}
1865 % Allowances and charges can added using these options.
1866 % They will be applied to a sequence which is used by \cs[no-index]{zugferd_write_AllowanceCharge:} to write all contained elements.
1867 % The Values match the actual \XML element names. There might be alias definitions added later to simplify the usage.
1868 % Please be aware that any calculation has to be imlemented within your own \pkg{zugferd-invoice.sty} variant.
1869 % \begin{examplecode}
1870 % \SetZUGFeRDData{
1871 % add-allowance={
1872 % CalculationPercent=100,
1873 % BasisAmount=50,
1874 % ActualAmount=50,% could be calculated
1875 % Reason=TEXT,
1876 % tax/category=S,
1877 % tax/rate=19
1878 % },
1879 % add-charge={
1880 % ActualAmount=50,
1881 % Reason=TEXT,
1882 % tax/category=S,
1883 % tax/rate=19
1884 % }
1885 % }
1886 %\end{examplecode}
1887 % \end{documentation}
1888 % \begin{implementation}
1889 % \begin{optionenv}{add-allowance}
1890 % \begin{macrocode}
1891 add-allowance .code:n = {
1892 \seq_gput_right:Nn \g_@@_AllowanceCharge_seq {
1893 Indicator=false,
1894 #1
1895 }
1896 },
1897 item / add-allowance .code:n = {
1898 \seq_put_right:Nn \l_@@_AllowanceCharge_seq {
1899 Indicator=false,
1900 #1
1901 }
1902 },
1903 % \end{macrocode}
1904 % \end{optionenv}
1905 % \begin{optionenv}{add-charge}
1906 % \begin{macrocode}
1907 add-charge .code:n = {
1908 \seq_gput_right:Nn \g_@@_AllowanceCharge_seq {
1909 Indicator=true,
1910 #1
1911 }
1912 },
1913 item / add-charge .code:n = {
1914 \seq_put_right:Nn \l_@@_AllowanceCharge_seq {
1915 Indicator=true,
1916 #1
1917 }
1918 },
1919 % \end{macrocode}
1920 % \end{optionenv}
1921 % \end{implementation}
1922 % \begin{documentation}
1923 % \subsubsection{Notes: Adding additional information}
1924 % \DescribeKeyOption{subject=komavar/\meta{Tokenlist}}{}
1925 % \DescribeKeyOption{fromaddress=komavar/\meta{Tokenlist}}{}
1926 % \DescribeKeyOption[BT-22]{add-note=\meta{Tokenlist}}{}*
1927 % The ZUGFeRD example files\cite{zugferd-download} use all visible data to add them to the \XML as a note.
1928 % \option{subject} and \option{fromaddress} are used to support this.
1929 % \changes{v0.9d}{2025-01-02}{Add note on subject not being the same as subject-code \issue{35}.}%
1930 % Please be aware that \option{subject-code} is not the same as \option{subject} even if some viewers might display it like that, \issue{35}.
1931 % The data should not be too relevant but \pkg{zugferd} want's to support adding additional data to the \XML using the note element.
1932 % So these fields can be left out but in case they are not empty, they will also be written to the \XML.
1933 %
1934 % The value \value{komavar} corresponds to the mechanism provided by \pkg{scrletter}.
1935 % It accesses the variable expands it to be used directly.
1936 % If you don't use this package, you can ignore this setting or add content manually.
1937 % \end{documentation}
1938 % \begin{implementation}
1939 % \begin{optionenv}{subject,fromaddress,add-note}
1940 % \begin{macrocode}
1941 subject .choice:,
1942 subject / komavar .code:n = {
1943 \tl_gset:Nf \g_@@_subject_tl {\scr@subject@var}
1944 },
1945 subject / unknown .code:n = \tl_gset:Nn \g_@@_subject_tl {#1},
1946 fromaddress .choice:,
1947 fromaddress / komavar .code:n = \tl_gset:Nf \g_@@_fromaddress_tl
1948 {\scr@fromaddress@var},
1949 fromaddress / unknown .code:n = \tl_gset:Nn \g_@@_fromaddress_tl {#1},
1950 add-note .code:n = \seq_gput_right:Nn \g_@@_notes_seq {#1},
1951 }
1952 \msg_new:nnnn {zugferd} {unknown-value} {
1953 You~selected~a~#1~which~was~not~predefined.\\
1954 I~will~directly~use~your~selection~'#1=#2'.
1955 Please~ensure~the~selection~is~valid!
1956 } {
1957 For~more~information~see~the~zugferd~documentation.
1958 }
1959 % \end{macrocode}
1960 % \end{optionenv}
1961 % Macro to write notes
1962 % \begin{macrocode}
1963 \cs_new:Nn \_@@_note_if_not_empty:N {%
1964 \tl_if_empty:NF #1 {%
1965 \_@@_write_note:n {#1}%
1966 }%
1967 }%
1968 % \end{macrocode}
1969 % \end{implementation}
1970 % \begin{documentation}
1971 % \subsection{Trade parties}
1972 % \label{sec:TradeParties}
1973 % The \XML scheme knows 6 different Trade Parties:
1974 % \begin{itemize}
1975 % \item Seller
1976 % \item Buyer
1977 % \item Payee
1978 % \item ShipTo
1979 % \item SellerTaxRepresentative
1980 % \end{itemize}
1981 %
1982 % \noindent Currently \pkg{zugferd} supports only Buyer, Seller and ShipTo, but can be easily extended to support the others as well.
1983 % The data for each party follows the same structure, except the \enquote{BuyerReference} which is described later in this section.
1984 %
1985 % Some of the data is optional for specific parties.
1986 % As this also depends on the selected scheme and version we will not list the details.
1987 % All fields for a trade party can be set using the \enquote{group} named by the party.
1988 % For example setting all the seller data is done in the following listing:
1989 % \changes{v0.9c}{2024-12-08}{Add support for extended Addresses including additionl legal data.}
1990 % \begin{examplecode}
1991 % \SetZUGFeRDData{
1992 % seller/id = {ID – usually internal ID provided by buyer},
1993 % seller/name = {peiTeX (Marei Peischl)},
1994 % seller/legal-description = {Additional legal information},
1995 % seller/legal-id = {legal registration ID},
1996 % seller/trading-name = {trading name},
1997 % seller/email = {[email protected]},
1998 % seller/vatid = {DE123456789},
1999 % seller/contact= {Marei\\+4900000000\\[email protected]},
2000 % seller/address = {Address Line 1\\Address Line 2\\Address Line 3},
2001 % seller/postcode = {20253},
2002 % seller/city ={Hamburg},
2003 % seller/country = {DE},
2004 % }
2005 % \end{examplecode}
2006 % \noindent All this data is saved within a property list, which is internally called \cs[no-index]{g_@@_\meta{seller/buyer/shipto}_prop}.
2007 % By default this property list is empty.
2008 % The users themselves have to ensure to add the required data.
2009 %
2010 % The outer braces are not required, if the data does not container an equal sign or a comma.
2011 % In case the final data is unknown, it's recommended to use them anyway.
2012 %
2013 % \DescribeKeyOption*{\meta{party}/name=\meta{name}}{}*
2014 % \DescribeKeyOption*{\meta{party}/email=\meta{email address}}{}*
2015 % \DescribeKeyOption*{\meta{party}/vatid=\meta{VAT ID}}{}*
2016 % \DescribeKeyOption*{\meta{party}/taxid=\meta{VAT ID}}{}*
2017 % \changes{v0.9c}{2024-12-08}{Add support for taxid.}
2018 %
2019 % \DescribeKeyOption*{\meta{party}/address=\meta{address}}{}*
2020 % \changes{v0.9c}{2024-12-08}{Add support for third address line.}
2021 % As shown in the example \option{address} can use three lines separted by |\\|.
2022 % It's possble to set all fields for all trade contacts, but e.\,g. for the |shipto|-party email and vatid will not be used in the \XML.
2023 %
2024 % Alternatively it's also possible to use \option{\meta{party}/lineone}, \option{\meta{party}/linetwo} and \option{\meta{party}\slash{}linethree} separately.
2025 % This may be helpful if you use a custom input format. In any way you should ensure that all macros used within the data either are expandable or disabled using \cs[no-index]{zugferd_disable_macros:}.
2026 %
2027 % \DescribeKeyOption*{\meta{party}/postcode=\meta{postal code}}{}*
2028 % \DescribeKeyOption*{\meta{party}/city=\meta{city}}{}*
2029 % \DescribeKeyOption*{\meta{party}/subdivision=\meta{subdivision}}{}*
2030 % \changes{v0.9c}{2024-12-08}{Add support for subdivision.}
2031 % \DescribeKeyOption*{\meta{party}/country=\meta{country code}}{}*
2032 % The two letter country codes allowed here can be found in \cite{country-codes}.
2033 %
2034 % % \DescribeKeyOption*{\meta{party}/contact=\meta{Combined contact data}}{}*
2035 % The contact person can either be set using the combined structure similar to \option{\meta{party}/\allowbreak address}.
2036 % It either consists of 3 or 4 entries, depending on if a department should be used or not.
2037 %
2038 % \begin{examplecode}
2039 % \SetZUGFeRDData{
2040 % seller/contact = {
2041 % |\meta{contact-name}|\\
2042 % |\meta{contact-phone}|\\
2043 % |\meta{contact-email}|
2044 % },
2045 % seller/contact = {
2046 % |\meta{contact-name}|\\
2047 % |\meta{contact-department}|\\
2048 % |\meta{contact-phone}|\\
2049 % |\meta{contact-email}|
2050 % }
2051 % }
2052 % \end{examplecode}
2053 % \noindent As for \option{seller/address} it's also possible to set the keys directly:
2054 % \begin{examplecode}
2055 % \SetZUGFeRDData{
2056 % seller/contact-name= {|\meta{contact-name}|},
2057 % seller/contact-department = {|\meta{contact-department}|},
2058 % seller/cotact-phone ={|\meta{contact-phone}|},
2059 % seller/contact-email= {|\meta{contact-email}|}
2060 % }
2061 % \end{examplecode}
2062 % \end{documentation}
2063 % \begin{implementation}
2064 % ApplicableHeaderTradeAgreement
2065 %
2066 % Contains information on seller and buyer trade party:
2067 % \begin{itemize}
2068 % \item BuyerReference
2069 % \item SellerTradeParty
2070 % \item BuyerTradeParty
2071 % \end{itemize}
2072 %
2073 % Seller, buyer and shipping address are specified the same way.
2074 % \begin{macrocode}
2075 \clist_map_inline:nn {seller,buyer,shipto} {
2076 % \end{macrocode}
2077 % \begin{variable}{\g_@@_seller_AddressData_prop,\g_@@_buyer_AddressData_prop,\g_@@_shipto_AddressData_prop}
2078 % \begin{macrocode}
2079 \prop_new:c {g_@@_#1_AddressData_prop}
2080 % \end{macrocode}
2081 % \end{variable}
2082 % \begin{macrocode}
2083 \keys_define:nn {zugferd / #1} {
2084 % \end{macrocode}
2085 % \begin{optionenv}{\meta{party}/address}
2086 % \begin{macrocode}
2087 address .code:n = {
2088 \seq_set_split:Nnn \l_tmpa_seq {\\} {##1}
2089 %TODO error if more than 2 lines or only 1
2090 \keys_set:nx {zugferd / #1} {
2091 lineone={\seq_item:Nn \l_tmpa_seq {1}},
2092 linetwo={\seq_item:Nn \l_tmpa_seq {2}},
2093 linethree={\seq_item:Nn \l_tmpa_seq {3}}
2094 }
2095 },
2096 % \end{macrocode}
2097 % \end{optionenv}
2098 % \begin{optionenv}{\meta{party}/contact}
2099 % \begin{macrocode}
2100 contact .code:n = {
2101 \seq_set_split:Nnn \l_tmpa_seq {\\} {##1}
2102 \int_compare:nNnTF {\seq_count:N \l_tmpa_seq} > {3} {
2103 \keys_set:ne {zugferd/#1} {
2104 contact-name = {\seq_item:Nn \l_tmpa_seq {1}},
2105 contact-department = {\seq_item:Nn \l_tmpa_seq {2}},
2106 contact-phone = {\seq_item:Nn \l_tmpa_seq {3}},
2107 contact-email= {\seq_item:Nn \l_tmpa_seq {4}},
2108 }
2109 }{
2110 \keys_set:ne {zugferd/#1} {
2111 contact-name = {\seq_item:Nn \l_tmpa_seq {1}},
2112 contact-phone = {\seq_item:Nn \l_tmpa_seq {2}},
2113 contact-email= {\seq_item:Nn \l_tmpa_seq {3}},
2114 }
2115 }
2116 },
2117 % \end{macrocode}
2118 % \end{optionenv}
2119 % \begin{optionenv}{\meta{party}/\meta{unknown}}
2120 % \begin{macrocode}
2121 unknown .code:n = \tl_if_blank:nF {##1} {
2122 \prop_gput:cVe {g_@@_#1_AddressData_prop}
2123 \l_keys_key_tl {\tl_trim_spaces:n {##1}}
2124 }
2125 % \end{macrocode}
2126 % \end{optionenv}
2127 % \begin{macrocode}
2128 }
2129 }
2130 % \end{macrocode}
2131 % \begin{macro}{\_@@_TradePartyIdentity:N \_@@_PostalTradeAddress:N,\_@@_DefinedTradeContact:N}
2132 % Wrappers to map the property list items to the writing macro.
2133 % \changes{v0.9c}{2024-12-08}{Add TradePartyName to support additional legal information.}
2134 % \begin{macrocode}
2135 \cs_new:Nn \_@@_TradePartyIdentity:N {
2136 \_@@_TradePartyIdentity:eeeee
2137 {\prop_item:Nn #1 {id}}
2138 {\prop_item:Nn #1 {name}}
2139 {\prop_item:Nn #1 {legal-description}}
2140 {\prop_item:Nn #1 {legal-id}}
2141 {\prop_item:Nn #1 {trading-name}}
2142 }
2143 \cs_new:Nn \_@@_PostalTradeAddress_short:N {
2144 \exp_args:Ne \tl_if_blank:nF {\prop_item:Nn #1 {name}}
2145 {<ram:Name>\prop_item:Nn #1 {name}</ram:Name>
2146 \iow_newline:\_@@_xml_auto_indent:}
2147 \_@@_PostalTradeAddress:eeeeeee
2148 {\prop_item:Nn #1 {postcode}}
2149 {\prop_item:Nn #1 {lineone}}
2150 {\prop_item:Nn #1 {linetwo}}
2151 {\prop_item:Nn #1 {linethree}}
2152 {\prop_item:Nn #1 {city}}
2153 {\prop_item:Nn #1 {country}}
2154 {\prop_item:Nn #1 {subdivision}}
2155 }
2156 \cs_new:Nn \_@@_PostalTradeAddress:N {%
2157 \_@@_PostalTradeAddress:eeeeeee
2158 {\prop_item:Nn #1 {postcode}}
2159 {\prop_item:Nn #1 {lineone}}
2160 {\prop_item:Nn #1 {linetwo}}
2161 {\prop_item:Nn #1 {linethree}}
2162 {\prop_item:Nn #1 {city}}
2163 {\prop_item:Nn #1 {country}}
2164 {\prop_item:Nn #1 {subdivision}}
2165 \_@@_UniversalCommunication:n {\prop_item:Nn #1 {email}}
2166 \_@@_TaxRegistration:Nnn #1 {vatid} {taxid}
2167 }%
2168 \cs_new:Nn \_@@_DefinedTradeContact:N {%
2169 \_@@_DefinedTradeContact:eeee
2170 {\prop_item:Nn #1 {contact-name}}
2171 {\prop_item:Nn #1 {contact-department}}
2172 {\prop_item:Nn #1 {contact-phone}}
2173 {\prop_item:Nn #1 {contact-email}}
2174 }%
2175 % \end{macrocode}
2176 % \end{macro}
2177 % \begin{macrocode}
2178 % \end{macrocode}
2179 % \iffalse
2180 % \_@@_TradePartyIdentity:eeeee ID Name description legal-id trading-name
2181 % \fi
2182 % \begin{macro}{\_@@_TradePartyIdentity:nnnnn}
2183 % \begin{arguments}
2184 % \item ID
2185 % \item Name
2186 % \item Additional legal Information
2187 % \item Legal registration Identifier
2188 % \item Trading Name
2189 % \end{arguments}
2190 % \begin{macrocode}
2191 \_@@_define_xml_content:Nn \_@@_TradePartyIdentity:nnnnn {%
2192 %%<!-- seller BT-29 | buyer BT-46 | shipto BT-71 -->
2193 \_@@_write_inline:nn {ram:ID} {#1}
2194 %%<!-- seller BT-27 | buyer BT-44 | shipto BT-70 -->
2195 \_@@_write_inline:nn {ram:Name} {#2}
2196 %%<!-- seller BT-33 -->
2197 \str_if_eq:VnF \g_@@_conformance_level_str {BASIC} {%
2198 \_@@_write_inline:nn {ram:Description} {#3}
2199 }%
2200 \tl_if_blank:eF {#4#5} {%
2201 \_@@_xml_newline_indent:
2202 <ram:SpecifiedLegalOrganization>
2203 %%%<!-- seller BT-30 | buyer BT-47 -->
2204 \_@@_write_inline_i:nnn {ram:ID} {~schemeID="0088"} {#4}
2205 %%<!-- seller BT-28 | buyer BT-45 -->
2206 \_@@_write_inline_i:nn {ram:TradingBusinessName} {#5}
2207 \_@@_xml_newline_indent:
2208 </ram:SpecifiedLegalOrganization>
2209 }%
2210 }%
2211 % \end{macrocode}
2212 % \end{macro}
2213 % \iffalse
2214 % \_@@_PostalTradeAddress:nnnnnnn Name/Firma PLZ Zeile1 Zeile2 Zeile3 Ort Ländercode Bundesland/Bezirk
2215 % \fi
2216 % \begin{macro}{\_@@_PostalTradeAddress:nnnnnnn}
2217 % \begin{macrocode}
2218 \_@@_define_xml_content:Nn \_@@_PostalTradeAddress:nnnnnnn {%
2219 \_@@_xml_newline_indent:
2220 <ram:PostalTradeAddress>
2221 \bool_if:NF \g_@@_minimum_bool {%
2222 \_@@_write_inline_i:nn {ram:PostcodeCode} {#1}
2223 \_@@_write_inline_i:nn {ram:LineOne} {#2}
2224 \_@@_write_inline_i:nn {ram:LineTwo} {#3}
2225 \_@@_write_inline_i:nn {ram:LineThree} {#4}
2226 \_@@_write_inline_i:nn {ram:CityName} {#5}
2227 }%
2228 \_@@_write_inline_i:nn {ram:CountryID} {#6}
2229 \bool_if:NF \g_@@_minimum_bool {%
2230 \_@@_write_inline_i:nn {ram:CountrySubDivisionName} {#7}
2231 }%
2232 \_@@_xml_newline_indent:
2233 </ram:PostalTradeAddress>%
2234 }%
2235 \cctab_begin:N \g_@@_xml_cctab%
2236 \bool_if:NTF \g_@@_minimum_bool {%
2237 \cs_set_eq:NN \_@@_UniversalCommunication:n \use_none:n%
2238 } {%
2239 \_@@_define_xml_content:Nn \_@@_UniversalCommunication:n {%
2240 \tl_if_blank:eF {#1} {
2241 <ram:URIUniversalCommunication>
2242 \_@@_indent: <ram:URIID~schemeID="EM">#1</ram:URIID>
2243 </ram:URIUniversalCommunication>%
2244 }%
2245 }%
2246 }%
2247 \_@@_define_xml_content:Nn \_@@_TaxRegistration:nn {%
2248 %%%<!-- BT-34 -->
2249 \tl_if_blank:eF {#1} {
2250 <ram:SpecifiedTaxRegistration>
2251 \_@@_indent: <ram:ID~schemeID="VA">#1</ram:ID>
2252 </ram:SpecifiedTaxRegistration>%
2253 }%
2254 %%%<!-- BT-32 -->
2255 \tl_if_blank:eF {#2} {
2256 <ram:SpecifiedTaxRegistration>
2257 \_@@_indent: <ram:ID~schemeID="FC">#2</ram:ID>
2258 </ram:SpecifiedTaxRegistration>%
2259 }%
2260 }%
2261 \cctab_end:
2262 \cs_new:Nn \_@@_TaxRegistration:Nnn {
2263 \_@@_TaxRegistration:nn {\prop_item:Nn #1 {#2}} {\prop_item:Nn #1 {#3}}
2264 }
2265 % \end{macrocode}
2266 % \end{macro}
2267 % Contact data phone/email to a specific contact person
2268 % \begin{macrocode}
2269 \_@@_define_xml_content:Nn \_@@_DefinedTradeContact:nnnn {%
2270 % Do not print if name is empty
2271 \tl_if_blank:eT {#1} {\use_none:nnn}
2272 \bool_if:NT \g_@@_writeTradeContact_bool {
2273 \_@@_xml_newline_indent:
2274 <ram:DefinedTradeContact>
2275 \_@@_write_inline_i:nn {ram:PersonName} {#1}
2276 \_@@_write_inline_i:nn {ram:DepartmentName} {#2}
2277 \_@@_write_inline_wrapped_i:nnn
2278 {ram:TelephoneUniversalCommunication} {ram:CompleteNumber} {#3}
2279 \_@@_write_inline_wrapped_i:nnn
2280 {ram:EmailURIUniversalCommunication} {ram:URIID} {#4}
2281 \_@@_xml_newline_indent:
2282 </ram:DefinedTradeContact>
2283 }
2284 }
2285
2286 \_@@_define_xml_writer:Nn \_@@_ApplicableHeaderTradeAgreement: {
2287 \_@@_write_xml:n {<ram:ApplicableHeaderTradeAgreement>}
2288 \int_gincr:N \g_@@_indent_int
2289 \bool_lazy_and:nnF
2290 {\tl_if_blank_p:V \g_@@_buyer_reference_tl}
2291 % \end{macrocode}
2292 % \changes{v0.11-dev}{2026-05-25}{BASIC does no longer require the buyer-reference}
2293 % \begin{macrocode}
2294 { \g_@@_minimum_bool || \str_if_eq_p:Vn \g_@@_conformance_level_str {BASIC} }
2295 {
2296 \_@@_write_xml:e {
2297 <ram:BuyerReference>\g_@@_buyer_reference_tl</ram:BuyerReference>
2298 }
2299 }
2300 \_@@_write_xml:n {<ram:SellerTradeParty>}
2301 \int_gincr:N \g_@@_indent_int
2302 \_@@_write_xml:e {
2303 \_@@_TradePartyIdentity:N \g_@@_seller_AddressData_prop
2304 \_@@_DefinedTradeContact:N \g_@@_seller_AddressData_prop
2305 \_@@_PostalTradeAddress:N \g_@@_seller_AddressData_prop
2306 }
2307 \int_gdecr:N \g_@@_indent_int
2308 \_@@_write_xml:e {
2309 </ram:SellerTradeParty>
2310 \_@@_xml_newline_indent:
2311 <ram:BuyerTradeParty>
2312 }
2313 \int_gincr:N \g_@@_indent_int
2314 \_@@_write_xml:e {
2315 \_@@_TradePartyIdentity:N \g_@@_buyer_AddressData_prop
2316 \bool_if:NF \g_@@_minimum_bool {
2317 \_@@_DefinedTradeContact:N \g_@@_buyer_AddressData_prop
2318 \_@@_PostalTradeAddress:N \g_@@_buyer_AddressData_prop
2319 }%
2320 }%
2321 \int_gdecr:N \g_@@_indent_int
2322 \_@@_write_xml:n {</ram:BuyerTradeParty>}
2323 \clist_map_inline:nn {SellerOrder,BuyerOrder,Contract} {
2324 \_@@_write_ReferencedDocument:n {##1}
2325 }
2326 \_@@_write_keyval:Nnn \g_@@_extra_fields_prop
2327 {SpecifiedProcuringProject} {BT-11}
2328 \int_gdecr:N \g_@@_indent_int
2329 \_@@_write_xml:n {</ram:ApplicableHeaderTradeAgreement>}
2330 \bool_if:NTF \g_@@_minimum_bool
2331 {\_@@_write_xml:n {<ram:ApplicableHeaderTradeDelivery/>}}
2332 {\_@@_ApplicableHeaderTradeDelivery:V \g_@@_delivery_date_tl}
2333 }
2334
2335 \cctab_begin:N \g_@@_xml_cctab%
2336 % \end{macrocode}
2337 % delivery date
2338 % \begin{macrocode}
2339 \_@@_define_xml_content:Nn \_@@_ApplicableHeaderTradeDelivery:n {%
2340 \bool_lazy_and:nnF {\prop_if_empty_p:N \g_@@_shipto_AddressData_prop}%
2341 {\tl_if_blank_p:n {#1}}%
2342 {%
2343 \_@@_write_xml:n {<ram:ApplicableHeaderTradeDelivery>}%
2344 \prop_if_empty:NF \g_@@_shipto_AddressData_prop {%
2345 \int_gincr:N \g_@@_indent_int%
2346 \_@@_write_xml:n {<ram:ShipToTradeParty>}%
2347 \int_gincr:N \g_@@_indent_int%
2348 \_@@_write_xml:e {%
2349 \_@@_PostalTradeAddress_short:N \g_@@_shipto_AddressData_prop%
2350 }%
2351 \int_gdecr:N \g_@@_indent_int%
2352 \_@@_write_xml:n {</ram:ShipToTradeParty>}%
2353 \int_gdecr:N \g_@@_indent_int%
2354 }%
2355 \tl_if_blank:nF {#1} {%
2356 \_@@_write_xml:n {%
2357 \_@@_indent: <ram:ActualDeliverySupplyChainEvent>
2358 \_@@_xml_date:nnn {2} {Occurrence} {#1}
2359 \_@@_indent: </ram:ActualDeliverySupplyChainEvent>%
2360 }%
2361 }%
2362 \_@@_write_xml:n {</ram:ApplicableHeaderTradeDelivery>}%
2363 }%
2364 }%
2365 %
2366 \cctab_end:
2367 \cs_generate_variant:Nn \_@@_TradePartyIdentity:nnnnn {eeeee}
2368 \cs_generate_variant:Nn \_@@_DefinedTradeContact:nnnn {eeee}
2369 \cs_generate_variant:Nn \_@@_PostalTradeAddress:nnnnnnn {eeeeeee}
2370 \cs_generate_variant:Nn \_@@_ApplicableHeaderTradeDelivery:n {V}
2371 % \end{macrocode}
2372 % \end{implementation}
2373 % \begin{documentation}
2374 % \subsubsection{Buyer Reference}
2375 % \DescribeKeyOption*[BT-10]{buyer/reference=komavar/\meta{Reference}}{}
2376 % The reference field only exists for the |buyer| trade party.
2377 % Depending on the process it's required to use some unique identifier referring to the |buyer|.
2378 % Within Germany these numbers are called \enquote{Leitweg-ID}\cite{leitweg-id}.
2379 %
2380 % In any way the |buyer| may choose what is used here. Also may be some PO number or similar reference.
2381 %
2382 % As defined for other variables the \option{reference} can also use the \value{komavar} value to refer to the value of komavar |yourref|\cite{scrletter}.
2383 % \end{documentation}
2384 % \begin{implementation}
2385 % \begin{optionenv}{buyer/reference}
2386 % \begin{macrocode}
2387 \tl_new:N \g_@@_buyer_reference_tl
2388 \keys_define:nn {zugferd/buyer} {
2389 reference .choice:,
2390 reference / komavar .code:n = {
2391 \tl_gset:Nf \g_@@_buyer_reference_tl {\scr@yourref@var}
2392 },
2393 reference / unknown .code:n = {
2394 \tl_gset:Nn \g_@@_buyer_reference_tl {#1}
2395 }
2396 }
2397 % \end{macrocode}
2398 % \end{optionenv}
2399 % \end{implementation}
2400 % \begin{documentation}
2401 % \subsubsection{Buyer Accounting Reference}
2402 % \changes{v0.10}{2025-07-01}{Add support for accounting-reference}
2403 % \DescribeKeyOption*[BT-19]{buyer/accounting-reference=\meta{Accounting reference}}{}
2404 % The reference field only exists for the |buyer| trade party.
2405 % Buyers will explicitly ask for this field.
2406 % \end{documentation}
2407 % \begin{implementation}
2408 % \begin{variable}{\g_@@_extra_fields_prop}
2409 % \begin{macrocode}
2410 \prop_new:N \g_@@_extra_fields_prop
2411 % \end{macrocode}
2412 % \end{variable}
2413 % \begin{optionenv}{buyer/accounting-reference}% BT-19
2414 % \begin{macrocode}
2415 \keys_define:nn {zugferd/buyer} {
2416 accounting-reference .code:n = \prop_gput:Nnn \g_@@_extra_fields_prop {BT-19} {#1}
2417 }
2418 % \end{macrocode}
2419 % \end{optionenv}
2420 % \end{implementation}
2421 % \begin{documentation}
2422 % \subsubsection{Project Reference}
2423 % \changes{v0.10}{2025-09-22}{Add support for project reference}
2424 % \DescribeKeyOption*[BT-11]{project=\meta{Project ID}\string\\\meta{name}}{}
2425 % The project reference consits of two two entries |id| and |name|.
2426 % As both are required most implementations use \enquote{Project Reference} for the name entry.
2427 % \pkg{zugferd} also uses this as a default if only one value was provided within \option{project}.
2428 %
2429 % Please be aware, that the first |\\| is used to separate ID and name, following ones will be part of the name.
2430 % In case none is found the text |Project~Reference| will be used as the name may not be empty.
2431 %
2432 % \end{documentation}
2433 % \begin{implementation}
2434 % \begin{optionenv}{project}% BT-11
2435 % \begin{macrocode}
2436 \keys_define:nn {zugferd} {
2437 project .code:n = {
2438 \seq_set_split:Nnn \l_tmpa_seq {\\} {#1}
2439 \seq_pop_left:NN \l_tmpa_seq \l_tmpa_tl
2440 \prop_gput:Nne \g_@@_extra_fields_prop {BT-11} {
2441 ram:ID={\exp_not:V \l_tmpa_tl},
2442 ram:Name={\seq_if_empty:NTF \l_tmpa_seq {Project~Reference} {\seq_use:Nn \l_tmpa_seq {\\}}}
2443 }
2444 },
2445 project-reference .meta:n = {project = {#1}},
2446 }
2447 % \end{macrocode}
2448 % \end{optionenv}
2449 % \end{implementation}
2450 % \begin{documentation}
2451 % \subsubsection{Document references}
2452 % Additionally to the general buyer reference there may be additional data used by the buyer a reference.
2453 % These fields are technically optional, but the buyer may enforce them to be used.
2454 % These were not supported before \version{0.9c}.
2455 %
2456 % \DescribeKeyOption*[BT-12]{contract-reference=\meta{Contract reference}}{}
2457 % \DescribeKeyOption*[BT-13]{purchase-order-reference=\meta{Purchase order reference}}{}
2458 % \DescribeKeyOption*[BT-14]{sales-order-reference=\meta{Sales order reference}}{}
2459 % \end{documentation}
2460 % \begin{implementation}
2461 % \begin{macrocode}
2462 \prop_new:N \g_@@_document_references_prop
2463 \clist_new:N \g_@@_buyer_document_references_clist
2464 \keys_define:nn {zugferd} {
2465 contract-reference .prop_gput:N = \g_@@_document_references_prop,
2466 buyerorder-reference .prop_gput:N = \g_@@_document_references_prop,
2467 purchase-order-reference .meta:n = {buyerorder-reference=#1},
2468 sellerorder-reference .prop_gput:N = \g_@@_document_references_prop,
2469 sales-order-reference .meta:n = {sellerorder-reference=#1},
2470 }
2471 \cctab_begin:N \g_@@_xml_cctab%
2472 \_@@_define_xml_writer:Nn \_@@_write_ReferencedDocument:n {%
2473 \prop_if_in:NeT \g_@@_document_references_prop {\str_lowercase:n {#1}-reference} {%
2474 \_@@_write_xml:e {%
2475 <ram:#1ReferencedDocument>
2476 \_@@_indent:<ram:IssuerAssignedID>\prop_item:Ne \g_@@_document_references_prop {\str_lowercase:n {#1}-reference}</ram:IssuerAssignedID>
2477 </ram:#1ReferencedDocument>%
2478 }%
2479 }%
2480 }%
2481 \cctab_end:
2482 % \end{macrocode}
2483 % \end{implementation}
2484 % \begin{documentation}
2485 % \paragraph{Referencing a specific item of an Order}
2486 % \DescribeKeyOption*[BT-132]{purchase-order-reference=\meta{date formatted as YYYYMMDD}}{}*
2487 % With version \version{0.11} it's possible to add references to positions of the specific order for an item.
2488 % The keys \option{buyerorder-reference} or \option{purchase-order-reference} are configured as alias for BT-132 and can be used to match the document reference keys.
2489 %
2490 % Please be aware that this is a local variable.
2491 % \end{documentation}
2492 % \begin{implementation}
2493 % \changes{v0.11-dev}{2026-05-25}{Add support for BT-132}
2494 % \begin{optionenv}{BT-132}
2495 % \begin{macrocode}
2496 \keys_define:nn {zugferd/item} {
2497 BT-132 .tl_set:c = {l_@@_BT-132_tl},
2498 buyerorder-reference .meta:n = {BT-132=#1},
2499 purchase-order-reference .meta:n = {BT-132=#1},
2500 }
2501 % \end{macrocode}
2502 % \end{optionenv}
2503 % \end{implementation}
2504 % \begin{documentation}
2505 % \subsubsection{Payment Means}
2506 % \label{sec:PaymentMeans}
2507 % The payment means are selected by numeric codes.
2508 % Currently we support:
2509 % \begin{itemize}
2510 % \UseName{exp_args:Nnnc} \UseName{exp_args:co} {clist_map_inline:nn} {zugferd@paymentMeans@english} {\item #1}
2511 % \end{itemize}
2512 % Others may be added in the future but it's not planned to include a full list.
2513 %
2514 % The codes will automatically add the corresponding string inside the \enquote{Information} field.
2515 % The initial version only included German strings, but currently they are also included in English.
2516 % It's possible to overwrite them using the same structure:
2517 %
2518 % \begin{examplecode}
2519 % \setupZUGFeRDStrings{payment-means}{
2520 % 10 = Bargeld,
2521 % 58 = Zahlung per SEPA Überweisung.,
2522 % }
2523 % \end{examplecode}
2524 % The language selection is done using at hook executed at |\begin{document}| and will try to use the document's language.
2525 % If this is not defined English will be used.
2526 %
2527 % Internally the commands are predefined as a key-value list like the argument in the example above.
2528 % They macros are called \cs[no-index]{zugferd@paymentMeans@\meta{languagename}}.
2529 % Currently \pkg{zugferd} defines these for |english| and |german| (also |ngerman| as an compatibility alias).
2530 % \end{documentation}
2531 % \begin{implementation}
2532 % \begin{optionenv}{payment-means}
2533 % \begin{macrocode}
2534 \ExplSyntaxOff
2535 \providecommand*{\zugferd@paymentMeans@german}{
2536 1 = Keine Zahlungsart definiert,
2537 10 = Bargeld,
2538 30 = Überweisung,
2539 42 = Zahlung an Bankkonto,
2540 48 = Kartenzahlung,
2541 49 = Lastschriftverfahren,
2542 57 = Dauerauftrag,
2543 58 = Zahlung per SEPA Überweisung.,
2544 59 = SEPA Lastschrift,
2545 97 = Ausgleich zwischen Partnern
2546 }
2547 \def\zugferd@paymentMeans@ngerman{\zugferd@paymentMeans@german}
2548 \providecommand*{\zugferd@paymentMeans@english}{
2549 1 = Instrument not defined,
2550 10 = In cash,
2551 30 = Credit Transfer,
2552 31 = Debit Transfer,
2553 42 = Payment to bank account,
2554 48 = Bank card,
2555 49 = Direct Debit,
2556 57 = Standing agreement,
2557 58 = SEPA credit transfer,
2558 59 = SEPA direct debit,
2559 97 = Clearing between partners
2560 }
2561 \ExplSyntaxOn
2562 \tl_new:N \g_@@_payment_means_tl
2563 \keys_define:nn {zugferd} {
2564 payment-means / type .choices:nn = {1,10,30,42,48,49,57,58,59,97} {
2565 \tl_gset_eq:NN \g_@@_payment_means_tl \l_keys_choice_tl
2566 },
2567 payment-means / unknown .code:n = {
2568 \bool_if:NT \g_@@_unknown_value_warning_bool {
2569 \msg_warning:nnn { zugferd } {unknown-value} {payment-means} {#1}
2570 }
2571 \tl_gset:Nn \g_@@_payment_means_tl {\int_eval:n {#1}}
2572 }
2573 }
2574
2575 \clist_map_inline:nn {iban,account-holder,bic} {
2576 \keys_define:nn {zugferd/payment-means} {
2577 #1 .tl_gset:c = {g_@@_payment_#1_tl}
2578 }
2579 % \end{macrocode}
2580 % \changes{v0.10}{2025-07-28}{Add data access-keys for payment-means}
2581 % \begin{macrocode}
2582 \keys_define:nn {zugferd/data} {
2583 payment-means / #1 .code:n = \_@@_access_data:c {g_@@_payment_#1_tl},
2584 payment-means / #1 .value_forbidden:n = true,
2585 }
2586 }
2587
2588 \prop_new:c {g_@@_payment-means_names_prop}
2589 \newcommand*{\setupZUGFeRDStrings}[2]{
2590 \prop_gset_from_keyval:cn {g_@@_#1_names_prop} {
2591 #2
2592 }
2593 }
2594
2595 \hook_gput_code:nnn {begindocument/end}{zugferd/payment-means}{
2596 \prop_if_empty:cT {g_@@_payment-means_names_prop} {
2597 \exp_args:Nne \setupZUGFeRDStrings{payment-means}{
2598 \use:c {zugferd@paymentMeans@
2599 \cs_if_exist:cTF {zugferd@paymentMeans@\languagename}
2600 {\languagename} {english}
2601 }
2602 }
2603 }
2604 }
2605 % \end{macrocode}
2606 % \end{optionenv}
2607 % \end{implementation}
2608 % \begin{documentation}
2609 % \subsection{Variables which may be changed per invoice item}
2610 % Some settings may have the same value for all invoice items.
2611 % These are defined to take some preset but are set locally.
2612 % So it's possible to adjust them for a single invoice item if necessary.
2613 % An example is shown in \autoref{sec:xml-interfaces}.
2614 % \subsubsection{Units}
2615 % \DescribeKeyOption*[BT-130]{unit=hour/day/one/piece/\meta{unit code}}{}
2616 % The Faktur-X standard requires the unit to be selected.
2617 % These are called \enquote{/UN/CEFACT Common Codes} and can be found withtin \cite{unit-codes}.
2618 %
2619 % Currently \pkg{zugferd} supports |hour| (|HUR|), |day| (|DAY|), |one| (C62) and |piece| (H87).
2620 % For these the corresponding codes have been implemented within the package.
2621 % Other units can be selected using the codes listed in \cite{unit-codes}.
2622 %
2623 % This option is not case sensitive
2624 % The value is automatically converted to uppercase.
2625 % If the selected option is different from the predefined ones, there will be a warning, as \pkg{zugferd} does not know if the selection is valid or not.
2626 % \begin{NOTE}
2627 % additional source: http://www.unece.org/fileadmin/DAM/cefact/recommendations/rec20/rec20_Rev9e_2014.xls
2628 % \end{NOTE}
2629 % \end{documentation}
2630 % \begin{implementation}
2631 % \begin{optionenv}{unit}
2632 % \begin{macrocode}
2633 \keys_define:nn { zugferd } {
2634 unit .choices:nn = {HUR,DAY,C62,H87} {
2635 \tl_set_eq:NN \l_@@_unit_code_tl \l_keys_choice_tl
2636 },
2637 unit / hour .meta:n = {unit=HUR},
2638 unit / day .meta:n = {unit=DAY},
2639 unit / one .meta:n= {unit= C62},
2640 unit / piece .meta:n = {unit=H87},
2641 % \end{macrocode}
2642 % If unknown, the value is converted to uppercase and we use the selection directly.
2643 % There is a warning in that case
2644 % \begin{macrocode}
2645 unit / unknown .code:n = {
2646 \tl_set:Nx \l_tmpa_tl {\str_uppercase:f {#1}}
2647 \exp_args:NnnV \keys_if_choice_exist:nnnTF {zugferd} {unit}
2648 \l_tmpa_tl
2649 {
2650 \keys_set:ne { zugferd } {unit= {\l_tmpa_tl}}
2651 } {
2652 \bool_if:NT \g_@@_unknown_value_warning_bool {
2653 \msg_warning:nnn { zugferd } {unknown-unit} {#1}
2654 }
2655 \tl_set_eq:NN \l_@@_unit_code_tl \l_tmpa_tl
2656 }
2657 },
2658 unit .usage:n = general,
2659 }
2660
2661 \msg_new:nnnn {zugferd} {unknown-unit} {
2662 You~selected~a~unit~which~was~not~predefined.\\
2663 I~~will~directly~use~your~selection~'unit=#1'~as~Common~Code.
2664 Please~ensure~the~selection~is~valid!
2665 } {
2666 For~more~information~see~the~zugferd~documentation\\
2667 and~the~/UN/CEFACT~Common~Code~list.
2668 }
2669 % \end{macrocode}
2670 % \end{optionenv}
2671 % \end{implementation}
2672 % \begin{documentation}
2673 % \subsubsection{Tax category and rate}
2674 % \label{sec:tax-category}
2675 % \DescribeKeyOption[BT-151]{tax/category=\meta{category code/alias}}{standard}*
2676 % The Tax data requires a category code. For details have a look at the Specification \cite[e.\,g. at][]{spec-xrechnung}.
2677 % \pkg{zugferd} implements all of those, but the user has to take care to select the correct one for each invoice item.
2678 % The example file includes 2 different VAT values using the same category.
2679 %
2680 % The labels have been chosen to simplify the usage. It's also possible to enter the codes directly.
2681 % This option is not case sensitive.
2682 % \begin{valuelist}
2683 % \item[standard] Standard rate and reduced rate item, |category=S|
2684 % \item[zero] Zero rated sale, |category=Z|
2685 % \item[exempt] Exempted from VAT. This requires a reason via \option{exemption-reason},|category=E|
2686 % \item[reverse-charge] Reverse Charge, |category=AE|
2687 % \item[intra-community\\\textnormal{or} EEA] Intra-Community Supply, |category=K|
2688 % \item[export] Free export item, tax not charged, |category=G|
2689 % \item[O] Services outside scope of tax
2690 % \item[canary-islands] Canary Islands general indirect tax, |category=L|
2691 % \item[ceuta\\\textnormal{or} melilla] Ceuta and Melilla, |category=M|
2692 % \end{valuelist}
2693 %
2694 % \end{documentation}
2695 % \begin{implementation}
2696 % \begin{macrocode}
2697 \msg_new:nnnn {zugferd} {unknown-tax-category} {
2698 You~selected~an~unknown~tax~category.\\
2699 I~~will~directly~use~your~selection~'category=#1'~as~Code.\\
2700 Please~ensure~the~selection~is~valid!
2701 } {
2702 For~more~information~see~the~zugferd~documentation\\
2703 and~the~corresponding~code~list.
2704 }
2705 \msg_new:nnnn {zugferd} {no-auto-exemption} {
2706 You~selected~tax/category=#1~together~with~the~auto-exemption~option.\\
2707 I~don't~have~any~pre-configured~exemption~setting~for~category=#1.\\
2708 Please~make~sure~you~add~a~valid~setting~yourself.
2709 } {
2710 For~more~information~see~the~zugferd~documentation.
2711 }
2712 % \end{macrocode}
2713 % \changes{v0.10}{2025-07-01}{Add interface for configuration of auto-exemption-reason}
2714 % \begin{macrocode}
2715 \cs_new:Nn \_@@_configure_auto_exemption:nn {
2716 \tl_if_in:nnTF {#2} {=} {
2717 \keys_define:nn { zugferd / tax } {
2718 exemption-reason-auto / #1 .code:n = {
2719 \keys_set:nn {zugferd/tax}{
2720 #2
2721 }
2722 }
2723 }
2724 } {
2725 \keys_define:nn { zugferd / tax } {
2726 exemption-reason-auto / #1 .code:n = {
2727 \keys_set:nn {zugferd/tax} {
2728 exemption-reason={#2}
2729 }
2730 }
2731 }
2732 }
2733 }
2734 % \end{macrocode}
2735 % \optionenv{category, exemption-reason,rate}
2736 % \begin{macrocode}
2737 \keys_define:nn { zugferd / tax } {
2738 category .choices:nn = {S,Z,E,AE,K,G,O,L,M} {
2739 \tl_set_eq:NN \l_@@_tax_category_code_tl \l_keys_choice_tl
2740 \bool_if:NT \g_@@_auto_exemption_bool {
2741 \keys_if_choice_exist:nnnTF {zugferd/tax} {exemption-reason-auto} {#1} {
2742 \keys_set:nn {zugferd/tax} {exemption-reason-auto=#1}
2743 } {
2744 \msg_warning:nnn { zugferd } {no-auto-exemption} {#1}
2745 }
2746 }
2747 },
2748 % \end{macrocode}
2749 % \end{implementation}
2750 % \begin{documentation}
2751 % \DescribeKeyOption*{tax/exemption-reason=\meta{Text}}{}*
2752 % \DescribeKeyOption*{tax/exemption-reason-code=\meta{exemption reason code}}{}*
2753 % Add Reasons for a tax exempt, as required by |category=E,K,AE,G,O|.
2754 % This can either be added using a text (|exemption-reason|) or a predefined code (|exemption-reason-code|).
2755 % The codes are listed at \cite{VAT-exemption-codes}.
2756 %
2757 % In most common cases \pkg{zugferd} tries to automatically match them if the package option \option{auto-exemption} is enabled, which is the default.
2758 % In that case the following settings would apply:
2759 %
2760 % \begin{valuelist}
2761 % \item[S] \accessTaxExemptionReason{S}
2762 % \item[Z] Not configured.
2763 % \item[E] Not configured, as there are too many options.
2764 % \item[AE] \accessTaxExemptionReason{AE}
2765 % \item[K] \accessTaxExemptionReason{K}
2766 % \item[G] \accessTaxExemptionReason{G}
2767 % \item[O] \accessTaxExemptionReason{O}
2768 % \end{valuelist}
2769 %
2770 % In case there is no pre-configured selection \pkg{zugferd} will create a warning to remind the user to add a selection themselves.
2771 %
2772 % \end{documentation}
2773 % \begin{implementation}
2774 % \begin{macrocode}
2775 exemption-reason .tl_set:N = \l_@@_tax_exemption_reason_tl,
2776 exemption-reason .initial:V = \c_empty_tl,
2777 exemption-reason .usage:n = general,
2778 exemption-reason-code .tl_set:N = \l_@@_tax_exemption_code_tl,
2779 exemption-reason-code .initial:V = \c_empty_tl,
2780 exemption-reason .usage:n = general,
2781 % \end{macrocode}
2782 % \changes{v0.7}{2024-09-10}{Added exemption-reason-auto key for pre-configured exemption-reasons.}
2783 % \begin{macrocode}
2784 exemption-reason-auto .choice:,
2785 exemption-reason-auto / S .code:n = {
2786 \keys_set:nn {zugferd/tax} {exemption-reason=,exemption-reason-code=}
2787 },
2788 exemption-reason-auto / K .code:n = {
2789 \keys_set:nn {zugferd/tax} {
2790 exemption-reason= Intra-Community~Supply,
2791 exemption-reason-code={vatex-eu-ic}
2792 }
2793 },
2794 exemption-reason-auto / AE .code:n = {
2795 \keys_set:nn {zugferd/tax}{
2796 exemption-reason=Reverse~Charge,
2797 exemption-reason-code={vatex-eu-ae}
2798 }
2799 },
2800 exemption-reason-auto / G .code:n = {
2801 \keys_set:nn {zugferd/tax}{
2802 exemption-reason=Export~outside~the~EU,
2803 exemption-reason-code={vatex-eu-g}
2804 }
2805 },
2806 exemption-reason-auto / O .code:n = {
2807 \keys_set:nn {zugferd/tax}{
2808 exemption-reason=No~subject~to~VAT,
2809 exemption-reason-code={vatex-eu-o}
2810 }
2811 },
2812 % \end{macrocode}
2813 % \changes{v0.10}{2025-07-01}{Remove exemption reason for category Z}
2814 % \begin{macrocode}
2815 exemption-reason-auto / Z .code:n = {
2816 \keys_set:nn {zugferd/tax}{
2817 exemption-reason=,
2818 exemption-reason-code=
2819 }
2820 },
2821 add-exemption-reason-auto .code:n = {
2822 %TODO Error if syntax doesn't match?
2823 \keyval_parse:nnn {\use_none:n} {\_@@_configure_auto_exemption:nn} {#1}
2824 },
2825 standard .meta:n = {category=S},
2826 zero .meta:n = {category=Z},
2827 exempt .meta:n = {category=E},
2828 reverse-charge .meta:n = {category=AE},
2829 intra-community .meta:n = {category=K},
2830 EEA .meta:n = {category=K},
2831 export .meta:n = {category=G},
2832 canary-islands .meta:n = {category=L},
2833 ceuta .meta:n = {category=M},
2834 melilla .meta:n = {category=M},
2835 category / unknown .code:n = {
2836 \exp_args:Nnnx \keys_if_choice_exist:nnnTF {zugferd} {category}
2837 {\str_uppercase:f {#1}}
2838 {
2839 \keys_set:nx { zugferd } {category= {\str_uppercase:f {#1}}}
2840 } {
2841 \tl_set:Ne \l_@@_tax_category_code_tl {\str_uppercase:f {#1}}
2842 \bool_if:NT \g_@@_unknown_value_warning_bool {
2843 \msg_warning:nnn { zugferd } {unknown-tax-category} {#1}
2844 }
2845 }
2846 },
2847 category .initial:n = S,
2848 category .usage:n = general,
2849 % \end{macrocode}
2850 % \end{implementation}
2851 % \begin{documentation}
2852 % \DescribeKeyOption[BT-152]{tax/rate=\meta{floating point}}{19}*
2853 % The value given will be used for tax calculation.
2854 % By default it's configured to |19| to match the German standard VAT rate.
2855 %
2856 % \end{documentation}
2857 % \begin{implementation}
2858 % \begin{macrocode}
2859 rate .fp_set:N = \l_@@_tax_rate_fp,
2860 rate .initial:n = 19,
2861 rate .usage:n = general
2862 }%
2863 \keys_define:nn {zugferd/item} {
2864 tax .choice:,
2865 tax / unknown .code:n = {
2866 \keys_set:ne {zugferd/tax} {
2867 \l_keys_key_str = \exp_not:V \l_keys_value_tl
2868 }
2869 },
2870 unknown .code:n = \keys_set:ne {zugferd}
2871 { \l_keys_key_str = \exp_not:V \l_keys_value_tl}
2872 }
2873 % \end{macrocode}
2874 % data interface to simplify access on tax data
2875 % \begin{macrocode}
2876 \keys_define:nn { zugferd / data / tax } {
2877 rate .code:n = \fp_use:N \l_@@_tax_rate_fp,
2878 category .code:n = \l_@@_tax_category_code_tl,
2879 exemption-reason .code:n = \l_@@_tax_exemption_reason_tl,
2880 exemption-reason-code .code:n = \l_@@_tax_exemption_code_tl,
2881 }
2882 % \end{macrocode}
2883 % \endoptionenv
2884 % \end{implementation}
2885 % \begin{documentation}
2886 % \DescribeKeyOption*[BT-134]{item/start-date=\meta{date formatted as YYYYMMDD}}{}*
2887 % \DescribeKeyOption*[BT-135]{item/end-date=\meta{date formatted as YYYYMMDD}}{}*
2888 % With version \version{0.9} support for |BillingSpecifiedPeriod| was added.
2889 % This supports setting |start-date| and |end-date| per item.
2890 % As this is optional, there is no default.
2891 % The element will be printed if both dates are set, as setting a single one will enforce the element to be invalid.
2892 % This element should be set as all the other dates (see \autoref{sec:dates}).
2893 % \end{documentation}
2894 % \begin{implementation}
2895 % \changes{v0.10}{2025-09-22}{Bugfix: set start-date only locally}
2896 % \optionenv{start-date,end-date}
2897 % \begin{macrocode}
2898 \keys_define:nn { zugferd / item } {
2899 start-date .tl_set:N = \l_@@_start_date_tl,
2900 start-date .initial:n =,
2901 end-date .tl_set:N = \l_@@_end_date_tl,
2902 end-date .initial:n =,
2903 }%
2904 % \end{macrocode}
2905 % \endoptionenv
2906 % \begin{macrocode}
2907 \_@@_define_xml_content:Nn \_@@_write_inline:nn {
2908 \_@@_write_inline:nnn {#1} {} {#2}
2909 }
2910 \cs_generate_variant:Nn \_@@_write_inline:nn {ne}
2911 \_@@_define_xml_content:Nn \_@@_write_inline:nnnn {
2912 \tl_if_blank:nF {#4} {
2913 \_@@_xml_newline_indent:n {#1}
2914 <#2#3>#4</#2>
2915 }
2916 }
2917 \_@@_define_xml_content:Nn \_@@_write_inline:nnn {
2918 \_@@_write_inline:nnnn {} {#1} {#2} {#3}
2919 }
2920 \_@@_define_xml_content:Nn \_@@_xml_wrapped:nnnnn {
2921 \_@@_indent:n {#1} <#2>\_@@_xml_newline_indent:
2922 \_@@_indent:n {#1+1} <#3#4>#5</#3>\_@@_xml_newline_indent:
2923 \_@@_indent:n {#1} </#2>
2924 }
2925 \_@@_define_xml_content:Nn \_@@_write_inline_wrapped:nnnn {
2926 \tl_if_blank:nF {#4} {
2927 \_@@_xml_newline_indent:
2928 \_@@_xml_wrapped:nnnnn {#1} {#2} {#3} {} {#4}
2929 }
2930 }
2931 \cs_generate_variant:Nn \_@@_write_inline_wrapped:nnnn {nnne}
2932
2933 \_@@_define_xml_content:Nn \_@@_xml_date:nnn {%
2934 \_@@_xml_wrapped:nnnnn {#1} {ram:#2DateTime}
2935 {udt:DateTimeString}{~format="102"}{#3}%
2936 }
2937
2938 \_@@_define_xml_writer:Nn \_@@_write_prop:Nnn {
2939 \prop_if_in:NeT #1 {#3} {
2940 \_@@_write_xml:e {
2941 <ram:#2>\prop_item:Ne #1 {#3}</ram:#2>
2942 }
2943 }
2944 }
2945
2946 \_@@_define_xml_writer:Nn \_@@_write_prop:Nn {
2947 \_@@_write_prop:Nnn #1 {#2} {#2}
2948 }
2949
2950 \cctab_begin:N \g_@@_xml_cctab%
2951 \_@@_define_xml_writer:Nn \_@@_write_prop_wrapped:Nnnn {%
2952 \prop_if_in:NeT #1 {#4} {%
2953 \_@@_write_xml:e {%
2954 <#2>
2955 \_@@_indent:<#3>\prop_item:Ne #1 {#4}</#3>
2956 </#2>%
2957 }%
2958 }%
2959 }%
2960 \cctab_end:
2961 \_@@_define_xml_writer:Nn \_@@_write_optional_wrapped:nnn {%
2962 \_@@_write_prop_wrapped:Nnnn \g_@@_extra_fields_prop
2963 {ram:#1} {ram:#2} {#3}
2964 }
2965
2966 \_@@_define_xml_content:Nn \_@@_write_inline_wrapped_i:nnn {
2967 \_@@_write_inline_wrapped:nnnn {1} {#1} {#2} {#3}
2968 }
2969 \cs_generate_variant:Nn \_@@_write_inline_wrapped_i:nnn {nne,nnv}
2970
2971 \_@@_define_xml_content:Nn \_@@_write_wrapped:nnn {
2972 \_@@_write_inline_wrapped:nnnn {1} {#1} {#2} {#3}
2973 }
2974 \cs_generate_variant:Nn \_@@_write_wrapped:nnn {nne}
2975 \_@@_define_xml_content:Nn \_@@_write_inline_i:nnn {
2976 \_@@_write_inline:nnnn {+1} {#1} {#2} {#3}
2977 }
2978 \_@@_define_xml_content:Nn \_@@_write_inline_i:nn {
2979 \_@@_write_inline_i:nnn {#1} {} {#2}
2980 }
2981
2982 \_@@_define_xml_writer:Nn \_@@_write_keyval:Nnn {
2983 \prop_if_in:NeT #1 {#3} {
2984 \_@@_write_xml:e {
2985 <ram:#2>
2986 \exp_args:Nnne \keyval_parse:nnn {\use_none:n} {
2987 \_@@_write_inline_i:nn
2988 } {\prop_item:Ne \g_@@_extra_fields_prop {#3}}
2989 \_@@_xml_newline_indent:
2990 </ram:#2>
2991 }
2992 }
2993 }
2994
2995 \cctab_begin:N \g_@@_xml_cctab%
2996 %
2997 \bool_if:NTF \g_@@_minimum_bool {%
2998 \cs_set_eq:NN \_@@_write_note:n \use_none:n%
2999 } {%
3000 \_@@_define_xml_writer:Nn \_@@_write_note:n {%
3001 \begingroup%
3002 \let\\\iow_newline:%
3003 \_@@_write_xml:e {%
3004 <ram:IncludedNote>
3005 \_@@_indent: <ram:Content>
3006 #1
3007 \_@@_indent: </ram:Content>
3008 </ram:IncludedNote>%
3009 }%
3010 \endgroup%
3011 }%
3012 }%
3013 %
3014 \begingroup%
3015 \char_set_catcode_other:N \#%
3016 \char_set_catcode:nn {32}{10}%
3017 \_@@_define_xml_writer:Nn \_@@_insert_Header: {%
3018 \_@@_write_xml:e {%
3019 <?xml version='1.0' encoding='UTF-8' ?>
3020 <rsm:CrossIndustryInvoice %
3021 xmlns:rsm="urn:un:unece:uncefact:data:standard:CrossIndustryInvoice:100" %
3022 xmlns:qdt="urn:un:unece:uncefact:data:standard:QualifiedDataType:100" %
3023 xmlns:ram="urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:100" %
3024 xmlns:xs="http://www.w3.org/2001/XMLSchema" %
3025 xmlns:udt="urn:un:unece:uncefact:data:standard:UnqualifiedDataType:100">%
3026 }%
3027 \int_gincr:N \g_@@_indent_int%
3028 \_@@_write_xml:n {<rsm:ExchangedDocumentContext>}%
3029 \int_gincr:N \g_@@_indent_int%
3030 \_@@_write_xml:e {%
3031 \str_if_empty:NF \g_@@_businessProcessId_str {%
3032 <ram:BusinessProcessSpecifiedDocumentContextParameter>
3033 \_@@_indent: <ram:ID>\g_@@_businessProcessId_str</ram:ID>
3034 </ram:BusinessProcessSpecifiedDocumentContextParameter>
3035 }%
3036 <ram:GuidelineSpecifiedDocumentContextParameter>
3037 \_@@_indent: <ram:ID>\g_@@_format_str</ram:ID>
3038 </ram:GuidelineSpecifiedDocumentContextParameter>%
3039 }%
3040 \int_gdecr:N \g_@@_indent_int%
3041 \_@@_write_xml:n {</rsm:ExchangedDocumentContext>}%
3042 }%
3043 \endgroup%
3044 \_@@_define_xml_writer:Nn \_@@_insert_FrontMatter: {%
3045 \_@@_write_xml:n {<rsm:ExchangedDocument>}%
3046 \int_gincr:N \g_@@_indent_int%
3047 \_@@_write_xml:e {%
3048 <ram:ID>\g_@@_id_tl</ram:ID>
3049 <ram:TypeCode>\g_@@_DocumentTypeCode_tl</ram:TypeCode>
3050 \_@@_xml_date:nnn {0} {Issue} {\g_@@_date_tl}%
3051 }%
3052 \_@@_note_if_not_empty:N \g_@@_subject_tl%
3053 \_@@_note_if_not_empty:N \g_@@_fromaddress_tl%
3054 \seq_map_inline:Nn \g_@@_notes_seq {%
3055 \_@@_write_note:n {##1}%
3056 }%
3057 \int_gdecr:N \g_@@_indent_int%
3058 \_@@_write_xml:e {%
3059 </rsm:ExchangedDocument>
3060 <rsm:SupplyChainTradeTransaction>%
3061 }%
3062 \int_gincr:N \g_@@_indent_int%
3063 }%
3064 %
3065 % footer
3066 \_@@_define_xml_writer:Nn \_@@_insert_Footer: {%
3067 \int_gdecr:N \g_@@_indent_int%
3068 \_@@_write_xml:n {</rsm:SupplyChainTradeTransaction>}%
3069 \int_gdecr:N \g_@@_indent_int%
3070 \_@@_write_xml:n {</rsm:CrossIndustryInvoice>}%
3071 }%
3072 \cctab_end:
3073 % \end{macrocode}
3074 %
3075 % \subsection{Invoice Items}
3076 % Each item consists of 5 parts:
3077 % \begin{itemize}
3078 % \item AssociatedDocumentLineDocument
3079 % \item SpecifiedTradeProduct
3080 % \item SpecifiedLineTradeAgreement
3081 % \item SpecifiedLineTradeDelivery
3082 % \item SpecifiedLineTradeSettlement
3083 % \end{itemize}
3084 % These are implemented as separate commands to be more flexible.
3085 % The wrapper command is called \cs[no-index]{@@_insert_TradeLineItem:nnnnnn} and is created to be used in your own invoicing package.
3086 % \begin{macrocode}
3087 \cctab_begin:N \g_@@_xml_cctab%
3088 % \end{macrocode}
3089 % \begin{function}{\_@@_AssociatedDocumentLineDocument:n}
3090 % \begin{macrocode}
3091 \_@@_define_xml_writer:Nn \_@@_AssociatedDocumentLineDocument:n {%
3092 <ram:AssociatedDocumentLineDocument>
3093 \_@@_indent: <ram:LineID>#1</ram:LineID>
3094 </ram:AssociatedDocumentLineDocument>%
3095 }%
3096 % \end{macrocode}
3097 % \end{function}
3098 % \begin{function}{\_@@_SpecifiedTradeProduct:nn}
3099 % \changes{v0.9c}{2024-12-08}{Don't use SellerAssignedID if format=basic, \issue{28}}
3100 % \begin{macrocode}
3101 \_@@_define_xml_content:Nn \_@@_SpecifiedTradeProduct:nn {%
3102 <ram:SpecifiedTradeProduct>
3103 \bool_lazy_or:nnF%
3104 {\tl_if_blank_p:n {#1}}%
3105 {\str_if_eq_p:Vn \g_@@_conformance_level_str {BASIC}} {%
3106 \_@@_indent: <ram:SellerAssignedID>#1</ram:SellerAssignedID>
3107 }%
3108 \_@@_indent: <ram:Name>#2</ram:Name>
3109 </ram:SpecifiedTradeProduct>%
3110 }%
3111 % \end{macrocode}
3112 % \end{function}
3113 % \begin{function}{\_@@_ProductTradePrice:nn}
3114 % \begin{macrocode}
3115 \_@@_define_xml_writer:Nn \_@@_ProductTradePrice:nn {%
3116 <ram:\str_uppercase:n #1PriceProductTradePrice>
3117 \_@@_indent: <ram:ChargeAmount>#2</ram:ChargeAmount>
3118 </ram:\str_uppercase:n #1PriceProductTradePrice>%
3119 }%
3120 % \end{macrocode}
3121 % \end{function}
3122 % \begin{function}{\_@@_SpecifiedLineTradeAgreement:nn}
3123 % \begin{macrocode}
3124 \_@@_define_xml_writer:Nn \_@@_SpecifiedLineTradeAgreement:nn {%
3125 <ram:SpecifiedLineTradeAgreement>
3126 \_@@_indent:<ram:GrossPriceProductTradePrice>
3127 \_@@_indent:n {2} <ram:ChargeAmount>#1</ram:ChargeAmount>
3128 \_@@_indent:</ram:GrossPriceProductTradePrice>
3129 \_@@_indent:<ram:NetPriceProductTradePrice>
3130 \_@@_indent:n {2} <ram:ChargeAmount>#2</ram:ChargeAmount>
3131 \_@@_indent:</ram:NetPriceProductTradePrice>
3132 </ram:SpecifiedLineTradeAgreement>
3133 }%
3134 % \end{macrocode}
3135 % \end{function}%:nn <unit code > <number>
3136 % \begin{function}{\_@@_SpecifiedLineTradeDelivery:nn}
3137 % \begin{macrocode}
3138 \_@@_define_xml_content:Nn \_@@_SpecifiedLineTradeDelivery:nn {%
3139 <ram:SpecifiedLineTradeDelivery>
3140 % SPACE!
3141 \_@@_indent: <ram:BilledQuantity~unitCode="#1">#2</ram:BilledQuantity>
3142 </ram:SpecifiedLineTradeDelivery>%
3143 }%
3144 % \end{macrocode}
3145 % \end{function}
3146 % \begin{function}{\_@@_SpecifiedLineTradeSettlement:nnn,\_@@_SpecifiedLineTradeSettlement:Vnn}
3147 % \changes{v0.9}{2024-10-23}{Split SpecifiedLineTradeSettlement to be more flexible and add support for BillingSpecifiedPeriod}
3148 % \begin{macrocode}
3149 \_@@_define_xml_writer:Nn \_@@_write_SpecifiedLineTradeSettlement:nnn {%
3150 \_@@_write_xml:n {<ram:SpecifiedLineTradeSettlement>}%
3151 \int_gincr:N \g_@@_indent_int%
3152 \_@@_write_xml:e {\_@@_Line_ApplicableTradeTax:nn {#1} {#2}}%
3153 \_@@_write_xml:e {\_@@_BillingSpecifiedPeriod:VV \l_@@_start_date_tl \l_@@_end_date_tl}%
3154 % \end{macrocode}
3155 % Allowance/Charge per item.
3156 % In this case the tax information has not to be added and should not be written to the XML.
3157 % \begin{macrocode}
3158 \seq_map_inline:Nn \l_@@_AllowanceCharge_seq {%
3159 \_@@_SpecifiedTradeAllowanceCharge:n {##1}%
3160 }%
3161 \_@@_write_xml:e {\_@@_SpecifiedTradeSettlementLineMonetarySummation:n {#3}}%
3162 \int_gdecr:N \g_@@_indent_int%
3163 \_@@_write_xml:n {</ram:SpecifiedLineTradeSettlement>}%
3164 }%
3165 \cs_generate_variant:Nn \_@@_write_SpecifiedLineTradeSettlement:nnn {Vnn}%
3166 \_@@_define_xml_content:Nn \_@@_Line_ApplicableTradeTax:nn {%
3167 <ram:ApplicableTradeTax>
3168 %BT-151
3169 \_@@_indent: <ram:TypeCode>VAT</ram:TypeCode>
3170 %BT-151
3171 \_@@_indent: <ram:CategoryCode>#1</ram:CategoryCode>
3172 %BT-152
3173 \_@@_indent: <ram:RateApplicablePercent>#2</ram:RateApplicablePercent>
3174 </ram:ApplicableTradeTax>%
3175 }%
3176 \_@@_define_xml_content:Nn \_@@_BillingSpecifiedPeriod:nn {%
3177 \bool_lazy_or:nnF {\tl_if_blank_p:n {#1}} {\tl_if_blank_p:n {#2}} {%
3178 <ram:BillingSpecifiedPeriod>%
3179 %<!-- BT-134 -- BT-73 -->
3180 \_@@_xml_date:nnn {1} {Start} {#1}%
3181 %<!-- BT-135 -- BT-74 -->
3182 \_@@_xml_date:nnn {1} {End} {#2}
3183 </ram:BillingSpecifiedPeriod>%
3184 }%
3185 }%
3186 \_@@_define_xml_content:Nn \_@@_SpecifiedTradeSettlementLineMonetarySummation:n {%
3187 <ram:SpecifiedTradeSettlementLineMonetarySummation>
3188 % BT-131
3189 \_@@_indent: <ram:LineTotalAmount>#1</ram:LineTotalAmount>
3190 </ram:SpecifiedTradeSettlementLineMonetarySummation>%
3191 }
3192
3193 % \end{macrocode}
3194 % \begin{macrocode}
3195 \cctab_end:
3196 \cs_generate_variant:Nn \_@@_SpecifiedLineTradeSettlement:nnn {Vnn}
3197 \cs_generate_variant:Nn \_@@_BillingSpecifiedPeriod:nn {VV}
3198 % \end{macrocode}
3199 % \end{function}
3200 % The exemption reason was placed wrong with the pre-CTAN release.
3201 % This was fixed in August 2024.
3202 % The old macro will be kept for a bit longer but will be removed soon.
3203 % Please update your own implementations accordingly.
3204 % \changes{v0.4}{2024-08-22}{Deprecate old syntax and add public interfaces.}
3205 % \begin{macrocode}
3206 \cs_new:Nn \_@@_SpecifiedLineTradeSettlement:nnnn {
3207 \msg_warning:nnnn {zugferd} {macro-deprecated}
3208 { \_@@_SpecifiedLineTradeSettlement:nnnn }
3209 { \_@@_SpecifiedLineTradeSettlement:nnn }
3210 \_@@_SpecifiedLineTradeSettlement:nnn {#2} {#3} {#4}
3211 }
3212 \cs_generate_variant:Nn \_@@_SpecifiedLineTradeSettlement:nnnn {VVnn}
3213 % \end{macrocode}
3214 % \end{implementation}
3215 % \begin{implementation}
3216 % \begin{macro}{ \_@@_insert_TradeLineItem:nnnnnn,\@@_write_TradeLineItem:nnnnnn}
3217 % Writing an invoice item using the helper commands defined before, to the \XMLfile.
3218 % \begin{macrocode}
3219 \_@@_define_xml_writer:Nn \_@@_insert_TradeLineItem:nnnnnn {
3220 \_@@_write_xml:n {<ram:IncludedSupplyChainTradeLineItem>}
3221 \int_gincr:N \g_@@_indent_int
3222 \_@@_write_xml:e {\_@@_AssociatedDocumentLineDocument:n {#1}}%
3223
3224 \begingroup
3225 \zugferd_disable_macros:
3226 \_@@_write_xml:e {\_@@_SpecifiedTradeProduct:nn {#2} {#3}}
3227 \endgroup
3228 \_@@_write_xml:e {
3229 <ram:SpecifiedLineTradeAgreement>
3230 \_@@_write_inline_wrapped_i:nnv
3231 {ram:BuyerOrderReferencedDocument} {ram:LineID} {l_@@_BT-132_tl}
3232 }
3233 \int_gincr:N \g_@@_indent_int%
3234 \_@@_write_xml:e {\_@@_ProductTradePrice:nn {net} {#4}}
3235 \int_gdecr:N \g_@@_indent_int%
3236 \_@@_write_xml:n {</ram:SpecifiedLineTradeAgreement>}
3237 \_@@_write_xml:e {%
3238 \_@@_SpecifiedLineTradeDelivery:nn { \l_@@_unit_code_tl } {#5}%
3239 }%
3240 \_@@_write_SpecifiedLineTradeSettlement:Vnn \l_@@_tax_category_code_tl %
3241 { \fp_use:N \l_@@_tax_rate_fp} {#6}%
3242 \int_gdecr:N \g_@@_indent_int%
3243 \_@@_write_xml:n {</ram:IncludedSupplyChainTradeLineItem>}
3244 }
3245 % \end{macrocode}
3246 % \end{macro}
3247 % \end{implementation}
3248 % \begin{implementation}
3249 % ApplicableHeaderTradeSettlement
3250 % \begin{macro}{\_@@_SpecifiedTradeSettlementHeaderMonetarySummation:nnnnnnnn}
3251 % \begin{macrocode}
3252 \_@@_define_xml_writer:Nn \_@@_SpecifiedTradeSettlementHeaderMonetarySummation:nnnnnnnn {%
3253 \_@@_write_xml:n {<ram:SpecifiedTradeSettlementHeaderMonetarySummation>}%
3254 \int_gincr:N \g_@@_indent_int%
3255 \bool_if:NF \g_@@_minimum_bool {
3256 \_@@_write_rounded:nnn {2} {LineTotalAmount} {#1}
3257 \_@@_write_rounded:nnn {2} {ChargeTotalAmount} {#2}
3258 \_@@_write_rounded:nnn {2} {AllowanceTotalAmount} {#3}
3259 }
3260 \_@@_write_rounded:nnn {2} {TaxBasisTotalAmount} {#4}
3261 \_@@_write_rounded:nnnn {2} {TaxTotalAmount}
3262 {~currencyID="\l_@@_currency_tl "} {#5}
3263 \_@@_write_rounded:nnn {2} {GrandTotalAmount} {#6}
3264 \bool_if:NF \g_@@_minimum_bool {
3265 \_@@_write_rounded:nnn {2} {TotalPrepaidAmount} {#7}
3266 }
3267 \_@@_write_rounded:nnn {2} {DuePayableAmount} {#8}
3268 \int_gdecr:N \g_@@_indent_int%
3269 \_@@_write_xml:n {</ram:SpecifiedTradeSettlementHeaderMonetarySummation>}%
3270 }%
3271 % \end{macrocode}
3272 % \end{macro}
3273 % \begin{macro}{\_@@_ApplicableTradeTax:nnnn}
3274 % \begin{macrocode}
3275 % ApplicableTradeTax CategoryCode Rate BaseAmount Result
3276 \_@@_define_xml_writer:Nn \_@@_ApplicableTradeTax:nnnn {%
3277 \_@@_write_xml:n {<ram:ApplicableTradeTax>}
3278 \int_gincr:N \g_@@_indent_int%
3279 \_@@_write_rounded:nnn {2} {CalculatedAmount} {#4}%BT117
3280 \_@@_write_xml:n {<ram:TypeCode>VAT</ram:TypeCode>}%BT118
3281 % \end{macrocode}
3282 % \changes{v0.9c}{2024-12-08}{Call exemption-reason-auto also locally inside ApplicableTradeTaxEntry}
3283 % \begin{macrocode}%
3284 \begingroup
3285 \bool_if:NT \g_@@_auto_exemption_bool {%
3286 \keys_set:nn { zugferd / tax } {exemption-reason-auto=#1}
3287 }%
3288 \tl_if_blank:VF \l_@@_tax_exemption_reason_tl {%BT-120
3289 \_@@_write_xml:e {<ram:ExemptionReason>
3290 \l_@@_tax_exemption_reason_tl
3291 </ram:ExemptionReason>}
3292 }
3293 {{\_@@_write_rounded:nnn {2} {BasisAmount} {#3}}}%BT-116
3294 \_@@_write_xml:e {<ram:CategoryCode>#1</ram:CategoryCode>}%BT-118
3295 % \end{macrocode}
3296 % \changes{v0.9c}{2024-12-08}{Don't use exemption-reason-code if format=BASIC \issue{28}}
3297 % \begin{macrocode}
3298 \bool_lazy_or:nnF% BT121
3299 {\tl_if_blank_p:V \l_@@_tax_exemption_code_tl}%
3300 {\str_if_eq_p:Vn \g_@@_conformance_level_str {BASIC}}%
3301 {%
3302 \_@@_write_xml:e {%
3303 <ram:ExemptionReasonCode>\l_@@_tax_exemption_code_tl</ram:ExemptionReasonCode>%
3304 }%
3305 }%
3306 \endgroup
3307 \_@@_write_xml:n {<ram:RateApplicablePercent>#2</ram:RateApplicablePercent>}%BT-119
3308 \int_gdecr:N \g_@@_indent_int%
3309 \_@@_write_xml:n {</ram:ApplicableTradeTax>}
3310 }%
3311 % \end{macrocode}
3312 % \end{macro}
3313 % ApplicableHeaderTradeSettlement needs to be splitted to be used in separate parts of the tabular.
3314 % \begin{macro}{\_@@_ApplicableHeaderTradeSettlement_start:,\_@@_ApplicableHeaderTradeSettlement_stop:}
3315 % \begin{macrocode}
3316 \_@@_define_xml_writer:Nn \_@@_ApplicableHeaderTradeSettlement_start: {
3317 \_@@_write_xml:n {<ram:ApplicableHeaderTradeSettlement>}
3318 \int_gincr:N \g_@@_indent_int
3319 \_@@_write_xml:e {
3320 \_@@_write_inline:ne {ram:InvoiceCurrencyCode} {\l_@@_currency_tl}
3321 }
3322 }
3323 \_@@_define_xml_writer:Nn \_@@_ApplicableHeaderTradeSettlement_stop: {
3324 \_@@_write_optional_wrapped:nnn {ReceivableSpecifiedTradeAccountingAccount} {ID} {BT-19}% BT-19
3325 \int_gdecr:N \g_@@_indent_int
3326 \_@@_write_xml:n {</ram:ApplicableHeaderTradeSettlement>}
3327 }
3328 % \end{macrocode}
3329 % \end{macro}
3330 % \changes{v0.10}{2025-09-08}{Add support for document level allowances and charges as requested by \issue{55}.}
3331 % SpecifiedTradeAllowanceCharge
3332 % \begin{macrocode}
3333 \seq_new:N \g_@@_AllowanceCharge_seq
3334 \seq_new:N \l_@@_AllowanceCharge_seq
3335 \clist_map_inline:nn {
3336 Indicator,
3337 CalculationPercent,
3338 BasisAmount,
3339 ActualAmount,
3340 ReasonCode,
3341 Reason,
3342 tax/category,
3343 tax/rate,
3344 } {
3345 \keys_define:nn {zugferd/allowance-charge} {
3346 #1 .code:n = \prop_put:Nnn \l_@@_AllowanceCharge_prop {#1} {##1}
3347 }
3348 }
3349
3350 \_@@_define_xml_writer:Nn \_@@_SpecifiedTradeAllowanceCharge: {
3351 \seq_map_inline:Nn \g_@@_AllowanceCharge_seq {
3352 \_@@_SpecifiedTradeAllowanceCharge:n {##1}
3353 }
3354 }
3355
3356 \_@@_define_xml_writer:Nn \_@@_SpecifiedTradeAllowanceCharge:n {
3357 \prop_clear_new:N \l_@@_AllowanceCharge_prop
3358 \keys_set:nn {zugferd/allowance-charge} {#1}
3359 \_@@_write_xml:n {<ram:SpecifiedTradeAllowanceCharge>}
3360 \int_gincr:N \g_@@_indent_int
3361 \_@@_write_prop_wrapped:Nnnn \l_@@_AllowanceCharge_prop
3362 {ram:ChargeIndicator} {udt:Indicator} {Indicator}
3363 \clist_map_inline:nn {
3364 CalculationPercent,% BT-101/BT-94
3365 BasisAmount,% BT-100/BT-93
3366 ActualAmount,% BT-99/BT-92
3367 ReasonCode,% BT-105/BT-98
3368 Reason% BT-104/BT-97
3369 } {
3370 \_@@_write_prop:Nn \l_@@_AllowanceCharge_prop {##1}
3371 }
3372 % TODO: maybe switch to only activate optional part if per-item?
3373 \prop_if_in:NnT \l_@@_AllowanceCharge_prop {tax/category} {%
3374 \_@@_write_xml:e {<ram:CategoryTradeTax>\iow_newline:%
3375 \_@@_xml_auto_indent:n {+1}%
3376 %<!-- BT-95/BT-102 -->%
3377 <ram:TypeCode>VAT</ram:TypeCode>%
3378 }%
3379 \int_incr:N \g_@@_indent_int%
3380 % TODO fall back to default VAT if unset?%
3381 %<!-- BT-95/BT-102 -->%
3382 \_@@_write_prop:Nnn \l_@@_AllowanceCharge_prop%
3383 {CategoryCode} {tax/category}%
3384 %<!-- BT-96/BT-103 -->%
3385 \_@@_write_prop:Nnn \l_@@_AllowanceCharge_prop%
3386 {RateApplicablePercent} {tax/rate}%
3387 \int_gdecr:N \g_@@_indent_int%
3388 \_@@_write_xml:n {</ram:CategoryTradeTax>}%
3389 }%
3390 \int_gdecr:N \g_@@_indent_int
3391 \_@@_write_xml:n {</ram:SpecifiedTradeAllowanceCharge>}
3392 }
3393 % \end{macrocode}
3394 % SpecifiedTradePaymentTerms
3395 % \begin{macrocode}
3396 \cctab_begin:N \g_@@_xml_cctab%
3397 \_@@_define_xml_writer:Nn \_@@_SpecifiedTradePaymentTerms:nn {%
3398 \_@@_write_xml:e {\_@@_BillingSpecifiedPeriod:VV \g_@@_start_date_tl \g_@@_end_date_tl}%
3399 \_@@_write_xml:n {<ram:SpecifiedTradePaymentTerms>}%
3400 \int_gincr:N \g_@@_indent_int%
3401 \_@@_write_xml:e {%
3402 \tl_if_blank:nF {#1} {%
3403 <ram:Description>#1</ram:Description>%
3404 }%
3405 \tl_if_blank:nF {#2} {
3406 \_@@_xml_date:nnn {0} {DueDate} {#2}%
3407 }%
3408 }%
3409 \int_gdecr:N \g_@@_indent_int%
3410 \_@@_write_xml:n {</ram:SpecifiedTradePaymentTerms>}%
3411 }%
3412 % \end{macrocode}
3413 % sums
3414 % \begin{macrocode}
3415 \_@@_define_xml_writer:Nn%
3416 \_@@_SpecifiedTradeSettlementPaymentMeans:nnn%
3417 {%
3418 \bool_if:NT \g_@@_writePaymentMeans_bool {%
3419 \_@@_write_xml:n {<ram:SpecifiedTradeSettlementPaymentMeans>}%
3420 \int_gincr:N \g_@@_indent_int%
3421 \_@@_write_xml:e {%
3422 <ram:TypeCode>\g_@@_payment_means_tl</ram:TypeCode>%
3423 \str_if_eq:VnT \g_@@_conformance_level_str {XRECHNUNG} {%
3424 \_@@_write_inline:ne {ram:Information} {%
3425 \prop_item:cV {g_@@_payment-means_names_prop} \g_@@_payment_means_tl%
3426 }%
3427 }%
3428 \tl_if_blank:nF {#1#2} {
3429 <ram:PayeePartyCreditorFinancialAccount>%
3430 \_@@_write_inline_i:nn {ram:IBANID} {#2}%
3431 \str_if_eq:VnT \g_@@_conformance_level_str {XRECHNUNG} {%
3432 \_@@_write_inline_i:nn {ram:AccountName} {#1}
3433 }%
3434 </ram:PayeePartyCreditorFinancialAccount>%
3435 }%
3436 \str_if_eq:VnT \g_@@_conformance_level_str {XRECHNUNG} {%
3437 \tl_if_blank:nF {#3} {%
3438 <ram:PayeeSpecifiedCreditorFinancialInstitution>%
3439 \_@@_write_inline_i:nn {ram:BICID} {#3}
3440 </ram:PayeeSpecifiedCreditorFinancialInstitution>%
3441 }%
3442 }%
3443 }%
3444 \int_gdecr:N \g_@@_indent_int%
3445 \_@@_write_xml:n {</ram:SpecifiedTradeSettlementPaymentMeans>}%
3446 }%
3447 }%
3448 \cctab_end:
3449 \cs_generate_variant:Nn \_@@_SpecifiedTradePaymentTerms:nn {VV}
3450 \_@@_define_xml_writer:Nn \_@@_SpecifiedTradePaymentTerms: {
3451 \bool_if:NF \g_@@_minimum_bool {
3452 \_@@_SpecifiedTradePaymentTerms:VV
3453 \g_@@_payment_terms_str \g_@@_due_date_tl
3454 }
3455 }
3456 % \end{macrocode}
3457 % \begin{function}{\_@@_SpecifiedTradeSettlementPaymentMeans:}
3458 % \begin{macrocode}
3459 \cs_generate_variant:Nn \_@@_SpecifiedTradeSettlementPaymentMeans:nnn {vvv}
3460 \_@@_define_xml_writer:Nn \_@@_SpecifiedTradeSettlementPaymentMeans: {
3461 \tl_if_blank:VF \g_@@_payment_means_tl {
3462 \_@@_SpecifiedTradeSettlementPaymentMeans:vvv
3463 {g_@@_payment_account-holder_tl}
3464 {g_@@_payment_iban_tl} {g_@@_payment_bic_tl}
3465 }
3466 }
3467 % \end{macrocode}
3468 % \end{function}
3469 % \end{implementation}
3470 % \begin{implementation}
3471 % \begin{macrocode}
3472 \msg_new:nnn {zugferd} {macro-deprecated} {
3473 The~function~#1~is~deprecated.\\
3474 It~was~replaced~by~#2.\\
3475 Please~adjust~your~mechanism~to~use~the~new~version.
3476 }
3477 % \end{macrocode}
3478 % \end{implementation}
3479 % \iffalse
3480 % \begin{macrocode}
3481 %</package>
3482 % \end{macrocode}
3483 % \fi
3484 % \Finale
3485 \endinput