From 9d8133643773912d54fb0c7d86ef04e6acffa8c9 Mon Sep 17 00:00:00 2001 From: polo Date: Sat, 25 Feb 2023 02:27:22 +0100 Subject: =?UTF-8?q?lire=20tables,=20modifications=20BDD,=20cr=C3=A9ation?= =?UTF-8?q?=20documents=20et=20enveloppes=20latex,=20suppression=20de=20tr?= =?UTF-8?q?aits.php?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/functions.php | 82 +++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 71 insertions(+), 11 deletions(-) (limited to 'src/functions.php') diff --git a/src/functions.php b/src/functions.php index b8779e8..89bfbc9 100644 --- a/src/functions.php +++ b/src/functions.php @@ -1,7 +1,7 @@ getAll(); + + if($Presta == null) // recto d'une enveloppe + { + $latex_path .= 'enveloppes_recto/'; + $pdf_path .= 'enveloppes_recto/'; + $data['code_postal'] = implode(' \ ', str_split($data['code_postal'])); // code postal avec 2 espaces entre chaque chiffre: 2 \ 9 \ 0 \ 0 \ 0 + $latex = makeLatex($documentType, $data); // injection des variables + $file_name = $Client->getCodeClient() . '.tex'; + } + else // facture, devis, location + { + $data = array_merge($data, $Presta->getAll()); + $Date = new Dates($Presta->getDate()); // entrée = timestamp (doit être un "int"!!) + $year = $Date->getYear(); + + // créer un sous-dossier pour la nouvelle année + $latex_path .= $year . '/'; + $pdf_path .= $year . '/'; + + if($Details != null) + { + $data = array_merge($data, $Details->getAll()); + } + + $latex = makeLatex($documentType, $data, $Date); // injection des variables + $file_name = $Presta->getCodePresta() . '.tex'; + } + } + + // création des fichiers + makeFolder($latex_path); + makeFolder($pdf_path); + file_put_contents($latex_path. $file_name, $latex); // écriture du fichier latexToPdf($latex_path, $file_name, $pdf_path); } -function getLatexFromTemplate(string $template, $data) +function makeLatex(string $documentType, array $data, Dates $Date = null) { - // variables à injecter - $nom_client = "M. Duchmol"; + $date = ''; + if($Date != null) + { + $date = $Date->getDate(); + $date = preg_replace('#\D#', '/', $date); // date avec des slashs / parce que j'aime bien + } // on obtient la variable $latex avec ob_get_clean() - include('latex_templates/' . $template . '.php'); + // 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('latex_templates/' . $documentType . '.php'); // on retourne le buffer // normallement le code PHP inséré avec include est nettoyé en quittant la fonction @@ -76,7 +136,7 @@ function latexToPdf(string $latexPath, string $fileName, string $pdfPath) // compilation exec('pdflatex ' . $outputDir . $latexPath . $fileName); - + // nettoyage $basename = basename($fileName, '.tex'); unlink($pdfPath . $basename . '.aux'); -- cgit v1.2.3