1 \NeedsTeXFormat{LaTeX2e}
2 \ProvidesPackage{kiviletter}[2020/04/24 Letter Layouts for Kivitendo]
6 \DeclareOption{reffields}{\@kivi@infoboxfalse}
7 \DeclareOption{infobox}{\@kivi@infoboxtrue}
8 \DeclareOption{nofooter}{\@kivi@footerfalse}
9 \DeclareOption{footer}{\@kivi@footertrue}
13 \DeclareOption*{\PassOptionsToPackage{\CurrentOption}{scrletter}}
18 \RequirePackage{expl3}
19 \RequirePackage{xparse}
20 \RequirePackage{iftex}
21 \KOMAoptions{fontsize=12pt}
22 % Schriftart, Eingabelayout der Tastatur
24 \RequirePackage[utf8]{inputenc}% Nur notwendig, wenn Basis älter als TL2018
25 \RequirePackage[T1]{fontenc}
26 \RequirePackage{lmodern}
28 \RequirePackage{eurosym}
29 \DeclareUnicodeCharacter{20AC}{\euro}
31 \RequirePackage{fontspec}
34 \RequirePackage{xltabular}
35 \RequirePackage{booktabs}
36 \RequirePackage{graphicx}
40 \RequirePackage[fromlogo,fromalign=right,
41 firstfoot=false,%Für einheitliche Randeinstellungen
44 \LoadLetterOption{DIN}
46 \newkomavar{transaction}
47 \newkomavar[\lieferschein{}~\nr]{delivery}
48 \newkomavar[\angebot{}~\nr]{quote}
49 \newkomavar[\auftragsnummer]{orderID}
50 \newkomavar[\projektnummer]{projectID}
51 \setkomavar*{fromphone}{\textTelefon}
52 \setkomavar*{fromemail}{\textEmail}
53 \setkomavar*{fromfax}{\textFax}
54 \setkomavar*{customer}{\kundennummer}
60 \dim_new:N \g_kivi_margin_dim
61 \dim_gset:Nn \g_kivi_margin_dim {\useplength{toaddrhpos}}
62 \geometry{a4paper,margin=\g_kivi_margin_dim,heightrounded}
64 \int_new:N \l_kivi_tmp_int
65 \bool_new:N \l_kivi_tmp_bool
66 \bool_new:N \g_kivi_TableFoot_bool
67 \dim_new:N \g_kivi_orig@textheight_dim
70 \newsavebox{\shippingAddressBox}
75 hoffset=\useplength{toaddrhpos},
76 voffset=\dimexpr\useplength{toaddrvpos}+\useplength{toaddrheight}+4\baselineskip,%sep to shippingaddressbox
77 contents={\usebox\shippingAddressBox}
78 ]{kivitendo.shippingaddress}
80 \newpairofpagestyles{kivitendo.letter}{}
82 \renewcommand*{\letterpagestyle}{kivitendo.letter}
84 \DeclareNewPageStyleByLayers{kivitendo.letter.first}{
85 kivitendo.shippingaddress,
86 plain.kivitendo.letter.head.odd,plain.kivitendo.letter.head.even,plain.kivitendo.letter.head.oneside,%
87 plain.kivitendo.letter.foot.odd,plain.kivitendo.letter.foot.even,plain.kivitendo.letter.foot.oneside,%
90 \setkomavar{backaddress}{\firma\ $\cdot$ \strasse\ $\cdot$ \ort}
92 \setkomavar{firsthead}{
94 \rlap{\usekomavar{fromlogo}}%
98 \@setplength{locwidth}{6cm}
101 \dim_new:N \l_kivi_tab_desc_leftskip_dim
105 \cs_new:Nn \__kivi_set_colwidth:nn {
106 \dim_set:cn {l_kivi_tab_#1_dim} {#2}
110 \cs_new:Nn \__kivi_initialize_columns: {
111 \clist_map_inline:Nn \g_kivi_pricingtable_col_clist {
112 \bool_if_exist:cF {l_kivi_col_##1_bool}
114 \bool_new:c {l_kivi_col_##1_bool}
115 \dim_new:c {l_kivi_tab_##1_dim}
116 \keys_define:nn {kivi/PricingTable} {
118 ##1 / true .code:n = \bool_set_true:c {l_kivi_col_##1_bool},
119 ##1 / false .code:n = \bool_set_false:c {l_kivi_col_##1_bool},
120 ##1 / unknown .code:n = {
121 \bool_set_true:c {l_kivi_col_##1_bool}
122 \dim_set:cn {l_kivi_tab_##1_dim} {####1}
124 ##1 .default:n = true,
125 ##1 .initial:n = true,
126 ##1 / header .prop_put:c = {l_kivi_col_##1_prop},
127 ##1 / colspec .prop_put:c = {l_kivi_col_##1_prop},
133 \clist_new:N \g_kivi_pricingtable_col_clist
135 \keys_define:nn {kivi/PricingTable} {
137 \clist_gset:Nn \g_kivi_pricingtable_col_clist {#1}
138 \__kivi_initialize_columns:,
139 columns .initial:n = {pos, id, desc, amount, price, pricetotal},
142 % set default values for colwidth
143 \keys_set:nn {kivi/PricingTable} {
150 pos/header=\position,
151 id/header=\artikelnummer,
152 desc/header=\bezeichnung,
153 amount/header=\menge,
154 price/header=\einzelpreis,
155 pricetotal/header=\gesamtpreis,
156 price / colspec = Price,
157 pricetotal / colspec = Price ,
160 \dim_new:N \g_kivi_tabcolsep_dim
161 \dim_gset:Nn \g_kivi_tabcolsep_dim {.5\tabcolsep}
163 \prg_new_conditional:Nnn \kivi_if_Price_col:n {T} {
164 \prop_get:cnN {l_kivi_col_#1_prop} {colspec} \l_tmpa_tl
165 \exp_args:NV \tl_if_eq:nnTF \l_tmpa_tl {Price}
171 \cs_new:Nn \__kivi_calc_desc_column: {
172 \dim_zero:N \l_kivi_tab_desc_leftskip_dim
173 \dim_zero:N \l_kivi_tab_desc_dim
174 \bool_set_false:N \l_tmpa_bool
175 \tl_gclear:N \g_kivi_Pricing_colspec_tl
176 \clist_map_inline:Nn \g_kivi_pricingtable_col_clist {
177 \tl_if_eq:nnTF {##1} {desc} {
178 \dim_set:Nn \l_kivi_tab_desc_dim {
179 \textwidth-\l_kivi_tab_desc_leftskip_dim
181 \bool_set_true:N \l_tmpa_bool
182 \tl_gput_right:Nn \g_kivi_Pricing_colspec_tl {p{\l_kivi_tab_desc_dim}}
184 \bool_if:cT {l_kivi_col_##1_bool} {
185 \bool_if:NTF \l_tmpa_bool {
186 \dim_sub:Nn \l_kivi_tab_desc_dim {
187 \dim_use:c {l_kivi_tab_##1_dim}+2\g_kivi_tabcolsep_dim
190 \dim_add:Nn \l_kivi_tab_desc_leftskip_dim {
191 \dim_use:c {l_kivi_tab_##1_dim}+2\g_kivi_tabcolsep_dim
194 \tl_gput_right:Nn \g_kivi_Pricing_colspec_tl {K{\dim_use:c {l_kivi_tab_##1_dim}}}
195 \kivi_if_Price_col:nT {##1} {\tl_gput_right:Nn \g_kivi_Pricing_colspec_tl {<{\__kivi_tab_column_currency:}}}
199 \tl_gput_left:Nn \g_kivi_Pricing_colspec_tl {@{}}
200 \tl_gput_right:Nn \g_kivi_Pricing_colspec_tl {@{}}
203 \newcolumntype{K}[1]{>{\raggedleft\arraybackslash}p{#1}}
204 \newcolumntype{P}[1]{K{#1}<{\__kivi_tab_column_currency:}}
206 \RequirePackage{tcolorbox}
207 \tcbuselibrary{breakable, skins}
209 \tcb@new@skin{kivi@LT}{base@unbroken,%
210 frame~engine=empty,interior~titled~engine=empty,interior~engine=empty,segmentation~engine=empty,title~engine=empty,%
211 skin~first=kivi@LT@first,skin~middle=kivi@LT@middle,skin~last=kivi@LT@last,
212 underlay~first~and~middle={
213 \node[anchor=north] at (interior.north) {\csname box_use:c\endcsname {g_kivi_LT@head_box}};
214 \node[anchor=south] at (interior.south) {\csname box_use:c\endcsname {g_kivi_LT@foot_box}};
216 underlay~unbroken~and~last={
217 \node[anchor=north] at (interior.north) {\csname box_use:c\endcsname {g_kivi_LT@head_box}};
218 \node[anchor=south] at (interior.south) {\csname box_use:c\endcsname {g_kivi_LT@lastfoot_box}};
224 bottom=\box_ht:N \g_kivi_LT@foot_box+\box_dp:N \g_kivi_LT@foot_box + \aboverulesep,
225 top=\box_ht:N \g_kivi_LT@head_box+\box_dp:N \g_kivi_LT@head_box +\belowrulesep,
229 \tcb@new@skin{kivi@LT@first}{base@first,%
230 frame~engine=empty,interior~titled~engine=empty,interior~engine=empty,segmentation~engine=empty,title~engine=empty,%
231 skin~first=kivi@LT@first,skin~middle=kivi@LT@middle,skin~last=kivi@LT@middle,
234 \tcb@new@skin{kivi@LT@middle}{base@middle,%
235 frame~engine=empty,interior~titled~engine=empty,interior~engine=empty,segmentation~engine=empty,title~engine=empty,%
236 skin~first=kivi@LT@middle,skin~middle=kivi@LT@middle,skin~last=kivi@LT@middle,
239 \tcb@new@skin{kivi@LT@last}{base@last,%
240 frame~engine=empty,interior~titled~engine=empty,interior~engine=empty,segmentation~engine=empty,title~engine=empty,%
241 skin~first=kivi@LT@middle,skin~middle=kivi@LT@middle,skin~last=kivi@LT@last,
244 \tcbset{kivi@LT/.style={skin=kivi@LT}}%
248 \seq_new:N \l_kivi_PricingTable_seq
249 \seq_new:N \l_kivi_columns_seq
250 \seq_new:N \g_kivi_extraDescription_seq
251 \newcommand{\FakeTable}[1]{
253 \seq_set_split:Nnn \l_kivi_PricingTable_seq {\tabularnewline} {#1}
254 \seq_remove_all:Nn \l_kivi_PricingTable_seq {}
256 \setlength{\parskip}{\c_zero_dim}
257 \let\ExtraDescription\__kivi_addExtraDescription:n
258 \setlength{\tabcolsep}{\g_kivi_tabcolsep_dim}
259 \seq_map_inline:Nn \l_kivi_PricingTable_seq {
260 \seq_set_split:Nnn \l_kivi_columns_seq {&} {##1}
261 \seq_gclear:N \g_kivi_extraDescription_seq
262 \exp_args:Nnx \use:n {\tabular[t]}\g_kivi_Pricing_colspec_tl
263 \seq_pop_left:NN \__l_FakeTable_columns_seq \l_tmpa_tl
264 \seq_item:Nn \l_kivi_columns_seq {\l_tmpa_tl}
265 \seq_map_inline:Nn \__l_FakeTable_columns_seq {
266 &\seq_item:Nn \l_kivi_columns_seq {####1}
269 \seq_if_empty:NTF \g_kivi_extraDescription_seq
273 \setlength{\hsize}{\dimexpr\l_kivi_tab_desc_dim+\l_kivi_tab_desc_leftskip_dim}
274 \setlength{\leftskip}{\l_kivi_tab_desc_leftskip_dim}
275 \usekomafont{extraDescription}
276 \seq_use:Nn \g_kivi_extraDescription_seq {\\}
285 \seq_new:N \__l_FakeTable_columns_seq
286 \cs_new:Nn \__kivi_setup_FakeTable: {
287 \seq_clear:N \__l_FakeTable_columns_seq
288 \int_zero:N \l_tmpa_int
289 \clist_map_inline:Nn \g_kivi_pricingtable_col_clist {
290 \int_incr:N \l_tmpa_int
291 \bool_if:cT {l_kivi_col_##1_bool} {\seq_put_right:Nx \__l_FakeTable_columns_seq {\int_use:N \l_tmpa_int}}
295 \tl_new:N \g_kivi_Pricing_colspec_tl
296 \tl_gset:Nn \g_kivi_Pricing_colspec_tl {
298 \bool_if:NT \l_kivi_col_pos_bool {p{\l_kivi_tab_pos_dim}}
299 \bool_if:NT \l_kivi_col_id_bool {p{\l_kivi_tab_id_dim}}
300 p{\l_kivi_tab_desc_dim}
301 \bool_if:NT \l_kivi_col_amount_bool {\exp_not:n {>{\raggedleft\arraybackslash}p{\l_kivi_tab_amount_dim}}}
302 \bool_if:NT \l_kivi_col_price_bool {\exp_not:n {>{\raggedleft\arraybackslash}p{\l_kivi_tab_price_dim}<{\__kivi_tab_column_currency:}}}
303 \bool_if:NT \l_kivi_col_pricetotal_bool {\exp_not:n {>{\raggedleft\arraybackslash}p{\l_kivi_tab_pricetotal_dim}<{\__kivi_tab_column_currency:}}}
307 \cs_new_protected:Nn \__kivi_tab_column_currency: {\,\currency}
308 \def\tabcurrency{\__kivi_tab_column_currency:}
309 \cs_set:Nn \__kivi_tab_column_header_currency: {}
310 \cs_set_eq:NN \__kivi_tab_column_body_currency: \__kivi_tab_column_currency:
312 \clist_map_inline:nn {head, foot, firsthead, lastfoot} {%TODO reduce
313 \box_new:c {g_kivi_LT@#1_box}
316 \newkomafont{PricingTableHeader}{\bfseries}
318 \cs_new:Nn \__kivi_setup_LT_boxes: {
319 \__kivi_calc_desc_column:
320 \hbox_gset:Nn \g_kivi_LT@head_box {
321 \setlength{\tabcolsep}{\g_kivi_tabcolsep_dim}
322 \exp_args:Nnx \use:n {\tabular[b]}\g_kivi_Pricing_colspec_tl
323 \__kivi_PricingTabular_header:
326 \hbox_gset:Nn \g_kivi_LT@foot_box {
328 \begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}r@{}}
330 \strut\weiteraufnaechsterseite
334 \hbox_gset:Nn \g_kivi_LT@lastfoot_box {
335 \raisebox{\dimexpr\depth+\baselineskip}[0pt][0pt]{
336 \begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}r@{}}
344 %Macht es sinn hier eine Variante zu machen, in der alle Spalten Belegbar sind?
345 \newenvironment{PricingTotal}{
348 \tabular[t]{@{}p{\dim_eval:n {\linewidth-\l_kivi_tab_pricetotal_dim-2\tabcolsep}}P{\l_kivi_tab_pricetotal_dim}@{}}
355 \newcommand*\ExtraDescription{
356 \PackageError{kiviletter}{The~command~\string\ExtraDescription\space~may~be~only~used~inside~the~\string\FakeTable\space~environment.}{See~documentation~for~details}
360 \cs_new:Nn \__kivi_addExtraDescription:n {\seq_gput_right:Nn \g_kivi_extraDescription_seq {#1}}
362 \newenvironment{PricingTabular}[1][]{
364 \dim_set:Nn \parskip {\c_zero_dim}
365 \tl_if_empty:nF {#1} {\keys_set:nn {kivi/PricingTable} {#1}}
366 \setlength{\tabcolsep}{\g_kivi_tabcolsep_dim}
367 \__kivi_calc_desc_column:
368 \exp_args:Nx \longtable \g_kivi_Pricing_colspec_tl
370 \__kivi_PricingTabular_header:
373 \rlap{\makebox[\textwidth][r]{\weiteraufnaechsterseite}}\\
382 \cs_set:Nn \__kivi_PricingTabular_header: {
384 \cs_gset_eq:NN \__kivi_tab_column_currency: \__kivi_tab_column_header_currency:
385 \bool_set_false:N \l_tmpa_bool
386 \clist_map_inline:Nn \g_kivi_pricingtable_col_clist {
387 \bool_if:cT {l_kivi_col_##1_bool} {
388 \bool_if:NT \l_tmpa_bool {&}
389 \bool_set_true:N \l_tmpa_bool
390 \usekomafont{PricingTableHeader}
391 \prop_item:cn {l_kivi_col_##1_prop} {header}
394 \cs_gset_eq:NN \__kivi_tab_column_currency: \__kivi_tab_column_body_currency:
400 \keys_define:nn {kivi/SimpleTabular} {
401 colspec .tl_set:N =\l_kivi_SimpleTabular_colspec_tl,
402 colspec .initial:n = {rrX},
403 headline .tl_set:N = \l_kivi_SimpleTabular_headline_tl,
404 headline .initial:n = {\bfseries\position & \bfseries\menge & \bfseries\bezeichnung},
407 \newcommand*{\SetupSimpleTabular}[1]{\keys_set:nn {kivi/SimpleTabular} {#1}}
408 \newcommand*{\SetupPricingTabular}[1]{\keys_set:nn {kivi/PricingTable} {#1}}
410 \newenvironment{SimpleTabular}[1][]
412 \tl_if_in:nnTF {#1} {=} {\keys_set:nn {kivi/SimpleTabular} {#1}} {\tl_if_empty:nF {#1} {\tl_set:Nn \l_kivi_SimpleTabular_headline_tl {#1}}}
413 \setlength{\tabcolsep}{\g_kivi_tabcolsep_dim}
414 \dim_set:Nn \parskip {\c_zero_dim}
415 \tl_put_right:Nn \l_kivi_SimpleTabular_colspec_tl {@{}}
416 \tl_put_left:Nn \l_kivi_SimpleTabular_colspec_tl {@{}}
417 \exp_args:NnV \xltabular{\linewidth}\l_kivi_SimpleTabular_colspec_tl
419 \cs_gset_eq:NN \__kivi_tab_column_currency: \__kivi_tab_column_header_currency:
420 \l_kivi_SimpleTabular_headline_tl
422 \noalign{\cs_gset_eq:NN \__kivi_tab_column_currency: \__kivi_tab_column_body_currency:}
426 \rlap{\makebox[\textwidth][r]{\weiteraufnaechsterseite}}\\
432 \def\@currenvir{tabularx}
436 %PricingTabular* kann automatisch spalten ignorieren
437 % \begin{PricingTabular*}[id=false]
438 % deaktiviert damit die Spalte der Produktnummer
439 % analog ist dies für pos, amount, price, pricetotal möglich.
440 % Die Spalte der Bezeichnung ist nicht deaktivierbar
441 \newenvironment{PricingTabular*}[1][]{
442 \tl_if_empty:nF {#1} {\keys_set:nn {kivi/PricingTable} {#1}}
443 \__kivi_setup_LT_boxes:
444 \__kivi_setup_FakeTable:
445 \dim_set:Nn \parskip {\c_zero_dim}
446 \PricingTabularBox\ignorespaces
447 }{\endPricingTabularBox}
449 \newtcolorbox{PricingTabularBox}{breakable,skin=kivi@LT}
455 \NewDocumentCommand{\locationentry}{som}{
456 \Ifkomavarempty{#3}{}{
464 \hbox_set:Nn \l_tmpa_box {\usekomavar{#3}}
465 \dim_compare:nTF {\box_wd:N \l_tmpa_box>\linewidth}
466 {\newline\hspace*{\fill}\llap}
468 {\box_use:N \l_tmpa_box\strut}
475 \parbox[t]{\dimexpr\linewidth-\hangindent}{
477 \usekomavar{#3}\strut
486 \setkomavar{location}{
487 \Ifkomavarempty{transaction}{}{
489 \usekomavar{transaction}
493 \parbox{\useplength{locwidth}}{
495 \locationentry{myref}
496 \locationentry{customer}
497 \locationentry{yourref}
498 \locationentry{delivery}
499 \locationentry{quote}
500 \locationentry{orderID}
501 \locationentry{projectID}
502 \locationentry[\ansprechpartner]{fromname}
503 \locationentry{fromphone}
504 \locationentry*{fromemail}
509 \ifdim\ht\shippingAddressBox>\z@
510 \@addtoplength{refvpos}{\dimexpr\ht\shippingAddressBox+\dp\shippingAddressBox}
511 \@addtoplength{refvpos}{4\baselineskip}%sep between address boxes
517 %Fallback for older KOMA-Script-Versions
518 \cs_if_exist:NF \Ifstr {\let\Ifstr\ifstr}
519 \cs_if_exist:NF \Ifkomavarempty {\let\Ifkomavarempty\ifkomavarempty}
521 %Definitionen für die insettings.tex
523 \newcommand*{\setupIdentpath}[1]{
524 \int_set:Nn \l_kivi_tmp_int {1}
525 \bool_set_true:N \l_kivi_tmp_bool
526 \bool_while_do:Nn \l_kivi_tmp_bool {
527 \file_if_exist:nTF {firma\int_use:N \l_kivi_tmp_int/ident.tex}
529 \exp_args:Nf \str_if_in:nnTF {#1} {Firma\int_use:N \l_kivi_tmp_int}
531 \newcommand*{\identpath}{firma\int_use:N \l_kivi_tmpa_int}
532 \bool_set_false:N \l_kivi_tmp_bool
534 {\int_incr:N \l_kivi_tmp_int}
537 \bool_set_false:N \l_kivi_tmp_bool
538 \newcommand*{\identpath}{firma}
543 \newcommand*{\setupCurrencyConfig}[2]{
544 \tl_new:N \g_kivi_currency_tl
545 \exp_args:Nf \str_if_in:nnT {#2} {USD} {\tl_gset:Nn \g_kivi_currency_tl {usd}}
546 \exp_args:Nf \str_if_in:nnT {#2} {CHF} {\tl_gset:Nn \g_kivi_currency_tl {chf}}
547 \exp_args:Nf \str_if_in:nnT {#2} {EUR} {\tl_gset:Nn \g_kivi_currency_tl {euro}}
548 \tl_if_empty:NT \g_kivi_currency_tl {
549 \tl_gset:Nn \g_kivi_currency_tl {default}
550 \edef \currency {\tl_to_str:N \lxcurrency}
552 \input{#1/\g_kivi_currency_tl _account.tex}
558 \renewcommand*{\raggedsignature}{\raggedright}
560 \newkomafont{extraDescription}{}