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 \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 {>{\raggedleft\arraybackslash}p{\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{P}[1]{>{\raggedleft\arraybackslash}p{#1}<{\__kivi_tab_column_currency:}}
205 \RequirePackage{tcolorbox}
206 \tcbuselibrary{breakable, skins}
208 \tcb@new@skin{kivi@LT}{base@unbroken,%
209 frame~engine=empty,interior~titled~engine=empty,interior~engine=empty,segmentation~engine=empty,title~engine=empty,%
210 skin~first=kivi@LT@first,skin~middle=kivi@LT@middle,skin~last=kivi@LT@last,
211 underlay~first~and~middle={
212 \node[anchor=north] at (interior.north) {\csname box_use:c\endcsname {g_kivi_LT@head_box}};
213 \node[anchor=south] at (interior.south) {\csname box_use:c\endcsname {g_kivi_LT@foot_box}};
215 underlay~unbroken~and~last={
216 \node[anchor=north] at (interior.north) {\csname box_use:c\endcsname {g_kivi_LT@head_box}};
217 \node[anchor=south] at (interior.south) {\csname box_use:c\endcsname {g_kivi_LT@lastfoot_box}};
223 bottom=\box_ht:N \g_kivi_LT@foot_box+\box_dp:N \g_kivi_LT@foot_box + \aboverulesep,
224 top=\box_ht:N \g_kivi_LT@head_box+\box_dp:N \g_kivi_LT@head_box +\belowrulesep,
228 \tcb@new@skin{kivi@LT@first}{base@first,%
229 frame~engine=empty,interior~titled~engine=empty,interior~engine=empty,segmentation~engine=empty,title~engine=empty,%
230 skin~first=kivi@LT@first,skin~middle=kivi@LT@middle,skin~last=kivi@LT@middle,
233 \tcb@new@skin{kivi@LT@middle}{base@middle,%
234 frame~engine=empty,interior~titled~engine=empty,interior~engine=empty,segmentation~engine=empty,title~engine=empty,%
235 skin~first=kivi@LT@middle,skin~middle=kivi@LT@middle,skin~last=kivi@LT@middle,
238 \tcb@new@skin{kivi@LT@last}{base@last,%
239 frame~engine=empty,interior~titled~engine=empty,interior~engine=empty,segmentation~engine=empty,title~engine=empty,%
240 skin~first=kivi@LT@middle,skin~middle=kivi@LT@middle,skin~last=kivi@LT@last,
243 \tcbset{kivi@LT/.style={skin=kivi@LT}}%
247 \seq_new:N \l_kivi_PricingTable_seq
248 \seq_new:N \l_kivi_columns_seq
249 \seq_new:N \g_kivi_extraDescription_seq
250 \newcommand{\FakeTable}[1]{
252 \seq_set_split:Nnn \l_kivi_PricingTable_seq {\tabularnewline} {#1}
253 \seq_remove_all:Nn \l_kivi_PricingTable_seq {}
255 \setlength{\parskip}{\c_zero_dim}
256 \let\ExtraDescription\__kivi_addExtraDescription:n
257 \setlength{\tabcolsep}{\g_kivi_tabcolsep_dim}
258 \seq_map_inline:Nn \l_kivi_PricingTable_seq {
259 \seq_set_split:Nnn \l_kivi_columns_seq {&} {##1}
260 \seq_gclear:N \g_kivi_extraDescription_seq
261 \exp_args:Nnx \use:n {\tabular[t]}\g_kivi_Pricing_colspec_tl
262 \seq_pop_left:NN \__l_FakeTable_columns_seq \l_tmpa_tl
263 \seq_item:Nn \l_kivi_columns_seq {\l_tmpa_tl}
264 \seq_map_inline:Nn \__l_FakeTable_columns_seq {
265 &\seq_item:Nn \l_kivi_columns_seq {####1}
268 \seq_if_empty:NTF \g_kivi_extraDescription_seq
272 \setlength{\hsize}{\dimexpr\l_kivi_tab_desc_dim+\l_kivi_tab_desc_leftskip_dim}
273 \setlength{\leftskip}{\l_kivi_tab_desc_leftskip_dim}
274 \usekomafont{extraDescription}
275 \seq_use:Nn \g_kivi_extraDescription_seq {\\}
284 \seq_new:N \__l_FakeTable_columns_seq
285 \cs_new:Nn \__kivi_setup_FakeTable: {
286 \seq_clear:N \__l_FakeTable_columns_seq
287 \int_zero:N \l_tmpa_int
288 \clist_map_inline:Nn \g_kivi_pricingtable_col_clist {
289 \int_incr:N \l_tmpa_int
290 \bool_if:cT {l_kivi_col_##1_bool} {\seq_put_right:Nx \__l_FakeTable_columns_seq {\int_use:N \l_tmpa_int}}
294 \tl_new:N \g_kivi_Pricing_colspec_tl
295 \tl_gset:Nn \g_kivi_Pricing_colspec_tl {
297 \bool_if:NT \l_kivi_col_pos_bool {p{\l_kivi_tab_pos_dim}}
298 \bool_if:NT \l_kivi_col_id_bool {p{\l_kivi_tab_id_dim}}
299 p{\l_kivi_tab_desc_dim}
300 \bool_if:NT \l_kivi_col_amount_bool {\exp_not:n {>{\raggedleft\arraybackslash}p{\l_kivi_tab_amount_dim}}}
301 \bool_if:NT \l_kivi_col_price_bool {\exp_not:n {>{\raggedleft\arraybackslash}p{\l_kivi_tab_price_dim}<{\__kivi_tab_column_currency:}}}
302 \bool_if:NT \l_kivi_col_pricetotal_bool {\exp_not:n {>{\raggedleft\arraybackslash}p{\l_kivi_tab_pricetotal_dim}<{\__kivi_tab_column_currency:}}}
306 \cs_new_protected:Nn \__kivi_tab_column_currency: {\,\currency}
307 \def\tabcurrency{\__kivi_tab_column_currency:}
308 \cs_set:Nn \__kivi_tab_column_header_currency: {}
309 \cs_set_eq:NN \__kivi_tab_column_body_currency: \__kivi_tab_column_currency:
311 \clist_map_inline:nn {head, foot, firsthead, lastfoot} {%TODO reduce
312 \box_new:c {g_kivi_LT@#1_box}
315 \newkomafont{PricingTableHeader}{\bfseries}
317 \cs_new:Nn \__kivi_setup_LT_boxes: {
318 \__kivi_calc_desc_column:
319 \hbox_gset:Nn \g_kivi_LT@head_box {
320 \setlength{\tabcolsep}{\g_kivi_tabcolsep_dim}
321 \exp_args:Nnx \use:n {\tabular[b]}\g_kivi_Pricing_colspec_tl
322 \__kivi_PricingTabular_header:
325 \hbox_gset:Nn \g_kivi_LT@foot_box {
327 \begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}r@{}}
329 \strut\weiteraufnaechsterseite
333 \hbox_gset:Nn \g_kivi_LT@lastfoot_box {
334 \raisebox{\dimexpr\depth+\baselineskip}[0pt][0pt]{
335 \begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}r@{}}
343 %Macht es sinn hier eine Variante zu machen, in der alle Spalten Belegbar sind?
344 \newenvironment{PricingTotal}{
347 \tabular[t]{@{}p{\dim_eval:n {\linewidth-\l_kivi_tab_pricetotal_dim-2\tabcolsep}}P{\l_kivi_tab_pricetotal_dim}@{}}
354 \newcommand*\ExtraDescription{
355 \PackageError{kiviletter}{The~command~\string\ExtraDescription\space~may~be~only~used~inside~the~\string\FakeTable\space~environment.}{See~documentation~for~details}
359 \cs_new:Nn \__kivi_addExtraDescription:n {\seq_gput_right:Nn \g_kivi_extraDescription_seq {#1}}
361 \newenvironment{PricingTabular}[1][]{
363 \dim_set:Nn \parskip {\c_zero_dim}
364 \tl_if_empty:nF {#1} {\keys_set:nn {kivi/PricingTable} {#1}}
365 \setlength{\tabcolsep}{\g_kivi_tabcolsep_dim}
366 \__kivi_calc_desc_column:
367 \exp_args:Nx \longtable \g_kivi_Pricing_colspec_tl
369 \__kivi_PricingTabular_header:
372 \rlap{\makebox[\textwidth][r]{\weiteraufnaechsterseite}}\\
381 \cs_set:Nn \__kivi_PricingTabular_header: {
383 \cs_gset_eq:NN \__kivi_tab_column_currency: \__kivi_tab_column_header_currency:
384 \bool_set_false:N \l_tmpa_bool
385 \clist_map_inline:Nn \g_kivi_pricingtable_col_clist {
386 \bool_if:cT {l_kivi_col_##1_bool} {
387 \bool_if:NT \l_tmpa_bool {&}
388 \bool_set_true:N \l_tmpa_bool
389 \usekomafont{PricingTableHeader}
390 \prop_item:cn {l_kivi_col_##1_prop} {header}
393 \cs_gset_eq:NN \__kivi_tab_column_currency: \__kivi_tab_column_body_currency:
399 \keys_define:nn {kivi/SimpleTabular} {
400 colspec .tl_set:N =\l_kivi_SimpleTabular_colspec_tl,
401 colspec .initial:n = {rrX},
402 headline .tl_set:N = \l_kivi_SimpleTabular_headline_tl,
403 headline .initial:n = {\bfseries\position & \bfseries\menge & \bfseries\bezeichnung},
406 \newcommand*{\SetupSimpleTabular}[1]{\keys_set:nn {kivi/SimpleTabular} {#1}}
407 \newcommand*{\SetupPricingTabular}[1]{\keys_set:nn {kivi/PricingTable} {#1}}
409 \newenvironment{SimpleTabular}[1][]
411 \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}}}
412 \setlength{\tabcolsep}{\g_kivi_tabcolsep_dim}
413 \dim_set:Nn \parskip {\c_zero_dim}
414 \tl_put_right:Nn \l_kivi_SimpleTabular_colspec_tl {@{}}
415 \tl_put_left:Nn \l_kivi_SimpleTabular_colspec_tl {@{}}
416 \exp_args:NnV \xltabular{\linewidth}\l_kivi_SimpleTabular_colspec_tl
418 \cs_gset_eq:NN \__kivi_tab_column_currency: \__kivi_tab_column_header_currency:
419 \l_kivi_SimpleTabular_headline_tl
421 \noalign{\cs_gset_eq:NN \__kivi_tab_column_currency: \__kivi_tab_column_body_currency:}
425 \rlap{\makebox[\textwidth][r]{\weiteraufnaechsterseite}}\\
431 \def\@currenvir{tabularx}
435 %PricingTabular* kann automatisch spalten ignorieren
436 % \begin{PricingTabular*}[id=false]
437 % deaktiviert damit die Spalte der Produktnummer
438 % analog ist dies für pos, amount, price, pricetotal möglich.
439 % Die Spalte der Bezeichnung ist nicht deaktivierbar
440 \newenvironment{PricingTabular*}[1][]{
441 \tl_if_empty:nF {#1} {\keys_set:nn {kivi/PricingTable} {#1}}
442 \__kivi_setup_LT_boxes:
443 \__kivi_setup_FakeTable:
444 \dim_set:Nn \parskip {\c_zero_dim}
445 \PricingTabularBox\ignorespaces
446 }{\endPricingTabularBox}
448 \newtcolorbox{PricingTabularBox}{breakable,skin=kivi@LT}
454 \NewDocumentCommand{\locationentry}{som}{
455 \Ifkomavarempty{#3}{}{
463 \hbox_set:Nn \l_tmpa_box {\usekomavar{#3}}
464 \dim_compare:nTF {\box_wd:N \l_tmpa_box>\linewidth}
465 {\newline\hspace*{\fill}\llap}
467 {\box_use:N \l_tmpa_box\strut}
474 \parbox[t]{\dimexpr\linewidth-\hangindent}{
476 \usekomavar{#3}\strut
485 \setkomavar{location}{
486 \Ifkomavarempty{transaction}{}{
488 \usekomavar{transaction}
492 \parbox{\useplength{locwidth}}{
494 \locationentry{myref}
495 \locationentry{customer}
496 \locationentry{yourref}
497 \locationentry{delivery}
498 \locationentry{quote}
499 \locationentry{orderID}
500 \locationentry{projectID}
501 \locationentry[\ansprechpartner]{fromname}
502 \locationentry{fromphone}
503 \locationentry*{fromemail}
508 \ifdim\ht\shippingAddressBox>\z@
509 \@addtoplength{refvpos}{\dimexpr\ht\shippingAddressBox+\dp\shippingAddressBox}
510 \@addtoplength{refvpos}{4\baselineskip}%sep between address boxes
516 %Fallback for older KOMA-Script-Versions
517 \cs_if_exist:NF \Ifstr {\let\Ifstr\ifstr}
518 \cs_if_exist:NF \Ifkomavarempty {\let\Ifkomavarempty\ifkomavarempty}
520 %Definitionen für die insettings.tex
522 \newcommand*{\setupIdentpath}[1]{
523 \int_set:Nn \l_kivi_tmp_int {1}
524 \bool_set_true:N \l_kivi_tmp_bool
525 \bool_while_do:Nn \l_kivi_tmp_bool {
526 \file_if_exist:nTF {firma\int_use:N \l_kivi_tmp_int/ident.tex}
528 \exp_args:Nf \str_if_in:nnTF {#1} {Firma\int_use:N \l_kivi_tmp_int}
530 \newcommand*{\identpath}{firma\int_use:N \l_kivi_tmpa_int}
531 \bool_set_false:N \l_kivi_tmp_bool
533 {\int_incr:N \l_kivi_tmp_int}
536 \bool_set_false:N \l_kivi_tmp_bool
537 \newcommand*{\identpath}{firma}
542 \newcommand*{\setupCurrencyConfig}[2]{
543 \tl_new:N \g_kivi_currency_tl
544 \exp_args:Nf \str_if_in:nnT {#2} {USD} {\tl_gset:Nn \g_kivi_currency_tl {usd}}
545 \exp_args:Nf \str_if_in:nnT {#2} {CHF} {\tl_gset:Nn \g_kivi_currency_tl {chf}}
546 \exp_args:Nf \str_if_in:nnT {#2} {EUR} {\tl_gset:Nn \g_kivi_currency_tl {euro}}
547 \tl_if_empty:NT \g_kivi_currency_tl {
548 \tl_gset:Nn \g_kivi_currency_tl {default}
549 \edef \currency {\tl_to_str:N \lxcurrency}
551 \input{#1/\g_kivi_currency_tl _account.tex}
557 \renewcommand*{\raggedsignature}{\raggedright}
559 \newkomafont{extraDescription}{}