summaryrefslogtreecommitdiff
path: root/src/functions.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/functions.php')
-rw-r--r--src/functions.php63
1 files changed, 21 insertions, 42 deletions
diff --git a/src/functions.php b/src/functions.php
index 0b075b5..1bbb40c 100644
--- a/src/functions.php
+++ b/src/functions.php
@@ -100,7 +100,9 @@ function rechercheClient(string $input, Clients $Client): array
100 return($result); 100 return($result);
101} 101}
102 102
103function makeLatexAndPdfDocument(Clients $Client = null, Prestations $Presta = null, $PrestaDetails = null) 103
104// remplacer par une classe Latex
105function makeLatexAndPdfDocuments(Clients $Client = null, Prestations $Presta = null, $PrestaDetails = null)
104{ 106{
105 $latex = ''; 107 $latex = '';
106 $year = ''; 108 $year = '';
@@ -111,7 +113,10 @@ function makeLatexAndPdfDocument(Clients $Client = null, Prestations $Presta = n
111 // verso d'une enveloppe 113 // verso d'une enveloppe
112 $latex = makeLatex('enveloppe_verso'); // pas de données transmises, elles sont dans la classe Config 114 $latex = makeLatex('enveloppe_verso'); // pas de données transmises, elles sont dans la classe Config
113 $file_name = 'enveloppe_verso.tex'; 115 $file_name = 'enveloppe_verso.tex';
114 makeFiles($latex_path, $pdf_path, $file_name, $latex); 116 makeFile($latex_path, $file_name, $latex);
117
118 latexToPdf($latex_path, $file_name, $pdf_path);
119
115 120
116 if($Client !== null) 121 if($Client !== null)
117 { 122 {
@@ -119,11 +124,16 @@ function makeLatexAndPdfDocument(Clients $Client = null, Prestations $Presta = n
119 124
120 // recto d'une enveloppe 125 // recto d'une enveloppe
121 $latex_recto_path = $latex_path . 'enveloppes_recto/'; 126 $latex_recto_path = $latex_path . 'enveloppes_recto/';
122 $pdf_verso_path = $pdf_path . 'enveloppes_recto/'; 127 $pdf_recto_path = $pdf_path . 'enveloppes_recto/';
123 $data['code_postal'] = implode(' \ ', str_split($data['code_postal'])); // code postal avec 2 espaces entre chaque chiffre: 2 \ 9 \ 0 \ 0 \ 0 128 $data['code_postal_espaces'] = implode(' \ ', str_split($data['code_postal'])); // code postal avec 2 espaces entre chaque chiffre: 2 \ 9 \ 0 \ 0 \ 0
129
124 $latex = makeLatex('enveloppe_recto', $data); // injection des variables 130 $latex = makeLatex('enveloppe_recto', $data); // injection des variables
125 $file_name = $Client->getCodeClient() . '.tex'; 131 $file_name = $Client->getCodeClient() . '.tex';
126 makeFiles($latex_recto_path, $pdf_verso_path, $file_name, $latex); 132 makeFolder($latex_recto_path);
133 makeFile($latex_recto_path, $file_name, $latex);
134
135 makeFolder($pdf_recto_path);
136 latexToPdf($latex_recto_path, $file_name, $pdf_recto_path);
127 137
128 // facture, devis, location 138 // facture, devis, location
129 if($Presta !== null && $PrestaDetails !== null) 139 if($Presta !== null && $PrestaDetails !== null)
@@ -138,9 +148,14 @@ function makeLatexAndPdfDocument(Clients $Client = null, Prestations $Presta = n
138 $latex_year_path = $latex_path . $year . '/'; // un sous-dossier par année 148 $latex_year_path = $latex_path . $year . '/'; // un sous-dossier par année
139 $pdf_year_path = $pdf_path . $year . '/'; 149 $pdf_year_path = $pdf_path . $year . '/';
140 $data = array_merge($data, $PrestaDetails->getAll()); 150 $data = array_merge($data, $PrestaDetails->getAll());
151
141 $latex = makeLatex($type, $data, $Date); // injection des variables 152 $latex = makeLatex($type, $data, $Date); // injection des variables
142 $file_name = $Presta->getCodePresta() . '.tex'; 153 $file_name = $Presta->getCodePresta() . '.tex';
143 makeFiles($latex_year_path, $pdf_year_path, $file_name, $latex); 154 makeFolder($latex_year_path);
155 makeFile($latex_year_path, $file_name, $latex);
156
157 makeFolder($pdf_year_path);
158 latexToPdf($latex_year_path, $file_name, $pdf_year_path);
144 } 159 }
145 elseif($type === 'cesu' || $type === 'non_vendue') 160 elseif($type === 'cesu' || $type === 'non_vendue')
146 {} // pas de document 161 {} // pas de document
@@ -153,7 +168,6 @@ function makeLatexAndPdfDocument(Clients $Client = null, Prestations $Presta = n
153 } 168 }
154} 169}
155 170
156
157function makeLatex(string $type, array $data = [], Dates $Date = null) 171function makeLatex(string $type, array $data = [], Dates $Date = null)
158{ 172{
159 $date = ''; 173 $date = '';
@@ -172,38 +186,3 @@ function makeLatex(string $type, array $data = [], Dates $Date = null)
172 // normallement le code PHP inséré avec include est nettoyé en quittant la fonction 186 // normallement le code PHP inséré avec include est nettoyé en quittant la fonction
173 return($latex); 187 return($latex);
174} 188}
175
176function makeFiles($latex_path, $pdf_path, $file_name, $latex)
177{
178 makeFolder($latex_path);
179 makeFolder($pdf_path);
180 file_put_contents($latex_path. $file_name, $latex); // écriture du fichier
181 latexToPdf($latex_path, $file_name, $pdf_path);
182}
183
184function makeFolder(string $path)
185{
186 if(!file_exists($path))
187 {
188 mkdir($path);
189 chmod($path, 0755); // droits en octal
190 }
191}
192
193// compilation à partir d'un fichier .tex
194function latexToPdf(string $latexPath, string $fileName, string $pdfPath)
195{
196 $outputDir = '';
197 if($pdfPath !== '')
198 {
199 $outputDir = '-output-directory=' . $pdfPath . ' ';
200 }
201
202 // compilation
203 exec('pdflatex ' . $outputDir . $latexPath . $fileName);
204
205 // nettoyage
206 $basename = basename($fileName, '.tex');
207 unlink($pdfPath . $basename . '.aux');
208 unlink($pdfPath . $basename . '.log');
209}