%%
%% This is file `zugferd.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% zugferd.dtx  (with options: `package')
%% 
%% Copyright (C) 2023--2024 by Marei Peischl (peiTeX) <marei@peitex.de>
%% 
\NeedsTeXFormat{LaTeX2e}[2023-11-01]
\ProvidesExplPackage{zugferd}{2024-11-07}{0.9a}{Create ZUGFerd invoices using LaTeX}
\tl_new:N \l__zugferd_tmp_tl
\str_new:N \g__zugferd_format_str
\str_new:N \g__zugferd_businessProcessId_str
\bool_new:N \g__zugferd_writeTradeContact_bool
\bool_new:N \g__zugferd_writePaymentMeans_bool
\bool_new:N \g__zugferd_minimum_bool
\str_new:N \g__zugferd_conformance_level_str
\char_set_catcode_other:N \#%
\keys_define:nn {zugferd} {
xrechnung .code:n = {
\bool_gset_true:N \g__zugferd_writeTradeContact_bool
\bool_gset_true:N \g__zugferd_writePaymentMeans_bool
\str_gset:Nn \g__zugferd_conformance_level_str {XRECHNUNG}
},
format .choice:,
format / xrechnung3.0 .code:n = {
\str_gset:Nx \g__zugferd_format_str {
urn:cen.eu:en16931:2017#compliant#urn:xeinkauf.de:kosit:xrechnung_3.0
}
\str_gset:Nx \g__zugferd_businessProcessId_str {
urn:fdc:peppol.eu:2017:poacc:billing:01:1.0
}
\keys_set:nn {zugferd}{xrechnung}
},
format / xrechnung2.3 .code:n = {
\str_gset:Nx \g__zugferd_format_str {
urn:cen.eu:en16931:2017#compliant#urn:xoev-de:kosit:standard:xrechnung_2.3
}
\keys_set:nn {zugferd}{xrechnung}
},
format  / basic .code:n = {
\str_gset:Nx \g__zugferd_format_str {
urn:cen.eu:en16931:2017#compliant#urn:factur-x.eu:1p0:basic
}
\bool_gset_false:N \g__zugferd_writeTradeContact_bool
\bool_gset_false:N \g__zugferd_writePaymentMeans_bool
\str_gset:Nn \g__zugferd_conformance_level_str {BASIC}
},
format  / minimum .code:n = {
\str_gset:Nx \g__zugferd_format_str {
urn:factur-x.eu:1p0:minimum
}
\bool_gset_true:N \g__zugferd_minimum_bool
\bool_gset_false:N \g__zugferd_writeTradeContact_bool
\bool_gset_false:N \g__zugferd_writePaymentMeans_bool
\str_gset:Nn \g__zugferd_conformance_level_str {MINIMUM}
},
format / xrechnung .meta:n = { format = xrechnung3.0 },
format .initial:n = xrechnung,
format .usage:n = load,
write-xml .bool_gset:N = \g__zugferd_write_xml_bool,
write-xml .initial:n = true,
write-xml .usage:n = load,
zugferd .bool_gset:N = \g__zugferd_active_bool,
zugferd .initial:n = true,
zugferd .default:n = true,
zugferd .usage:n = load,
ZUGFerD .meta:n = {zugferd = #1},
xml-file .tl_gset:N = \g__zugferd_xml_file_tl,
xml-file .initial:n = \jobname _zugferd.xml,
xml-file .usage:n = load,
auto-exemption .bool_gset:N = \g__zugferd_auto_exemption_bool,
auto-exemption .initial:n = true,
auto-exemption .default:n = true,
auto-exemption .usage:n =load,
}
\char_set_catcode_parameter:N \#%

\ProcessKeyOptions[zugferd]
\iow_new:N \__zugferd_xml_writer_iow
\bool_if:NT \g__zugferd_active_bool {
\cs_if_exist:NF \pdfmeta_xmp_xmlns_new:nn {
\msg_new:nnnn {zugferd} {PDFmanagement-not-active} {
The~\LaTeX~PDF~management~is~not~active.\\
Activate~it~using~\string\DocumentMetadata.
} {
See~ZUGFeRD~or~PDFmanagement~documentation~for~more~information.
}
\msg_error:nn {zugferd} {PDFmanagement-not-active}
}
\IfPackageAtLeastF{pdfmanagement-testphase}{2024/09/13}{
\msg_new:nnn {zugferd} {PDFmanagement-too-old} {
Your~version~of~\LaTeX's~PDF~management~is~too~old.
You~need~to~update~your~LaTeX~distribution~to~be~able~to~use~the~zugferd~package~correctly.
}
\msg_error:nn{zugferd} {PDFmanagement-too-old}
}
%% based on experiments for l3pdfmeta by Ulrike Fischer
\pdfmeta_xmp_xmlns_new:nn {fx}{
urn:factur-x:pdfa:CrossIndustryDocument:invoice:1p0\c_hash_str
}

\pdfmeta_xmp_schema_new:nnn
  {Factur-X~PDFA~Extension~Schema}
  {fx}
  {urn:factur-x:pdfa:CrossIndustryDocument:invoice:1p0\c_hash_str}

\pdfmeta_xmp_property_new:nnnnn
  {fx}
  {DocumentFileName}
  {Text}
  {external}
  {name~of~the~embedded~XML~invoice~file}

\pdfmeta_xmp_property_new:nnnnn
  {fx}
  {DocumentType}
  {Text}
  {external}
  {INVOICE}

\pdfmeta_xmp_property_new:nnnnn
  {fx}
  {Version}
  {Text}
  {external}
  {The~actual~version~of~the~factur-x~schema}

\pdfmeta_xmp_property_new:nnnnn
  {fx}
  {ConformanceLevel}
  {Text}
  {external}
  {The~conformance~level~of~the~factur-x~data}

\exp_args:Ne \pdfmeta_xmp_add:n {
<fx:DocumentType>INVOICE</fx:DocumentType>\iow_newline:
<fx:DocumentFileName>factur-x.xml</fx:DocumentFileName>\iow_newline:
<fx:Version>1.0</fx:Version>\iow_newline:
<fx:ConformanceLevel>\g__zugferd_conformance_level_str</fx:ConformanceLevel>%
\iow_newline:
}
}
\NewDocumentCommand{\SetZUGFeRDData}{sm}{
\IfBooleanTF{#1}
{\keys_set:ne}
{\keys_set:nn}
{zugferd} {#2}
}
\let\SetZugferdData\SetZUGFeRDData
\NewDocumentCommand{\InsertZUGFeRDData}{om}{
\str_case:nnF {#1} {
{AddressData} {
\clist_map_inline:nn {name, lineone, linetwo} {
\prop_if_in:cnT {g__zugferd_#2_AddressData_prop } {##1} {
\prop_item:cn {g__zugferd_#2_AddressData_prop } {##1}\\
}
}
\prop_item:cn {g__zugferd_#2_AddressData_prop } {postcode}
\space
\prop_item:cn {g__zugferd_#2_AddressData_prop } {city}
}
{set-today} {
\__zugferd_set_today:v {g__zugferd_#2_tl}
}
} {
\str_set:Ne \l_tmpa_str {#2}
\str_replace_all:Nnn \l_tmpa_str {-} {_}
\str_replace_all:Nnn \l_tmpa_str {/} {_}
\bool_set_true:N \g_tmpa_bool
\clist_map_inline:nn {tl, str} {
\clist_map_inline:nn {g, l} {
\use:c {##1 _if_exist:cT} {####1__zugferd_ \l_tmpa_str _##1}
{
\use:c {####1__zugferd_ \l_tmpa_str _##1}
\bool_gset_false:N \g_tmpa_bool
}
\bool_if:NF \g_tmpa_bool {\clist_map_break:}
}
\bool_if:NF \g_tmpa_bool {\clist_map_break:}
}
}
}
\providecommand{\InsertZugferdData}{\InsertZUGFeRDData}
\providecommand{\insertZugferdData}{\InsertZUGFeRDData}
\cs_new:Nn \__zugferd_set_today:n {
\__zugferd_set_today_aux:w #1 \q_stop
}
\cs_generate_variant:Nn \__zugferd_set_today:n {v}
\cs_new:Npn \__zugferd_set_today_aux:w #1 #2 #3 #4 #5 #6 #7 #8 \q_stop{
\int_set:Nn \year {#1#2#3#4}
\int_set:Nn \month {#5#6}
\int_set:Nn \day {#7#8}
}
\NewDocumentEnvironment{ZUGFeRD}{o}{
\IfNoValueF{#1}{
\SetZUGFeRDData{#1}
}
\zugferd_enable_XML_interfaces:
\startWritingZUGFeRDxml
\zugferd_write_Header:
\ignorespaces
}{
\zugferd_enable_XML_interfaces:
\zugferd_write_Footer:
\stopWritingZUGFeRDxml
\zugferd_disable_XML_interfaces:
}
\newcommand*{\startWritingZUGFeRDxml}{
\begingroup
\bool_if:NTF \g__zugferd_write_xml_bool {
\char_set_active_eq:nN {13} \__zugferd_xml_newline_indent:
\iow_open:Nn \__zugferd_xml_writer_iow {\g__zugferd_xml_file_tl}
}{
\msg_info:nn {zugferd} {no-xml-write}
}
}
\msg_new:nnn {zugferd} {no-xml-write} {
The~option~write-xml=false~was~set.\\
Writing~of~XML~file~is~deactivated.
}
%% The metadata elements are taken by Ulrike Fischer's faktur-x experiments
%% https://github.com/latex3/pdfresources/tree/main/experiments/factur-x-bills
\newcommand*{\stopWritingZUGFeRDxml}{%
\bool_if:NT \g__zugferd_write_xml_bool
{\iow_close:N \__zugferd_xml_writer_iow}%
\endgroup
\bool_if:NT \g__zugferd_active_bool {
\group_begin:
\pdfdict_put:nnn {l_pdffile/Filespec} {AFRelationship}{/Alternative}
\pdfdict_put:nnn {l_pdffile/Filespec} {Desc}{(Factur-X/ZUGFeRD-Rechnung)}
\pdffile_embed_file:nnn {\g__zugferd_xml_file_tl}{factur-x.xml}
{zugferd/rechnung}
\group_end:
\pdfmanagement_add:nnx
{Catalog/Names}
{EmbeddedFiles}
{\pdf_object_ref:n{zugferd/rechnung}}
\pdfmanagement_add:nnx{Catalog}{AF}{\pdf_object_ref:n{zugferd/rechnung}}
}
}
%% Code using the data for visual representation
\cs_new:Nn \zugferd_enable_XML_interfaces: {
\bool_if:NT \g__zugferd_write_xml_bool {
\cs_gset:Nn \zugferd_write_Header: {
\__zugferd_insert_Header:
\__zugferd_insert_FrontMatter:
}
\cs_gset:Nn \zugferd_write_Footer: {
\__zugferd_insert_Footer:
}
\bool_if:NTF \g__zugferd_minimum_bool {
\cs_gset_eq:NN \zugferd_write_Item:nnnnnn \use_none:nnnnnn
}{
\cs_gset_eq:NN \zugferd_write_Item:nnnnnn
\__zugferd_insert_TradeLineItem:nnnnnn
}
\cs_gset:Nn \zugferd_startInvoiceSums: {
\__zugferd_ApplicableHeaderTradeAgreement:
\__zugferd_ApplicableHeaderTradeSettlement_start:
\__zugferd_SpecifiedTradeSettlementPaymentMeans:
}
\cs_gset:Nn \zugferd_stopInvoiceSums:  {
\__zugferd_ApplicableHeaderTradeSettlement_stop:
}
\bool_if:NTF \g__zugferd_minimum_bool {
\cs_gset_eq:NN \zugferd_write_TaxEntry:nnnn  \use_none:nnnn
} {
\cs_gset_eq:NN \zugferd_write_TaxEntry:nnnn \__zugferd_ApplicableTradeTax:nnnn
}
\cs_gset:Nn \zugferd_write_Summation:nnnnnnnn {
\__zugferd_SpecifiedTradePaymentTerms:
\__zugferd_SpecifiedTradeSettlementHeaderMonetarySummation:nnnnnnnn
{##1} {##2} {##3} {##4} {##5} {##6} {##7} {##8}
}
}
}
\cs_new:Nn \zugferd_disable_XML_interfaces: {
\cs_gset_eq:NN \zugferd_write_Header: \prg_do_nothing:
\cs_gset_eq:NN \zugferd_write_Footer: \prg_do_nothing:
\cs_gset_eq:NN \zugferd_write_Item:nnnnnn \use_none:nnnnnn
\cs_gset_eq:NN \zugferd_startInvoiceSums: \prg_do_nothing:
\cs_gset_eq:NN \zugferd_stopInvoiceSums: \prg_do_nothing:
\cs_gset_eq:NN \zugferd_write_TaxEntry:nnnn \use_none:nnnn
\cs_gset_eq:NN \zugferd_write_Summation:nnnnnnnn \use_none:nnnnnnnn
}
\bool_if:NTF \g__zugferd_write_xml_bool {
\zugferd_enable_XML_interfaces:
}{
\zugferd_disable_XML_interfaces:
}
\cs_new:Nn \zugferd_write_Item:nnnnnnn {
\group_begin:
\keys_set:nn {zugferd/item} {#1}
\zugferd_write_Item:nnnnnn {#2} {#3} {#4} {#5} {#6} {#7}
\group_end:
}
\cs_generate_variant:Nn \zugferd_write_Item:nnnnnnn {ennnnnn}
\bool_if:NTF \g__zugferd_write_xml_bool {
\cs_new:Nn \__zugferd_write_xml:n {
\iow_now:Ne \__zugferd_xml_writer_iow {\__zugferd_xml_auto_indent: #1}
}
\cs_new_eq:NN \__zugferd_define_xml_writer:Nn \cs_new:Nn
\cs_new_eq:NN \__zugferd_define_xml_content:Nn \cs_new:Nn
} {
\cs_set_eq:NN \__zugferd_write_xml:n \use_none:n
\cs_set:Nn \__zugferd_define_xml_writer:Nn {\cs_new:Nn #1 {}}
\cs_set:Nn \__zugferd_define_xml_content:Nn {\cs_new:Nn #1 {}}
}

\cs_generate_variant:Nn \__zugferd_write_xml:n {e}
\RequirePackage{siunitx}
\cs_new:Nn \__zugferd_number_format:nNn {
\sisetup{
parse-numbers=true,
round-mode=places,
round-precision=#1,
round-pad = false,
group-digits=false,
minimum-decimal-digits=#1,
output-decimal-marker=.
}
\siunitx_number_format:nN {#3} #2
}
\cs_generate_variant:Nn \__zugferd_number_format:nNn {nNe}
\cs_new:Nn \__zugferd_write_rounded:nnnn {
\__zugferd_number_format:nNe {#1} \l__zugferd_tmp_tl {#4}
\__zugferd_write_xml:e {<ram:#2#3>\l__zugferd_tmp_tl</ram:#2>}
}
\cs_new:Nn \__zugferd_write_rounded:nnn {
\__zugferd_write_rounded:nnnn {#1} {#2} {} {#3}
}
\int_new:N \g__zugferd_indent_int
\cs_new:Nn \__zugferd_indent: {
\space\space
}
\cs_new:Nn \__zugferd_indent:n {
\prg_replicate:nn {#1} {\__zugferd_indent:}
}
\cs_new:Nn \__zugferd_xml_auto_indent: {
\__zugferd_indent:n {\g__zugferd_indent_int}
}
\cs_new:Nn \__zugferd_xml_newline_indent: {
\iow_newline: \__zugferd_xml_auto_indent:
}
\cctab_new:N \g__zugferd_xml_cctab
\begingroup%
\endlinechar=13%
\char_set_catcode:nn {13}{13}%
\cctab_gsave_current:N \g__zugferd_xml_cctab%
\endgroup
%% modified list taken from hyperref.sty v7.01i
%% Copyright
%% 1995-2001 Sebastian Rahtz, with portions written by David Carlisle and Heiko Oberdiek
%% 2001-2015 Heiko Oberdiek
%% 2016-2019 Oberdiek Package Support Group
%% 2019-2024 LaTeX Project
%% modifications have been made to support the mechanism if hyperref is not loaded
\cs_new:Nn \zugferd_disable_macros: {
\let\{\textbraceleft
\let\}\textbraceright
\let\\\textbackslash
\let\#\textnumbersign
\let\$\textdollar
\let\%\textpercent
\let\&\textampersand
\let\_\textunderscore
\let\P\textparagraph
\let\ldots\textellipsis
\let\dots\textellipsis
\def\\{\space}%
\def\newline{\space}%
\def\TeX{TeX}%
\def\LaTeX{La\TeX}%
\def\LaTeXe{\LaTeX2e}%
\def\eTeX{e-\TeX}%
\def\SliTeX{Sli\TeX}%
\def\MF{Metafont}%
\def\MP{Metapost}%
\let\fontencoding\@gobble
\let\fontfamily\@gobble
\let\fontseries\@gobble
\let\fontshape\@gobble
\let\fontsize\@gobbletwo
\let\selectfont\@empty
\let\usefont\@gobblefour
\let\emph\@firstofone
\let\textnormal\@firstofone
\let\textrm\@firstofone
\let\textsf\@firstofone
\let\texttt\@firstofone
\let\textbf\@firstofone
\let\textmd\@firstofone
\let\textit\@firstofone
\let\textsc\@firstofone
\let\textsl\@firstofone
\let\textup\@firstofone
\let\normalfont\@empty
\let\rmfamily\@empty
\let\sffamily\@empty
\let\ttfamily\@empty
\let\bfseries\@empty
\let\mdseries\@empty
\let\itshape\@empty
\let\scshape\@empty
\let\slshape\@empty
\let\upshape\@empty
\let\em\@empty
\let\rm\@empty
\let\Huge\@empty
\let\LARGE\@empty
\let\Large\@empty
\let\footnotesize\@empty
\let\huge\@empty
\let\large\@empty
\let\normalsize\@empty
\let\scriptsize\@empty
\let\small\@empty
\let\tiny\@empty
\let\mathversion\@gobble
\let\phantom\@gobble
\let\vphantom\@gobble
\let\hphantom\@gobble
\let\ding\HyPsd@ding
\let\Cube\HyPsd@DieFace
\def\begin##1{\csname##1\endcsname}%
\def\end##1{\csname end##1\endcsname}%
\def\textcolor##1##{\@secondoftwo}%
\def\TextOrMath{\ifmmode\expandafter\@secondoftwo\else\expandafter\@firstoftwo\fi}%
\let\foreignlanguage\@secondoftwo
\let\textlatin\@firstofone
\let\cyr\relax
\let\glqq\textglqq
\let\grqq\textgrqq
\let\glq\textglq
\let\grq\textgrq
\let\flqq\textflqq
\let\frqq\textfrqq
\let\flq\textflq
\let\frq\textfrq
\let\if@mid@expandable\@firstoftwo
\let\hspace\@gobble
\let\label\@gobble
\let\index\@gobble
\let\glossary\@gobble
\let\@mkboth\@gobbletwo
\let\leavevmode\@empty
\let\mbox\@empty
\def\halign{\@gobble}%
\let\Hy@SectionAnchorHref\@gobble
\let\ref\@gobble
\let\href\@gobble
\let\pageref\@gobble
\let\nameref\@gobble
\let\autoref\@gobble
\let\ignorespaces\relax
\let\ensuremath\@firstofone
\def\ {\space\relax}% space
\exp_args:NV \cs_set_nopar:cpn \c_space_tl {\space}
\let\nobreakspace\space
\hook_use:n {zugferd/disable-macros}
}
\hook_new:n {zugferd/disable-macros}
\cs_set:Nn \zugferd_fp_set_rounded:Nn {
\__zugferd_number_format:nNn {2} \l__zugferd_tmp_tl {\fp_eval:n {#2}}
\fp_set:Nn  #1 {\l__zugferd_tmp_tl }
}
\cs_set:Nn \zugferd_fp_gset_rounded:Nn {
\__zugferd_number_format:nNn {2} \l__zugferd_tmp_tl {\fp_eval:n {#2}}
\fp_gset:Nn  #1 {\l__zugferd_tmp_tl }
}
\seq_new:N \g__zugferd_notes_seq
\tl_new:N \g__zugferd_id_tl
\tl_new:N \g__zugferd_date_tl
\tl_new:N \g__zugferd_delivery_date_tl
\tl_new:N \g__zugferd_subject_tl
\tl_new:N \g__zugferd_fromaddress_tl
\tl_new:N \g__zugferd_DocumentTypeCode_tl
\tl_new:N \l__zugferd_currency_tl
\keys_define:nn { zugferd } {
document-type .choice:,
document-type / commercial-invoice .code:n =
\tl_gset:Nn \g__zugferd_DocumentTypeCode_tl {380},
document-type .initial:n = commercial-invoice,
id .choice:,
id / komavar .code:n = \tl_gset:Nf \g__zugferd_id_tl {\scr@invoice@var},
id / unknown .code:n = \tl_gset:Nn \g__zugferd_id_tl {#1},
currency .choices:nn = {EUR, USD, CHF} {
\tl_set_eq:NN \l__zugferd_currency_tl \l_keys_choice_tl
},
currency / € .meta:n = {currency = EUR},
currency / unknown .code:n = {
\exp_args:Nnnx \keys_if_choice_exist:nnnTF {zugferd} {unit} {
\str_uppercase:f {#1}
}
{\keys_set:nx { zugferd } {unit= {\str_uppercase:f {#1}}}}
{
\msg_warning:nnn { zugferd } {unknown-value} {currency} {#1}
\tl_set:Ne \l__zugferd_currency_tl {\str_uppercase:f {#1}}
}
},
currency .initial:n = EUR,
date .choice:,
date / auto .code:n = \tl_gset:Ne \g__zugferd_date_tl {
\the\year
\int_compare:nNnT {\month} < {10} {0} \the\month
\int_compare:nNnT {\day} < {10} {0}\the\day
},
date / unknown .code:n = \tl_gset:Nn \g__zugferd_date_tl {#1},
date .initial:n = auto,
delivery-date .choice:,
delivery-date / auto .code:n = \tl_gset:Ne \g__zugferd_delivery_date_tl {
\the\year
\int_compare:nNnT {\month} < {10} {0} \the\month
\int_compare:nNnT {\day} < {10} {0}\the\day
},
delivery-date / unknown .code:n = {
\tl_gset:Nn \g__zugferd_delivery_date_tl {#1}
},
delivery-date .initial:n = auto,
due-date .tl_gset:N = \g__zugferd_due_date_tl,
due-date .initial:n =,
payment-terms .str_gset:N = \g__zugferd_payment_terms_str,
payment-terms .initial:n =,
subject .choice:,
subject / komavar .code:n = {
\tl_gset:Nf \g__zugferd_subject_tl {\scr@subject@var}
},
subject / unknown .code:n  = \tl_gset:Nn \g__zugferd_subject_tl {#1},
fromaddress .choice:,
fromaddress / komavar .code:n = \tl_gset:Nf \g__zugferd_fromaddress_tl
{\scr@fromaddress@var},
fromaddress / unknown .code:n = \tl_gset:Nn \g__zugferd_fromaddress_tl {#1},
add-note .code:n = \seq_gput_right:Nn \g__zugferd_notes_seq {#1},
}
\msg_new:nnnn {zugferd} {unknown-value} {
You~selected~a~#1~which~was~not~predefined.\\
I~will~directly~use~your~selection~'#1=#2'.
Please~ensure~the~selection~is~valid!
} {
For~more~information~see~the~zugferd~documentation.
}
\cs_new:Nn \__zugferd_note_if_not_empty:N {%
\tl_if_empty:NF #1 {%
\__zugferd_write_note:n {#1}%
}%
}%
\clist_map_inline:nn {seller,buyer,shipto} {
\prop_new:c {g__zugferd_#1_AddressData_prop}
\keys_define:nn {zugferd / #1} {
address .code:n = {
\seq_set_split:Nnn \l_tmpa_seq {\\} {##1}
\keys_set:nx {zugferd / #1} {
lineone=\seq_item:Nn \l_tmpa_seq {1},
linetwo=\seq_item:Nn \l_tmpa_seq {2}
}
},
contact .code:n = {
\seq_set_split:Nnn \l_tmpa_seq {\\} {##1}
\int_compare:nNnTF {\seq_count:N \l_tmpa_seq} > {3} {
\keys_set:ne {zugferd/#1} {
contact-name = \seq_item:Nn \l_tmpa_seq {1},
contact-department = \seq_item:Nn \l_tmpa_seq {2},
contact-phone = \seq_item:Nn \l_tmpa_seq {3},
contact-email= \seq_item:Nn \l_tmpa_seq {4}
}
}{
\keys_set:ne {zugferd/#1} {
contact-name = \seq_item:Nn \l_tmpa_seq {1},
contact-phone = \seq_item:Nn \l_tmpa_seq {2},
contact-email= \seq_item:Nn \l_tmpa_seq {3}
}
}
},
unknown .code:n = \tl_if_blank:nF {##1} {
\prop_gput:cVe {g__zugferd_#1_AddressData_prop}
\l_keys_key_tl {\tl_trim_spaces:n {##1}}
}
}
}
\cs_new:Nn \__zugferd_PostalTradeAddress_short:N {
\exp_args:Ne \tl_if_blank:nF {\prop_item:Nn #1 {name}}
{<ram:Name>\prop_item:Nn #1 {name}</ram:Name>\iow_newline:\__zugferd_xml_auto_indent:}
\__zugferd_PostalTradeAddress:eeeee
{\prop_item:Nn #1 {postcode}}
{\prop_item:Nn #1 {lineone}}
{\prop_item:Nn #1 {linetwo}}
{\prop_item:Nn #1 {city}}
{\prop_item:Nn #1 {country}}
}
\cs_new:Nn \__zugferd_PostalTradeAddress:N {%
\__zugferd_PostalTradeAddress:eeeeeee
{\prop_item:Nn #1 {postcode}}
{\prop_item:Nn #1 {lineone}}
{\prop_item:Nn #1 {linetwo}}
{\prop_item:Nn #1 {city}}
{\prop_item:Nn #1 {country}}
{\prop_item:Nn #1 {email}}
{\prop_item:Nn #1 {vatid}}
}%
\cs_new:Nn \__zugferd_DefinedTradeContact:N {%
\__zugferd_DefinedTradeContact:eeee
{\prop_item:Nn #1 {contact-name}}
{\prop_item:Nn #1 {contact-department}}
{\prop_item:Nn #1 {contact-phone}}
{\prop_item:Nn #1 {contact-email}}
}%
\cctab_begin:N \g__zugferd_xml_cctab%
\__zugferd_define_xml_content:Nn \__zugferd_PostalTradeAddress:nnnnn {%
<ram:PostalTradeAddress>
\bool_if:NF \g__zugferd_minimum_bool {%
\__zugferd_indent: <ram:PostcodeCode>#1</ram:PostcodeCode>
\tl_if_blank:nF {#2} {%
\__zugferd_indent: <ram:LineOne>#2</ram:LineOne>
}%
\tl_if_blank:nF {#3} {%
\__zugferd_indent: <ram:LineTwo>#3</ram:LineTwo>
}%
\__zugferd_indent: <ram:CityName>#4</ram:CityName>
}%
\__zugferd_indent: <ram:CountryID>#5</ram:CountryID>
</ram:PostalTradeAddress>%
}
\__zugferd_define_xml_content:Nn \__zugferd_PostalTradeAddress:nnnnnnn {%
\__zugferd_PostalTradeAddress:nnnnn {#1} {#2} {#3} {#4} {#5}%
\bool_lazy_or:nnF {\g__zugferd_minimum_bool}%
{\tl_if_blank_p:n {#6}}%
{%
\__zugferd_xml_newline_indent:%
<ram:URIUniversalCommunication>
\__zugferd_indent: <ram:URIID~schemeID="EM">#6</ram:URIID>
</ram:URIUniversalCommunication>%
}%
\tl_if_empty:nF {#7} {
<ram:SpecifiedTaxRegistration>
\__zugferd_indent: <ram:ID~schemeID="VA">#7</ram:ID>
</ram:SpecifiedTaxRegistration>%
}%
}%
\__zugferd_define_xml_content:Nn \__zugferd_DefinedTradeContact:nnnn {%
\tl_if_blank:nT {#1} {\use_none:nnn} %
\bool_if:NT \g__zugferd_writeTradeContact_bool {%
<ram:DefinedTradeContact>
\__zugferd_indent: <ram:PersonName>#1</ram:PersonName>
\tl_if_blank:nF {#2} {%
\__zugferd_indent: <ram:DepartmentName>#2</ram:DepartmentName>
}%
\tl_if_blank:nF {#3} {%
\__zugferd_indent: <ram:TelephoneUniversalCommunication>
\__zugferd_indent:n {2} <ram:CompleteNumber>#3</ram:CompleteNumber>
\__zugferd_indent: </ram:TelephoneUniversalCommunication>
}%
\tl_if_blank:nF {#4} {%
\__zugferd_indent: <ram:EmailURIUniversalCommunication>
\__zugferd_indent:n {2} <ram:URIID>#4</ram:URIID>
\__zugferd_indent: </ram:EmailURIUniversalCommunication>
}%
</ram:DefinedTradeContact>%
}%
}%
\__zugferd_define_xml_writer:Nn \__zugferd_ApplicableHeaderTradeAgreement: {%
\__zugferd_write_xml:n {<ram:ApplicableHeaderTradeAgreement>}%
\int_gincr:N \g__zugferd_indent_int%
\bool_lazy_and:nnF%
{\tl_if_blank_p:V \g__zugferd_buyer_reference_tl}%
{\g__zugferd_minimum_bool}%
{%
\__zugferd_write_xml:e {%
<ram:BuyerReference>\g__zugferd_buyer_reference_tl</ram:BuyerReference>
}
}%
\__zugferd_write_xml:n {<ram:SellerTradeParty>}%
\int_gincr:N \g__zugferd_indent_int%
\__zugferd_write_xml:e {%
<ram:Name>\prop_item:Nn \g__zugferd_seller_AddressData_prop {name}</ram:Name>
\__zugferd_DefinedTradeContact:N \g__zugferd_seller_AddressData_prop%
\__zugferd_PostalTradeAddress:N \g__zugferd_seller_AddressData_prop%
}%
\int_gdecr:N \g__zugferd_indent_int%
\__zugferd_write_xml:e {%
</ram:SellerTradeParty>
<ram:BuyerTradeParty>%
}%
\int_gincr:N \g__zugferd_indent_int%
\__zugferd_write_xml:e {%
<ram:Name>\prop_item:Nn \g__zugferd_buyer_AddressData_prop {name}</ram:Name>%
\bool_if:NF \g__zugferd_minimum_bool {
\__zugferd_DefinedTradeContact:N \g__zugferd_buyer_AddressData_prop%
\__zugferd_PostalTradeAddress:N \g__zugferd_buyer_AddressData_prop%
}%
}%
\int_gdecr:N \g__zugferd_indent_int%
\__zugferd_write_xml:n {</ram:BuyerTradeParty>}%
\int_gdecr:N \g__zugferd_indent_int%
\__zugferd_write_xml:n {</ram:ApplicableHeaderTradeAgreement>}%
\bool_if:NTF \g__zugferd_minimum_bool%
{\__zugferd_write_xml:n {<ram:ApplicableHeaderTradeDelivery/>}}%
{\__zugferd_ApplicableHeaderTradeDelivery:V \g__zugferd_delivery_date_tl}%
}%
\__zugferd_define_xml_content:Nn \__zugferd_ApplicableHeaderTradeDelivery:n {%
\bool_lazy_and:nnF {\prop_if_empty_p:N \g__zugferd_shipto_AddressData_prop}%
{\tl_if_blank_p:n {#1}}%
{%
\__zugferd_write_xml:n {<ram:ApplicableHeaderTradeDelivery>}%
\prop_if_empty:NF \g__zugferd_shipto_AddressData_prop {%
\int_gincr:N \g__zugferd_indent_int%
\__zugferd_write_xml:n {<ram:ShipToTradeParty>}%
\int_gincr:N \g__zugferd_indent_int%
\__zugferd_write_xml:e {%
\__zugferd_PostalTradeAddress_short:N \g__zugferd_shipto_AddressData_prop%
}%
\int_gdecr:N \g__zugferd_indent_int%
\__zugferd_write_xml:n {</ram:ShipToTradeParty>}%
\int_gdecr:N \g__zugferd_indent_int%
}%
\tl_if_blank:nF {#1} {%
\__zugferd_write_xml:n {%
\__zugferd_indent: <ram:ActualDeliverySupplyChainEvent>
\__zugferd_indent:n {2} <ram:OccurrenceDateTime>
\__zugferd_indent:n {3}<udt:DateTimeString~format="102">#1</udt:DateTimeString>
\__zugferd_indent:n {2} </ram:OccurrenceDateTime>
\__zugferd_indent: </ram:ActualDeliverySupplyChainEvent>%
}%
}%
\__zugferd_write_xml:n {</ram:ApplicableHeaderTradeDelivery>}%
}%
}%
\cctab_end:
\cs_generate_variant:Nn \__zugferd_DefinedTradeContact:nnnn {eeee}
\cs_generate_variant:Nn \__zugferd_PostalTradeAddress:nnnnn {eeeee}%
\cs_generate_variant:Nn \__zugferd_PostalTradeAddress:nnnnnnn {eeeeeee}
\cs_generate_variant:Nn \__zugferd_ApplicableHeaderTradeDelivery:n {V}
\tl_new:N \g__zugferd_buyer_reference_tl
\keys_define:nn {zugferd/buyer} {
reference .choice:,
reference / komavar .code:n = {
\tl_gset:Nf \g__zugferd_buyer_reference_tl {\scr@yourref@var}
},
reference / unknown .code:n = {
\tl_gset:Nn \g__zugferd_buyer_reference_tl {#1}
}
}
\ExplSyntaxOff
\providecommand*{\zugferd@paymentMeans@german}{
 1 = Keine Zahlungsart definiert,
10 = Bargeld,
30 = Überweisung,
42 = Zahlung an Bankkonto,
48 = Kartenzahlung,
49 = Lastschriftverfahren,
57 = Dauerauftrag,
58 = Zahlung per SEPA Überweisung.,
59 = SEPA Lastschrift,
97 = Ausgleich zwischen Partnern
}
\def\zugferd@paymentMeans@ngerman{\zugferd@paymentMeans@german}
\providecommand*{\zugferd@paymentMeans@english}{
 1 = Instrument not defined,
10 = In cash,
30 = Credit Transfer,
31 = Debit Transfer,
42 = Payment to bank account,
48 = Bank card,
49 = Direct Debit,
57 = Standing agreement,
58 = SEPA credit transfer,
59 = SEPA direct debit,
97 = Clearing between partners
}
\ExplSyntaxOn
\tl_new:N \g__zugferd_payment_means_tl
\keys_define:nn {zugferd} {
payment-means / type .choices:nn = {1,10,30,42,48,49,57,58,59,97} {
\tl_gset_eq:NN \g__zugferd_payment_means_tl \l_keys_choice_tl
},
payment-means / unknown .code:n = {
\msg_warning:nnn { zugferd } {unknown-value} {payment-means} {#1}
\tl_gset:Nn \g__zugferd_payment_means_tl {\int_eval:n {#1}}
}
}

\clist_map_inline:nn {iban,account-holder,bic} {
\keys_define:nn {zugferd/payment-means} {
#1 .tl_gset:c = {g__zugferd_payment_#1_tl}
}
}

\prop_new:c {g__zugferd_payment-means_names_prop}
\newcommand*{\setupZUGFeRDStrings}[2]{
\prop_gset_from_keyval:cn {g__zugferd_#1_names_prop} {
#2
}
}

\hook_gput_code:nnn {begindocument/end}{zugferd/payment-means}{
\prop_if_empty:cT {g__zugferd_payment-means_names_prop} {
\exp_args:Nne \setupZUGFeRDStrings{payment-means}{
\use:c {zugferd@paymentMeans@
\cs_if_exist:cTF {zugferd@paymentMeans@\languagename} {\languagename} {english}
}
}
}
}
\keys_define:nn { zugferd } {
unit .choices:nn = {HUR,DAY,C62,H87} {
\tl_set_eq:NN \l__zugferd_unit_code_tl \l_keys_choice_tl
},
unit / hour .meta:n = {unit=HUR},
unit / day .meta:n = {unit=DAY},
unit / one .meta:n= {unit= C62},
unit / piece .meta:n = {unit=H87},
unit / unknown .code:n = {
\tl_set:Nx \l_tmpa_tl {\str_uppercase:f {#1}}
\exp_args:NnnV \keys_if_choice_exist:nnnTF {zugferd} {unit}
\l_tmpa_tl
{
\keys_set:ne { zugferd } {unit= {\l_tmpa_tl}}
} {
\msg_warning:nnn { zugferd } {unknown-unit} {#1}
\tl_set_eq:NN \l__zugferd_unit_code_tl \l_tmpa_tl
}
},
unit .usage:n = general,
}

\msg_new:nnnn {zugferd} {unknown-unit} {
You~selected~a~unit~which~was~not~predefined.\\
I~~will~directly~use~your~selection~'unit=#1'~as~Common~Code.
Please~ensure~the~selection~is~valid!
} {
For~more~information~see~the~zugferd~documentation\\
and~the~/UN/CEFACT~Common~Code~list.
}
\msg_new:nnnn {zugferd} {unknown-tax-category} {
You~selected~an~unknown~tax~category.\\
I~~will~directly~use~your~selection~'category=#1'~as~Code.\\
Please~ensure~the~selection~is~valid!
} {
For~more~information~see~the~zugferd~documentation\\
and~the~corresponding~code~list.
}
\msg_new:nnnn {zugferd} {no-auto-exemption} {
You~selected~tax/category=#1~together~with~the~auto-exemption~option.\\
I~don't~have~any~pre-configured~exemption~setting~for~category=#1.\\
Please~make~sure~you~add~a~valid~setting~yourself.
} {
For~more~information~see~the~zugferd~documentation.
}
\keys_define:nn { zugferd / tax } {
category .choices:nn = {S,Z,E,AE,K,G,O,L,M} {
\tl_set_eq:NN \l__zugferd_tax_category_code_tl \l_keys_choice_tl
\bool_if:NT \g__zugferd_auto_exemption_bool {
\keys_if_choice_exist:nnnTF {zugferd/tax}  {exemption-reason-auto} {#1} {
\keys_set:nn  {zugferd/tax}  {exemption-reason-auto=#1}
} {
\msg_warning:nnn { zugferd } {no-auto-exemption} {#1}
}
}
},
exemption-reason .tl_set:N = \l__zugferd_tax_exemption_reason_tl,
exemption-reason  .initial:V = \c_empty_tl,
exemption-reason .usage:n = general,
exemption-reason-code .tl_set:N  = \l__zugferd_tax_exemption_code_tl,
exemption-reason-code  .initial:V = \c_empty_tl,
exemption-reason .usage:n = general,
exemption-reason-auto .choice:,
exemption-reason-auto / S .code:n = {
\keys_set:nn {zugferd/tax} {exemption-reason=,exemption-reason-code=}
},
exemption-reason-auto / K .code:n = {
\keys_set:nn {zugferd/tax} {
exemption-reason= Intra-Community~Supply,
exemption-reason-code={vatex-eu-ic}
}
},
exemption-reason-auto / AE .code:n = {
\keys_set:nn {zugferd/tax}{
exemption-reason=Reverse~Charge,
exemption-reason-code={vatex-eu-ae}
}
},
exemption-reason-auto / G .code:n = {
\keys_set:nn {zugferd/tax}{
exemption-reason=Export~outside~the~EU,
exemption-reason-code={vatex-eu-g}
}
},
exemption-reason-auto / O .code:n = {
\keys_set:nn {zugferd/tax}{
exemption-reason=No~subject~to~VAT,
exemption-reason-code={vatex-eu-o}
}
},
standard .meta:n = {category=S},
zero .meta:n = {category=Z},
exempt .meta:n = {category=E},
reverse-charge .meta:n = {category=AE},
intra-community .meta:n = {category=K},
EEA .meta:n = {category=K},
export .meta:n = {category=G},
canary-islands .meta:n = {category=L},
ceuta .meta:n = {category=M},
melilla .meta:n = {category=M},
category / unknown .code:n = {
\exp_args:Nnnx \keys_if_choice_exist:nnnTF {zugferd} {category}
{\str_uppercase:f {#1}}
{
\keys_set:nx { zugferd } {category= {\str_uppercase:f {#1}}}
} {
\msg_warning:nnn { zugferd } {unknown-tax-category} {#1}
}
},
category .initial:n =  S,
category .usage:n = general,
rate .fp_set:N =  \l__zugferd_tax_rate_fp,
rate .initial:n = 19,
rate .usage:n = general
}%
\keys_define:nn {zugferd/item} {
tax .choice:,
tax / unknown .code:n = \keys_set:ne {zugferd/tax} { \l_keys_key_str = \exp_not:V \l_keys_value_tl},
unknown .code:n = \keys_set:ne {zugferd} { \l_keys_key_str = \exp_not:V \l_keys_value_tl}
}
\keys_define:nn { zugferd / item } {
start-date .tl_gset:N = \l__zugferd_start_date_tl,
start-date .initial:n =,
end-date .tl_gset:N = \l__zugferd_end_date_tl,
end-date .initial:n =,
}%
\__zugferd_define_xml_writer:Nn \__zugferd_write_inline:nn {
\tl_if_blank:nF {#2} {
<#1>#2</#1>
}
}
\cs_generate_variant:Nn \__zugferd_write_inline:nn {ne}
\__zugferd_define_xml_writer:Nn  \__zugferd_write_inline_i:nn {
\__zugferd_indent: \__zugferd_write_inline:nn {#1} {#2}
}
\cctab_begin:N \g__zugferd_xml_cctab%
\bool_if:NTF \g__zugferd_minimum_bool {%
\cs_set_eq:NN \__zugferd_write_note:n \use_none:n%
} {%
\__zugferd_define_xml_writer:Nn \__zugferd_write_note:n {%
\begingroup%
\let\\\iow_newline:%
\__zugferd_write_xml:e {%
<ram:IncludedNote>
\__zugferd_indent: <ram:Content>
#1
\__zugferd_indent: </ram:Content>
</ram:IncludedNote>%
}%
\endgroup%
}%
}%
\begingroup%
\char_set_catcode_other:N \#%
\char_set_catcode:nn {32}{10}%
\__zugferd_define_xml_writer:Nn \__zugferd_insert_Header: {%
\__zugferd_write_xml:e {%
<?xml version='1.0' encoding='UTF-8' ?>
<rsm:CrossIndustryInvoice %
xmlns:rsm="urn:un:unece:uncefact:data:standard:CrossIndustryInvoice:100" %
xmlns:qdt="urn:un:unece:uncefact:data:standard:QualifiedDataType:100" %
xmlns:ram="urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:100" %
xmlns:xs="http://www.w3.org/2001/XMLSchema" %
xmlns:udt="urn:un:unece:uncefact:data:standard:UnqualifiedDataType:100">%
}%
\int_gincr:N \g__zugferd_indent_int%
\__zugferd_write_xml:n {<rsm:ExchangedDocumentContext>}%
\int_gincr:N \g__zugferd_indent_int%
\__zugferd_write_xml:e {%
\str_if_empty:NF \g__zugferd_businessProcessId_str {%
<ram:BusinessProcessSpecifiedDocumentContextParameter>
\__zugferd_indent: <ram:ID>\g__zugferd_businessProcessId_str</ram:ID>
</ram:BusinessProcessSpecifiedDocumentContextParameter>
}%
<ram:GuidelineSpecifiedDocumentContextParameter>
\__zugferd_indent: <ram:ID>\g__zugferd_format_str</ram:ID>
</ram:GuidelineSpecifiedDocumentContextParameter>%
}%
\int_gdecr:N \g__zugferd_indent_int%
\__zugferd_write_xml:n {</rsm:ExchangedDocumentContext>}%
}%
\endgroup%
\__zugferd_define_xml_writer:Nn \__zugferd_insert_FrontMatter: {%
\__zugferd_write_xml:n {<rsm:ExchangedDocument>}%
\int_gincr:N \g__zugferd_indent_int%
\__zugferd_write_xml:e {%
<ram:ID>\g__zugferd_id_tl</ram:ID>
<ram:TypeCode>\g__zugferd_DocumentTypeCode_tl</ram:TypeCode>
<ram:IssueDateTime>
\__zugferd_indent:<udt:DateTimeString~format="102">\g__zugferd_date_tl</udt:DateTimeString>
</ram:IssueDateTime>%
}%
\__zugferd_note_if_not_empty:N \g__zugferd_subject_tl%
\__zugferd_note_if_not_empty:N \g__zugferd_fromaddress_tl%
\seq_map_inline:Nn \g__zugferd_notes_seq {%
\__zugferd_write_note:n {##1}%
}%
\int_gdecr:N \g__zugferd_indent_int%
\__zugferd_write_xml:e {%
</rsm:ExchangedDocument>
<rsm:SupplyChainTradeTransaction>%
}%
\int_gincr:N \g__zugferd_indent_int%
}%
\__zugferd_define_xml_writer:Nn \__zugferd_insert_Footer: {%
\int_gdecr:N \g__zugferd_indent_int%
\__zugferd_write_xml:n {</rsm:SupplyChainTradeTransaction>}%
\int_gdecr:N \g__zugferd_indent_int%
\__zugferd_write_xml:n {</rsm:CrossIndustryInvoice>}%
}%
\cctab_end:
\cctab_begin:N \g__zugferd_xml_cctab%
\__zugferd_define_xml_writer:Nn \__zugferd_AssociatedDocumentLineDocument:n {%
<ram:AssociatedDocumentLineDocument>
\__zugferd_indent: <ram:LineID>#1</ram:LineID>
</ram:AssociatedDocumentLineDocument>%
}%
\__zugferd_define_xml_writer:Nn \__zugferd_SpecifiedTradeProduct:nn {%
<ram:SpecifiedTradeProduct>
\tl_if_empty:nF {#1} {%
\__zugferd_indent: <ram:SellerAssignedID>#1</ram:SellerAssignedID>
}%
\__zugferd_indent: <ram:Name>#2</ram:Name>
</ram:SpecifiedTradeProduct>%
}%
\__zugferd_define_xml_writer:Nn \__zugferd_ProductTradePrice:nn {%
<ram:\str_uppercase:n #1PriceProductTradePrice>
\__zugferd_indent: <ram:ChargeAmount>#2</ram:ChargeAmount>
</ram:\str_uppercase:n #1PriceProductTradePrice>%
}%
\__zugferd_define_xml_writer:Nn \__zugferd_SpecifiedLineTradeAgreement:nn {%
<ram:SpecifiedLineTradeAgreement>
\__zugferd_indent:<ram:GrossPriceProductTradePrice>
\__zugferd_indent:n {2} <ram:ChargeAmount>#1</ram:ChargeAmount>
\__zugferd_indent:</ram:GrossPriceProductTradePrice>
\__zugferd_indent:<ram:NetPriceProductTradePrice>
\__zugferd_indent:n {2} <ram:ChargeAmount>#2</ram:ChargeAmount>
\__zugferd_indent:</ram:NetPriceProductTradePrice>
</ram:SpecifiedLineTradeAgreement>
}%
%%%\subsubsection{SpecifiedLineTradeDelivery}%:nn <unit code > <number>
\__zugferd_define_xml_content:Nn \__zugferd_SpecifiedLineTradeDelivery:nn {%
<ram:SpecifiedLineTradeDelivery>
\__zugferd_indent: <ram:BilledQuantity~unitCode="#1">#2</ram:BilledQuantity>
</ram:SpecifiedLineTradeDelivery>
}%
\__zugferd_define_xml_writer:Nn \__zugferd_write_SpecifiedLineTradeSettlement:nnn {%
\__zugferd_write_xml:n {<ram:SpecifiedLineTradeSettlement>}%
\int_gincr:N \g__zugferd_indent_int%
 \__zugferd_write_xml:e {\__zugferd_Line_ApplicableTradeTax:nn {#1} {#2}}%
 \__zugferd_write_xml:e {\__zugferd_BillingSpecifiedPeriod:VV \l__zugferd_start_date_tl \l__zugferd_end_date_tl}%
\__zugferd_write_xml:e {\__zugferd_SpecifiedTradeSettlementLineMonetarySummation:n {#3}}%
\int_gdecr:N \g__zugferd_indent_int%
\__zugferd_write_xml:n {</ram:SpecifiedLineTradeSettlement>}%
}%
\cs_generate_variant:Nn \__zugferd_write_SpecifiedLineTradeSettlement:nnn {Vnn}%
\__zugferd_define_xml_content:Nn \__zugferd_Line_ApplicableTradeTax:nn {%
<ram:ApplicableTradeTax>
\__zugferd_indent: <ram:TypeCode>VAT</ram:TypeCode>
\__zugferd_indent:  <ram:CategoryCode>#1</ram:CategoryCode>
\__zugferd_indent: <ram:RateApplicablePercent>#2</ram:RateApplicablePercent>
</ram:ApplicableTradeTax>
}%
\__zugferd_define_xml_content:Nn \__zugferd_BillingSpecifiedPeriod:nn {%
\bool_lazy_or:nnF {\tl_if_blank_p:n {#1}} {\tl_if_blank_p:n {#2}} {%
<ram:BillingSpecifiedPeriod>

\__zugferd_indent:<ram:StartDateTime>
\__zugferd_indent:n {2} <udt:DateTimeString~format="102">#1</udt:DateTimeString>
\__zugferd_indent:</ram:StartDateTime>

\__zugferd_indent:<ram:EndDateTime>
\__zugferd_indent:n {2} <udt:DateTimeString~format="102">#2</udt:DateTimeString>
\__zugferd_indent:</ram:EndDateTime>
     </ram:BillingSpecifiedPeriod>%
     }%
}%
\__zugferd_define_xml_content:Nn \__zugferd_SpecifiedTradeSettlementLineMonetarySummation:n {%
<ram:SpecifiedTradeSettlementLineMonetarySummation>
\__zugferd_indent: <ram:LineTotalAmount>#1</ram:LineTotalAmount>
 </ram:SpecifiedTradeSettlementLineMonetarySummation>%
}

\cctab_end:
\cs_generate_variant:Nn \__zugferd_SpecifiedLineTradeSettlement:nnn {Vnn}
\cs_generate_variant:Nn \__zugferd_BillingSpecifiedPeriod:nn {VV}
\cs_new:Nn \__zugferd_SpecifiedLineTradeSettlement:nnnn {
\msg_warning:nnnn {zugferd} {macro-deprecated}
{ \__zugferd_SpecifiedLineTradeSettlement:nnnn }
{ \__zugferd_SpecifiedLineTradeSettlement:nnn }
\__zugferd_SpecifiedLineTradeSettlement:nnn {#2} {#3} {#4}
}
\cs_generate_variant:Nn \__zugferd_SpecifiedLineTradeSettlement:nnnn {VVnn}
\__zugferd_define_xml_writer:Nn \__zugferd_insert_TradeLineItem:nnnnnn {
\__zugferd_write_xml:n {<ram:IncludedSupplyChainTradeLineItem>}
\int_gincr:N \g__zugferd_indent_int
\__zugferd_write_xml:e {\__zugferd_AssociatedDocumentLineDocument:n {#1}}%

\begingroup
\zugferd_disable_macros:
\__zugferd_write_xml:e {\__zugferd_SpecifiedTradeProduct:nn {#2} {#3}}
\endgroup

\__zugferd_write_xml:n {<ram:SpecifiedLineTradeAgreement>}
\int_gincr:N \g__zugferd_indent_int%
\__zugferd_write_xml:e {\__zugferd_ProductTradePrice:nn {net} {#4}}
\int_gdecr:N \g__zugferd_indent_int%
\__zugferd_write_xml:n {</ram:SpecifiedLineTradeAgreement>}
\__zugferd_write_xml:e {%
\__zugferd_SpecifiedLineTradeDelivery:nn { \l__zugferd_unit_code_tl } {#5}
}%
\__zugferd_write_SpecifiedLineTradeSettlement:Vnn \l__zugferd_tax_category_code_tl %
{ \fp_use:N \l__zugferd_tax_rate_fp} {#6}%
\int_gdecr:N \g__zugferd_indent_int%
\__zugferd_write_xml:n {</ram:IncludedSupplyChainTradeLineItem>}
}
\__zugferd_define_xml_writer:Nn \__zugferd_SpecifiedTradeSettlementHeaderMonetarySummation:nnnnnnnn {%
\__zugferd_write_xml:n {<ram:SpecifiedTradeSettlementHeaderMonetarySummation>}%
\int_gincr:N \g__zugferd_indent_int%
\bool_if:NF \g__zugferd_minimum_bool {
\__zugferd_write_rounded:nnn {2} {LineTotalAmount} {#1}
\__zugferd_write_rounded:nnn {2} {ChargeTotalAmount} {#2}
\__zugferd_write_rounded:nnn {2} {AllowanceTotalAmount} {#3}
}
\__zugferd_write_rounded:nnn {2} {TaxBasisTotalAmount} {#4}
\__zugferd_write_rounded:nnnn {2} {TaxTotalAmount} {~currencyID="\l__zugferd_currency_tl "} {#5}
\__zugferd_write_rounded:nnn {2} {GrandTotalAmount} {#6}
\bool_if:NF \g__zugferd_minimum_bool {
\__zugferd_write_rounded:nnn {2} {TotalPrepaidAmount} {#7}
}
\__zugferd_write_rounded:nnn {2} {DuePayableAmount} {#8}
\int_gdecr:N \g__zugferd_indent_int%
\__zugferd_write_xml:n {</ram:SpecifiedTradeSettlementHeaderMonetarySummation>}%
}%
\__zugferd_define_xml_writer:Nn \__zugferd_ApplicableTradeTax:nnnn {%
\__zugferd_write_xml:n {<ram:ApplicableTradeTax>}
\int_gincr:N \g__zugferd_indent_int%
\__zugferd_write_rounded:nnn {2} {CalculatedAmount} {#4}%BT117
\__zugferd_write_xml:n {<ram:TypeCode>VAT</ram:TypeCode>}%BT118
\tl_if_blank:VF \l__zugferd_tax_exemption_reason_tl {%BT-120
\__zugferd_write_xml:e {<ram:ExemptionReason>
\l__zugferd_tax_exemption_reason_tl
</ram:ExemptionReason>}
}
{{\__zugferd_write_rounded:nnn {2} {BasisAmount} {#3}}}%BT-116
\__zugferd_write_xml:e {<ram:CategoryCode>#1</ram:CategoryCode>}%BT-118
\tl_if_blank:VF \l__zugferd_tax_exemption_code_tl {%BT121
\__zugferd_write_xml:e {<ram:ExemptionReasonCode>
\l__zugferd_tax_exemption_code_tl
</ram:ExemptionReasonCode>}
}
\__zugferd_write_xml:n {<ram:RateApplicablePercent>#2</ram:RateApplicablePercent>}%BT-119
\int_gdecr:N \g__zugferd_indent_int%
\__zugferd_write_xml:n {</ram:ApplicableTradeTax>}
}%
\cctab_begin:N \g__zugferd_xml_cctab%
\__zugferd_define_xml_writer:Nn \__zugferd_ApplicableHeaderTradeSettlement:nnnnnnnn {%

}%
\__zugferd_define_xml_writer:Nn \__zugferd_ApplicableHeaderTradeSettlement_start: {%
\__zugferd_write_xml:n {<ram:ApplicableHeaderTradeSettlement>}%
\int_gincr:N \g__zugferd_indent_int%
\__zugferd_write_xml:e {<ram:InvoiceCurrencyCode>\l__zugferd_currency_tl</ram:InvoiceCurrencyCode>}%
}%
\__zugferd_define_xml_writer:Nn \__zugferd_ApplicableHeaderTradeSettlement_stop: {%
\int_gdecr:N \g__zugferd_indent_int%
\__zugferd_write_xml:n {</ram:ApplicableHeaderTradeSettlement>}%
}%
\__zugferd_define_xml_writer:Nn \__zugferd_SpecifiedTradePaymentTerms:nn {%
\__zugferd_write_xml:n {<ram:SpecifiedTradePaymentTerms>}%
\int_gincr:N \g__zugferd_indent_int%
\__zugferd_write_xml:e {%
\tl_if_blank:nF {#1} {%
<ram:Description>#1</ram:Description>%
}%
\tl_if_blank:nF {#2} {%
<ram:DueDateDateTime>
\__zugferd_indent: <udt:DateTimeString~format="102">#2</udt:DateTimeString>
</ram:DueDateDateTime>%
}%
}%
\int_gdecr:N \g__zugferd_indent_int%
\__zugferd_write_xml:n {</ram:SpecifiedTradePaymentTerms>}%
}%
\__zugferd_define_xml_writer:Nn \__zugferd_SpecifiedTradeSettlementPaymentMeans:nnn {%
\bool_if:NT \g__zugferd_writePaymentMeans_bool {%
\__zugferd_write_xml:n {<ram:SpecifiedTradeSettlementPaymentMeans>}%
\int_gincr:N \g__zugferd_indent_int%
\__zugferd_write_xml:e {%
<ram:TypeCode>\g__zugferd_payment_means_tl</ram:TypeCode>
\__zugferd_write_inline:ne {ram:Information} {\prop_item:cV {g__zugferd_payment-means_names_prop} \g__zugferd_payment_means_tl}%
\tl_if_blank:nF {#1#2} {%
<ram:PayeePartyCreditorFinancialAccount>
\__zugferd_write_inline_i:nn {ram:IBANID} {#2}
\__zugferd_write_inline_i:nn {ram:AccountName} {#1}
</ram:PayeePartyCreditorFinancialAccount>
}%
\tl_if_blank:nF {#3} {%
<ram:PayeeSpecifiedCreditorFinancialInstitution>
\__zugferd_write_inline_i:nn {ram:BICID} {#3}
</ram:PayeeSpecifiedCreditorFinancialInstitution>%
}%
}%
\int_gdecr:N \g__zugferd_indent_int%
\__zugferd_write_xml:n {</ram:SpecifiedTradeSettlementPaymentMeans>}%
}%
}%
\cctab_end:
\cs_generate_variant:Nn \__zugferd_SpecifiedTradePaymentTerms:nn {VV}
\__zugferd_define_xml_writer:Nn \__zugferd_SpecifiedTradePaymentTerms: {
\bool_if:NF \g__zugferd_minimum_bool {
\__zugferd_SpecifiedTradePaymentTerms:VV \g__zugferd_payment_terms_str \g__zugferd_due_date_tl
}
}
\cs_generate_variant:Nn  \__zugferd_SpecifiedTradeSettlementPaymentMeans:nnn {vvv}
\__zugferd_define_xml_writer:Nn \__zugferd_SpecifiedTradeSettlementPaymentMeans: {
\tl_if_blank:VF \g__zugferd_payment_means_tl {
\__zugferd_SpecifiedTradeSettlementPaymentMeans:vvv
{g__zugferd_payment_account-holder_tl} {g__zugferd_payment_iban_tl} {g__zugferd_payment_bic_tl}
}
}
\msg_new:nnn {zugferd} {macro-deprecated} {
The~function~#1~is~deprecated.\\
It~was~replaced~by~#2.\\
Please~adjust~your~mechanism~to~use~the~new~version.
}
\endinput
%%
%% End of file `zugferd.sty'.
