summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/profcollege/latex/PfCTicketCaisse.tex
blob: 1c460e3693957be131e5a60077c1610edc6936f0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
%%%
% Ticket de caisse
%%%
\newcounter{PfCNbInsulte}%
\setcounter{PfCNbInsulte}{0}%

\NewDocumentCommand\PfCPrixInsulte{sm}{%
  \setsepchar{,}\ignoreemptyitems%
  \readlist*\PfCListeInsulte{\%,!,§,\#,*,@,-}%
  \reademptyitems%
  \IfBooleanTF{#1}{%
    \MelangeListe{1,2,3,4,5,6,7}{5}%
  }{%
    \stepcounter{PfCNbInsulte}%
    \MelangeListe{1,2,3,4,5,6,7}{3}%
  }%
  \setsepchar{,}\ignoreemptyitems%
  \readlist*\ListeInsulteMelange{\faa}%
  \reademptyitems%
  \ifboolKV[TicketCaisse]{Solution}{\textcolor{PfCTicketCouleurSolution}{#2}}{%
    \xintFor* ##1 in{\xintSeq{1}{\ListeInsulteMelangelen}}\do{%
      \xdef\Titi{\ListeInsulteMelange[##1]}%
      \PfCListeInsulte[\Titi]%
    }%
  }%
}%

\makeatletter
\NewDocumentCommand\PrixTicket{om}{%
  \ifboolKV[TicketCaisse]{CHF}{%
    \DeclareSIUnit{\Tempo}{\PfCCHF}%
  }{%
    \ifboolKV[TicketCaisse]{CFA}{%
      \DeclareSIUnit{\Tempo}{\PfCCFA}%
    }{%
      \ifboolKV[TicketCaisse]{CFP}{%
        \DeclareSIUnit{\Tempo}{\PfCCFP}%
      }{%
        \ifboolKV[TicketCaisse]{US}{%
          \DeclareSIUnit{\Tempo}{\Dollar}%
        }{%
          \ifboolKV[TicketCaisse]{UK}{%
            \DeclareSIUnit{\Tempo}{\LivreSterling}%
          }{%
            \ifboolKV[TicketCaisse]{Euro}{%
              \DeclareSIUnit{\Tempo}{\EuRo}%
            }{%
              \if@CHF%
                \setKV[TicketCaisse]{CHF}%
              \fi%
              \DeclareSIUnit{\Tempo}{\DeviseDefaut}%
            }%
          }%
        }%
      }%
    }%
  }%
  \IfInteger{#2}{%
    \ifboolKV[TicketCaisse]{CHF}{%
      \si{\PfCCHF}~\num{#2}.-%
    }{%
      \SI[round-mode=places,round-precision=2]{#2}{\Tempo}%
    }%
  }{%
    \SI[round-mode=places,round-precision=2]{#2}{\Tempo}%
  }%
}%
\makeatother

\setKVdefault[TicketCaisse]{Largeur=222,Especes=50,Enseigne=Au comptoir des maths,DateAchat=\today,HeureAchat=15:13:34,Taches=false,Rendu,Total,UK=false,US=false,CFA=false,CFP=false,CHF=false,Euro=false,Solution=false}
\defKV[TicketCaisse]{Couleur=\colorlet{PfCTicketCouleurSolution}{#1}\setKV[TicketCaisse]{Solution}}

\NewDocumentCommand\TicketCaisse{om}{%
  \setcounter{PfCNbInsulte}{0}%
  \useKVdefault[TicketCaisse]%
  \setKV[TicketCaisse]{#1}%
  \setsepchar[*]{,*/}%
  \readlist*\ListeAchats{#2}%
  % On fait trois listes pour les retenir
  % Liste Quantités
  \xdef\PfCFooQuantites{}%
  \foreachitem\compteur\in\ListeAchats{%
    \StrChar{\ListeAchats[\compteurcnt,1]}{1}[\MyLetter]%
    \IfStrEq{\MyLetter}{!}{%
      \StrBehind{\ListeAchats[\compteurcnt,1]}{!}[\Titi]%
      \xdef\PfCFooQuantites{\PfCFooQuantites,\Titi}%
    }{%
      \xdef\PfCFooQuantites{\PfCFooQuantites,\ListeAchats[\compteurcnt,1]}%
    }%
  }%
  % Liste Elements
  \xdef\PfCFooElements{}%
  \foreachitem\compteur\in\ListeAchats{%
    \xdef\PfCFooElements{\PfCFooElements,\ListeAchats[\compteurcnt,2]}%
  }%
  % Liste Prix Unitaire
  \xdef\PfCFooPUnitaires{}%
  \foreachitem\compteur\in\ListeAchats{%
    \StrChar{\ListeAchats[\compteurcnt,3]}{1}[\MyLetter]%
    \IfStrEqCase{\MyLetter}{%
      {!}{%
        \StrBehind{\ListeAchats[\compteurcnt,3]}{!}[\Titi]%
        \StrChar{\Titi}{1}[\Toto]%
        \IfStrEq{\Toto}{*}{%
          \StrBehind{\ListeAchats[\compteurcnt,3]}{!*}[\Tata]%
          \xdef\PfCFooPUnitaires{\PfCFooPUnitaires,\Tata}%
        }{%
          \xdef\PfCFooPUnitaires{\PfCFooPUnitaires,\Titi}%
        }%
      }% 
      {*}{\StrBehind{\ListeAchats[\compteurcnt,3]}{*}[\Titi]%
        \xdef\PfCFooPUnitaires{\PfCFooPUnitaires,\Titi}}%
    }[\xdef\PfCFooPUnitaires{\PfCFooPUnitaires,\ListeAchats[\compteurcnt,3]}]%
  }%
  % On les lit
  \setsepchar{,}\ignoreemptyitems%
  \readlist*\ListeQuantites{\PfCFooQuantites}%
  \readlist*\ListeElements{\PfCFooElements}%
  \readlist*\ListePUnitaires{\PfCFooPUnitaires}%
  % On calcul le coût total
  \xdef\PfCTCTotal{0}%
  \xintFor* ##1 in{\xintSeq{1}{\ListeAchatslen}}\do{%
    \xdef\PfCTCTotal{\fpeval{\PfCTCTotal+\ListeQuantites[##1]*\ListePUnitaires[##1]}}%
  }%
%  Le coût total est \PfCTCTotal\\
  {\ttfamily%
    \begin{NiceTabular}{m{107pt}m{29pt}m{36pt}m{50pt}}%
      \CodeBefore
      \tikz\node[opacity=0.2,yshift=-1.5cm] at ($(1-|1)!0.5!(1-|last)$) {\Large\bfseries\reflectbox{
          \begin{tabular}{c}
            Papier garanti\\
            sans Phénol
          \end{tabular}
        }
      };
      \tikz\node[opacity=0.2,anchor=center,yshift=1cm] at ($(last-|1)!0.5!(last-|last)$) {\Large\bfseries\reflectbox{%
          \faRecycle~Pensez à trier.%
        }%
      };%
      \tikz\node[opacity=0.5,anchor=center,yshift=2cm] at ($(last-|1)!0.5!(last-|last)$) {\Large\bfseries\reflectbox{
          \LogoRecyclage[Couleur=0.8white]%
        }%
      };%
      \tikz\draw[fill=Ivory,opacity=0.5] (1-|1) rectangle (last-|last);%
    \Body
    &&&\\%
    \Block{1-4}{\Large\bfseries\useKV[TicketCaisse]{Enseigne}}&&&\\%
    \\%
    \Cdots\\%
    \\%
    \Block[l]{}{\footnotesize\sc Description}&\Block{}{\footnotesize\sc Qte.}&\Block{}{\footnotesize\sc P.u.}&\Block[r]{}{\footnotesize\sc Prix Net}\\%
    \\%
    \xintFor* ##1 in{\xintSeq{1}{\ListeAchatslen}}\do{%
      \ListeElements[##1]&%
      \Block{}{%
        \footnotesize%
        \StrChar{\ListeAchats[##1,1]}{1}[\MyLetter]%
        \IfStrEq{\MyLetter}{!}{\PfCPrixInsulte*{\ListeQuantites[##1]}}{\xintifboolexpr{\fpeval{\ListeQuantites[##1]}==1}{}{\num{\ListeQuantites[##1]}}}%
      }&
      \Block[r]{}{%
        \footnotesize
        %Savoir si le nombre d'articles est affiché
        \StrChar{\ListeAchats[##1,1]}{1}[\MyLetter]%
        % Si le nombre d'articles n'est pas affiché, il faut impérativement afficher le prix unitaire
        \IfStrEq{\MyLetter}{!}{%
          \PrixTicket{\ListePUnitaires[##1]}%
        }{%
          % On regarde si on affiche le prix unitaire
          \StrChar{\ListeAchats[##1,3]}{1}[\MyLettera]%
          % Si c'est un !, on affiche pas
          % Sinon, on affiche
          \IfStrEq{\MyLettera}{!}{%
            \PfCPrixInsulte*{\PrixTicket{\ListePUnitaires[##1]}}%
          }{%
            \xintifboolexpr{\fpeval{\ListeQuantites[##1]}==1}{}{%
              \PrixTicket{\ListePUnitaires[##1]}%
            }%
          }%
        }%
      }%
      &\Block[r]{}{%
        \StrChar{\ListeAchats[##1,3]}{1}[\MyLetter]%
        % Si le premier caractère est !, il faut regarder si le deuxième caractère est une étoile
        \IfStrEq{\MyLetter}{!}{%
          \StrChar{\ListeAchats[##1,3]}{2}[\MyLettera]%
          \IfStrEq{\MyLettera}{*}{%
            \PfCPrixInsulte*{\PrixTicket{\fpeval{\ListeQuantites[##1]*\ListePUnitaires[##1]}}}%
          }{%
            \PrixTicket{\fpeval{\ListeQuantites[##1]*\ListePUnitaires[##1]}}%
          }%
        }{%il faut regarder si c'est une étoile
          \StrChar{\ListeAchats[##1,3]}{1}[\MyLettera]%
          \IfStrEq{\MyLettera}{*}{%
            \PfCPrixInsulte{\PrixTicket{\fpeval{\ListeQuantites[##1]*\ListePUnitaires[##1]}}}%
          }{%
            \PrixTicket{\fpeval{\ListeQuantites[##1]*\ListePUnitaires[##1]}}%
          }%
        }%
      }\\
    }%
    \\%
    \Cdots\\%
    Total&&&\Block[r]{}{\ifboolKV[TicketCaisse]{Total}{\ifnum\thePfCNbInsulte=0\relax\PrixTicket{\PfCTCTotal}\else\PfCPrixInsulte*{\PrixTicket{\PfCTCTotal}}\fi}{\PfCPrixInsulte*{\PrixTicket{\PfCTCTotal}}}}\\%
    Espèces&&&\Block[r]{}{\PrixTicket{\useKV[TicketCaisse]{Especes}}}\\%
    Rendu&&&\Block[r]{}{\ifboolKV[TicketCaisse]{Rendu}{\PrixTicket{\fpeval{\useKV[TicketCaisse]{Especes}-\PfCTCTotal}}}{\PfCPrixInsulte*{\PrixTicket{\fpeval{\useKV[TicketCaisse]{Especes}-\PfCTCTotal}}}}}\\%
      \\%
      \Block{1-4}{\footnotesize\useKV[TicketCaisse]{DateAchat}\qquad\useKV[TicketCaisse]{HeureAchat}}&&&\\%
    \end{NiceTabular}
  }%
}%