diff options
author | polo <ordipolo@gmx.fr> | 2023-07-05 01:39:29 +0200 |
---|---|---|
committer | polo <ordipolo@gmx.fr> | 2023-07-05 01:39:29 +0200 |
commit | 9bdfb5196a2ee1cbfc403702e8d2ef88076d366f (patch) | |
tree | 6a92d8011dae746e5fe7a618eb4af2b77e922572 /src/Latex.php | |
parent | 884493c1fb985adaaa537c11f4350d940cc68cb1 (diff) | |
download | AppliGestionPHP-9bdfb5196a2ee1cbfc403702e8d2ef88076d366f.zip |
classe Latex "fonctionnelle"
Diffstat (limited to 'src/Latex.php')
-rw-r--r-- | src/Latex.php | 177 |
1 files changed, 130 insertions, 47 deletions
diff --git a/src/Latex.php b/src/Latex.php index a766fd6..051c48b 100644 --- a/src/Latex.php +++ b/src/Latex.php | |||
@@ -5,9 +5,12 @@ | |||
5 | 5 | ||
6 | abstract class Latex | 6 | abstract class Latex |
7 | { | 7 | { |
8 | protected $fileName = ''; | 8 | protected $type = ''; |
9 | protected $latexPath = ''; | 9 | protected $file_name = ''; |
10 | protected $pdfPath = ''; | 10 | protected $latex_path = ''; |
11 | protected $pdf_path = ''; | ||
12 | protected $data = []; // données à insérer dans le template | ||
13 | protected $latex = ''; // latex pur | ||
11 | 14 | ||
12 | static function makeLatexSubClass(string $type): Object | 15 | static function makeLatexSubClass(string $type): Object |
13 | { | 16 | { |
@@ -15,15 +18,15 @@ abstract class Latex | |||
15 | { | 18 | { |
16 | // documents pour les clients | 19 | // documents pour les clients |
17 | case 'devis': | 20 | case 'devis': |
18 | return new DevisLatex(); | 21 | return new DevisLatex($type); |
19 | case 'facture': | 22 | case 'facture': |
20 | return new FactireLatex(); | 23 | return new FactureLatex($type); |
21 | case 'location': | 24 | case 'location': |
22 | return new LocationLatex(); | 25 | return new LocationLatex($type); |
23 | case 'enveloppe_recto': | 26 | case 'enveloppe_recto': |
24 | return new EnveloppeRectoLatex(); | 27 | return new EnveloppeRectoLatex($type); |
25 | case 'enveloppe_verso': | 28 | case 'enveloppe_verso': |
26 | return new EnveloppeVersoLatex(); | 29 | return new EnveloppeVersoLatex($type); |
27 | 30 | ||
28 | // documents pour la compta | 31 | // documents pour la compta |
29 | 32 | ||
@@ -33,72 +36,152 @@ abstract class Latex | |||
33 | } | 36 | } |
34 | } | 37 | } |
35 | 38 | ||
36 | protected function createFile(string $latex, string $fileName, string $latexPath) | 39 | // tester en private? |
40 | public function __construct(string $type) | ||
37 | { | 41 | { |
38 | // nom du fichier créé = nom.tex | 42 | $this->type = $type; |
39 | // pour les devis, factures et enveloppes, le nom est le code la prestation | 43 | } |
40 | // pour les livre de recettes et registres des achats mensuels: | 44 | |
41 | // le nom du fichier suit cet exemple: "Recettes-2022-06-Juin.tex" | 45 | public function makeLatex() |
42 | // pour le livre de recette ou le registre des achats annuel, même principe: "Achats-2022.tex" | 46 | { |
43 | // pour le bilan comptable annuel, ça donne: "Bilan-2022.tex" | 47 | $data = $this->data; |
44 | $fichier = fopen($latexPath . $fileName, "w+"); | 48 | |
45 | fputs($fichier, $latex); | 49 | // on obtient la variable $latex avec ob_get_clean() |
46 | fclose($fichier); | 50 | // le include() ici, c'est du génie ou c'est moche ou les deux? |
51 | // un nouveau fichier php est inséré à chaque itération | ||
52 | include('latex_templates/' . $this->type . '.php'); | ||
53 | |||
54 | // on retourne le buffer | ||
55 | // normallement le code PHP inséré avec include est nettoyé en quittant la fonction | ||
56 | $this->latex = $latex; | ||
57 | //return($latex); | ||
58 | } | ||
59 | |||
60 | // getters | ||
61 | public function getFileName(): string | ||
62 | { | ||
63 | return $this->file_name; | ||
64 | } | ||
65 | public function getLatexPath(): string | ||
66 | { | ||
67 | return $this->latex_path; | ||
68 | } | ||
69 | public function getPdfPath(): string | ||
70 | { | ||
71 | return $this->pdf_path; | ||
72 | } | ||
73 | |||
74 | public function getLatex(): string | ||
75 | { | ||
76 | return $this->latex; | ||
77 | } | ||
78 | |||
79 | // setters | ||
80 | public function setFileName(string $file_name) | ||
81 | { | ||
82 | $this->file_name = $file_name; | ||
83 | } | ||
84 | public function setLatexPath(string $latex_path) | ||
85 | { | ||
86 | $this->latex_path = $latex_path; | ||
87 | } | ||
88 | public function setPdfPath(string $pdf_path) | ||
89 | { | ||
90 | $this->pdf_path = $pdf_path; | ||
91 | } | ||
92 | |||
93 | public function setData(Object $Object) | ||
94 | { | ||
95 | $this->data = array_merge($this->data, $Object->getAll()); // nécessite des tableaux associatifs | ||
96 | //return $Object; // pour chainer les méthodes | ||
47 | } | 97 | } |
48 | } | 98 | } |
49 | 99 | ||
50 | 100 | ||
51 | |||
52 | abstract class PrestaLatex extends Latex | 101 | abstract class PrestaLatex extends Latex |
53 | { | 102 | { |
54 | public function __construct(string $quoi, string $codePresta) | 103 | protected $Date; // sera un type "Dates" |
104 | protected $year = ''; | ||
105 | |||
106 | //~ public function __construct(string $type) // surcharge Latex::__construct() | ||
107 | //~ { | ||
108 | //~ $this->type = $type; | ||
109 | //~ $this->Date = new Dates(); | ||
110 | //~ $this->year = $this->Date->getYear(); | ||
111 | //~ } | ||
112 | |||
113 | public function getYear(): string // parce que Dates::getDate() retourne une chaine | ||
55 | { | 114 | { |
56 | nameTheFile($quoi, $codePresta); | 115 | return $this->year; |
116 | } | ||
117 | |||
118 | public function makeDateInstance(int $date) | ||
119 | { | ||
120 | $this->Date = new Dates($date); | ||
121 | $this->year = $this->Date->getYear(); | ||
57 | } | 122 | } |
58 | 123 | ||
59 | // forme = code-presta.tex | 124 | // forme = code-presta.tex |
60 | protected function nameTheFile(string $quoi, string $codePresta) | 125 | //~ protected function nameTheFile(string $quoi, string $codePresta) |
126 | //~ { | ||
127 | //~ $this->fileName = $quoi . '-' . $codePresta . '.tex'; | ||
128 | //~ } | ||
129 | |||
130 | public function makeLatex() | ||
61 | { | 131 | { |
62 | $this->fileName = $quoi . '-' . $codePresta . '.tex'; | 132 | $data = $this->data; |
133 | $date = preg_replace('#\D#', '/', $this->Date->getDate()); // date avec des slashs / parce que j'aime bien | ||
134 | |||
135 | // on obtient la variable $latex avec ob_get_clean() | ||
136 | // le include() ici, c'est du génie ou c'est moche ou les deux? | ||
137 | // un nouveau fichier php est inséré à chaque itération | ||
138 | include('latex_templates/' . $this->type . '.php'); | ||
139 | |||
140 | // on retourne le buffer | ||
141 | // normallement le code PHP inséré avec include est nettoyé en quittant la fonction | ||
142 | $this->latex = $latex; | ||
143 | //return($latex); | ||
63 | } | 144 | } |
64 | } | 145 | } |
65 | 146 | ||
66 | //~ class PrestaClassFactory extends PrestaLatex | 147 | class DevisLatex extends PrestaLatex // extends Latex |
67 | //~ {} | ||
68 | |||
69 | class DevisLatex extends PrestaLatex | ||
70 | {} | 148 | {} |
71 | class FactureLatex extends PrestaLatex | 149 | class FactureLatex extends PrestaLatex // extends Latex |
72 | {} | 150 | {} |
73 | class LocationLatex extends PrestaLatex | 151 | class LocationLatex extends PrestaLatex // extends Latex |
74 | {} | ||
75 | |||
76 | class EnveloppeRectoLatex// extends PrestaLatex | ||
77 | {} | 152 | {} |
78 | class EnveloppeVersoLatex// extends PrestaLatex | 153 | class EnveloppeRectoLatex extends Latex |
154 | { | ||
155 | // code postal avec 2 espaces entre chaque chiffre: 2 \ 9 \ 0 \ 0 \ 0 | ||
156 | public function spacesInPostCode() | ||
157 | { | ||
158 | $this->data['code_postal_espaces'] = implode(' \ ', str_split($this->data['code_postal'])); | ||
159 | } | ||
160 | } | ||
161 | class EnveloppeVersoLatex extends Latex | ||
79 | {} | 162 | {} |
80 | 163 | ||
81 | 164 | ||
82 | 165 | ||
83 | abstract class ComptaLatex extends Latex | 166 | abstract class ComptaLatex extends Latex |
84 | { | 167 | { |
85 | public function __construct(string $quoi, string $annee, int $numeroMois = 0) | 168 | //~ public function __construct(string $quoi, string $annee, int $numeroMois = 0) |
86 | { | 169 | //~ { |
87 | nameTheFile($quoi, $annee, $numeroMois); | 170 | //~ nameTheFile($quoi, $annee, $numeroMois); |
88 | } | 171 | //~ } |
89 | 172 | ||
90 | // forme = Recettes-2022-06-Juin.tex ou Recettes-2022.tex | 173 | // forme = Recettes-2022-06-Juin.tex ou Recettes-2022.tex |
91 | // type de 'annee'? | 174 | // type de 'annee'? |
92 | protected function nameTheFile(string $quoi, string $annee, int $numeroMois = 0) | 175 | //~ protected function nameTheFile(string $quoi, string $annee, int $numeroMois = 0) |
93 | { | 176 | //~ { |
94 | $this->fileName = $quoi . '-' . $annee; | 177 | //~ $this->fileName = $quoi . '-' . $annee; |
95 | $mois = ['', 'Janvier', 'Février', 'Mars', 'Avril', 'Mai', 'Juin', 'Juillet', 'Août', 'Septembre', 'Octobre', 'Novembre', 'Décembre']; | 178 | //~ $mois = ['', 'Janvier', 'Février', 'Mars', 'Avril', 'Mai', 'Juin', 'Juillet', 'Août', 'Septembre', 'Octobre', 'Novembre', 'Décembre']; |
96 | if($numeroMois > 0 && $numeroMois <= 12) | 179 | //~ if($numeroMois > 0 && $numeroMois <= 12) |
97 | { | 180 | //~ { |
98 | $this->fileName .= '-' . $numeroMois . '-' . $mois[$numeroMois]; | 181 | //~ $this->fileName .= '-' . $numeroMois . '-' . $mois[$numeroMois]; |
99 | } | 182 | //~ } |
100 | $this->fileName .= '.tex'; | 183 | //~ $this->fileName .= '.tex'; |
101 | } | 184 | //~ } |
102 | } | 185 | } |
103 | 186 | ||
104 | class LivreRecettesLatex extends ComptaLatex | 187 | class LivreRecettesLatex extends ComptaLatex |