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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
|
<?php
// src/Latex.php
//
// génération du code LaTeX
abstract class Latex
{
protected string $type;
protected string $file_name;
protected string $latex_path;
protected string $pdf_path;
protected array $data = []; // données à insérer dans le template
protected string $latex; // latex pur
static function makeInstance(string $type)
{
switch($type)
{
// documents pour les clients
case 'devis':
return new DevisLatex;
case 'facture':
return new FactureLatex;
case 'location':
return new LocationLatex;
case 'enveloppe_recto':
return new EnveloppeRectoLatex;
case 'enveloppe_verso':
return new EnveloppeVersoLatex;
// pas de document
case 'cesu':
return null;
case 'non_vendue':
return null;
// documents pour la compta
// erreur
default:
echo "erreur, la sous-classe latex à initialiser n'existe pas\n";
}
}
//~ public function __construct()
//~ {}
public function makeLatex()
{
$data = $this->data; // tableau à inséré dans du code latex
include('src/latex_templates/' . $this->type . '.php');
$this->latex = $latex; // buffer récupéré par ob_get_clean()
// QUESTION:
// cette utilisation de include(), c'est du génie ou c'est moche ou les deux?
// un nouveau fichier est inséré à chaque appel de makeLatex()
// puis la mémoire est libérée à la fin de la fonction
// le PHP inséré fait donc partie de cette "mémoire"
}
// getters
public function getFileName(): string
{
return $this->file_name;
}
public function getLatexPath(): string
{
return $this->latex_path;
}
public function getPdfPath(): string
{
return $this->pdf_path;
}
public function getLatex(): string
{
return $this->latex;
}
// setters
//~ public function setFileName(string $file_name)
//~ {
//~ $this->file_name = $file_name;
//~ }
//~ public function setLatexPath(string $latex_path)
//~ {
//~ $this->latex_path = $latex_path;
//~ }
//~ public function setPdfPath(string $pdf_path)
//~ {
//~ $this->pdf_path = $pdf_path;
//~ }
public function setData(Object $Object)
{
$this->data = array_merge($this->data, $Object->getAll()); // nécessite des tableaux associatifs
}
}
abstract class PrestaLatex extends Latex
{
protected Dates $Date;
public function setData(Object $Object): self
{
$this->data = array_merge($this->data, $Object->getAll()); // nécessite des tableaux associatifs
if(get_class($Object) === 'Prestation')
{
$this->file_name = $Object->getCodePresta() . '.tex';
$this->makeDateInstance($Object->getDate()); // paramètre = int
$this->latex_path = Config::$latex_path . $this->Date->getYear() . '/';
$this->pdf_path = Config::$pdf_path . $this->Date->getYear() . '/';
}
return $this; // pour chainer les méthodes
}
//~ public function getYear(): string // parce que Dates::getDate() retourne une chaine
//~ {
//~ return $this->year;
//~ }
protected function makeDateInstance(int $timestamp)
{
$this->Date = new Dates($timestamp);
}
// forme = code-presta.tex
//~ protected function nameTheFile(string $quoi, string $codePresta)
//~ {
//~ $this->fileName = $quoi . '-' . $codePresta . '.tex';
//~ }
public function makeLatex()
{
$data = $this->data;
$date = preg_replace('#\D#', '/', $this->Date->getDate()); // date avec des slashs / parce que j'aime bien
// on obtient la variable $latex avec ob_get_clean()
// le include() ici, c'est du génie ou c'est moche ou les deux?
// un nouveau fichier php est inséré à chaque itération
include('src/latex_templates/' . $this->type . '.php');
// on retourne le buffer
// normallement le code PHP inséré avec include est nettoyé en quittant la fonction
$this->latex = $latex;
//return($latex);
}
}
class DevisLatex extends PrestaLatex // extends Latex
{
public function __construct()
{
$this->type = 'devis';
}
}
class FactureLatex extends PrestaLatex // extends Latex
{
public function __construct()
{
$this->type = 'facture';
}
}
class LocationLatex extends PrestaLatex // extends Latex
{
public function __construct()
{
$this->type = 'location';
}
}
class EnveloppeRectoLatex extends Latex
{
public function __construct()
{
$this->type = 'enveloppe_recto';
$this->latex_path = Config::$latex_path . 'enveloppes_recto/';
$this->pdf_path = Config::$pdf_path . 'enveloppes_recto/';
}
public function setData(Object $Client) // ici de type Clients
{
$this->file_name = $Client->getCodeClient() . '.tex';
$this->data = array_merge($this->data, $Client->getAll()); // nécessite des tableaux associatifs
$this->spacesInPostCode(); // nécessite $this->data
}
// code postal avec 2 espaces entre chaque chiffre: 2 \ 9 \ 0 \ 0 \ 0
protected function spacesInPostCode()
{
$this->data['code_postal_espaces'] = implode(' \ ', str_split($this->data['code_postal']));
}
}
class EnveloppeVersoLatex extends Latex
{
public function __construct()
{
$this->type = 'enveloppe_verso';
$this->file_name = 'enveloppe_verso.tex';
$this->latex_path = Config::$latex_path;
$this->pdf_path = Config::$pdf_path;
}
}
abstract class ComptaLatex extends Latex
{
//~ public function __construct(string $quoi, string $annee, int $numeroMois = 0)
//~ {
//~ nameTheFile($quoi, $annee, $numeroMois);
//~ }
// forme = Recettes-2022-06-Juin.tex ou Recettes-2022.tex
// type de 'annee'?
//~ protected function nameTheFile(string $quoi, string $annee, int $numeroMois = 0)
//~ {
//~ $this->fileName = $quoi . '-' . $annee;
//~ $mois = ['', 'Janvier', 'Février', 'Mars', 'Avril', 'Mai', 'Juin', 'Juillet', 'Août', 'Septembre', 'Octobre', 'Novembre', 'Décembre'];
//~ if($numeroMois > 0 && $numeroMois <= 12)
//~ {
//~ $this->fileName .= '-' . $numeroMois . '-' . $mois[$numeroMois];
//~ }
//~ $this->fileName .= '.tex';
//~ }
}
class LivreRecettesLatex extends ComptaLatex
{}
class RegistreAchatsLatex extends ComptaLatex
{}
class BilanLatex extends ComptaLatex
{}
|